twitter 8.2.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.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.md +1 -1
  3. data/README.md +172 -10
  4. data/lib/twitter/arguments.rb +14 -1
  5. data/lib/twitter/base.rb +72 -11
  6. data/lib/twitter/basic_user.rb +7 -1
  7. data/lib/twitter/client.rb +94 -3
  8. data/lib/twitter/creatable.rb +11 -2
  9. data/lib/twitter/cursor.rb +58 -11
  10. data/lib/twitter/direct_message.rb +32 -4
  11. data/lib/twitter/direct_message_event.rb +34 -10
  12. data/lib/twitter/direct_messages/welcome_message.rb +22 -1
  13. data/lib/twitter/direct_messages/welcome_message_rule.rb +7 -0
  14. data/lib/twitter/direct_messages/welcome_message_rule_wrapper.rb +26 -3
  15. data/lib/twitter/direct_messages/welcome_message_wrapper.rb +36 -11
  16. data/lib/twitter/entities.rb +84 -8
  17. data/lib/twitter/entity/hashtag.rb +7 -1
  18. data/lib/twitter/entity/symbol.rb +7 -1
  19. data/lib/twitter/entity/uri.rb +2 -1
  20. data/lib/twitter/entity/user_mention.rb +20 -1
  21. data/lib/twitter/entity.rb +7 -1
  22. data/lib/twitter/enumerable.rb +20 -3
  23. data/lib/twitter/error.rb +137 -61
  24. data/lib/twitter/factory.rb +9 -5
  25. data/lib/twitter/geo/point.rb +37 -5
  26. data/lib/twitter/geo/polygon.rb +1 -0
  27. data/lib/twitter/geo.rb +16 -2
  28. data/lib/twitter/geo_factory.rb +7 -3
  29. data/lib/twitter/geo_results.rb +39 -8
  30. data/lib/twitter/headers.rb +44 -7
  31. data/lib/twitter/identity.rb +13 -3
  32. data/lib/twitter/language.rb +21 -1
  33. data/lib/twitter/list.rb +101 -11
  34. data/lib/twitter/media/animated_gif.rb +1 -0
  35. data/lib/twitter/media/photo.rb +19 -3
  36. data/lib/twitter/media/video.rb +21 -3
  37. data/lib/twitter/media/video_info.rb +15 -1
  38. data/lib/twitter/media_factory.rb +7 -3
  39. data/lib/twitter/metadata.rb +14 -1
  40. data/lib/twitter/null_object.rb +16 -14
  41. data/lib/twitter/oembed.rb +56 -2
  42. data/lib/twitter/place.rb +74 -6
  43. data/lib/twitter/premium_search_results.rb +87 -18
  44. data/lib/twitter/profile.rb +100 -44
  45. data/lib/twitter/profile_banner.rb +9 -4
  46. data/lib/twitter/rate_limit.rb +32 -3
  47. data/lib/twitter/relationship.rb +8 -5
  48. data/lib/twitter/rest/account_activity.rb +55 -26
  49. data/lib/twitter/rest/api.rb +2 -0
  50. data/lib/twitter/rest/client.rb +18 -0
  51. data/lib/twitter/rest/direct_messages/welcome_messages.rb +89 -18
  52. data/lib/twitter/rest/direct_messages.rb +158 -94
  53. data/lib/twitter/rest/favorites.rb +57 -21
  54. data/lib/twitter/rest/form_encoder.rb +57 -17
  55. data/lib/twitter/rest/friends_and_followers.rb +101 -35
  56. data/lib/twitter/rest/help.rb +13 -3
  57. data/lib/twitter/rest/lists.rb +133 -45
  58. data/lib/twitter/rest/oauth.rb +23 -17
  59. data/lib/twitter/rest/places_and_geo.rb +44 -28
  60. data/lib/twitter/rest/premium_search.rb +18 -13
  61. data/lib/twitter/rest/request.rb +171 -53
  62. data/lib/twitter/rest/saved_searches.rb +22 -7
  63. data/lib/twitter/rest/search.rb +20 -16
  64. data/lib/twitter/rest/spam_reporting.rb +5 -1
  65. data/lib/twitter/rest/suggested_users.rb +14 -5
  66. data/lib/twitter/rest/timelines.rb +92 -52
  67. data/lib/twitter/rest/trends.rb +31 -12
  68. data/lib/twitter/rest/tweets.rb +145 -88
  69. data/lib/twitter/rest/undocumented.rb +11 -2
  70. data/lib/twitter/rest/upload_utils.rb +42 -26
  71. data/lib/twitter/rest/users.rb +150 -71
  72. data/lib/twitter/rest/utils.rb +135 -39
  73. data/lib/twitter/saved_search.rb +23 -2
  74. data/lib/twitter/search_results.rb +62 -17
  75. data/lib/twitter/settings.rb +37 -11
  76. data/lib/twitter/size.rb +37 -3
  77. data/lib/twitter/source_user.rb +4 -3
  78. data/lib/twitter/streaming/client.rb +60 -8
  79. data/lib/twitter/streaming/connection.rb +55 -8
  80. data/lib/twitter/streaming/deleted_tweet.rb +8 -0
  81. data/lib/twitter/streaming/event.rb +43 -1
  82. data/lib/twitter/streaming/friend_list.rb +1 -0
  83. data/lib/twitter/streaming/message_parser.rb +20 -10
  84. data/lib/twitter/streaming/response.rb +31 -5
  85. data/lib/twitter/streaming/stall_warning.rb +23 -0
  86. data/lib/twitter/suggestion.rb +25 -1
  87. data/lib/twitter/target_user.rb +2 -1
  88. data/lib/twitter/trend.rb +29 -1
  89. data/lib/twitter/trend_results.rb +50 -7
  90. data/lib/twitter/tweet.rb +180 -21
  91. data/lib/twitter/user.rb +289 -53
  92. data/lib/twitter/utils.rb +12 -13
  93. data/lib/twitter/variant.rb +12 -1
  94. data/lib/twitter/version.rb +66 -29
  95. data/lib/twitter.rb +6 -1
  96. metadata +23 -57
  97. data/.yardopts +0 -16
  98. data/CHANGELOG.md +0 -1040
  99. data/CONTRIBUTING.md +0 -49
  100. data/twitter.gemspec +0 -40
@@ -3,23 +3,47 @@ require "twitter/rest/request"
3
3
  require "twitter/utils"
4
4
 
5
5
  module Twitter
6
+ # Represents a cursor for paginating through Twitter API responses
6
7
  class Cursor
7
- include Twitter::Enumerable
8
- include Twitter::Utils
8
+ include Enumerable
9
+ include Utils
10
+
11
+ # The raw response attributes
12
+ #
13
+ # @api public
14
+ # @example
15
+ # cursor.attrs # => {users: [...], next_cursor: 123}
9
16
  # @return [Hash]
10
17
  attr_reader :attrs
11
- alias to_h attrs
12
- alias to_hash to_h
18
+
19
+ # @!method to_h
20
+ # Returns the attributes as a hash
21
+ # @api public
22
+ # @example
23
+ # cursor.to_h # => {users: [...], next_cursor: 123}
24
+ # @return [Hash]
25
+ alias_method :to_h, :attrs
26
+
27
+ # @!method to_hash
28
+ # Returns the attributes as a hash
29
+ # @api public
30
+ # @example
31
+ # cursor.to_hash # => {users: [...], next_cursor: 123}
32
+ # @return [Hash]
33
+ alias_method :to_hash, :to_h
13
34
 
14
35
  # Initializes a new Cursor
15
36
  #
37
+ # @api public
38
+ # @example
39
+ # cursor = Twitter::Cursor.new(:users, Twitter::User, request)
16
40
  # @param key [String, Symbol] The key to fetch the data from the response
17
41
  # @param klass [Class] The class to instantiate objects in the response
18
42
  # @param request [Twitter::REST::Request]
19
43
  # @param limit [Integer] After reaching the limit, we stop fetching next page
20
44
  # @return [Twitter::Cursor]
21
45
  def initialize(key, klass, request, limit = nil)
22
- @key = key.to_sym
46
+ @key = key
23
47
  @klass = klass
24
48
  @client = request.client
25
49
  @request_method = request.verb
@@ -30,14 +54,25 @@ module Twitter
30
54
  self.attrs = request.perform
31
55
  end
32
56
 
33
- private
57
+ private
34
58
 
59
+ # The next cursor value for pagination
60
+ #
61
+ # @api private
35
62
  # @return [Integer]
36
63
  def next_cursor
37
64
  @attrs[:next_cursor]
38
65
  end
39
- alias next next_cursor
40
66
 
67
+ # @!method next
68
+ # The next cursor value for pagination
69
+ # @api private
70
+ # @return [Integer]
71
+ alias_method :next, :next_cursor
72
+
73
+ # Check if this is the last page of results
74
+ #
75
+ # @api private
41
76
  # @return [Boolean]
42
77
  def last?
43
78
  return false if next_cursor.is_a?(String)
@@ -46,25 +81,37 @@ module Twitter
46
81
  next_cursor.zero?
47
82
  end
48
83
 
84
+ # Check if the limit has been reached
85
+ #
86
+ # @api private
49
87
  # @return [Boolean]
50
88
  def reached_limit?
51
- @limit && @limit <= attrs[@key].count
89
+ limit = @limit
90
+ return false if limit.nil?
91
+
92
+ limit <= attrs[@key].count
52
93
  end
53
94
 
95
+ # Fetch the next page of results
96
+ #
97
+ # @api private
54
98
  # @return [Hash]
55
99
  def fetch_next_page
56
- response = Twitter::REST::Request.new(@client, @request_method, @path, @options.merge(cursor: next_cursor)).perform
100
+ response = REST::Request.new(@client, @request_method, @path, @options.merge(cursor: next_cursor)).perform
57
101
  self.attrs = response
58
102
  end
59
103
 
104
+ # Set the attributes and populate the collection
105
+ #
106
+ # @api private
60
107
  # @param attrs [Hash]
61
108
  # @return [Hash]
62
109
  def attrs=(attrs)
63
110
  @attrs = attrs
111
+ klass = @klass
64
112
  @attrs.fetch(@key, []).each do |element|
65
- @collection << (@klass ? @klass.new(element) : element)
113
+ @collection << (klass ? klass.new(element) : element) # steep:ignore UnexpectedPositionalArgument
66
114
  end
67
- @attrs
68
115
  end
69
116
  end
70
117
  end
@@ -3,13 +3,41 @@ require "twitter/entities"
3
3
  require "twitter/identity"
4
4
 
5
5
  module Twitter
6
- class DirectMessage < Twitter::Identity
7
- include Twitter::Creatable
8
- include Twitter::Entities
6
+ # Represents a Twitter direct message
7
+ class DirectMessage < Identity
8
+ include Creatable
9
+ include Entities
10
+
11
+ # The text content of the direct message
12
+ #
13
+ # @api public
14
+ # @example
15
+ # direct_message.text
9
16
  # @return [String]
10
17
  attr_reader :text
18
+
19
+ # The ID of the user who sent this direct message
20
+ #
21
+ # @api public
22
+ # @example
23
+ # direct_message.sender_id
24
+ # @return [Integer]
25
+
26
+ # The ID of the user who received this direct message
27
+ #
28
+ # @api public
29
+ # @example
30
+ # direct_message.recipient_id
31
+ # @return [Integer]
11
32
  attr_reader :sender_id, :recipient_id
12
- alias full_text text
33
+
34
+ # @!method full_text
35
+ # The full text content of the direct message
36
+ # @api public
37
+ # @example
38
+ # direct_message.full_text
39
+ # @return [String]
40
+ alias_method :full_text, :text
13
41
  object_attr_reader :User, :recipient
14
42
  object_attr_reader :User, :sender
15
43
  end
@@ -3,37 +3,61 @@ require "twitter/entities"
3
3
  require "twitter/identity"
4
4
 
5
5
  module Twitter
6
- class DirectMessageEvent < Twitter::Identity
7
- include Twitter::Creatable
8
- include Twitter::Entities
6
+ # Represents a Twitter direct message event
7
+ class DirectMessageEvent < Identity
8
+ include Creatable
9
+ include Entities
9
10
 
11
+ # The timestamp when the event was created
12
+ #
13
+ # @api public
14
+ # @example
15
+ # event.created_timestamp
16
+ # @return [String]
10
17
  attr_reader :created_timestamp
11
18
 
12
19
  object_attr_reader :DirectMessage, :direct_message
13
20
 
21
+ # Initializes a new DirectMessageEvent
22
+ #
23
+ # @api public
24
+ # @example
25
+ # Twitter::DirectMessageEvent.new(attrs)
26
+ # @param attrs [Hash] The attributes hash from the API response
27
+ # @return [Twitter::DirectMessageEvent]
14
28
  def initialize(attrs)
15
29
  attrs = read_from_response(attrs)
16
30
  text = attrs.dig(:message_create, :message_data, :text)
17
31
  urls = attrs.dig(:message_create, :message_data, :entities, :urls)
18
32
 
19
- text.gsub!(urls[0][:url], urls[0][:expanded_url]) if urls.any?
33
+ text = text.gsub(urls[0][:url], urls[0][:expanded_url]) if urls.any?
20
34
 
21
35
  attrs[:direct_message] = build_direct_message(attrs, text)
22
36
  super
23
37
  end
24
38
 
25
- private
39
+ private
26
40
 
27
- # @return [Hash] Normalized hash of attrs
41
+ # Normalizes the response attributes
42
+ #
43
+ # @api private
44
+ # @param attrs [Hash] The raw attributes hash
45
+ # @return [Hash]
28
46
  def read_from_response(attrs)
29
47
  attrs[:event].nil? ? attrs : attrs[:event]
30
48
  end
31
49
 
50
+ # Builds the direct message hash from event attributes
51
+ #
52
+ # @api private
53
+ # @param attrs [Hash] The event attributes
54
+ # @param text [String] The message text
55
+ # @return [Hash]
32
56
  def build_direct_message(attrs, text)
33
- recipient_id = attrs[:message_create][:target][:recipient_id].to_i
34
- sender_id = attrs[:message_create][:sender_id].to_i
35
- {id: attrs[:id].to_i,
36
- created_at: Time.at(attrs[:created_timestamp].to_i / 1000.0),
57
+ recipient_id = Integer(attrs.fetch(:message_create).fetch(:target).fetch(:recipient_id))
58
+ sender_id = Integer(attrs.fetch(:message_create).fetch(:sender_id))
59
+ {id: Integer(attrs.fetch(:id)),
60
+ created_at: Time.at(Integer(attrs.fetch(:created_timestamp)) / 1000.0),
37
61
  sender: {id: sender_id},
38
62
  sender_id:,
39
63
  recipient: {id: recipient_id},
@@ -3,15 +3,36 @@ require "twitter/entities"
3
3
  require "twitter/identity"
4
4
 
5
5
  module Twitter
6
+ # Namespace for direct message related classes
6
7
  module DirectMessages
8
+ # Represents a Twitter welcome message for direct messages
7
9
  class WelcomeMessage < Twitter::Identity
8
10
  include Twitter::Creatable
9
11
  include Twitter::Entities
12
+
13
+ # The text content of the welcome message
14
+ #
15
+ # @api public
16
+ # @example
17
+ # welcome_message.text
10
18
  # @return [String]
11
19
  attr_reader :text
20
+
21
+ # The name of the welcome message
22
+ #
23
+ # @api public
24
+ # @example
25
+ # welcome_message.name
12
26
  # @return [String]
13
27
  attr_reader :name
14
- alias full_text text
28
+
29
+ # @!method full_text
30
+ # The full text content of the welcome message
31
+ # @api public
32
+ # @example
33
+ # welcome_message.full_text
34
+ # @return [String]
35
+ alias_method :full_text, :text
15
36
  end
16
37
  end
17
38
  end
@@ -3,8 +3,15 @@ require "twitter/identity"
3
3
 
4
4
  module Twitter
5
5
  module DirectMessages
6
+ # Represents a Twitter welcome message rule
6
7
  class WelcomeMessageRule < Twitter::Identity
7
8
  include Twitter::Creatable
9
+
10
+ # The ID of the associated welcome message
11
+ #
12
+ # @api public
13
+ # @example
14
+ # rule.welcome_message_id
8
15
  # @return [Integer]
9
16
  attr_reader :welcome_message_id
10
17
  end
@@ -3,11 +3,25 @@ require "twitter/identity"
3
3
 
4
4
  module Twitter
5
5
  module DirectMessages
6
+ # Wraps a Twitter welcome message rule response
6
7
  class WelcomeMessageRuleWrapper < Twitter::Identity
8
+ # The timestamp when the rule was created
9
+ #
10
+ # @api public
11
+ # @example
12
+ # wrapper.created_timestamp
13
+ # @return [String]
7
14
  attr_reader :created_timestamp
8
15
 
9
16
  object_attr_reader "DirectMessages::WelcomeMessageRule", :welcome_message_rule
10
17
 
18
+ # Initializes a new WelcomeMessageRuleWrapper
19
+ #
20
+ # @api public
21
+ # @example
22
+ # Twitter::DirectMessages::WelcomeMessageRuleWrapper.new(attrs)
23
+ # @param attrs [Hash] The attributes hash from the API response
24
+ # @return [Twitter::DirectMessages::WelcomeMessageRuleWrapper]
11
25
  def initialize(attrs)
12
26
  attrs = read_from_response(attrs)
13
27
 
@@ -15,20 +29,29 @@ module Twitter
15
29
  super
16
30
  end
17
31
 
18
- private
32
+ private
19
33
 
20
- # @return [Hash] Normalized hash of attrs
34
+ # Normalizes the response attributes
35
+ #
36
+ # @api private
37
+ # @param attrs [Hash] The raw attributes hash
38
+ # @return [Hash]
21
39
  def read_from_response(attrs)
22
40
  return attrs[:welcome_message_rule] unless attrs[:welcome_message_rule].nil?
23
41
 
24
42
  attrs
25
43
  end
26
44
 
45
+ # Builds the welcome message rule hash from attributes
46
+ #
47
+ # @api private
48
+ # @param attrs [Hash] The wrapper attributes
49
+ # @return [Hash]
27
50
  def build_welcome_message_rule(attrs)
28
51
  {
29
52
  id: attrs[:id].to_i,
30
53
  created_at: Time.at(attrs[:created_timestamp].to_i / 1000.0),
31
- welcome_message_id: attrs[:welcome_message_id].to_i,
54
+ welcome_message_id: attrs[:welcome_message_id].to_i
32
55
  }
33
56
  end
34
57
  end
@@ -3,38 +3,63 @@ require "twitter/identity"
3
3
 
4
4
  module Twitter
5
5
  module DirectMessages
6
+ # Wraps a Twitter welcome message response
6
7
  class WelcomeMessageWrapper < Twitter::Identity
8
+ # The timestamp when the message was created
9
+ #
10
+ # @api public
11
+ # @example
12
+ # wrapper.created_timestamp
13
+ # @return [String]
7
14
  attr_reader :created_timestamp
8
15
 
9
16
  object_attr_reader "DirectMessages::WelcomeMessage", :welcome_message
10
17
 
18
+ # Initializes a new WelcomeMessageWrapper
19
+ #
20
+ # @api public
21
+ # @example
22
+ # Twitter::DirectMessages::WelcomeMessageWrapper.new(attrs)
23
+ # @param attrs [Hash] The attributes hash from the API response
24
+ # @return [Twitter::DirectMessages::WelcomeMessageWrapper]
11
25
  def initialize(attrs)
12
26
  attrs = read_from_response(attrs)
13
- text = attrs.dig(:message_data, :text)
14
- urls = attrs.dig(:message_data, :entities, :urls)
27
+ message_data = attrs.fetch(:message_data)
28
+ text = message_data.fetch(:text)
29
+ urls = message_data.fetch(:entities).fetch(:urls)
15
30
 
16
- text.gsub!(urls[0][:url], urls[0][:expanded_url]) if urls.any?
31
+ text = text.gsub(urls.fetch(0).fetch(:url), urls.fetch(0).fetch(:expanded_url)) if urls.any?
17
32
 
18
- attrs[:welcome_message] = build_welcome_message(attrs, text)
33
+ attrs[:welcome_message] = build_welcome_message(attrs, text, message_data)
19
34
  super
20
35
  end
21
36
 
22
- private
37
+ private
23
38
 
24
- # @return [Hash] Normalized hash of attrs
39
+ # Normalizes the response attributes
40
+ #
41
+ # @api private
42
+ # @param attrs [Hash] The raw attributes hash
43
+ # @return [Hash]
25
44
  def read_from_response(attrs)
26
- return attrs[:welcome_message] unless attrs[:welcome_message].nil?
45
+ return attrs.fetch(:welcome_message) unless attrs[:welcome_message].nil?
27
46
 
28
47
  attrs
29
48
  end
30
49
 
31
- def build_welcome_message(attrs, text)
50
+ # Builds the welcome message hash from attributes
51
+ #
52
+ # @api private
53
+ # @param attrs [Hash] The wrapper attributes
54
+ # @param text [String] The message text
55
+ # @return [Hash]
56
+ def build_welcome_message(attrs, text, message_data)
32
57
  {
33
- id: attrs[:id].to_i,
34
- created_at: Time.at(attrs[:created_timestamp].to_i / 1000.0),
58
+ id: Integer(attrs.fetch(:id)),
59
+ created_at: Time.at(Integer(attrs.fetch(:created_timestamp)) / 1000.0),
35
60
  text:,
36
61
  name: attrs[:name],
37
- entities: attrs.dig(:message_data, :entities),
62
+ entities: message_data.fetch(:entities)
38
63
  }
39
64
  end
40
65
  end
@@ -6,29 +6,50 @@ require "twitter/entity/user_mention"
6
6
  require "twitter/media_factory"
7
7
 
8
8
  module Twitter
9
+ # Provides methods for accessing entities in tweets
9
10
  module Entities
10
11
  include Memoizable
11
12
 
13
+ # Returns true if the object has any entities
14
+ #
15
+ # @api public
16
+ # @example
17
+ # tweet.entities?
12
18
  # @return [Boolean]
13
19
  def entities?
14
- !@attrs[:entities].nil? && @attrs[:entities].any? { |_, array| array.any? }
20
+ !@attrs[:entities].nil? && @attrs[:entities].any? { |_, array| array.any? } # steep:ignore FallbackAny
15
21
  end
16
22
  memoize :entities?
17
23
 
24
+ # Returns an array of hashtags in the object
25
+ #
26
+ # @api public
18
27
  # @note Must include entities in your request for this method to work
28
+ # @example
29
+ # tweet.hashtags
19
30
  # @return [Array<Twitter::Entity::Hashtag>]
20
31
  def hashtags
21
32
  entities(Entity::Hashtag, :hashtags)
22
33
  end
23
34
  memoize :hashtags
24
35
 
36
+ # Returns true if the object has any hashtags
37
+ #
38
+ # @api public
39
+ # @example
40
+ # tweet.hashtags?
25
41
  # @return [Boolean]
26
42
  def hashtags?
27
43
  hashtags.any?
28
44
  end
29
45
  memoize :hashtags?
30
46
 
47
+ # Returns an array of media in the object
48
+ #
49
+ # @api public
31
50
  # @note Must include entities in your request for this method to work
51
+ # @example
52
+ # tweet.media
32
53
  # @return [Array<Twitter::Media>]
33
54
  def media
34
55
  extended_entities = entities(MediaFactory, :media, :extended_entities)
@@ -36,59 +57,114 @@ module Twitter
36
57
  end
37
58
  memoize :media
38
59
 
60
+ # Returns true if the object has any media
61
+ #
62
+ # @api public
63
+ # @example
64
+ # tweet.media?
39
65
  # @return [Boolean]
40
66
  def media?
41
67
  media.any?
42
68
  end
43
69
  memoize :media?
44
70
 
71
+ # Returns an array of symbols in the object
72
+ #
73
+ # @api public
45
74
  # @note Must include entities in your request for this method to work
75
+ # @example
76
+ # tweet.symbols
46
77
  # @return [Array<Twitter::Entity::Symbol>]
47
78
  def symbols
48
79
  entities(Entity::Symbol, :symbols)
49
80
  end
50
81
  memoize :symbols
51
82
 
83
+ # Returns true if the object has any symbols
84
+ #
85
+ # @api public
86
+ # @example
87
+ # tweet.symbols?
52
88
  # @return [Boolean]
53
89
  def symbols?
54
90
  symbols.any?
55
91
  end
56
92
  memoize :symbols?
57
93
 
94
+ # Returns an array of URIs in the object
95
+ #
96
+ # @api public
58
97
  # @note Must include entities in your request for this method to work
98
+ # @example
99
+ # tweet.uris
59
100
  # @return [Array<Twitter::Entity::URI>]
60
101
  def uris
61
102
  entities(Entity::URI, :urls)
62
103
  end
63
104
  memoize :uris
64
- alias urls uris
65
105
 
106
+ # @!method urls
107
+ # Returns an array of URLs in the object
108
+ # @api public
109
+ # @example
110
+ # tweet.urls
111
+ # @return [Array<Twitter::Entity::URI>]
112
+ alias_method :urls, :uris
113
+
114
+ # Returns true if the object has any URIs
115
+ #
116
+ # @api public
117
+ # @example
118
+ # tweet.uris?
66
119
  # @return [Boolean]
67
120
  def uris?
68
121
  uris.any?
69
122
  end
70
- alias urls? uris?
71
123
 
124
+ # @!method urls?
125
+ # Returns true if the object has any URLs
126
+ # @api public
127
+ # @example
128
+ # tweet.urls?
129
+ # @return [Boolean]
130
+ alias_method :urls?, :uris?
131
+
132
+ # Returns an array of user mentions in the object
133
+ #
134
+ # @api public
72
135
  # @note Must include entities in your request for this method to work
136
+ # @example
137
+ # tweet.user_mentions
73
138
  # @return [Array<Twitter::Entity::UserMention>]
74
139
  def user_mentions
75
140
  entities(Entity::UserMention, :user_mentions)
76
141
  end
77
142
  memoize :user_mentions
78
143
 
144
+ # Returns true if the object has any user mentions
145
+ #
146
+ # @api public
147
+ # @example
148
+ # tweet.user_mentions?
79
149
  # @return [Boolean]
80
150
  def user_mentions?
81
151
  user_mentions.any?
82
152
  end
83
153
  memoize :user_mentions?
84
154
 
85
- private
155
+ private
86
156
 
87
- # @param klass [Class]
88
- # @param key2 [Symbol]
89
- # @param key1 [Symbol]
157
+ # Extracts entities of a given type from the attributes
158
+ #
159
+ # @api private
160
+ # @param klass [Class] The class to instantiate for each entity
161
+ # @param key2 [Symbol] The key within the entities hash
162
+ # @param key1 [Symbol] The top-level key containing entities
163
+ # @return [Array]
90
164
  def entities(klass, key2, key1 = :entities)
91
- @attrs.fetch(key1.to_sym, {}).fetch(key2.to_sym, []).collect do |entity|
165
+ empty_hash = {} # : Hash[Symbol, untyped]
166
+ empty_array = [] # : Array[untyped]
167
+ @attrs.fetch(key1.to_sym, empty_hash).fetch(key2.to_sym, empty_array).collect do |entity| # steep:ignore FallbackAny
92
168
  klass.new(entity)
93
169
  end
94
170
  end
@@ -2,7 +2,13 @@ require "twitter/entity"
2
2
 
3
3
  module Twitter
4
4
  class Entity
5
- class Hashtag < Twitter::Entity
5
+ # Represents a Twitter hashtag entity
6
+ class Hashtag < Entity
7
+ # The text of the hashtag without the hash symbol
8
+ #
9
+ # @api public
10
+ # @example
11
+ # hashtag.text
6
12
  # @return [String]
7
13
  attr_reader :text
8
14
  end
@@ -2,7 +2,13 @@ require "twitter/entity"
2
2
 
3
3
  module Twitter
4
4
  class Entity
5
- class Symbol < Twitter::Entity
5
+ # Represents a Twitter cashtag symbol entity
6
+ class Symbol < Entity
7
+ # The text of the cashtag without the dollar sign
8
+ #
9
+ # @api public
10
+ # @example
11
+ # symbol.text
6
12
  # @return [String]
7
13
  attr_reader :text
8
14
  end
@@ -2,7 +2,8 @@ require "twitter/entity"
2
2
 
3
3
  module Twitter
4
4
  class Entity
5
- class URI < Twitter::Entity
5
+ # Represents a URI entity in a tweet
6
+ class URI < Entity
6
7
  display_uri_attr_reader
7
8
  uri_attr_reader :expanded_uri, :uri
8
9
  end
@@ -2,9 +2,28 @@ require "twitter/entity"
2
2
 
3
3
  module Twitter
4
4
  class Entity
5
- class UserMention < Twitter::Entity
5
+ # Represents a Twitter user mention entity
6
+ class UserMention < Entity
7
+ # The ID of the mentioned user
8
+ #
9
+ # @api public
10
+ # @example
11
+ # user_mention.id
6
12
  # @return [Integer]
7
13
  attr_reader :id
14
+
15
+ # The display name of the mentioned user
16
+ #
17
+ # @api public
18
+ # @example
19
+ # user_mention.name
20
+ # @return [String]
21
+
22
+ # The screen name of the mentioned user
23
+ #
24
+ # @api public
25
+ # @example
26
+ # user_mention.screen_name
8
27
  # @return [String]
9
28
  attr_reader :name, :screen_name
10
29
  end
@@ -1,7 +1,13 @@
1
1
  require "twitter/base"
2
2
 
3
3
  module Twitter
4
- class Entity < Twitter::Base
4
+ # Represents a Twitter entity with position information
5
+ class Entity < Base
6
+ # The indices of this entity in the text
7
+ #
8
+ # @api public
9
+ # @example
10
+ # entity.indices
5
11
  # @return [Array<Integer>]
6
12
  attr_reader :indices
7
13
  end