Permalink
Browse files

Move Twitter::Client into REST namespace

  • Loading branch information...
1 parent 5d83f1f commit 5b8c3fd243227888fc0886b0bf864ecd3a018f99 @sferik committed Aug 18, 2013
Showing with 3,063 additions and 3,023 deletions.
  1. +4 −4 README.md
  2. +1 −1 lib/twitter.rb
  3. +0 −13 lib/twitter/api/arguments.rb
  4. +0 −133 lib/twitter/api/direct_messages.rb
  5. +0 −118 lib/twitter/api/favorites.rb
  6. +0 −288 lib/twitter/api/friends_and_followers.rb
  7. +0 −56 lib/twitter/api/help.rb
  8. +0 −489 lib/twitter/api/lists.rb
  9. +0 −42 lib/twitter/api/oauth.rb
  10. +0 −102 lib/twitter/api/places_and_geo.rb
  11. +0 −89 lib/twitter/api/saved_searches.rb
  12. +0 −35 lib/twitter/api/search.rb
  13. +0 −27 lib/twitter/api/spam_reporting.rb
  14. +0 −49 lib/twitter/api/suggested_users.rb
  15. +0 −200 lib/twitter/api/timelines.rb
  16. +0 −56 lib/twitter/api/trends.rb
  17. +0 −291 lib/twitter/api/tweets.rb
  18. +0 −51 lib/twitter/api/undocumented.rb
  19. +0 −381 lib/twitter/api/users.rb
  20. +0 −217 lib/twitter/api/utils.rb
  21. +0 −247 lib/twitter/client.rb
  22. +2 −2 lib/twitter/cursor.rb
  23. +0 −34 lib/twitter/request/multipart_with_file.rb
  24. +0 −25 lib/twitter/response/parse_json.rb
  25. +15 −0 lib/twitter/rest/api/arguments.rb
  26. +135 −0 lib/twitter/rest/api/direct_messages.rb
  27. +120 −0 lib/twitter/rest/api/favorites.rb
  28. +290 −0 lib/twitter/rest/api/friends_and_followers.rb
  29. +58 −0 lib/twitter/rest/api/help.rb
  30. +491 −0 lib/twitter/rest/api/lists.rb
  31. +45 −0 lib/twitter/rest/api/oauth.rb
  32. +104 −0 lib/twitter/rest/api/places_and_geo.rb
  33. +91 −0 lib/twitter/rest/api/saved_searches.rb
  34. +37 −0 lib/twitter/rest/api/search.rb
  35. +29 −0 lib/twitter/rest/api/spam_reporting.rb
  36. +51 −0 lib/twitter/rest/api/suggested_users.rb
  37. +202 −0 lib/twitter/rest/api/timelines.rb
  38. +58 −0 lib/twitter/rest/api/trends.rb
  39. +293 −0 lib/twitter/rest/api/tweets.rb
  40. +53 −0 lib/twitter/rest/api/undocumented.rb
  41. +383 −0 lib/twitter/rest/api/users.rb
  42. +219 −0 lib/twitter/rest/api/utils.rb
  43. +249 −0 lib/twitter/rest/client.rb
  44. +36 −0 lib/twitter/rest/request/multipart_with_file.rb
  45. +27 −0 lib/twitter/rest/response/parse_json.rb
  46. +8 −11 lib/twitter/{ → rest}/response/raise_error.rb
  47. +8 −8 spec/helper.rb
  48. +5 −5 spec/twitter/cursor_spec.rb
  49. +1 −1 spec/twitter/error_spec.rb
  50. +2 −2 spec/twitter/{ → rest}/api/direct_messages_spec.rb
  51. +2 −2 spec/twitter/{ → rest}/api/favorites_spec.rb
  52. +2 −2 spec/twitter/{ → rest}/api/friends_and_followers_spec.rb
  53. +2 −2 spec/twitter/{ → rest}/api/geo_spec.rb
  54. +2 −2 spec/twitter/{ → rest}/api/help_spec.rb
  55. +2 −2 spec/twitter/{ → rest}/api/lists_spec.rb
  56. +2 −2 spec/twitter/{ → rest}/api/oauth_spec.rb
  57. +2 −2 spec/twitter/{ → rest}/api/saved_searches_spec.rb
  58. +2 −2 spec/twitter/{ → rest}/api/search_spec.rb
  59. +2 −2 spec/twitter/{ → rest}/api/spam_reporting_spec.rb
  60. +2 −2 spec/twitter/{ → rest}/api/suggested_users_spec.rb
  61. +2 −2 spec/twitter/{ → rest}/api/timelines_spec.rb
  62. +2 −2 spec/twitter/{ → rest}/api/trends_spec.rb
  63. +2 −2 spec/twitter/{ → rest}/api/tweets_spec.rb
  64. +2 −2 spec/twitter/{ → rest}/api/undocumented_spec.rb
  65. +2 −2 spec/twitter/{ → rest}/api/users_spec.rb
  66. +16 −16 spec/twitter/{ → rest}/client_spec.rb
View
@@ -62,11 +62,11 @@ wiki][apps]!
## What's New in Version 5?
### Configuration
Twitter global configuration has been removed, since it was not threadsafe.
-Instead, you can configure a Twitter::Client by passing it a configuration
+Instead, you can configure a Twitter::REST::Client by passing it a configuration
block when it's initialized.
```ruby
-client = Twitter::Client.new do |config|
+client = Twitter::REST::Client.new do |config|
config.consumer_key = YOUR_CONSUMER_KEY
config.consumer_secret = YOUR_CONSUMER_SECRET
config.oauth_token = YOUR_OAUTH_TOKEN
@@ -337,10 +337,10 @@ error:
Bad Authentication data
-You can pass configuration options as a block to `Twitter::Client.new`.
+You can pass configuration options as a block to `Twitter::REST::Client.new`.
```ruby
-client = Twitter::Client.new do |config|
+client = Twitter::REST::Client.new do |config|
config.consumer_key = YOUR_CONSUMER_KEY
config.consumer_secret = YOUR_CONSUMER_SECRET
config.oauth_token = YOUR_OAUTH_TOKEN
View
@@ -1,5 +1,4 @@
require 'twitter/action_factory'
-require 'twitter/client'
require 'twitter/configuration'
require 'twitter/cursor'
require 'twitter/direct_message'
@@ -18,6 +17,7 @@
require 'twitter/profile_banner'
require 'twitter/rate_limit'
require 'twitter/relationship'
+require 'twitter/rest/client'
require 'twitter/saved_search'
require 'twitter/search_results'
require 'twitter/settings'
@@ -1,13 +0,0 @@
-module Twitter
- module API
- class Arguments < Array
- attr_reader :options
-
- def initialize(args)
- @options = args.last.is_a?(::Hash) ? args.pop : {}
- super(args)
- end
-
- end
- end
-end
@@ -1,133 +0,0 @@
-require 'twitter/api/arguments'
-require 'twitter/api/utils'
-require 'twitter/direct_message'
-require 'twitter/user'
-
-module Twitter
- module API
- module DirectMessages
- include Twitter::API::Utils
-
- # Returns the 20 most recent direct messages sent to the authenticating user
- #
- # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
- # @rate_limited Yes
- # @authentication Requires user context
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
- # @return [Array<Twitter::DirectMessage>] Direct messages sent to the authenticating user.
- # @param options [Hash] A customizable set of options.
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
- # @option options [Integer] :page Specifies the page of results to retrieve.
- def direct_messages_received(options={})
- objects_from_response(Twitter::DirectMessage, :get, "/1.1/direct_messages.json", options)
- end
-
- # Returns the 20 most recent direct messages sent by the authenticating user
- #
- # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/sent
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
- # @rate_limited Yes
- # @authentication Requires user context
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
- # @return [Array<Twitter::DirectMessage>] Direct messages sent by the authenticating user.
- # @param options [Hash] A customizable set of options.
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
- # @option options [Integer] :page Specifies the page of results to retrieve.
- def direct_messages_sent(options={})
- objects_from_response(Twitter::DirectMessage, :get, "/1.1/direct_messages/sent.json", options)
- end
-
- # Returns a direct message
- #
- # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/show
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
- # @rate_limited Yes
- # @authentication Requires user context
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
- # @return [Twitter::DirectMessage] The requested messages.
- # @param id [Integer] A direct message ID.
- # @param options [Hash] A customizable set of options.
- def direct_message(id, options={})
- options[:id] = id
- object_from_response(Twitter::DirectMessage, :get, "/1.1/direct_messages/show.json", options)
- end
-
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
- # @rate_limited Yes
- # @authentication Requires user context
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
- # @return [Array<Twitter::DirectMessage>] The requested messages.
- # @overload direct_messages(options={})
- # Returns the 20 most recent direct messages sent to the authenticating user
- #
- # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages
- # @param options [Hash] A customizable set of options.
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
- # @option options [Integer] :page Specifies the page of results to retrieve.
- # @overload direct_messages(*ids)
- # Returns direct messages
- #
- # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/show
- # @param ids [Enumerable<Integer>] A collection of direct message IDs.
- # @overload direct_messages(*ids, options)
- # Returns direct messages
- #
- # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/show
- # @param ids [Enumerable<Integer>] A collection of direct message IDs.
- # @param options [Hash] A customizable set of options.
- def direct_messages(*args)
- arguments = Twitter::API::Arguments.new(args)
- if arguments.empty?
- direct_messages_received(arguments.options)
- else
- arguments.flatten.threaded_map do |id|
- direct_message(id, arguments.options)
- end
- end
- end
-
- # Destroys direct messages
- #
- # @see https://dev.twitter.com/docs/api/1.1/post/direct_messages/destroy
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
- # @rate_limited No
- # @authentication Requires user context
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
- # @return [Array<Twitter::DirectMessage>] Deleted direct message.
- # @overload direct_message_destroy(*ids)
- # @param ids [Enumerable<Integer>] A collection of direct message IDs.
- # @overload direct_message_destroy(*ids, options)
- # @param ids [Enumerable<Integer>] A collection of direct message IDs.
- # @param options [Hash] A customizable set of options.
- def direct_message_destroy(*args)
- threaded_object_from_response(Twitter::DirectMessage, :post, "/1.1/direct_messages/destroy.json", args)
- end
-
- # Sends a new direct message to the specified user from the authenticating user
- #
- # @see https://dev.twitter.com/docs/api/1.1/post/direct_messages/new
- # @rate_limited No
- # @authentication Requires user context
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
- # @return [Twitter::DirectMessage] The sent message.
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
- # @param text [String] The text of your direct message, up to 140 characters.
- # @param options [Hash] A customizable set of options.
- def direct_message_create(user, text, options={})
- merge_user!(options, user)
- options[:text] = text
- object_from_response(Twitter::DirectMessage, :post, "/1.1/direct_messages/new.json", options)
- end
- alias d direct_message_create
- alias m direct_message_create
-
- end
- end
-end
@@ -1,118 +0,0 @@
-require 'twitter/api/arguments'
-require 'twitter/api/utils'
-require 'twitter/error/already_favorited'
-require 'twitter/error/forbidden'
-require 'twitter/tweet'
-require 'twitter/user'
-
-module Twitter
- module API
- module Favorites
- include Twitter::API::Utils
-
- # @see https://dev.twitter.com/docs/api/1.1/get/favorites/list
- # @rate_limited Yes
- # @authentication Requires user context
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
- # @return [Array<Twitter::Tweet>] favorite Tweets.
- # @overload favorites(options={})
- # Returns the 20 most recent favorite Tweets for the authenticating user
- #
- # @param options [Hash] A customizable set of options.
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
- # @overload favorites(user, options={})
- # Returns the 20 most recent favorite Tweets for the specified user
- #
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
- # @param options [Hash] A customizable set of options.
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
- def favorites(*args)
- arguments = Twitter::API::Arguments.new(args)
- if user = arguments.pop
- merge_user!(arguments.options, user)
- end
- objects_from_response(Twitter::Tweet, :get, "/1.1/favorites/list.json", arguments.options)
- end
- alias favourites favorites
-
- # Un-favorites the specified Tweets as the authenticating user
- #
- # @see https://dev.twitter.com/docs/api/1.1/post/favorites/destroy
- # @rate_limited No
- # @authentication Requires user context
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
- # @return [Array<Twitter::Tweet>] The un-favorited Tweets.
- # @overload unfavorite(*tweets)
- # @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
- # @overload unfavorite(*tweets, options)
- # @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
- # @param options [Hash] A customizable set of options.
- def unfavorite(*args)
- threaded_object_from_response(Twitter::Tweet, :post, "/1.1/favorites/destroy.json", args)
- end
- alias favorite_destroy unfavorite
- alias favourite_destroy unfavorite
- alias unfavourite unfavorite
-
- # Favorites the specified Tweets as the authenticating user
- #
- # @see https://dev.twitter.com/docs/api/1.1/post/favorites/create
- # @rate_limited No
- # @authentication Requires user context
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
- # @return [Array<Twitter::Tweet>] The favorited Tweets.
- # @overload favorite(*tweets)
- # @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
- # @overload favorite(*tweets, options)
- # @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
- # @param options [Hash] A customizable set of options.
- def favorite(*args)
- arguments = Twitter::API::Arguments.new(args)
- arguments.flatten.threaded_map do |tweet|
- id = extract_id(tweet)
- begin
- object_from_response(Twitter::Tweet, :post, "/1.1/favorites/create.json", arguments.options.merge(:id => id))
- rescue Twitter::Error::Forbidden => error
- raise unless error.message == Twitter::Error::AlreadyFavorited::MESSAGE
- end
- end.compact
- end
- alias fav favorite
- alias fave favorite
- alias favorite_create favorite
- alias favourite_create favorite
-
- # Favorites the specified Tweets as the authenticating user and raises an error if one has already been favorited
- #
- # @see https://dev.twitter.com/docs/api/1.1/post/favorites/create
- # @rate_limited No
- # @authentication Requires user context
- # @raise [Twitter::Error::AlreadyFavorited] Error raised when tweet has already been favorited.
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
- # @return [Array<Twitter::Tweet>] The favorited Tweets.
- # @overload favorite(*tweets)
- # @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
- # @overload favorite(*tweets, options)
- # @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
- # @param options [Hash] A customizable set of options.
- def favorite!(*args)
- arguments = Twitter::API::Arguments.new(args)
- arguments.flatten.threaded_map do |tweet|
- id = extract_id(tweet)
- begin
- object_from_response(Twitter::Tweet, :post, "/1.1/favorites/create.json", arguments.options.merge(:id => id))
- rescue Twitter::Error::Forbidden => error
- handle_forbidden_error(Twitter::Error::AlreadyFavorited, error)
- end
- end
- end
- alias fav! favorite!
- alias fave! favorite!
- alias favorite_create! favorite!
- alias favourite_create! favorite!
-
- end
- end
-end
Oops, something went wrong.

0 comments on commit 5b8c3fd

Please sign in to comment.