twitter_labs_api 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +6 -3
- data/lib/twitter_labs_api/client.rb +14 -4
- data/lib/twitter_labs_api/resources/tweet.rb +10 -0
- 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: ec82ff15b22f8a14b4dc1ad25721f80f2b24b3765015a57153b23cd08682eee8
|
4
|
+
data.tar.gz: d4b233244f69b5f8c32de63f80b5ad3f1e78c126b4cf7d6cd45331f7dcab8eb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3b8f6f74db6c566164f33694844f8b06a49d50cd4a2d6707cb3896ef7243eddd771cfef300b9028599f5c817283829ec3731241296de203edb32a75f89ba9ca
|
7
|
+
data.tar.gz: e039b095549909701d0a8fd9dfff4e622c398de4111718acbf0327e247d8e3cb449d45689b36cc7e939ece61c54b490e6b85664c473fa3ba6c665fbcfee93590
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -5,9 +5,9 @@ A basic implementation of a Twitter Labs API client as a handy Ruby [gem](https:
|
|
5
5
|
## Usage
|
6
6
|
|
7
7
|
### Prerequisite
|
8
|
-
All one needs is a Twitter [bearer token](https://developer.twitter.com/en/docs/basics/authentication/oauth-2-0/bearer-tokens) to get started.
|
8
|
+
All one needs is a Twitter [bearer token](https://developer.twitter.com/en/docs/basics/authentication/oauth-2-0/bearer-tokens) to get started. The bearer token is available on the 'Tokens and Keys' page within your app's dashboard on the [Twitter for Developers](https://developer.twitter.com/) site.
|
9
9
|
|
10
|
-
|
10
|
+
Alternatively, one can get a bearer token using [this method](https://www.rubydoc.info/gems/twitter/Twitter/REST/Client#bearer_token%3F-instance_method) from https://github.com/sferik/twitter.
|
11
11
|
|
12
12
|
### Setup
|
13
13
|
|
@@ -62,6 +62,7 @@ Currently, the following endpoints are implemented:
|
|
62
62
|
|
63
63
|
- `TwitterLabsAPI#get_tweet` ([docs](https://developer.twitter.com/en/docs/labs/tweets-and-users/api-reference/get-tweets-id)) - Retrieve a single Tweet object with an `id`
|
64
64
|
- `TwitterLabsAPI#get_tweets` ([docs](https://developer.twitter.com/en/docs/labs/tweets-and-users/api-reference/get-tweets)) - Retrieve multiple Tweets with a collection of `ids`
|
65
|
+
- `TwitterLabsAPI#hide_reply` ([docs](https://developer.twitter.com/en/docs/labs/hide-replies/api-reference/put-hidden)) - Hide a reply by referencing it's `id`; must be in a conversation belonging to the authenticating user
|
65
66
|
|
66
67
|
#### Users
|
67
68
|
|
@@ -71,7 +72,9 @@ Currently, the following endpoints are implemented:
|
|
71
72
|
|
72
73
|
## Roadmap
|
73
74
|
|
74
|
-
|
75
|
+
Currently focused on implementing support for all v2 endpoints; if there is enough interest, I will add v1 endpoint support as well.
|
76
|
+
|
77
|
+
And of course, contributions are welcome :)
|
75
78
|
|
76
79
|
## Dependencies
|
77
80
|
|
@@ -17,13 +17,14 @@ module TwitterLabsAPI
|
|
17
17
|
|
18
18
|
private
|
19
19
|
|
20
|
-
def make_request(url:, params: {}, is_collection: false)
|
20
|
+
def make_request(url:, params: {}, is_collection: false, method: :get)
|
21
21
|
uri = URI.parse(url)
|
22
22
|
uri.query = URI.encode_www_form(params)
|
23
|
-
request =
|
23
|
+
request = http_adapter(method).new(uri)
|
24
24
|
request['Authorization'] = "Bearer #{bearer_token}"
|
25
|
+
request['User-Agent'] = "twitter_labs_api gem #{TwitterLabsAPI::VERSION}"
|
25
26
|
req_options = { use_ssl: uri.scheme == 'https' }
|
26
|
-
|
27
|
+
|
27
28
|
self.api_response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
28
29
|
http.request(request)
|
29
30
|
end
|
@@ -36,7 +37,16 @@ module TwitterLabsAPI
|
|
36
37
|
|
37
38
|
is_collection ? handle_collection : handle_single
|
38
39
|
end
|
39
|
-
|
40
|
+
|
41
|
+
def http_adapter(method)
|
42
|
+
case method
|
43
|
+
when :put
|
44
|
+
Net::HTTP::Put
|
45
|
+
else
|
46
|
+
Net::HTTP::Get
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
40
50
|
def error_response?
|
41
51
|
parsed_response.key?('errors')
|
42
52
|
end
|
@@ -5,6 +5,7 @@ module TwitterLabsAPI
|
|
5
5
|
|
6
6
|
# @param [String] :id the ID of the requested Tweet
|
7
7
|
# @param [Array<String>] :tweet_fields (["id", "author_id", "created_at", "lang", "public_metrics"]) the list of fields to retrieve for the given tweet
|
8
|
+
# @return Hash an object with requested tweet fields
|
8
9
|
def get_tweet(id:, tweet_fields: DEFAULT_TWEET_FIELDS)
|
9
10
|
url = "https://api.twitter.com/labs/2/tweets/#{id}"
|
10
11
|
params = {
|
@@ -16,6 +17,7 @@ module TwitterLabsAPI
|
|
16
17
|
|
17
18
|
# @param [Array<String>] :ids the collection of requested Tweet IDs
|
18
19
|
# @param [Array<String>] :tweet_fields (["id", "author_id", "created_at", "lang", "public_metrics"]) the list of fields to retrieve for the given tweet
|
20
|
+
# @return [Array<Hash>] of tweet objects with the requested tweet fields
|
19
21
|
def get_tweets(ids:, tweet_fields: DEFAULT_TWEET_FIELDS)
|
20
22
|
url = 'https://api.twitter.com/labs/2/tweets'
|
21
23
|
params = {
|
@@ -25,6 +27,14 @@ module TwitterLabsAPI
|
|
25
27
|
|
26
28
|
make_request(url: url, params: params, is_collection: true)
|
27
29
|
end
|
30
|
+
|
31
|
+
# @param [String] :id the ID of the requested Tweet; must belong to a conversation by the authenticated user
|
32
|
+
# @return boolean indicating the hidden status of the requested tweet
|
33
|
+
def hide_reply(id:)
|
34
|
+
url = "https://api.twitter.com/labs/2/tweets/#{id}/hidden"
|
35
|
+
|
36
|
+
make_request(url: url, method: :put)[:hidden]
|
37
|
+
end
|
28
38
|
end
|
29
39
|
end
|
30
40
|
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.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tomholford
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|