twitter_labs_api 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f31f636cbf46ed53a3d35e61c3376b9f47184220db4b23277f4f7c504f4be251
4
- data.tar.gz: be3ae4940e263fe6bf33661686072c62c807236f9c2814488661efc8da8799a8
3
+ metadata.gz: ec82ff15b22f8a14b4dc1ad25721f80f2b24b3765015a57153b23cd08682eee8
4
+ data.tar.gz: d4b233244f69b5f8c32de63f80b5ad3f1e78c126b4cf7d6cd45331f7dcab8eb4
5
5
  SHA512:
6
- metadata.gz: 6062719f695c9979a327d94396795df7365559e92598fe08e727d2e87dc2e4a987a4f6bf689954cd2efc2b6c20f0ad5ae3003f651e0e45fc0caea12f46a57688
7
- data.tar.gz: 7c1616a9f97582a2dda4061f2a0c540b7967d4d525c0bd344141643723450d91a4208357d919b8acf4d0d89a17d2046e0f6fba75a5c3eb6e9a10d9f6caa4df31
6
+ metadata.gz: b3b8f6f74db6c566164f33694844f8b06a49d50cd4a2d6707cb3896ef7243eddd771cfef300b9028599f5c817283829ec3731241296de203edb32a75f89ba9ca
7
+ data.tar.gz: e039b095549909701d0a8fd9dfff4e622c398de4111718acbf0327e247d8e3cb449d45689b36cc7e939ece61c54b490e6b85664c473fa3ba6c665fbcfee93590
@@ -1,3 +1,8 @@
1
+ # 0.5.1 - 28 July 2020
2
+
3
+ - Add `User-Agent` request header
4
+ - Add `hide_reply`
5
+
1
6
  # 0.5.0 - 27 July 2020
2
7
 
3
8
  - Refactor structure to prepare for adding additional API endpoints
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- twitter_labs_api (0.5.0)
4
+ twitter_labs_api (0.5.1)
5
5
  activesupport (~> 6.0)
6
6
  httplog (~> 1.4)
7
7
 
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
- One easy way to get a bearer token is to use [this method](https://www.rubydoc.info/gems/twitter/Twitter/REST/Client#bearer_token%3F-instance_method) from https://github.com/sferik/twitter.
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
- Since this project is initially driven by my own usage of the API, I will focus on implementing and refining the Tweets, Users, and Metrics endpoints. If this repo gets enough interest, I might implement the other endpoints and create a proper `.gemspec`. And of course, contributions are welcome :)
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 = Net::HTTP::Get.new(uri)
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
@@ -1,3 +1,3 @@
1
1
  module TwitterLabsAPI
2
- VERSION = '0.5.0'.freeze
2
+ VERSION = '0.5.1'.freeze
3
3
  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.0
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-27 00:00:00.000000000 Z
11
+ date: 2020-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport