twitter 4.8.1 → 5.0.0.rc.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.
Files changed (197) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG.md +30 -0
  3. data/LICENSE.md +1 -1
  4. data/README.md +386 -266
  5. data/lib/twitter.rb +4 -39
  6. data/lib/twitter/arguments.rb +11 -0
  7. data/lib/twitter/base.rb +89 -68
  8. data/lib/twitter/client.rb +69 -110
  9. data/lib/twitter/configuration.rb +7 -3
  10. data/lib/twitter/creatable.rb +2 -4
  11. data/lib/twitter/cursor.rb +50 -42
  12. data/lib/twitter/direct_message.rb +2 -11
  13. data/lib/twitter/entity/uri.rb +13 -0
  14. data/lib/twitter/enumerable.rb +15 -0
  15. data/lib/twitter/error.rb +55 -7
  16. data/lib/twitter/error/already_favorited.rb +1 -1
  17. data/lib/twitter/error/already_posted.rb +10 -0
  18. data/lib/twitter/error/already_retweeted.rb +1 -1
  19. data/lib/twitter/error/bad_gateway.rb +2 -3
  20. data/lib/twitter/error/bad_request.rb +2 -2
  21. data/lib/twitter/error/forbidden.rb +2 -2
  22. data/lib/twitter/error/gateway_timeout.rb +2 -3
  23. data/lib/twitter/error/internal_server_error.rb +2 -3
  24. data/lib/twitter/error/not_acceptable.rb +2 -2
  25. data/lib/twitter/error/not_found.rb +2 -2
  26. data/lib/twitter/error/service_unavailable.rb +2 -3
  27. data/lib/twitter/error/too_many_requests.rb +2 -2
  28. data/lib/twitter/error/unauthorized.rb +2 -2
  29. data/lib/twitter/error/unprocessable_entity.rb +2 -2
  30. data/lib/twitter/factory.rb +2 -8
  31. data/lib/twitter/geo_factory.rb +2 -2
  32. data/lib/twitter/geo_results.rb +36 -0
  33. data/lib/twitter/identity.rb +0 -22
  34. data/lib/twitter/list.rb +18 -4
  35. data/lib/twitter/media/photo.rb +3 -3
  36. data/lib/twitter/media_factory.rb +2 -2
  37. data/lib/twitter/null_object.rb +24 -0
  38. data/lib/twitter/oembed.rb +3 -2
  39. data/lib/twitter/place.rb +15 -9
  40. data/lib/twitter/profile_banner.rb +5 -3
  41. data/lib/twitter/rate_limit.rb +1 -17
  42. data/lib/twitter/relationship.rb +2 -10
  43. data/lib/twitter/rest/api/direct_messages.rb +135 -0
  44. data/lib/twitter/rest/api/favorites.rb +120 -0
  45. data/lib/twitter/rest/api/friends_and_followers.rb +290 -0
  46. data/lib/twitter/rest/api/help.rb +58 -0
  47. data/lib/twitter/rest/api/lists.rb +491 -0
  48. data/lib/twitter/rest/api/oauth.rb +45 -0
  49. data/lib/twitter/rest/api/places_and_geo.rb +104 -0
  50. data/lib/twitter/rest/api/saved_searches.rb +91 -0
  51. data/lib/twitter/rest/api/search.rb +37 -0
  52. data/lib/twitter/rest/api/spam_reporting.rb +29 -0
  53. data/lib/twitter/rest/api/suggested_users.rb +51 -0
  54. data/lib/twitter/rest/api/timelines.rb +202 -0
  55. data/lib/twitter/rest/api/trends.rb +58 -0
  56. data/lib/twitter/rest/api/tweets.rb +293 -0
  57. data/lib/twitter/rest/api/undocumented.rb +52 -0
  58. data/lib/twitter/rest/api/users.rb +383 -0
  59. data/lib/twitter/rest/api/utils.rb +219 -0
  60. data/lib/twitter/rest/client.rb +193 -0
  61. data/lib/twitter/rest/request/multipart_with_file.rb +36 -0
  62. data/lib/twitter/rest/response/parse_json.rb +27 -0
  63. data/lib/twitter/{response → rest/response}/raise_error.rb +8 -11
  64. data/lib/twitter/search_results.rb +33 -21
  65. data/lib/twitter/settings.rb +1 -6
  66. data/lib/twitter/size.rb +1 -1
  67. data/lib/twitter/streaming/client.rb +77 -0
  68. data/lib/twitter/streaming/connection.rb +22 -0
  69. data/lib/twitter/streaming/response.rb +30 -0
  70. data/lib/twitter/suggestion.rb +4 -2
  71. data/lib/twitter/token.rb +8 -0
  72. data/lib/twitter/trend.rb +2 -1
  73. data/lib/twitter/trend_results.rb +59 -0
  74. data/lib/twitter/tweet.rb +41 -85
  75. data/lib/twitter/user.rb +51 -41
  76. data/lib/twitter/version.rb +4 -4
  77. data/spec/fixtures/already_posted.json +1 -0
  78. data/spec/fixtures/ids_list.json +1 -1
  79. data/spec/fixtures/ids_list2.json +1 -1
  80. data/spec/fixtures/search.json +1 -1
  81. data/spec/fixtures/search_malformed.json +1 -1
  82. data/spec/fixtures/track_streaming.json +3 -0
  83. data/spec/helper.rb +8 -13
  84. data/spec/twitter/base_spec.rb +25 -99
  85. data/spec/twitter/configuration_spec.rb +1 -1
  86. data/spec/twitter/cursor_spec.rb +13 -31
  87. data/spec/twitter/direct_message_spec.rb +41 -8
  88. data/spec/twitter/entity/uri_spec.rb +74 -0
  89. data/spec/twitter/error_spec.rb +59 -11
  90. data/spec/twitter/geo/point_spec.rb +1 -1
  91. data/spec/twitter/geo_factory_spec.rb +3 -3
  92. data/spec/twitter/geo_results_spec.rb +35 -0
  93. data/spec/twitter/identifiable_spec.rb +0 -21
  94. data/spec/twitter/list_spec.rb +51 -8
  95. data/spec/twitter/media/photo_spec.rb +118 -3
  96. data/spec/twitter/media_factory_spec.rb +2 -2
  97. data/spec/twitter/null_object_spec.rb +26 -0
  98. data/spec/twitter/oembed_spec.rb +69 -45
  99. data/spec/twitter/place_spec.rb +68 -12
  100. data/spec/twitter/profile_banner_spec.rb +1 -1
  101. data/spec/twitter/rate_limit_spec.rb +12 -12
  102. data/spec/twitter/relationship_spec.rb +31 -9
  103. data/spec/twitter/{api → rest/api}/direct_messages_spec.rb +22 -9
  104. data/spec/twitter/{api → rest/api}/favorites_spec.rb +80 -7
  105. data/spec/twitter/{api → rest/api}/friends_and_followers_spec.rb +104 -65
  106. data/spec/twitter/{api → rest/api}/geo_spec.rb +10 -10
  107. data/spec/twitter/{api → rest/api}/help_spec.rb +6 -6
  108. data/spec/twitter/{api → rest/api}/lists_spec.rb +77 -56
  109. data/spec/twitter/{api → rest/api}/oauth_spec.rb +6 -6
  110. data/spec/twitter/{api → rest/api}/saved_searches_spec.rb +7 -7
  111. data/spec/twitter/{api → rest/api}/search_spec.rb +8 -9
  112. data/spec/twitter/{api → rest/api}/spam_reporting_spec.rb +3 -3
  113. data/spec/twitter/{api → rest/api}/suggested_users_spec.rb +5 -5
  114. data/spec/twitter/{api → rest/api}/timelines_spec.rb +9 -9
  115. data/spec/twitter/{api → rest/api}/trends_spec.rb +6 -6
  116. data/spec/twitter/rest/api/tweets_spec.rb +503 -0
  117. data/spec/twitter/{api → rest/api}/undocumented_spec.rb +19 -45
  118. data/spec/twitter/{api → rest/api}/users_spec.rb +60 -35
  119. data/spec/twitter/rest/client_spec.rb +193 -0
  120. data/spec/twitter/saved_search_spec.rb +11 -0
  121. data/spec/twitter/search_results_spec.rb +29 -42
  122. data/spec/twitter/settings_spec.rb +17 -6
  123. data/spec/twitter/streaming/client_spec.rb +75 -0
  124. data/spec/twitter/token_spec.rb +16 -0
  125. data/spec/twitter/trend_results_spec.rb +89 -0
  126. data/spec/twitter/trend_spec.rb +23 -0
  127. data/spec/twitter/tweet_spec.rb +122 -115
  128. data/spec/twitter/user_spec.rb +136 -77
  129. data/spec/twitter_spec.rb +0 -119
  130. data/twitter.gemspec +8 -5
  131. metadata +148 -141
  132. metadata.gz.sig +0 -0
  133. data/lib/twitter/action/favorite.rb +0 -19
  134. data/lib/twitter/action/follow.rb +0 -30
  135. data/lib/twitter/action/list_member_added.rb +0 -39
  136. data/lib/twitter/action/mention.rb +0 -46
  137. data/lib/twitter/action/reply.rb +0 -27
  138. data/lib/twitter/action/retweet.rb +0 -27
  139. data/lib/twitter/action/tweet.rb +0 -20
  140. data/lib/twitter/action_factory.rb +0 -22
  141. data/lib/twitter/api/arguments.rb +0 -13
  142. data/lib/twitter/api/direct_messages.rb +0 -148
  143. data/lib/twitter/api/favorites.rb +0 -126
  144. data/lib/twitter/api/friends_and_followers.rb +0 -334
  145. data/lib/twitter/api/help.rb +0 -64
  146. data/lib/twitter/api/lists.rb +0 -618
  147. data/lib/twitter/api/oauth.rb +0 -44
  148. data/lib/twitter/api/places_and_geo.rb +0 -121
  149. data/lib/twitter/api/saved_searches.rb +0 -99
  150. data/lib/twitter/api/search.rb +0 -37
  151. data/lib/twitter/api/spam_reporting.rb +0 -30
  152. data/lib/twitter/api/suggested_users.rb +0 -55
  153. data/lib/twitter/api/timelines.rb +0 -214
  154. data/lib/twitter/api/trends.rb +0 -63
  155. data/lib/twitter/api/tweets.rb +0 -304
  156. data/lib/twitter/api/undocumented.rb +0 -97
  157. data/lib/twitter/api/users.rb +0 -439
  158. data/lib/twitter/api/utils.rb +0 -187
  159. data/lib/twitter/configurable.rb +0 -96
  160. data/lib/twitter/default.rb +0 -102
  161. data/lib/twitter/entity/url.rb +0 -9
  162. data/lib/twitter/error/client_error.rb +0 -35
  163. data/lib/twitter/error/decode_error.rb +0 -9
  164. data/lib/twitter/error/identity_map_key_error.rb +0 -9
  165. data/lib/twitter/error/server_error.rb +0 -28
  166. data/lib/twitter/exceptable.rb +0 -36
  167. data/lib/twitter/identity_map.rb +0 -22
  168. data/lib/twitter/request/multipart_with_file.rb +0 -34
  169. data/lib/twitter/response/parse_json.rb +0 -25
  170. data/spec/fixtures/about_me.json +0 -1
  171. data/spec/fixtures/activity_summary.json +0 -1
  172. data/spec/fixtures/bad_gateway.json +0 -1
  173. data/spec/fixtures/bad_request.json +0 -1
  174. data/spec/fixtures/by_friends.json +0 -1
  175. data/spec/fixtures/end_session.json +0 -1
  176. data/spec/fixtures/forbidden.json +0 -1
  177. data/spec/fixtures/internal_server_error.json +0 -1
  178. data/spec/fixtures/not_acceptable.json +0 -1
  179. data/spec/fixtures/phoenix_search.phoenix +0 -1
  180. data/spec/fixtures/resolve.json +0 -1
  181. data/spec/fixtures/service_unavailable.json +0 -1
  182. data/spec/fixtures/totals.json +0 -1
  183. data/spec/fixtures/trends.json +0 -1
  184. data/spec/fixtures/unauthorized.json +0 -1
  185. data/spec/fixtures/video_facets.json +0 -1
  186. data/spec/twitter/action/favorite_spec.rb +0 -29
  187. data/spec/twitter/action/follow_spec.rb +0 -29
  188. data/spec/twitter/action/list_member_added_spec.rb +0 -41
  189. data/spec/twitter/action/mention_spec.rb +0 -52
  190. data/spec/twitter/action/reply_spec.rb +0 -41
  191. data/spec/twitter/action/retweet_spec.rb +0 -41
  192. data/spec/twitter/action_factory_spec.rb +0 -35
  193. data/spec/twitter/action_spec.rb +0 -16
  194. data/spec/twitter/api/tweets_spec.rb +0 -285
  195. data/spec/twitter/client_spec.rb +0 -223
  196. data/spec/twitter/error/client_error_spec.rb +0 -23
  197. data/spec/twitter/error/server_error_spec.rb +0 -20
@@ -1,9 +1,9 @@
1
- require 'twitter/error/client_error'
1
+ require 'twitter/error'
2
2
 
3
3
  module Twitter
4
4
  class Error
5
5
  # Raised when Twitter returns the HTTP status code 401
6
- class Unauthorized < Twitter::Error::ClientError
6
+ class Unauthorized < Twitter::Error
7
7
  HTTP_STATUS_CODE = 401
8
8
  end
9
9
  end
@@ -1,9 +1,9 @@
1
- require 'twitter/error/client_error'
1
+ require 'twitter/error'
2
2
 
3
3
  module Twitter
4
4
  class Error
5
5
  # Raised when Twitter returns the HTTP status code 422
6
- class UnprocessableEntity < Twitter::Error::ClientError
6
+ class UnprocessableEntity < Twitter::Error
7
7
  HTTP_STATUS_CODE = 422
8
8
  end
9
9
  end
@@ -1,17 +1,11 @@
1
1
  module Twitter
2
2
  class Factory
3
3
 
4
- # Instantiates a new action object
5
- #
6
- # @param attrs [Hash]
7
- # @raise [ArgumentError] Error raised when supplied argument is missing an :action key.
8
- # @return [Twitter::Action::Favorite, Twitter::Action::Follow, Twitter::Action::ListMemberAdded, Twitter::Action::Mention, Twitter::Action::Reply, Twitter::Action::Retweet]
9
- def self.fetch_or_new(method, klass, attrs={})
10
- return unless attrs
4
+ def self.new(method, klass, attrs={})
11
5
  type = attrs.delete(method.to_sym)
12
6
  if type
13
7
  const_name = type.gsub(/\/(.?)/){"::#{$1.upcase}"}.gsub(/(?:^|_)(.)/){$1.upcase}
14
- klass.const_get(const_name.to_sym).fetch_or_new(attrs)
8
+ klass.const_get(const_name.to_sym).new(attrs)
15
9
  else
16
10
  raise ArgumentError, "argument must have :#{method} key"
17
11
  end
@@ -5,12 +5,12 @@ require 'twitter/geo/polygon'
5
5
  module Twitter
6
6
  class GeoFactory < Twitter::Factory
7
7
 
8
- # Instantiates a new geo object
8
+ # Construct a new geo object
9
9
  #
10
10
  # @param attrs [Hash]
11
11
  # @raise [ArgumentError] Error raised when supplied argument is missing a :type key.
12
12
  # @return [Twitter::Geo]
13
- def self.fetch_or_new(attrs={})
13
+ def self.new(attrs={})
14
14
  super(:type, Twitter::Geo, attrs)
15
15
  end
16
16
 
@@ -0,0 +1,36 @@
1
+ require 'twitter/enumerable'
2
+
3
+ module Twitter
4
+ class GeoResults
5
+ include Twitter::Enumerable
6
+ attr_reader :attrs
7
+ alias to_h attrs
8
+ alias to_hash attrs
9
+ alias to_hsh attrs
10
+
11
+ # Construct a new SearchResults object from a response hash
12
+ #
13
+ # @param response [Hash]
14
+ # @return [Twitter::Base]
15
+ def self.from_response(response={})
16
+ new(response[:body])
17
+ end
18
+
19
+ # Initializes a new SearchResults object
20
+ #
21
+ # @param attrs [Hash]
22
+ # @return [Twitter::GeoResults]
23
+ def initialize(attrs={})
24
+ @attrs = attrs
25
+ @collection = Array(@attrs[:result][:places]).map do |place|
26
+ Twitter::Place.new(place)
27
+ end
28
+ end
29
+
30
+ # @return [String]
31
+ def token
32
+ @attrs[:token]
33
+ end
34
+
35
+ end
36
+ end
@@ -1,30 +1,8 @@
1
1
  require 'twitter/base'
2
- require 'twitter/error/identity_map_key_error'
3
2
 
4
3
  module Twitter
5
4
  class Identity < Twitter::Base
6
5
 
7
- def self.fetch(attrs)
8
- return unless identity_map
9
-
10
- id = attrs[:id]
11
- if id && object = identity_map.fetch(id)
12
- return object.update(attrs)
13
- end
14
-
15
- return yield if block_given?
16
- raise Twitter::Error::IdentityMapKeyError, "key not found"
17
- end
18
-
19
- # Stores an object in the identity map.
20
- #
21
- # @param object [Object]
22
- # @return [Twitter::Identity]
23
- def self.store(object)
24
- return object unless identity_map
25
- identity_map.store(object.id, object)
26
- end
27
-
28
6
  # Initializes a new object
29
7
  #
30
8
  # @param attrs [Hash]
@@ -5,12 +5,26 @@ module Twitter
5
5
  class List < Twitter::Identity
6
6
  include Twitter::Creatable
7
7
  attr_reader :description, :following, :full_name, :member_count,
8
- :mode, :name, :slug, :subscriber_count, :uri
8
+ :mode, :name, :slug, :subscriber_count
9
+ object_attr_reader :User, :user
9
10
 
10
- # @return [Twitter::User]
11
- def user
12
- @user ||= Twitter::User.fetch_or_new(@attrs[:user])
11
+ # @return [URI] The URI to the list members.
12
+ def members_uri
13
+ @members_uri ||= ::URI.parse("https://twitter.com/#{user.screen_name}/#{slug}/members")
13
14
  end
15
+ alias members_url members_uri
16
+
17
+ # @return [URI] The URI to the list subscribers.
18
+ def subscribers_uri
19
+ @subscribers_uri ||= ::URI.parse("https://twitter.com/#{user.screen_name}/#{slug}/subscribers")
20
+ end
21
+ alias subscribers_url subscribers_uri
22
+
23
+ # @return [URI] The URI to the list.
24
+ def uri
25
+ @uri ||= ::URI.parse("https://twitter.com/#{user.screen_name}/#{slug}")
26
+ end
27
+ alias url uri
14
28
 
15
29
  end
16
30
  end
@@ -3,15 +3,15 @@ require 'twitter/identity'
3
3
  module Twitter
4
4
  module Media
5
5
  class Photo < Twitter::Identity
6
- attr_reader :display_url, :expanded_url, :indices, :media_url,
7
- :media_url_https, :url
6
+ attr_reader :indices
7
+ uri_attr_reader :display_uri, :expanded_uri, :media_uri, :media_uri_https, :uri
8
8
 
9
9
  # Returns an array of photo sizes
10
10
  #
11
11
  # @return [Array<Twitter::Size>]
12
12
  def sizes
13
13
  @sizes ||= Array(@attrs[:sizes]).inject({}) do |object, (key, value)|
14
- object[key] = Twitter::Size.fetch_or_new(value)
14
+ object[key] = Twitter::Size.new(value)
15
15
  object
16
16
  end
17
17
  end
@@ -4,12 +4,12 @@ require 'twitter/media/photo'
4
4
  module Twitter
5
5
  class MediaFactory < Twitter::Factory
6
6
 
7
- # Instantiates a new media object
7
+ # Construct a new media object
8
8
  #
9
9
  # @param attrs [Hash]
10
10
  # @raise [ArgumentError] Error raised when supplied argument is missing a :type key.
11
11
  # @return [Twitter::Media]
12
- def self.fetch_or_new(attrs={})
12
+ def self.new(attrs={})
13
13
  super(:type, Twitter::Media, attrs)
14
14
  end
15
15
 
@@ -0,0 +1,24 @@
1
+ require 'singleton'
2
+
3
+ module Twitter
4
+ class NullObject
5
+ include Singleton
6
+
7
+ def nil?
8
+ true
9
+ end
10
+
11
+ def method_missing(*args, &block)
12
+ self
13
+ end
14
+
15
+ def respond_to?(method_name, include_private=false)
16
+ true
17
+ end if RUBY_VERSION < "1.9"
18
+
19
+ def respond_to_missing?(method_name, include_private=false)
20
+ true
21
+ end if RUBY_VERSION >= "1.9"
22
+
23
+ end
24
+ end
@@ -2,7 +2,8 @@ require 'twitter/base'
2
2
 
3
3
  module Twitter
4
4
  class OEmbed < Twitter::Base
5
- attr_reader :author_name, :author_url, :cache_age, :height, :html,
6
- :provider_name, :provider_url, :type, :url, :version, :width
5
+ attr_reader :author_name, :cache_age, :height, :html, :provider_name,
6
+ :type, :version, :width
7
+ uri_attr_reader :author_uri, :provider_uri, :uri
7
8
  end
8
9
  end
@@ -2,29 +2,35 @@ require 'twitter/identity'
2
2
 
3
3
  module Twitter
4
4
  class Place < Twitter::Identity
5
- attr_reader :attributes, :country, :full_name, :name, :url, :woeid
5
+ attr_reader :attributes, :country, :full_name, :name, :woeid
6
6
  alias woe_id woeid
7
-
8
- # @return [Twitter::Geo]
9
- def bounding_box
10
- @bounding_box ||= Twitter::GeoFactory.fetch_or_new(@attrs[:bounding_box])
11
- end
7
+ object_attr_reader :GeoFactory, :bounding_box
8
+ object_attr_reader :Place, :contained_within
9
+ alias contained? contained_within?
10
+ uri_attr_reader :uri
12
11
 
13
12
  # @return [String]
14
13
  def country_code
15
- @country_code ||= @attrs[:country_code] || @attrs[:countryCode]
14
+ memoize(:country_code) do
15
+ @attrs[:country_code] || @attrs[:countryCode]
16
+ end
16
17
  end
17
18
 
18
19
  # @return [Integer]
19
20
  def parent_id
20
- @parent_id ||= @attrs[:parentid]
21
+ memoize(:parent_id) do
22
+ @attrs[:parentid]
23
+ end
21
24
  end
22
25
 
23
26
  # @return [String]
24
27
  def place_type
25
- @place_type ||= @attrs[:place_type] || @attrs[:placeType] && @attrs[:placeType][:name]
28
+ memoize(:place_type) do
29
+ @attrs[:place_type] || @attrs[:placeType] && @attrs[:placeType][:name]
30
+ end
26
31
  end
27
32
 
33
+ # return [Integer]
28
34
  def id
29
35
  @attrs[:id] || @attrs[:woeid]
30
36
  end
@@ -7,9 +7,11 @@ module Twitter
7
7
  #
8
8
  # @return [Array<Twitter::Size>]
9
9
  def sizes
10
- @sizes ||= Array(@attrs[:sizes]).inject({}) do |object, (key, value)|
11
- object[key] = Twitter::Size.fetch_or_new(value)
12
- object
10
+ memoize(:sizes) do
11
+ Array(@attrs[:sizes]).inject({}) do |object, (key, value)|
12
+ object[key] = Twitter::Size.new(value)
13
+ object
14
+ end
13
15
  end
14
16
  end
15
17
 
@@ -1,12 +1,5 @@
1
1
  module Twitter
2
- class RateLimit
3
- attr_reader :attrs
4
- alias to_hash attrs
5
-
6
- # @return [Twitter::RateLimit]
7
- def initialize(attrs={})
8
- @attrs = attrs
9
- end
2
+ class RateLimit < Twitter::Base
10
3
 
11
4
  # @return [Integer]
12
5
  def limit
@@ -32,14 +25,5 @@ module Twitter
32
25
  end
33
26
  alias retry_after reset_in
34
27
 
35
- # Update the attributes of a RateLimit
36
- #
37
- # @param attrs [Hash]
38
- # @return [Twitter::RateLimit]
39
- def update(attrs)
40
- @attrs.update(attrs)
41
- self
42
- end
43
-
44
28
  end
45
29
  end
@@ -2,6 +2,8 @@ require 'twitter/base'
2
2
 
3
3
  module Twitter
4
4
  class Relationship < Twitter::Base
5
+ object_attr_reader :SourceUser, :source
6
+ object_attr_reader :TargetUser, :target
5
7
 
6
8
  # Initializes a new object
7
9
  #
@@ -11,16 +13,6 @@ module Twitter
11
13
  @attrs = attrs[:relationship]
12
14
  end
13
15
 
14
- # @return [Twitter::SourceUser]
15
- def source
16
- @source ||= Twitter::SourceUser.fetch_or_new(@attrs[:source])
17
- end
18
-
19
- # @return [Twitter::TargetUser]
20
- def target
21
- @target ||= Twitter::TargetUser.fetch_or_new(@attrs[:target])
22
- end
23
-
24
16
  # Update the attributes of a Relationship
25
17
  #
26
18
  # @param attrs [Hash]
@@ -0,0 +1,135 @@
1
+ require 'twitter/arguments'
2
+ require 'twitter/direct_message'
3
+ require 'twitter/rest/api/utils'
4
+ require 'twitter/user'
5
+
6
+ module Twitter
7
+ module REST
8
+ module API
9
+ module DirectMessages
10
+ include Twitter::REST::API::Utils
11
+
12
+ # Returns the 20 most recent direct messages sent to the authenticating user
13
+ #
14
+ # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages
15
+ # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
16
+ # @rate_limited Yes
17
+ # @authentication Requires user context
18
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
19
+ # @return [Array<Twitter::DirectMessage>] Direct messages sent to the authenticating user.
20
+ # @param options [Hash] A customizable set of options.
21
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
22
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
23
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
24
+ # @option options [Integer] :page Specifies the page of results to retrieve.
25
+ def direct_messages_received(options={})
26
+ objects_from_response(Twitter::DirectMessage, :get, "/1.1/direct_messages.json", options)
27
+ end
28
+
29
+ # Returns the 20 most recent direct messages sent by the authenticating user
30
+ #
31
+ # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/sent
32
+ # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
33
+ # @rate_limited Yes
34
+ # @authentication Requires user context
35
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
36
+ # @return [Array<Twitter::DirectMessage>] Direct messages sent by the authenticating user.
37
+ # @param options [Hash] A customizable set of options.
38
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
39
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
40
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
41
+ # @option options [Integer] :page Specifies the page of results to retrieve.
42
+ def direct_messages_sent(options={})
43
+ objects_from_response(Twitter::DirectMessage, :get, "/1.1/direct_messages/sent.json", options)
44
+ end
45
+
46
+ # Returns a direct message
47
+ #
48
+ # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/show
49
+ # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
50
+ # @rate_limited Yes
51
+ # @authentication Requires user context
52
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
53
+ # @return [Twitter::DirectMessage] The requested messages.
54
+ # @param id [Integer] A direct message ID.
55
+ # @param options [Hash] A customizable set of options.
56
+ def direct_message(id, options={})
57
+ options[:id] = id
58
+ object_from_response(Twitter::DirectMessage, :get, "/1.1/direct_messages/show.json", options)
59
+ end
60
+
61
+ # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
62
+ # @rate_limited Yes
63
+ # @authentication Requires user context
64
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
65
+ # @return [Array<Twitter::DirectMessage>] The requested messages.
66
+ # @overload direct_messages(options={})
67
+ # Returns the 20 most recent direct messages sent to the authenticating user
68
+ #
69
+ # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages
70
+ # @param options [Hash] A customizable set of options.
71
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
72
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
73
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
74
+ # @option options [Integer] :page Specifies the page of results to retrieve.
75
+ # @overload direct_messages(*ids)
76
+ # Returns direct messages
77
+ #
78
+ # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/show
79
+ # @param ids [Enumerable<Integer>] A collection of direct message IDs.
80
+ # @overload direct_messages(*ids, options)
81
+ # Returns direct messages
82
+ #
83
+ # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/show
84
+ # @param ids [Enumerable<Integer>] A collection of direct message IDs.
85
+ # @param options [Hash] A customizable set of options.
86
+ def direct_messages(*args)
87
+ arguments = Twitter::Arguments.new(args)
88
+ if arguments.empty?
89
+ direct_messages_received(arguments.options)
90
+ else
91
+ arguments.flatten.threaded_map do |id|
92
+ direct_message(id, arguments.options)
93
+ end
94
+ end
95
+ end
96
+
97
+ # Destroys direct messages
98
+ #
99
+ # @see https://dev.twitter.com/docs/api/1.1/post/direct_messages/destroy
100
+ # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
101
+ # @rate_limited No
102
+ # @authentication Requires user context
103
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
104
+ # @return [Array<Twitter::DirectMessage>] Deleted direct message.
105
+ # @overload direct_message_destroy(*ids)
106
+ # @param ids [Enumerable<Integer>] A collection of direct message IDs.
107
+ # @overload direct_message_destroy(*ids, options)
108
+ # @param ids [Enumerable<Integer>] A collection of direct message IDs.
109
+ # @param options [Hash] A customizable set of options.
110
+ def direct_message_destroy(*args)
111
+ threaded_objects_from_response(Twitter::DirectMessage, :post, "/1.1/direct_messages/destroy.json", args)
112
+ end
113
+
114
+ # Sends a new direct message to the specified user from the authenticating user
115
+ #
116
+ # @see https://dev.twitter.com/docs/api/1.1/post/direct_messages/new
117
+ # @rate_limited No
118
+ # @authentication Requires user context
119
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
120
+ # @return [Twitter::DirectMessage] The sent message.
121
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
122
+ # @param text [String] The text of your direct message, up to 140 characters.
123
+ # @param options [Hash] A customizable set of options.
124
+ def direct_message_create(user, text, options={})
125
+ merge_user!(options, user)
126
+ options[:text] = text
127
+ object_from_response(Twitter::DirectMessage, :post, "/1.1/direct_messages/new.json", options)
128
+ end
129
+ alias d direct_message_create
130
+ alias m direct_message_create
131
+
132
+ end
133
+ end
134
+ end
135
+ end