Class: Twitter::REST::Request
- Inherits:
-
Object
- Object
- Twitter::REST::Request
- Includes:
- Utils
- Defined in:
- lib/twitter/rest/request.rb
Constant Summary collapse
- BASE_URL =
'https://api.twitter.com'.freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#options ⇒ Object
Returns the value of attribute options.
-
#path ⇒ Object
Returns the value of attribute path.
-
#rate_limit ⇒ Object
Returns the value of attribute rate_limit.
-
#request_method ⇒ Object
(also: #verb)
Returns the value of attribute request_method.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
- #initialize(client, request_method, path, options = {}) ⇒ Twitter::REST::Request constructor
- #perform ⇒ Array, Hash
Methods included from Utils
Constructor Details
#initialize(client, request_method, path, options = {}) ⇒ Twitter::REST::Request
25 26 27 28 29 30 31 |
# File 'lib/twitter/rest/request.rb', line 25 def initialize(client, request_method, path, = {}) @client = client @uri = Addressable::URI.parse(path.start_with?('http') ? path : BASE_URL + path) (request_method, ) @path = uri.path @options = end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
16 17 18 |
# File 'lib/twitter/rest/request.rb', line 16 def client @client end |
#headers ⇒ Object
Returns the value of attribute headers.
16 17 18 |
# File 'lib/twitter/rest/request.rb', line 16 def headers @headers end |
#options ⇒ Object
Returns the value of attribute options.
16 17 18 |
# File 'lib/twitter/rest/request.rb', line 16 def @options end |
#path ⇒ Object
Returns the value of attribute path.
16 17 18 |
# File 'lib/twitter/rest/request.rb', line 16 def path @path end |
#rate_limit ⇒ Object
Returns the value of attribute rate_limit.
16 17 18 |
# File 'lib/twitter/rest/request.rb', line 16 def rate_limit @rate_limit end |
#request_method ⇒ Object Also known as: verb
Returns the value of attribute request_method.
16 17 18 |
# File 'lib/twitter/rest/request.rb', line 16 def request_method @request_method end |
#uri ⇒ Object
Returns the value of attribute uri.
16 17 18 |
# File 'lib/twitter/rest/request.rb', line 16 def uri @uri end |
Instance Method Details
#perform ⇒ Array, Hash
34 35 36 37 38 39 40 |
# File 'lib/twitter/rest/request.rb', line 34 def perform = @request_method == :get ? :params : :form response = http_client.headers(@headers).public_send(@request_method, @uri.to_s, => @options) response_body = response.body.empty? ? '' : symbolize_keys!(response.parse) response_headers = response.headers fail_or_return_response_body(response.code, response_body, response_headers) end |