Class: Twitter::REST::Request
- Inherits:
-
Object
- Object
- Twitter::REST::Request
- Includes:
- Utils
- Defined in:
- lib/twitter/rest/request.rb
Overview
Handles HTTP requests to the Twitter API
Constant Summary collapse
- BASE_URL =
The base URL for Twitter API requests
"https://api.twitter.com".freeze
Instance Attribute Summary collapse
-
#client ⇒ Twitter::Client
The client making the request.
-
#headers ⇒ Hash
The request headers.
-
#options ⇒ Hash
The request options.
-
#path ⇒ String
The request path.
-
#rate_limit ⇒ Twitter::RateLimit
The rate limit information from the response.
-
#request_method ⇒ Symbol
The HTTP request method.
-
#uri ⇒ URI::Generic
The request URI.
Instance Method Summary collapse
-
#initialize(client, request_method, path, options = {}, params = nil) ⇒ Twitter::REST::Request
constructor
Initializes a new Request.
-
#perform ⇒ Array, Hash
Performs the HTTP request and returns the response.
-
#verb ⇒ Symbol
Returns the HTTP verb.
Methods included from Utils
Constructor Details
#initialize(client, request_method, path, options = {}, params = nil) ⇒ Twitter::REST::Request
Initializes a new Request
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/twitter/rest/request.rb', line 97 def initialize(client, request_method, path, = {}, params = nil) @client = client @uri = URI.parse(path.start_with?("http") ? path : BASE_URL + path) = params || (request_method, ) @path = uri.path # steep:ignore NoMethod,IncompatibleAssignment @options = @options_key = {get: :params, json_post: :json, json_put: :json, delete: :params}[request_method] || :form @params = params end |
Instance Attribute Details
#client ⇒ Twitter::Client
The client making the request
26 27 28 |
# File 'lib/twitter/rest/request.rb', line 26 def client @client end |
#headers ⇒ Hash
The request headers
34 35 36 |
# File 'lib/twitter/rest/request.rb', line 34 def headers @headers end |
#options ⇒ Hash
The request options
42 43 44 |
# File 'lib/twitter/rest/request.rb', line 42 def @options end |
#path ⇒ String
The request path
50 51 52 |
# File 'lib/twitter/rest/request.rb', line 50 def path @path end |
#rate_limit ⇒ Twitter::RateLimit
The rate limit information from the response
58 59 60 |
# File 'lib/twitter/rest/request.rb', line 58 def rate_limit @rate_limit end |
#request_method ⇒ Symbol
The HTTP request method
66 67 68 |
# File 'lib/twitter/rest/request.rb', line 66 def request_method @request_method end |
#uri ⇒ URI::Generic
The request URI
74 75 76 |
# File 'lib/twitter/rest/request.rb', line 74 def uri @uri end |
Instance Method Details
#perform ⇒ Array, Hash
Performs the HTTP request and returns the response
114 115 116 117 118 |
# File 'lib/twitter/rest/request.rb', line 114 def perform response = http_client.headers(@headers).public_send(@request_method, @uri.to_str, **) response_body = response.body.empty? ? "" : symbolize_keys!(response.parse) fail_or_return_response_body(response.code, response_body, response) end |
#verb ⇒ Symbol
Returns the HTTP verb
82 83 84 |
# File 'lib/twitter/rest/request.rb', line 82 def verb request_method end |