Skip to content

Commit 4c35e6a

Browse files
author
julianfoo
committed
Fixed Faraday error mentioned in issue #9 by bumping Faraday version to v1.9.3. Moved dependencies to gemspec and added Gemfile.lock to gitignore. Fixed tests for post and delete tweets
1 parent 0855cb4 commit 4c35e6a

8 files changed

Lines changed: 51 additions & 38 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
/tmp/
99
.env
1010
!.env.example
11+
Gemfile.lock

Gemfile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@ source "https://rubygems.org"
33
# Specify your gem's dependencies in tweetkit.gemspec
44
gemspec
55

6-
gem 'faraday'
7-
gem 'faraday_middleware'
8-
gem "rake", "~> 12.0"
9-
gem 'simple_oauth', "~> 0.3.0"
6+
gem 'rake'
107

118
group :development do
129
gem 'yard'
1310
end
1411

1512
group :test, :development do
1613
gem 'dotenv'
17-
gem 'pry', '~> 0.13.1'
14+
gem 'pry'
1815
gem 'rspec'
1916
end

Gemfile.lock

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,75 @@
11
PATH
22
remote: .
33
specs:
4-
tweetkit (0.1.4)
5-
faraday (>= 0.9)
6-
faraday_middleware (~> 1.0.0)
4+
tweetkit (0.2.0)
5+
faraday (~> 1.9.3)
6+
faraday_middleware (~> 1.2.0)
77
simple_oauth (~> 0.3.0)
88

99
GEM
1010
remote: https://rubygems.org/
1111
specs:
1212
coderay (1.1.3)
13-
diff-lcs (1.4.4)
13+
diff-lcs (1.5.0)
1414
dotenv (2.7.6)
15-
faraday (1.5.1)
15+
faraday (1.9.3)
1616
faraday-em_http (~> 1.0)
1717
faraday-em_synchrony (~> 1.0)
1818
faraday-excon (~> 1.1)
19-
faraday-httpclient (~> 1.0.1)
19+
faraday-httpclient (~> 1.0)
20+
faraday-multipart (~> 1.0)
2021
faraday-net_http (~> 1.0)
21-
faraday-net_http_persistent (~> 1.1)
22+
faraday-net_http_persistent (~> 1.0)
2223
faraday-patron (~> 1.0)
23-
multipart-post (>= 1.2, < 3)
24+
faraday-rack (~> 1.0)
25+
faraday-retry (~> 1.0)
2426
ruby2_keywords (>= 0.0.4)
2527
faraday-em_http (1.0.0)
2628
faraday-em_synchrony (1.0.0)
2729
faraday-excon (1.1.0)
2830
faraday-httpclient (1.0.1)
31+
faraday-multipart (1.0.3)
32+
multipart-post (>= 1.2, < 3)
2933
faraday-net_http (1.0.1)
30-
faraday-net_http_persistent (1.1.0)
34+
faraday-net_http_persistent (1.2.0)
3135
faraday-patron (1.0.0)
32-
faraday_middleware (1.0.0)
36+
faraday-rack (1.0.0)
37+
faraday-retry (1.0.3)
38+
faraday_middleware (1.2.0)
3339
faraday (~> 1.0)
3440
method_source (1.0.0)
3541
multipart-post (2.1.1)
36-
pry (0.13.1)
42+
pry (0.14.1)
3743
coderay (~> 1.1)
3844
method_source (~> 1.0)
39-
rake (12.3.3)
45+
rake (13.0.6)
4046
rspec (3.10.0)
4147
rspec-core (~> 3.10.0)
4248
rspec-expectations (~> 3.10.0)
4349
rspec-mocks (~> 3.10.0)
4450
rspec-core (3.10.1)
4551
rspec-support (~> 3.10.0)
46-
rspec-expectations (3.10.1)
52+
rspec-expectations (3.10.2)
4753
diff-lcs (>= 1.2.0, < 2.0)
4854
rspec-support (~> 3.10.0)
49-
rspec-mocks (3.10.1)
55+
rspec-mocks (3.10.2)
5056
diff-lcs (>= 1.2.0, < 2.0)
5157
rspec-support (~> 3.10.0)
52-
rspec-support (3.10.1)
53-
ruby2_keywords (0.0.4)
58+
rspec-support (3.10.3)
59+
ruby2_keywords (0.0.5)
5460
simple_oauth (0.3.1)
55-
yard (0.9.26)
61+
webrick (1.7.0)
62+
yard (0.9.27)
63+
webrick (~> 1.7.0)
5664

5765
PLATFORMS
5866
ruby
5967

6068
DEPENDENCIES
6169
dotenv
62-
faraday
63-
faraday_middleware
64-
pry (~> 0.13.1)
65-
rake (~> 12.0)
70+
pry
71+
rake
6672
rspec
67-
simple_oauth (~> 0.3.0)
6873
tweetkit!
6974
yard
7075

lib/tweetkit/client/tweets.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def search(query = '', type: :tweet, **options, &block)
2323
end
2424

2525
def post_tweet(**options)
26-
post "tweets", **options
26+
post 'tweets', **options
2727
end
2828

2929
def delete_tweet(id)

lib/tweetkit/connection.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,20 @@ def request(method, endpoint, data, **options)
4242
else
4343
raise NotImplementedError, 'No known authentication types were configured'
4444
end
45+
46+
conn.request :json
47+
conn.response :json
4548
end
4649

4750
response = case method
4851
when :get
4952
connection.get(url, data)
5053
when :post
51-
connection.post(url, data.to_json, 'Content-Type' => 'application/json')
54+
connection.post(url, data, 'Content-Type' => 'application/json')
5255
when :put
53-
connection.put(url, data.to_json, 'Content-Type' => 'application/json')
56+
connection.put(url, data, 'Content-Type' => 'application/json')
5457
when :delete
55-
connection.delete(url, data.to_json, 'Content-Type' => 'application/json')
58+
connection.delete(url, data, 'Content-Type' => 'application/json')
5659
end
5760

5861
Tweetkit::Response::Tweets.new response, connection: connection, twitter_request: { previous_url: @previous_url, previous_query: @previous_query }

lib/tweetkit/response.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ def parse!(response, **options)
2525
end
2626

2727
def parse_response(response)
28-
@original_response = response.body
29-
@response = JSON.parse(@original_response)
28+
@response = response.body
3029
end
3130

3231
def extract_and_save_tweets

spec/client/tweets_spec.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,27 @@
4444

4545
describe '.post_tweet' do
4646
it 'posts text' do
47-
response = client.post_tweet(text: 'Hello world')
47+
response = client.post_tweet(text: random_test_string)
4848
expect(response.tweet.text).not_to be_empty
4949
end
5050
end
5151

5252
describe '.delete_tweet' do
5353
it 'deletes a tweet' do
54-
create_response = client.post_tweet(text: 'Hello world')
55-
tweet_id = create_response.tweet.id.to_i
54+
response = client.post_tweet(text: random_test_string)
55+
tweet_id = response.tweet.id.to_i
5656
delete_response = client.delete_tweet(tweet_id)
5757

5858
expect(delete_response.response.dig('data', 'deleted')).to be(true)
5959
end
6060
end
6161
end
62+
63+
private
64+
65+
def random_test_string
66+
length = 8
67+
random_string = rand(36 ** length).to_s(36)
68+
"Hi this is a random string to test the tweetkit gem: #{random_string}"
69+
end
6270
end

tweetkit.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
2424
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
2525
spec.require_paths = ["lib"]
2626

27-
spec.add_dependency 'faraday', '>= 0.9'
28-
spec.add_dependency 'faraday_middleware', '~> 1.0.0'
27+
spec.add_dependency 'faraday', '~> 1.9.3'
28+
spec.add_dependency 'faraday_middleware', '~> 1.2.0'
2929
spec.add_dependency 'simple_oauth', '~> 0.3.0'
3030
end

0 commit comments

Comments
 (0)