Skip to content

Commit

Permalink
Move Twitter::Request into Twitter::REST namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Nov 4, 2014
1 parent 2b1ccec commit a46d9f2
Show file tree
Hide file tree
Showing 23 changed files with 67 additions and 80 deletions.
4 changes: 2 additions & 2 deletions etc/erd.dot
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ digraph classes {
Twitter__Place [label="Twitter::Place"]
Twitter__ProfileBanner [label="Twitter::ProfileBanner"]
Twitter__REST__Client [label="Twitter::REST::Client"]
Twitter__REST__Request [label="Twitter::REST::Request"]
Twitter__REST__Request__MultipartWithFile [label="Twitter::REST::Request::MultipartWithFile"]
Twitter__REST__Response__ParseErrorJson [label="Twitter::REST::Response::ParseErrorJson"]
Twitter__REST__Response__ParseJson [label="Twitter::REST::Response::ParseJson"]
Twitter__REST__Response__RaiseError [label="Twitter::REST::Response::RaiseError"]
Twitter__RateLimit [label="Twitter::RateLimit"]
Twitter__Relationship [label="Twitter::Relationship"]
Twitter__Request [label="Twitter::Request"]
Twitter__SavedSearch [label="Twitter::SavedSearch"]
Twitter__SearchResults [label="Twitter::SearchResults"]
Twitter__Settings [label="Twitter::Settings"]
Expand Down Expand Up @@ -142,13 +142,13 @@ digraph classes {
Twitter__Place -> Twitter__Identity
Twitter__ProfileBanner -> Twitter__Base
Twitter__REST__Client -> Twitter__Client
Twitter__REST__Request -> Object
Twitter__REST__Request__MultipartWithFile -> Faraday__Middleware
Twitter__REST__Response__ParseErrorJson -> Twitter__REST__Response__ParseJson
Twitter__REST__Response__ParseJson -> Faraday__Response__Middleware
Twitter__REST__Response__RaiseError -> Faraday__Response__Middleware
Twitter__RateLimit -> Twitter__Base
Twitter__Relationship -> Twitter__Base
Twitter__Request -> Object
Twitter__SavedSearch -> Twitter__Identity
Twitter__SearchResults -> Object
Twitter__Settings -> Twitter__Base
Expand Down
Binary file modified etc/erd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions lib/twitter/cursor.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'twitter/enumerable'
require 'twitter/request'
require 'twitter/rest/request'
require 'twitter/utils'

module Twitter
Expand All @@ -17,7 +17,7 @@ class Cursor
# @param attrs [Hash]
# @param key [String, Symbol] The key to fetch the data from the response
# @param klass [Class] The class to instantiate objects in the response
# @param request [Twitter::Request]
# @param request [Twitter::REST::Request]
# @return [Twitter::Cursor]
def initialize(attrs, key, klass, request)
@key = key.to_sym
Expand Down Expand Up @@ -45,7 +45,7 @@ def last?

# @return [Hash]
def fetch_next_page
response = Twitter::Request.new(@client, @request_method, @path, @options.merge(:cursor => next_cursor)).perform
response = Twitter::REST::Request.new(@client, @request_method, @path, @options.merge(:cursor => next_cursor)).perform
self.attrs = response
end

Expand Down
50 changes: 0 additions & 50 deletions lib/twitter/request.rb

This file was deleted.

1 change: 0 additions & 1 deletion lib/twitter/rest/direct_messages.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'twitter/arguments'
require 'twitter/direct_message'
require 'twitter/request'
require 'twitter/rest/utils'
require 'twitter/user'
require 'twitter/utils'
Expand Down
1 change: 0 additions & 1 deletion lib/twitter/rest/favorites.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'twitter/arguments'
require 'twitter/error'
require 'twitter/request'
require 'twitter/rest/utils'
require 'twitter/tweet'
require 'twitter/user'
Expand Down
1 change: 0 additions & 1 deletion lib/twitter/rest/friends_and_followers.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'twitter/arguments'
require 'twitter/cursor'
require 'twitter/relationship'
require 'twitter/request'
require 'twitter/rest/utils'
require 'twitter/user'
require 'twitter/utils'
Expand Down
1 change: 0 additions & 1 deletion lib/twitter/rest/help.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'twitter/configuration'
require 'twitter/language'
require 'twitter/request'
require 'twitter/rest/utils'

module Twitter
Expand Down
1 change: 0 additions & 1 deletion lib/twitter/rest/lists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
require 'twitter/cursor'
require 'twitter/error'
require 'twitter/list'
require 'twitter/request'
require 'twitter/rest/utils'
require 'twitter/tweet'
require 'twitter/user'
Expand Down
1 change: 0 additions & 1 deletion lib/twitter/rest/oauth.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'twitter/request'
require 'twitter/rest/utils'
require 'twitter/rest/response/parse_error_json'
require 'twitter/token'
Expand Down
1 change: 0 additions & 1 deletion lib/twitter/rest/places_and_geo.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'twitter/geo_results'
require 'twitter/place'
require 'twitter/request'
require 'twitter/rest/utils'

module Twitter
Expand Down
51 changes: 51 additions & 0 deletions lib/twitter/rest/request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'twitter/cursor'
require 'twitter/rate_limit'

module Twitter
module REST
class Request
attr_accessor :client, :rate_limit, :request_method, :path, :options
alias_method :verb, :request_method

# @param client [Twitter::Client]
# @param request_method [String, Symbol]
# @param path [String]
# @param options [Hash]
# @return [Twitter::REST::Request]
def initialize(client, request_method, path, options = {})
@client = client
@request_method = request_method.to_sym
@path = path
@options = options
end

# @return [Hash]
def perform
response = @client.send(@request_method, @path, @options)
@rate_limit = Twitter::RateLimit.new(response.response_headers)
response.body
end

# @param klass [Class]
# @return [Object]
def perform_with_object(klass)
klass.new(perform)
end

# @param collection_name [Symbol]
# @param klass [Class]
# @return [Twitter::Cursor]
def perform_with_cursor(collection_name, klass = nil)
Twitter::Cursor.new(perform, collection_name.to_sym, klass, self)
end

# @param klass [Class]
# @return [Array]
def perform_with_objects(klass)
perform.collect do |element|
klass.new(element)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/twitter/rest/request/multipart_with_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Twitter
module REST
module Request
class Request
class MultipartWithFile < Faraday::Middleware
CONTENT_TYPE = 'Content-Type'
GIF_REGEX = /\.gif$/i
Expand Down
1 change: 0 additions & 1 deletion lib/twitter/rest/saved_searches.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'twitter/arguments'
require 'twitter/request'
require 'twitter/rest/utils'
require 'twitter/saved_search'
require 'twitter/utils'
Expand Down
4 changes: 2 additions & 2 deletions lib/twitter/rest/search.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'twitter/request'
require 'twitter/rest/request'
require 'twitter/search_results'

module Twitter
Expand Down Expand Up @@ -27,7 +27,7 @@ module Search
# @return [Twitter::SearchResults] Return tweets that match a specified query with search metadata
def search(q, options = {})
options[:count] ||= MAX_TWEETS_PER_REQUEST
request = Twitter::Request.new(self, :get, '/1.1/search/tweets.json', options.merge(:q => q))
request = Twitter::REST::Request.new(self, :get, '/1.1/search/tweets.json', options.merge(:q => q))
response = get(request.path, request.options).body
Twitter::SearchResults.new(response, request)
end
Expand Down
1 change: 0 additions & 1 deletion lib/twitter/rest/spam_reporting.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'twitter/request'
require 'twitter/rest/utils'
require 'twitter/user'

Expand Down
1 change: 0 additions & 1 deletion lib/twitter/rest/suggested_users.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'twitter/arguments'
require 'twitter/request'
require 'twitter/rest/utils'
require 'twitter/suggestion'
require 'twitter/user'
Expand Down
1 change: 0 additions & 1 deletion lib/twitter/rest/timelines.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'twitter/request'
require 'twitter/rest/utils'
require 'twitter/tweet'
require 'twitter/user'
Expand Down
1 change: 0 additions & 1 deletion lib/twitter/rest/trends.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'twitter/place'
require 'twitter/request'
require 'twitter/rest/utils'
require 'twitter/trend_results'

Expand Down
1 change: 0 additions & 1 deletion lib/twitter/rest/tweets.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'twitter/arguments'
require 'twitter/error'
require 'twitter/oembed'
require 'twitter/request'
require 'twitter/rest/utils'
require 'twitter/tweet'
require 'twitter/utils'
Expand Down
1 change: 0 additions & 1 deletion lib/twitter/rest/users.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'twitter/arguments'
require 'twitter/error'
require 'twitter/profile_banner'
require 'twitter/request'
require 'twitter/rest/utils'
require 'twitter/settings'
require 'twitter/user'
Expand Down
10 changes: 5 additions & 5 deletions lib/twitter/rest/utils.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'addressable/uri'
require 'twitter/arguments'
require 'twitter/request'
require 'twitter/rest/request'
require 'twitter/user'
require 'twitter/utils'

Expand Down Expand Up @@ -49,7 +49,7 @@ def post_with_object(path, options, klass)
# @param options [Hash]
# @param klass [Class]
def request_with_object(request_method, path, options, klass)
request = Twitter::Request.new(self, request_method, path, options)
request = Twitter::REST::Request.new(self, request_method, path, options)
request.perform_with_object(klass)
end

Expand All @@ -72,7 +72,7 @@ def post_with_objects(path, options, klass)
# @param options [Hash]
# @param klass [Class]
def request_with_objects(request_method, path, options, klass)
request = Twitter::Request.new(self, request_method, path, options)
request = Twitter::REST::Request.new(self, request_method, path, options)
request.perform_with_objects(klass)
end

Expand All @@ -82,7 +82,7 @@ def request_with_objects(request_method, path, options, klass)
# @param klass [Class]
def get_with_cursor(path, options, collection_name, klass = nil)
merge_default_cursor!(options)
request = Twitter::Request.new(self, :get, path, options)
request = Twitter::REST::Request.new(self, :get, path, options)
request.perform_with_cursor(collection_name.to_sym, klass)
end

Expand All @@ -93,7 +93,7 @@ def get_with_cursor(path, options, collection_name, klass = nil)
# @param klass [Class]
def request_with_cursor(request_method, path, options, collection_name, klass = nil) # rubocop:disable ParameterLists
merge_default_cursor!(options)
request = Twitter::Request.new(self, request_method, path, options)
request = Twitter::REST::Request.new(self, request_method, path, options)
request.perform_with_cursor(collection_name.to_sym, klass)
end

Expand Down
6 changes: 3 additions & 3 deletions lib/twitter/search_results.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'cgi'
require 'twitter/enumerable'
require 'twitter/request'
require 'twitter/rest/request'
require 'twitter/utils'
require 'uri'

Expand All @@ -17,7 +17,7 @@ class SearchResults
# Initializes a new SearchResults object
#
# @param attrs [Hash]
# @param request [Twitter::Request]
# @param request [Twitter::REST::Request]
# @return [Twitter::SearchResults]
def initialize(attrs, request)
@client = request.client
Expand Down Expand Up @@ -50,7 +50,7 @@ def next_page

# @return [Hash]
def fetch_next_page
response = Twitter::Request.new(@client, @request_method, @path, next_page).perform
response = Twitter::REST::Request.new(@client, @request_method, @path, next_page).perform
self.attrs = response
end

Expand Down

0 comments on commit a46d9f2

Please sign in to comment.