twttr 0.0.4 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/twttr/client/endpoint/v2/users/follows.rb +34 -1
- data/lib/twttr/client/endpoint/v2/users.rb +14 -0
- data/lib/twttr/model/user.rb +14 -0
- 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: a0b322657f3a30ce0b0d95982d37f869bac57f5a388cd72bd5ec0674ffd280ec
|
4
|
+
data.tar.gz: f5a7ceef4eed89d1f62200c27e1a793474721c9dffc2abf074fb04372917541a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d93cfe971f58080b87a2213c2a46249b931e89e192d9115287a61e78decc48893449f9c8803557b07abffdd457f09b71c96c68040a5de95cc4ef6fc06c81597
|
7
|
+
data.tar.gz: 940d45503a781eaf9efdb4ef246b23c386219ca0bdfc69b0d9f0e36cb6cec444f868d24e822307ba8e15c73a8a779cba6a9ea44bc5288e7f772f8d1d5ba8162a
|
@@ -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
|
#
|
@@ -29,7 +62,7 @@ module Twttr
|
|
29
62
|
pagination_token: pagination_token
|
30
63
|
}.compact)
|
31
64
|
|
32
|
-
return []
|
65
|
+
return [] if response['meta']['result_count'].zero?
|
33
66
|
|
34
67
|
users = response['data'].map { |v| Model::User.new(v, self) }
|
35
68
|
|
@@ -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
|
data/lib/twttr/model/user.rb
CHANGED
@@ -15,6 +15,20 @@ module Twttr
|
|
15
15
|
@client = client
|
16
16
|
end
|
17
17
|
|
18
|
+
# GET /2/users/:id/followers
|
19
|
+
# https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/get-users-id-followers
|
20
|
+
#
|
21
|
+
# Returns paginated list of users following user_id.
|
22
|
+
#
|
23
|
+
# @param max_results [Integer] Max number of results per peage.
|
24
|
+
# @param pagination_token [String] Initial page pagination token.
|
25
|
+
# @yield [Array<Twttr::Model::User>] User followers page.
|
26
|
+
# @yield [String,NilClass] Pagination token.
|
27
|
+
# @return [Array<Twttr::Model::User>] Follower Users.
|
28
|
+
def followers(max_results: nil, pagination_token: nil, &block)
|
29
|
+
client.followers(id, max_results: max_results, pagination_token: pagination_token, &block)
|
30
|
+
end
|
31
|
+
|
18
32
|
# Forwards to Follows#following setting user_id to current user's id.
|
19
33
|
#
|
20
34
|
# GET /2/users/:id/following
|
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.
|
4
|
+
version: 0.0.7
|
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-
|
11
|
+
date: 2022-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth
|