twitter_labs_api 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +15 -9
- data/README.md +15 -0
- data/lib/twitter_labs_api.rb +17 -3
- data/lib/twitter_labs_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 471a4a8a8b2f248f11d0337240451d5b5bc2fdff5601370335f0ab080038cb0a
|
4
|
+
data.tar.gz: 25f2097f036e2ba1b9431f5e4a01db6a062ea7507f05b648c85b9d3514c5d083
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df432778d2baef5046f1c0d36ddd1b96f17e58414063ce3e76f15fdb9d7f78abc82327c598bc2a0e67fc3e205a430c5e5f851e1afb16691176a5722e506fe226
|
7
|
+
data.tar.gz: bcad0b98629f789f004974fdc505929b7a7f42af362490a8d9bd5e3ade4389ae770e25cf1550cd46af308f3336b2c4f3018a71580e41e9f92e48d42d1aea5fca
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,31 +1,36 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
twitter_labs_api (0.
|
4
|
+
twitter_labs_api (0.4.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
activesupport (6.0.
|
9
|
+
activesupport (6.0.3.2)
|
10
10
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
11
|
i18n (>= 0.7, < 2)
|
12
12
|
minitest (~> 5.1)
|
13
13
|
tzinfo (~> 1.1)
|
14
|
-
zeitwerk (~> 2.
|
14
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
15
|
+
coderay (1.1.3)
|
15
16
|
concurrent-ruby (1.1.6)
|
16
17
|
httplog (1.3.2)
|
17
18
|
rack (>= 1.0)
|
18
19
|
rainbow (>= 2.0.0)
|
19
|
-
i18n (1.
|
20
|
+
i18n (1.8.5)
|
20
21
|
concurrent-ruby (~> 1.0)
|
21
|
-
|
22
|
-
|
22
|
+
method_source (1.0.0)
|
23
|
+
minitest (5.14.1)
|
24
|
+
pry (0.13.1)
|
25
|
+
coderay (~> 1.1)
|
26
|
+
method_source (~> 1.0)
|
27
|
+
rack (2.2.3)
|
23
28
|
rainbow (3.0.0)
|
24
29
|
rake (13.0.1)
|
25
30
|
thread_safe (0.3.6)
|
26
|
-
tzinfo (1.2.
|
31
|
+
tzinfo (1.2.7)
|
27
32
|
thread_safe (~> 0.1)
|
28
|
-
zeitwerk (2.
|
33
|
+
zeitwerk (2.4.0)
|
29
34
|
|
30
35
|
PLATFORMS
|
31
36
|
ruby
|
@@ -34,8 +39,9 @@ DEPENDENCIES
|
|
34
39
|
activesupport
|
35
40
|
bundler (~> 2.0)
|
36
41
|
httplog
|
42
|
+
pry
|
37
43
|
rake (~> 13.0)
|
38
44
|
twitter_labs_api!
|
39
45
|
|
40
46
|
BUNDLED WITH
|
41
|
-
2.
|
47
|
+
2.1.4
|
data/README.md
CHANGED
@@ -40,6 +40,21 @@ api.get_tweet(id: '1235508591232090112', tweet_fields: my_fields)
|
|
40
40
|
>> {"author_id"=>"229708614", "created_at"=>"2020-03-05T10:12:57.000Z", "id"=>"1235508591232090112", "text"=>"Hot take: coronavirus will not boost remote work in the long run because spur-of-the-moment work-from-home for in-person companies is likely to be a shitshow."}
|
41
41
|
```
|
42
42
|
|
43
|
+
#### API Errors
|
44
|
+
|
45
|
+
Sometimes the API will respond with an error, for example `429 Too Many Requests`. The gem will throw an error with the `Net::HTTP` response as an attribute for proper exception-handling by the consuming app:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
def my_twitter_request
|
49
|
+
api.get_tweet(id: '1235508591232090112', tweet_fields: my_fields)
|
50
|
+
|
51
|
+
rescue TwitterLabsAPI::APIError => e
|
52
|
+
puts e.msg # 429 Too Many Requests
|
53
|
+
puts e.response # <Net::HTTPTooManyRequests 429 Too Many Requests readbody=true>
|
54
|
+
# do something with the Net::HTTP response...
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
43
58
|
### Status
|
44
59
|
Currently, the following endpoints are implemented:
|
45
60
|
|
data/lib/twitter_labs_api.rb
CHANGED
@@ -10,7 +10,17 @@ DEFAULT_USER_FIELDS = %w[name username].freeze
|
|
10
10
|
class TwitterLabsAPI
|
11
11
|
attr_accessor :bearer_token, :debug, :api_response, :parsed_response
|
12
12
|
|
13
|
-
class
|
13
|
+
class APIError < StandardError
|
14
|
+
DEFAULT_MESSAGE = 'Twitter Labs API error, check the response attribute'.freeze
|
15
|
+
|
16
|
+
attr_reader :response
|
17
|
+
|
18
|
+
def initialize(msg = DEFAULT_MESSAGE, response = nil)
|
19
|
+
@response = response
|
20
|
+
|
21
|
+
super(msg)
|
22
|
+
end
|
23
|
+
end
|
14
24
|
|
15
25
|
def initialize(bearer_token:, debug: false)
|
16
26
|
@bearer_token = bearer_token
|
@@ -77,7 +87,7 @@ class TwitterLabsAPI
|
|
77
87
|
http.request(request)
|
78
88
|
end
|
79
89
|
|
80
|
-
|
90
|
+
raise_http_error unless api_response.is_a?(Net::HTTPSuccess)
|
81
91
|
|
82
92
|
self.parsed_response = JSON.parse(api_response.body)
|
83
93
|
|
@@ -98,9 +108,13 @@ class TwitterLabsAPI
|
|
98
108
|
parsed_response['data'].map(&:with_indifferent_access)
|
99
109
|
end
|
100
110
|
|
111
|
+
def raise_http_error
|
112
|
+
raise(APIError.new("#{api_response.code} #{api_response.msg}", api_response))
|
113
|
+
end
|
114
|
+
|
101
115
|
def handle_api_error
|
102
116
|
error = parsed_response['errors'].first
|
103
117
|
|
104
|
-
raise
|
118
|
+
raise APIError.new("#{error['title']}: #{error['detail']} #{error['type']}", api_response)
|
105
119
|
end
|
106
120
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter_labs_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tomholford
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|