1+ require 'pry'
12require 'faraday'
23require 'tweetkit/auth'
34require 'tweetkit/default'
@@ -7,23 +8,14 @@ module Tweetkit
78 module Connection
89 include Tweetkit ::Auth
910
10- CONVENIENCE_HEADERS = Set . new ( [ :accept , :content_type ] )
1111 BASE_URL = 'https://api.twitter.com/2/'
1212
13- def get ( url , **options )
14- request :get , url , parse_query_and_convenience_headers ( options )
13+ def get ( endpoint , **options )
14+ request :get , endpoint , parse_query_and_convenience_headers ( options )
1515 end
1616
1717 def request ( method , endpoint , data , **options )
18- if data . is_a? ( Hash )
19- options [ :headers ] = data . delete ( :headers ) || { }
20- if accept = data . delete ( :accept )
21- options [ :headers ] [ :accept ] = accept
22- end
23- end
24-
25- headers = options [ :headers ] . merge ( oauth_headers )
26-
18+ headers = data . delete ( :headers )
2719 url = URI . parse ( "#{ BASE_URL } #{ endpoint } " )
2820
2921 if method == :get
@@ -36,8 +28,9 @@ def request(method, endpoint, data, **options)
3628 raise e
3729 end
3830
39- def oauth_headers
40- if bearer_auth?
31+ def auth_headers ( type = 'bearer' )
32+ case type
33+ when 'bearer'
4134 { 'Authorization' : "Bearer #{ @bearer_token } " }
4235 end
4336 end
@@ -83,19 +76,12 @@ def build_expansions(options)
8376
8477 def parse_query_and_convenience_headers ( options )
8578 options = options . dup
86- headers = options . delete ( :headers ) { Hash . new }
87- CONVENIENCE_HEADERS . each do |h |
88- if header = options . delete ( h )
89- headers [ h ] = header
90- end
91- end
79+ options [ :headers ] = auth_headers
9280 fields = build_fields ( options )
93- opts = options . merge! ( fields )
81+ options . merge! ( fields )
9482 expansions = build_expansions ( options )
95- opts . merge! ( expansions )
96- opts [ :headers ] = headers unless headers . empty?
97-
98- opts
83+ options . merge! ( expansions )
84+ options
9985 end
10086 end
10187end
0 commit comments