Class: Twitter::REST::Request

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/twitter/rest/request.rb

Constant Summary

BASE_URL =
'https://api.twitter.com'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

flat_pmap, pmap

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, options = {})
  @client = client
  @uri = Addressable::URI.parse(path.start_with?('http') ? path : BASE_URL + path)
  set_multipart_options!(request_method, options)
  @path = uri.path
  @options = options
end

Instance Attribute Details

#clientObject

Returns the value of attribute client



16
17
18
# File 'lib/twitter/rest/request.rb', line 16

def client
  @client
end

#headersObject

Returns the value of attribute headers



16
17
18
# File 'lib/twitter/rest/request.rb', line 16

def headers
  @headers
end

#optionsObject

Returns the value of attribute options



16
17
18
# File 'lib/twitter/rest/request.rb', line 16

def options
  @options
end

#pathObject

Returns the value of attribute path



16
17
18
# File 'lib/twitter/rest/request.rb', line 16

def path
  @path
end

#rate_limitObject

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_methodObject 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

#uriObject

Returns the value of attribute uri



16
17
18
# File 'lib/twitter/rest/request.rb', line 16

def uri
  @uri
end

Instance Method Details

#performArray, Hash



34
35
36
37
38
39
40
# File 'lib/twitter/rest/request.rb', line 34

def perform
  options_key = @request_method == :get ? :params : :form
  response = http_client.headers(@headers).public_send(@request_method, @uri.to_s, options_key => @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