twttr 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f243e0ac613090cfeabaeb49b72f9fa3cca1b210bf8578313d23ce264f7fb76e
4
- data.tar.gz: 320ed5bcce042083e80be627237eab12459d3694a86b3033b576b03f65f6eca2
3
+ metadata.gz: ce5304b9106f2f665c6787d7e3ee22f83076712f8ee96b33f6b7615a85759dae
4
+ data.tar.gz: bf914ca056645501d2f012900f76286cb9f0a18baa347618d3ef297f04c2c01e
5
5
  SHA512:
6
- metadata.gz: 36181b93842dd22bdf49759f92e970a63b59121e3a025d229820fe75e0ce101d6eeafdb87459c063d3826b86d23e5908601d2ffb1f0e2a7e83da4261c4182cce
7
- data.tar.gz: 8e44f6b807d3abe417b78a563bb341ba3297a193701846a06885ef6cf8f590bb16720d84647c9b723b51bb91d7c7ac2c519054bd042b59a8789ed6e1293eabbd
6
+ metadata.gz: 54d2b7ed3ab4bebd4a82fa58965456eee9c5c8896ca8ef29054578f81ce6500dc1906fa8361c85c1300fdf6e2e6631d95f175f17f2ebee60dd5eaab2ac1fba18
7
+ data.tar.gz: 948a69e7cab9210b857526594131641565e44beeb50932a8967fef0a3c6ca794714ee9dd1f527f4ab277ea6caf3b27a539de817db17fc28fbc3487d45126193a
@@ -8,8 +8,41 @@ module Twttr
8
8
  # Twitter API V2 User Follow related endpoints
9
9
  # https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference
10
10
  module Follows
11
+ FOLLOWERS_PATH = "#{Users::USER_PATH}/followers"
11
12
  FOLLOWING_PATH = "#{Users::USER_PATH}/following"
12
13
 
14
+ # GET /2/users/:id/followers
15
+ # https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/get-users-id-followers
16
+ #
17
+ # Returns paginated list of users following user_id.
18
+ #
19
+ # @param user_id [String] The user ID whose followers you would like to retrieve.
20
+ # @param max_results [Integer] Max number of results per peage.
21
+ # @param pagination_token [String] Initial page pagination token.
22
+ # @yield [Array<Twttr::Model::User>] User followers page.
23
+ # @yield [String,NilClass] Pagination token.
24
+ # @return [Array<Twttr::Model::User>] Follower Users.
25
+ def followers(user_id, max_results: nil, pagination_token: nil, &block) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
26
+ response = get(FOLLOWERS_PATH, params: { user_id: user_id },
27
+ query_params: {
28
+ 'user.fields': config.user_fields,
29
+ max_results: max_results,
30
+ pagination_token: pagination_token
31
+ }.compact)
32
+
33
+ return [] if response['meta']['result_count'].zero?
34
+
35
+ users = response['data'].map { |v| Model::User.new(v, self) }
36
+
37
+ pagination_token = response['meta']['pagination_token']
38
+
39
+ yield users, pagination_token if block_given?
40
+
41
+ return users if pagination_token.nil?
42
+
43
+ users + followers(user_id, pagination_token: pagination_token, &block)
44
+ end
45
+
13
46
  # GET /2/users/:id/following
14
47
  # https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/get-users-id-following
15
48
  #
@@ -9,6 +9,7 @@ module Twttr
9
9
  module Users
10
10
  ME_PATH = "#{V2::V2_PATH}/users/me"
11
11
  USERS_PATH = "#{V2::V2_PATH}/users"
12
+ USERS_BY_PATH = "#{V2::V2_PATH}/users/by"
12
13
  USER_BY_USERNAME_PATH = "#{V2::V2_PATH}/users/by/username/%<username>s"
13
14
  USER_PATH = "#{V2::V2_PATH}/users/%<user_id>s"
14
15
 
@@ -73,6 +74,19 @@ module Twttr
73
74
  query_params: { ids: user_ids.join(','), 'user.fields': config.user_fields })
74
75
  response['data'].map { |v| Model::User.new(v, self) }
75
76
  end
77
+
78
+ # GET /2/users/by
79
+ # https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-by
80
+ #
81
+ # Returns target users by username
82
+ #
83
+ # @param usernames [Array<String>] Traget usernames.
84
+ # @return [Array<Twttr::Model::User>] Target users.
85
+ def users_by(usernames)
86
+ response = get(USERS_BY_PATH,
87
+ query_params: { usernames: usernames.join(','), 'user.fields': config.user_fields })
88
+ response['data'].map { |v| Model::User.new(v, self) }
89
+ end
76
90
  end
77
91
  end
78
92
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twttr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Decurnex
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-17 00:00:00.000000000 Z
11
+ date: 2022-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth