Skip to content

Commit 2ae2309

Browse files
author
julianfoo
committed
Added feature to config client via code block. WIP: Clean up authentication logic and query processing logic
1 parent 5206a69 commit 2ae2309

4 files changed

Lines changed: 6 additions & 16 deletions

File tree

lib/tweetkit/client.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@ class Client
1010
attr_accessor :access_token, :access_token_secret, :bearer_token, :consumer_key, :consumer_token, :email, :password
1111

1212
def initialize(options = {})
13-
Tweetkit::Configurable.keys.each do |key|
14-
if options.key?(key)
15-
value = options[key]
16-
else
17-
Tweetkit.instance_variable_get(:"@#{key}")
18-
end
13+
options.each do |key, value|
1914
instance_variable_set(:"@#{key}", value)
2015
end
16+
yield self if block_given?
2117
end
2218
end
2319
end

lib/tweetkit/connection.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ module Connection
88
include Tweetkit::Auth
99

1010
CONVENIENCE_HEADERS = Set.new([:accept, :content_type])
11+
BASE_URL = 'https://api.twitter.com/2/'
1112

1213
def get(url, **options)
1314
request :get, url, parse_query_and_convenience_headers(options)
1415
end
1516

16-
def request(method, path, data, options = {})
17+
def request(method, endpoint, data, **options)
1718
if data.is_a?(Hash)
1819
options[:headers] = data.delete(:headers) || {}
1920
if accept = data.delete(:accept)
@@ -23,7 +24,7 @@ def request(method, path, data, options = {})
2324

2425
headers = options[:headers].merge(oauth_headers)
2526

26-
url = URI.parse(Tweetkit::Default.endpoint + path)
27+
url = URI.parse("#{BASE_URL}#{endpoint}")
2728

2829
if method == :get
2930
response = Faraday.get(url, data, headers)

lib/tweetkit/default.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@
22

33
module Tweetkit
44
module Default
5-
ENDPOINT = 'https://api.twitter.com/2/'
6-
75
class << self
86
def options
97
Hash[Tweetkit::Configurable.keys.map { |key| [key, send(key)] }]
108
end
11-
12-
def endpoint
13-
ENDPOINT
14-
end
159
end
1610
end
1711
end

lib/tweetkit/response.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
require 'json'
2-
require 'pry'
32

43
module Tweetkit
54
class Response
6-
attr_accessor :body, :tweets, :meta, :expansions
5+
attr_accessor :tweets, :meta, :expansions
76

87
def initialize(response)
98
@original_response = response.body

0 commit comments

Comments
 (0)