Class: Twitter::REST::Request
- Inherits:
-
Object
- Object
- Twitter::REST::Request
- Includes:
- Utils
- Defined in:
- lib/twitter/rest/request.rb
Overview
rubocop:disable Metrics/ClassLength
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 = {}, params = nil) ⇒ Twitter::REST::Request constructor
- #perform ⇒ Array, Hash
Methods included from Utils
Constructor Details
#initialize(client, request_method, path, options = {}, params = nil) ⇒ Twitter::REST::Request
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/twitter/rest/request.rb', line 26 def initialize(client, request_method, path, = {}, params = nil) @client = client @uri = Addressable::URI.parse(path.start_with?("http") ? path : BASE_URL + path) = params || (request_method, ) @path = uri.path @options = @options_key = {get: :params, json_post: :json, json_put: :json, delete: :params}[request_method] || :form @params = params end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
17 18 19 |
# File 'lib/twitter/rest/request.rb', line 17 def client @client end |
#headers ⇒ Object
Returns the value of attribute headers.
17 18 19 |
# File 'lib/twitter/rest/request.rb', line 17 def headers @headers end |
#options ⇒ Object
Returns the value of attribute options.
17 18 19 |
# File 'lib/twitter/rest/request.rb', line 17 def @options end |
#path ⇒ Object
Returns the value of attribute path.
17 18 19 |
# File 'lib/twitter/rest/request.rb', line 17 def path @path end |
#rate_limit ⇒ Object
Returns the value of attribute rate_limit.
17 18 19 |
# File 'lib/twitter/rest/request.rb', line 17 def rate_limit @rate_limit end |
#request_method ⇒ Object Also known as: verb
Returns the value of attribute request_method.
17 18 19 |
# File 'lib/twitter/rest/request.rb', line 17 def request_method @request_method end |
#uri ⇒ Object
Returns the value of attribute uri.
17 18 19 |
# File 'lib/twitter/rest/request.rb', line 17 def uri @uri end |
Instance Method Details
#perform ⇒ Array, Hash
38 39 40 41 42 43 |
# File 'lib/twitter/rest/request.rb', line 38 def perform response = http_client.headers(@headers).public_send(@request_method, @uri.to_s, ) 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 |