twitter 8.1.0 → 8.3.0
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 +4 -4
- data/LICENSE.md +1 -1
- data/README.md +173 -11
- data/lib/twitter/arguments.rb +14 -1
- data/lib/twitter/base.rb +72 -11
- data/lib/twitter/basic_user.rb +7 -1
- data/lib/twitter/client.rb +94 -3
- data/lib/twitter/creatable.rb +11 -2
- data/lib/twitter/cursor.rb +58 -11
- data/lib/twitter/direct_message.rb +32 -4
- data/lib/twitter/direct_message_event.rb +34 -10
- data/lib/twitter/direct_messages/welcome_message.rb +22 -1
- data/lib/twitter/direct_messages/welcome_message_rule.rb +7 -0
- data/lib/twitter/direct_messages/welcome_message_rule_wrapper.rb +26 -3
- data/lib/twitter/direct_messages/welcome_message_wrapper.rb +36 -11
- data/lib/twitter/entities.rb +84 -8
- data/lib/twitter/entity/hashtag.rb +7 -1
- data/lib/twitter/entity/symbol.rb +7 -1
- data/lib/twitter/entity/uri.rb +2 -1
- data/lib/twitter/entity/user_mention.rb +20 -1
- data/lib/twitter/entity.rb +7 -1
- data/lib/twitter/enumerable.rb +20 -3
- data/lib/twitter/error.rb +137 -61
- data/lib/twitter/factory.rb +9 -5
- data/lib/twitter/geo/point.rb +37 -5
- data/lib/twitter/geo/polygon.rb +1 -0
- data/lib/twitter/geo.rb +16 -2
- data/lib/twitter/geo_factory.rb +7 -3
- data/lib/twitter/geo_results.rb +39 -8
- data/lib/twitter/headers.rb +44 -7
- data/lib/twitter/identity.rb +13 -3
- data/lib/twitter/language.rb +21 -1
- data/lib/twitter/list.rb +101 -11
- data/lib/twitter/media/animated_gif.rb +1 -0
- data/lib/twitter/media/photo.rb +19 -3
- data/lib/twitter/media/video.rb +21 -3
- data/lib/twitter/media/video_info.rb +15 -1
- data/lib/twitter/media_factory.rb +7 -3
- data/lib/twitter/metadata.rb +14 -1
- data/lib/twitter/null_object.rb +16 -14
- data/lib/twitter/oembed.rb +56 -2
- data/lib/twitter/place.rb +74 -6
- data/lib/twitter/premium_search_results.rb +87 -18
- data/lib/twitter/profile.rb +100 -44
- data/lib/twitter/profile_banner.rb +9 -4
- data/lib/twitter/rate_limit.rb +32 -3
- data/lib/twitter/relationship.rb +8 -5
- data/lib/twitter/rest/account_activity.rb +55 -26
- data/lib/twitter/rest/api.rb +2 -0
- data/lib/twitter/rest/client.rb +18 -0
- data/lib/twitter/rest/direct_messages/welcome_messages.rb +89 -18
- data/lib/twitter/rest/direct_messages.rb +158 -94
- data/lib/twitter/rest/favorites.rb +57 -21
- data/lib/twitter/rest/form_encoder.rb +57 -17
- data/lib/twitter/rest/friends_and_followers.rb +101 -35
- data/lib/twitter/rest/help.rb +13 -3
- data/lib/twitter/rest/lists.rb +133 -45
- data/lib/twitter/rest/oauth.rb +23 -17
- data/lib/twitter/rest/places_and_geo.rb +44 -28
- data/lib/twitter/rest/premium_search.rb +18 -13
- data/lib/twitter/rest/request.rb +171 -53
- data/lib/twitter/rest/saved_searches.rb +22 -7
- data/lib/twitter/rest/search.rb +20 -16
- data/lib/twitter/rest/spam_reporting.rb +5 -1
- data/lib/twitter/rest/suggested_users.rb +14 -5
- data/lib/twitter/rest/timelines.rb +92 -52
- data/lib/twitter/rest/trends.rb +31 -12
- data/lib/twitter/rest/tweets.rb +145 -88
- data/lib/twitter/rest/undocumented.rb +11 -2
- data/lib/twitter/rest/upload_utils.rb +42 -26
- data/lib/twitter/rest/users.rb +150 -71
- data/lib/twitter/rest/utils.rb +135 -39
- data/lib/twitter/saved_search.rb +23 -2
- data/lib/twitter/search_results.rb +62 -17
- data/lib/twitter/settings.rb +37 -11
- data/lib/twitter/size.rb +37 -3
- data/lib/twitter/source_user.rb +4 -3
- data/lib/twitter/streaming/client.rb +60 -8
- data/lib/twitter/streaming/connection.rb +55 -8
- data/lib/twitter/streaming/deleted_tweet.rb +8 -0
- data/lib/twitter/streaming/event.rb +43 -1
- data/lib/twitter/streaming/friend_list.rb +1 -0
- data/lib/twitter/streaming/message_parser.rb +20 -10
- data/lib/twitter/streaming/response.rb +31 -5
- data/lib/twitter/streaming/stall_warning.rb +23 -0
- data/lib/twitter/suggestion.rb +25 -1
- data/lib/twitter/target_user.rb +2 -1
- data/lib/twitter/trend.rb +29 -1
- data/lib/twitter/trend_results.rb +50 -7
- data/lib/twitter/tweet.rb +180 -21
- data/lib/twitter/user.rb +289 -53
- data/lib/twitter/utils.rb +12 -13
- data/lib/twitter/variant.rb +12 -1
- data/lib/twitter/version.rb +66 -29
- data/lib/twitter.rb +6 -1
- metadata +29 -73
- data/.yardopts +0 -16
- data/CHANGELOG.md +0 -1035
- data/CONTRIBUTING.md +0 -49
- data/twitter.gemspec +0 -57
data/lib/twitter/tweet.rb
CHANGED
|
@@ -3,42 +3,189 @@ require "twitter/entities"
|
|
|
3
3
|
require "twitter/identity"
|
|
4
4
|
|
|
5
5
|
module Twitter
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
include
|
|
6
|
+
# Represents a Twitter tweet
|
|
7
|
+
class Tweet < Identity
|
|
8
|
+
include Creatable
|
|
9
|
+
include Entities
|
|
10
|
+
|
|
11
|
+
# The filter level of the tweet
|
|
12
|
+
#
|
|
13
|
+
# @api public
|
|
14
|
+
# @example
|
|
15
|
+
# tweet.filter_level
|
|
16
|
+
# @return [String]
|
|
17
|
+
|
|
18
|
+
# The screen name of the user being replied to
|
|
19
|
+
#
|
|
20
|
+
# @api public
|
|
21
|
+
# @example
|
|
22
|
+
# tweet.in_reply_to_screen_name
|
|
23
|
+
# @return [String]
|
|
24
|
+
|
|
25
|
+
# The language of the tweet
|
|
26
|
+
#
|
|
27
|
+
# @api public
|
|
28
|
+
# @example
|
|
29
|
+
# tweet.lang
|
|
30
|
+
# @return [String]
|
|
31
|
+
|
|
32
|
+
# The source of the tweet
|
|
33
|
+
#
|
|
34
|
+
# @api public
|
|
35
|
+
# @example
|
|
36
|
+
# tweet.source
|
|
37
|
+
# @return [String]
|
|
38
|
+
|
|
39
|
+
# The text of the tweet
|
|
40
|
+
#
|
|
41
|
+
# @api public
|
|
42
|
+
# @example
|
|
43
|
+
# tweet.text
|
|
9
44
|
# @return [String]
|
|
10
45
|
attr_reader :filter_level, :in_reply_to_screen_name, :lang, :source, :text
|
|
46
|
+
|
|
47
|
+
# The number of times this tweet has been favorited
|
|
48
|
+
#
|
|
49
|
+
# @api public
|
|
50
|
+
# @example
|
|
51
|
+
# tweet.favorite_count
|
|
52
|
+
# @return [Integer]
|
|
53
|
+
|
|
54
|
+
# The ID of the status being replied to
|
|
55
|
+
#
|
|
56
|
+
# @api public
|
|
57
|
+
# @example
|
|
58
|
+
# tweet.in_reply_to_status_id
|
|
59
|
+
# @return [Integer]
|
|
60
|
+
|
|
61
|
+
# The ID of the user being replied to
|
|
62
|
+
#
|
|
63
|
+
# @api public
|
|
64
|
+
# @example
|
|
65
|
+
# tweet.in_reply_to_user_id
|
|
66
|
+
# @return [Integer]
|
|
67
|
+
|
|
68
|
+
# The number of times this tweet has been quoted
|
|
69
|
+
#
|
|
70
|
+
# @api public
|
|
71
|
+
# @example
|
|
72
|
+
# tweet.quote_count
|
|
73
|
+
# @return [Integer]
|
|
74
|
+
|
|
75
|
+
# The number of replies to this tweet
|
|
76
|
+
#
|
|
77
|
+
# @api public
|
|
78
|
+
# @example
|
|
79
|
+
# tweet.reply_count
|
|
80
|
+
# @return [Integer]
|
|
81
|
+
|
|
82
|
+
# The number of times this tweet has been retweeted
|
|
83
|
+
#
|
|
84
|
+
# @api public
|
|
85
|
+
# @example
|
|
86
|
+
# tweet.retweet_count
|
|
11
87
|
# @return [Integer]
|
|
12
88
|
attr_reader :favorite_count, :in_reply_to_status_id, :in_reply_to_user_id,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
89
|
+
:quote_count, :reply_count, :retweet_count
|
|
90
|
+
|
|
91
|
+
# @!method in_reply_to_tweet_id
|
|
92
|
+
# The ID of the tweet being replied to
|
|
93
|
+
# @api public
|
|
94
|
+
# @example
|
|
95
|
+
# tweet.in_reply_to_tweet_id
|
|
96
|
+
# @return [Integer]
|
|
97
|
+
alias_method :in_reply_to_tweet_id, :in_reply_to_status_id
|
|
98
|
+
|
|
99
|
+
# Returns true if this is a reply
|
|
100
|
+
#
|
|
101
|
+
# @!method reply?
|
|
102
|
+
# @api public
|
|
103
|
+
# @example
|
|
104
|
+
# tweet.reply?
|
|
105
|
+
# @return [Boolean]
|
|
106
|
+
alias_method :reply?, :in_reply_to_user_id?
|
|
16
107
|
object_attr_reader :GeoFactory, :geo
|
|
17
108
|
object_attr_reader :Metadata, :metadata
|
|
18
109
|
object_attr_reader :Place, :place
|
|
19
110
|
object_attr_reader :Tweet, :retweeted_status
|
|
20
111
|
object_attr_reader :Tweet, :quoted_status
|
|
21
112
|
object_attr_reader :Tweet, :current_user_retweet
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
113
|
+
|
|
114
|
+
# Returns the retweeted tweet
|
|
115
|
+
#
|
|
116
|
+
# @!method retweeted_tweet
|
|
117
|
+
# @api public
|
|
118
|
+
# @example
|
|
119
|
+
# tweet.retweeted_tweet
|
|
120
|
+
# @return [Twitter::Tweet]
|
|
121
|
+
alias_method :retweeted_tweet, :retweeted_status
|
|
122
|
+
|
|
123
|
+
# Returns true if this is a retweet
|
|
124
|
+
#
|
|
125
|
+
# @!method retweet?
|
|
126
|
+
# @api public
|
|
127
|
+
# @example
|
|
128
|
+
# tweet.retweet?
|
|
129
|
+
# @return [Boolean]
|
|
130
|
+
alias_method :retweet?, :retweeted_status?
|
|
131
|
+
|
|
132
|
+
# Returns true if this has a retweeted tweet
|
|
133
|
+
#
|
|
134
|
+
# @!method retweeted_tweet?
|
|
135
|
+
# @api public
|
|
136
|
+
# @example
|
|
137
|
+
# tweet.retweeted_tweet?
|
|
138
|
+
# @return [Boolean]
|
|
139
|
+
alias_method :retweeted_tweet?, :retweeted_status?
|
|
140
|
+
|
|
141
|
+
# Returns the quoted tweet
|
|
142
|
+
#
|
|
143
|
+
# @!method quoted_tweet
|
|
144
|
+
# @api public
|
|
145
|
+
# @example
|
|
146
|
+
# tweet.quoted_tweet
|
|
147
|
+
# @return [Twitter::Tweet]
|
|
148
|
+
alias_method :quoted_tweet, :quoted_status
|
|
149
|
+
|
|
150
|
+
# Returns true if this is a quote tweet
|
|
151
|
+
#
|
|
152
|
+
# @!method quote?
|
|
153
|
+
# @api public
|
|
154
|
+
# @example
|
|
155
|
+
# tweet.quote?
|
|
156
|
+
# @return [Boolean]
|
|
157
|
+
alias_method :quote?, :quoted_status?
|
|
158
|
+
|
|
159
|
+
# Returns true if this has a quoted tweet
|
|
160
|
+
#
|
|
161
|
+
# @!method quoted_tweet?
|
|
162
|
+
# @api public
|
|
163
|
+
# @example
|
|
164
|
+
# tweet.quoted_tweet?
|
|
165
|
+
# @return [Boolean]
|
|
166
|
+
alias_method :quoted_tweet?, :quoted_status?
|
|
28
167
|
object_attr_reader :User, :user, :status
|
|
29
168
|
predicate_attr_reader :favorited, :possibly_sensitive, :retweeted,
|
|
30
|
-
|
|
169
|
+
:truncated
|
|
31
170
|
|
|
32
|
-
# Initializes a new object
|
|
171
|
+
# Initializes a new Tweet object
|
|
33
172
|
#
|
|
34
|
-
# @
|
|
173
|
+
# @api public
|
|
174
|
+
# @example
|
|
175
|
+
# Twitter::Tweet.new(id: 123, text: "Hello")
|
|
176
|
+
# @param attrs [Hash] The attributes hash containing at least :id
|
|
35
177
|
# @return [Twitter::Tweet]
|
|
36
|
-
def initialize(attrs
|
|
37
|
-
attrs[:text]
|
|
178
|
+
def initialize(attrs)
|
|
179
|
+
attrs[:text] ||= attrs[:full_text]
|
|
38
180
|
super
|
|
39
181
|
end
|
|
40
182
|
|
|
41
|
-
#
|
|
183
|
+
# Returns the full text of the tweet
|
|
184
|
+
#
|
|
185
|
+
# @api public
|
|
186
|
+
# @note May be > 280 characters
|
|
187
|
+
# @example
|
|
188
|
+
# tweet.full_text
|
|
42
189
|
# @return [String]
|
|
43
190
|
def full_text
|
|
44
191
|
if retweet?
|
|
@@ -50,11 +197,23 @@ module Twitter
|
|
|
50
197
|
end
|
|
51
198
|
memoize :full_text
|
|
52
199
|
|
|
53
|
-
#
|
|
200
|
+
# Returns the URI to the tweet
|
|
201
|
+
#
|
|
202
|
+
# @api public
|
|
203
|
+
# @example
|
|
204
|
+
# tweet.uri
|
|
205
|
+
# @return [URI::Generic]
|
|
54
206
|
def uri
|
|
55
|
-
|
|
207
|
+
URI.parse("https://twitter.com/#{user.screen_name}/status/#{id}") if user?
|
|
56
208
|
end
|
|
57
209
|
memoize :uri
|
|
58
|
-
|
|
210
|
+
|
|
211
|
+
# @!method url
|
|
212
|
+
# Returns the URL to the tweet
|
|
213
|
+
# @api public
|
|
214
|
+
# @example
|
|
215
|
+
# tweet.url
|
|
216
|
+
# @return [URI::Generic]
|
|
217
|
+
alias_method :url, :uri
|
|
59
218
|
end
|
|
60
219
|
end
|
data/lib/twitter/user.rb
CHANGED
|
@@ -1,99 +1,335 @@
|
|
|
1
|
-
require "
|
|
1
|
+
require "uri"
|
|
2
2
|
require "twitter/basic_user"
|
|
3
3
|
require "twitter/creatable"
|
|
4
4
|
require "twitter/entity/uri"
|
|
5
5
|
require "twitter/profile"
|
|
6
6
|
|
|
7
7
|
module Twitter
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
include
|
|
8
|
+
# Represents a Twitter user
|
|
9
|
+
class User < BasicUser
|
|
10
|
+
include Creatable
|
|
11
|
+
include Profile
|
|
12
|
+
|
|
13
|
+
# The user's connections
|
|
14
|
+
#
|
|
15
|
+
# @api public
|
|
16
|
+
# @example
|
|
17
|
+
# user.connections
|
|
11
18
|
# @return [Array]
|
|
12
19
|
attr_reader :connections
|
|
20
|
+
|
|
21
|
+
# The number of favourites
|
|
22
|
+
#
|
|
23
|
+
# @api public
|
|
24
|
+
# @example
|
|
25
|
+
# user.favourites_count
|
|
26
|
+
# @return [Integer]
|
|
27
|
+
|
|
28
|
+
# The number of followers
|
|
29
|
+
#
|
|
30
|
+
# @api public
|
|
31
|
+
# @example
|
|
32
|
+
# user.followers_count
|
|
33
|
+
# @return [Integer]
|
|
34
|
+
|
|
35
|
+
# The number of friends (following)
|
|
36
|
+
#
|
|
37
|
+
# @api public
|
|
38
|
+
# @example
|
|
39
|
+
# user.friends_count
|
|
40
|
+
# @return [Integer]
|
|
41
|
+
|
|
42
|
+
# The number of lists this user is on
|
|
43
|
+
#
|
|
44
|
+
# @api public
|
|
45
|
+
# @example
|
|
46
|
+
# user.listed_count
|
|
47
|
+
# @return [Integer]
|
|
48
|
+
|
|
49
|
+
# The number of statuses/tweets
|
|
50
|
+
#
|
|
51
|
+
# @api public
|
|
52
|
+
# @example
|
|
53
|
+
# user.statuses_count
|
|
54
|
+
# @return [Integer]
|
|
55
|
+
|
|
56
|
+
# The UTC offset in seconds
|
|
57
|
+
#
|
|
58
|
+
# @api public
|
|
59
|
+
# @example
|
|
60
|
+
# user.utc_offset
|
|
13
61
|
# @return [Integer]
|
|
14
62
|
attr_reader :favourites_count, :followers_count, :friends_count,
|
|
15
|
-
|
|
63
|
+
:listed_count, :statuses_count, :utc_offset
|
|
64
|
+
|
|
65
|
+
# The user's description
|
|
66
|
+
#
|
|
67
|
+
# @api public
|
|
68
|
+
# @example
|
|
69
|
+
# user.description
|
|
70
|
+
# @return [String]
|
|
71
|
+
|
|
72
|
+
# The user's email address
|
|
73
|
+
#
|
|
74
|
+
# @api public
|
|
75
|
+
# @example
|
|
76
|
+
# user.email
|
|
77
|
+
# @return [String]
|
|
78
|
+
|
|
79
|
+
# The user's language
|
|
80
|
+
#
|
|
81
|
+
# @api public
|
|
82
|
+
# @example
|
|
83
|
+
# user.lang
|
|
84
|
+
# @return [String]
|
|
85
|
+
|
|
86
|
+
# The user's location
|
|
87
|
+
#
|
|
88
|
+
# @api public
|
|
89
|
+
# @example
|
|
90
|
+
# user.location
|
|
91
|
+
# @return [String]
|
|
92
|
+
|
|
93
|
+
# The user's name
|
|
94
|
+
#
|
|
95
|
+
# @api public
|
|
96
|
+
# @example
|
|
97
|
+
# user.name
|
|
98
|
+
# @return [String]
|
|
99
|
+
|
|
100
|
+
# The profile background color
|
|
101
|
+
#
|
|
102
|
+
# @api public
|
|
103
|
+
# @example
|
|
104
|
+
# user.profile_background_color
|
|
105
|
+
# @return [String]
|
|
106
|
+
|
|
107
|
+
# The profile link color
|
|
108
|
+
#
|
|
109
|
+
# @api public
|
|
110
|
+
# @example
|
|
111
|
+
# user.profile_link_color
|
|
112
|
+
# @return [String]
|
|
113
|
+
|
|
114
|
+
# The profile sidebar border color
|
|
115
|
+
#
|
|
116
|
+
# @api public
|
|
117
|
+
# @example
|
|
118
|
+
# user.profile_sidebar_border_color
|
|
119
|
+
# @return [String]
|
|
120
|
+
|
|
121
|
+
# The profile sidebar fill color
|
|
122
|
+
#
|
|
123
|
+
# @api public
|
|
124
|
+
# @example
|
|
125
|
+
# user.profile_sidebar_fill_color
|
|
126
|
+
# @return [String]
|
|
127
|
+
|
|
128
|
+
# The profile text color
|
|
129
|
+
#
|
|
130
|
+
# @api public
|
|
131
|
+
# @example
|
|
132
|
+
# user.profile_text_color
|
|
133
|
+
# @return [String]
|
|
134
|
+
|
|
135
|
+
# The user's time zone
|
|
136
|
+
#
|
|
137
|
+
# @api public
|
|
138
|
+
# @example
|
|
139
|
+
# user.time_zone
|
|
16
140
|
# @return [String]
|
|
17
141
|
attr_reader :description, :email, :lang, :location, :name,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
142
|
+
:profile_background_color, :profile_link_color,
|
|
143
|
+
:profile_sidebar_border_color, :profile_sidebar_fill_color,
|
|
144
|
+
:profile_text_color, :time_zone
|
|
145
|
+
|
|
146
|
+
# @!method favorites_count
|
|
147
|
+
# The number of favorites (US spelling)
|
|
148
|
+
# @api public
|
|
149
|
+
# @example
|
|
150
|
+
# user.favorites_count
|
|
151
|
+
# @return [Integer]
|
|
152
|
+
alias_method :favorites_count, :favourites_count
|
|
153
|
+
|
|
154
|
+
# @!method tweets_count
|
|
155
|
+
# The number of tweets
|
|
156
|
+
# @api public
|
|
157
|
+
# @example
|
|
158
|
+
# user.tweets_count
|
|
159
|
+
# @return [Integer]
|
|
160
|
+
alias_method :tweets_count, :statuses_count
|
|
23
161
|
object_attr_reader :Tweet, :status, :user
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
162
|
+
|
|
163
|
+
# The user's latest tweet
|
|
164
|
+
#
|
|
165
|
+
# @!method tweet
|
|
166
|
+
# @api public
|
|
167
|
+
# @example
|
|
168
|
+
# user.tweet
|
|
169
|
+
# @return [Twitter::Tweet]
|
|
170
|
+
alias_method :tweet, :status
|
|
171
|
+
|
|
172
|
+
# Returns true if the user has a tweet
|
|
173
|
+
#
|
|
174
|
+
# @!method tweet?
|
|
175
|
+
# @api public
|
|
176
|
+
# @example
|
|
177
|
+
# user.tweet?
|
|
178
|
+
# @return [Boolean]
|
|
179
|
+
alias_method :tweet?, :status?
|
|
180
|
+
|
|
181
|
+
# Returns true if the user has tweeted
|
|
182
|
+
#
|
|
183
|
+
# @!method tweeted?
|
|
184
|
+
# @api public
|
|
185
|
+
# @example
|
|
186
|
+
# user.tweeted?
|
|
187
|
+
# @return [Boolean]
|
|
188
|
+
alias_method :tweeted?, :status?
|
|
27
189
|
predicate_attr_reader :contributors_enabled, :default_profile,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
190
|
+
:default_profile_image, :follow_request_sent,
|
|
191
|
+
:geo_enabled, :muting, :needs_phone_verification,
|
|
192
|
+
:notifications, :protected, :profile_background_tile,
|
|
193
|
+
:profile_use_background_image, :suspended, :verified
|
|
32
194
|
define_predicate_method :translator, :is_translator
|
|
33
195
|
define_predicate_method :translation_enabled, :is_translation_enabled
|
|
34
196
|
uri_attr_reader :profile_background_image_uri, :profile_background_image_uri_https
|
|
35
197
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
url_key = array.join("_").to_sym
|
|
48
|
-
define_entity_uris_method(key1, key2)
|
|
49
|
-
alias_method(url_key, key1)
|
|
50
|
-
define_entity_uris_predicate_method(key1)
|
|
51
|
-
alias_method(:"#{url_key}?", :"#{key1}?")
|
|
198
|
+
# Returns an array of URIs in the user's description
|
|
199
|
+
#
|
|
200
|
+
# @api public
|
|
201
|
+
# @example
|
|
202
|
+
# user.description_uris
|
|
203
|
+
# @return [Array<Twitter::Entity::URI>]
|
|
204
|
+
def description_uris
|
|
205
|
+
empty_hash = {} # : Hash[Symbol, untyped]
|
|
206
|
+
empty_array = [] # : Array[untyped]
|
|
207
|
+
@attrs.fetch(:entities, empty_hash).fetch(:description, empty_hash).fetch(:urls, empty_array).collect do |url| # steep:ignore FallbackAny
|
|
208
|
+
Entity::URI.new(url)
|
|
52
209
|
end
|
|
210
|
+
end
|
|
211
|
+
memoize :description_uris
|
|
53
212
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
213
|
+
# @!method description_urls
|
|
214
|
+
# Returns an array of URLs in the user's description
|
|
215
|
+
# @api public
|
|
216
|
+
# @example
|
|
217
|
+
# user.description_urls
|
|
218
|
+
# @return [Array<Twitter::Entity::URI>]
|
|
219
|
+
alias_method :description_urls, :description_uris
|
|
220
|
+
|
|
221
|
+
# Returns true if the user has description URIs
|
|
222
|
+
#
|
|
223
|
+
# @api public
|
|
224
|
+
# @example
|
|
225
|
+
# user.description_uris?
|
|
226
|
+
# @return [Boolean]
|
|
227
|
+
def description_uris?
|
|
228
|
+
description_uris.any?
|
|
229
|
+
end
|
|
230
|
+
memoize :description_uris?
|
|
231
|
+
|
|
232
|
+
# @!method description_urls?
|
|
233
|
+
# Returns true if the user has description URLs
|
|
234
|
+
# @api public
|
|
235
|
+
# @example
|
|
236
|
+
# user.description_urls?
|
|
237
|
+
# @return [Boolean]
|
|
238
|
+
alias_method :description_urls?, :description_uris?
|
|
62
239
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
240
|
+
# Returns an array of URIs in the user's website
|
|
241
|
+
#
|
|
242
|
+
# @api public
|
|
243
|
+
# @example
|
|
244
|
+
# user.website_uris
|
|
245
|
+
# @return [Array<Twitter::Entity::URI>]
|
|
246
|
+
def website_uris
|
|
247
|
+
empty_hash = {} # : Hash[Symbol, untyped]
|
|
248
|
+
empty_array = [] # : Array[untyped]
|
|
249
|
+
@attrs.fetch(:entities, empty_hash).fetch(:url, empty_hash).fetch(:urls, empty_array).collect do |url| # steep:ignore FallbackAny
|
|
250
|
+
Entity::URI.new(url)
|
|
68
251
|
end
|
|
69
252
|
end
|
|
253
|
+
memoize :website_uris
|
|
70
254
|
|
|
71
|
-
|
|
72
|
-
|
|
255
|
+
# @!method website_urls
|
|
256
|
+
# Returns an array of URLs in the user's website
|
|
257
|
+
# @api public
|
|
258
|
+
# @example
|
|
259
|
+
# user.website_urls
|
|
260
|
+
# @return [Array<Twitter::Entity::URI>]
|
|
261
|
+
alias_method :website_urls, :website_uris
|
|
73
262
|
|
|
263
|
+
# Returns true if the user has website URIs
|
|
264
|
+
#
|
|
265
|
+
# @api public
|
|
266
|
+
# @example
|
|
267
|
+
# user.website_uris?
|
|
268
|
+
# @return [Boolean]
|
|
269
|
+
def website_uris?
|
|
270
|
+
website_uris.any?
|
|
271
|
+
end
|
|
272
|
+
memoize :website_uris?
|
|
273
|
+
|
|
274
|
+
# @!method website_urls?
|
|
275
|
+
# Returns true if the user has website URLs
|
|
276
|
+
# @api public
|
|
277
|
+
# @example
|
|
278
|
+
# user.website_urls?
|
|
279
|
+
# @return [Boolean]
|
|
280
|
+
alias_method :website_urls?, :website_uris?
|
|
281
|
+
|
|
282
|
+
# Returns true if the user has entities
|
|
283
|
+
#
|
|
284
|
+
# @api public
|
|
285
|
+
# @example
|
|
286
|
+
# user.entities?
|
|
74
287
|
# @return [Boolean]
|
|
75
288
|
def entities?
|
|
76
289
|
!@attrs[:entities].nil? && @attrs[:entities].any? { |_, hash| hash[:urls].any? }
|
|
77
290
|
end
|
|
78
291
|
memoize :entities?
|
|
79
292
|
|
|
80
|
-
#
|
|
293
|
+
# Returns the URI to the user's profile
|
|
294
|
+
#
|
|
295
|
+
# @api public
|
|
296
|
+
# @example
|
|
297
|
+
# user.uri
|
|
298
|
+
# @return [URI::Generic]
|
|
81
299
|
def uri
|
|
82
|
-
|
|
300
|
+
URI.parse("https://twitter.com/#{screen_name}") if screen_name?
|
|
83
301
|
end
|
|
84
302
|
memoize :uri
|
|
85
|
-
alias url uri
|
|
86
303
|
|
|
87
|
-
#
|
|
304
|
+
# @!method url
|
|
305
|
+
# Returns the URL to the user's profile
|
|
306
|
+
# @api public
|
|
307
|
+
# @example
|
|
308
|
+
# user.url
|
|
309
|
+
# @return [URI::Generic]
|
|
310
|
+
alias_method :url, :uri
|
|
311
|
+
|
|
312
|
+
# Returns the user's website URL
|
|
313
|
+
#
|
|
314
|
+
# @api public
|
|
315
|
+
# @example
|
|
316
|
+
# user.website
|
|
317
|
+
# @return [URI::Generic]
|
|
88
318
|
def website
|
|
89
319
|
if website_uris?
|
|
90
320
|
website_uris.first.expanded_url
|
|
91
321
|
else
|
|
92
|
-
|
|
322
|
+
URI.parse(@attrs[:url]) unless @attrs[:url].nil?
|
|
93
323
|
end
|
|
94
324
|
end
|
|
95
325
|
memoize :website
|
|
96
326
|
|
|
327
|
+
# Returns true if the user has a website
|
|
328
|
+
#
|
|
329
|
+
# @api public
|
|
330
|
+
# @example
|
|
331
|
+
# user.website?
|
|
332
|
+
# @return [Boolean]
|
|
97
333
|
def website?
|
|
98
334
|
!!(website_uris? || @attrs[:url])
|
|
99
335
|
end
|
data/lib/twitter/utils.rb
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
module Twitter
|
|
2
|
+
# Utility methods for parallel mapping
|
|
3
|
+
#
|
|
4
|
+
# @api private
|
|
2
5
|
module Utils
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
# Returns a new array with the concatenated results of running block once for every element in enumerable.
|
|
6
|
-
# If no block is given, an enumerator is returned instead.
|
|
6
|
+
# Parallel flat_map for enumerables
|
|
7
7
|
#
|
|
8
|
+
# @api private
|
|
8
9
|
# @param enumerable [Enumerable]
|
|
9
10
|
# @return [Array, Enumerator]
|
|
10
11
|
def flat_pmap(enumerable, &block)
|
|
@@ -12,20 +13,18 @@ module Twitter
|
|
|
12
13
|
|
|
13
14
|
pmap(enumerable, &block).flatten(1)
|
|
14
15
|
end
|
|
16
|
+
module_function :flat_pmap
|
|
15
17
|
|
|
16
|
-
#
|
|
17
|
-
# If no block is given, an enumerator is returned instead.
|
|
18
|
+
# Parallel map for enumerables
|
|
18
19
|
#
|
|
20
|
+
# @api private
|
|
19
21
|
# @param enumerable [Enumerable]
|
|
20
22
|
# @return [Array, Enumerator]
|
|
21
|
-
def pmap(enumerable, &
|
|
22
|
-
return to_enum(:pmap, enumerable) unless
|
|
23
|
+
def pmap(enumerable, &)
|
|
24
|
+
return to_enum(:pmap, enumerable) unless block_given?
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
enumerable.collect(&block)
|
|
26
|
-
else
|
|
27
|
-
enumerable.collect { |object| Thread.new { yield(object) } }.collect(&:value)
|
|
28
|
-
end
|
|
26
|
+
enumerable.collect(&)
|
|
29
27
|
end
|
|
28
|
+
module_function :pmap
|
|
30
29
|
end
|
|
31
30
|
end
|
data/lib/twitter/variant.rb
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
require "twitter/base"
|
|
2
2
|
|
|
3
3
|
module Twitter
|
|
4
|
-
|
|
4
|
+
# Represents a video variant with a specific bitrate and format
|
|
5
|
+
class Variant < Base
|
|
6
|
+
# The bitrate of this variant in bits per second
|
|
7
|
+
#
|
|
8
|
+
# @api public
|
|
9
|
+
# @example
|
|
10
|
+
# variant.bitrate
|
|
5
11
|
# @return [Integer]
|
|
6
12
|
attr_reader :bitrate
|
|
7
13
|
|
|
14
|
+
# The content type (MIME type) of this variant
|
|
15
|
+
#
|
|
16
|
+
# @api public
|
|
17
|
+
# @example
|
|
18
|
+
# variant.content_type
|
|
8
19
|
# @return [String]
|
|
9
20
|
attr_reader :content_type
|
|
10
21
|
|