Class: Twitter::REST::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter/rest/request.rb,
lib/twitter/rest/request/multipart_with_file.rb

Defined Under Namespace

Classes: MultipartWithFile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, request_method, path, options = {}) ⇒ Twitter::REST::Request



21
22
23
24
25
26
27
# File 'lib/twitter/rest/request.rb', line 21

def initialize(client, request_method, path, options = {})
  @client = client
  @request_method = request_method.to_sym
  @path = path
  @uri = Addressable::URI.parse(client.connection.url_prefix + path)
  @options = options
end

Instance Attribute Details

#clientObject

Returns the value of attribute client



12
13
14
# File 'lib/twitter/rest/request.rb', line 12

def client
  @client
end

#headersObject

Returns the value of attribute headers



12
13
14
# File 'lib/twitter/rest/request.rb', line 12

def headers
  @headers
end

#optionsObject

Returns the value of attribute options



12
13
14
# File 'lib/twitter/rest/request.rb', line 12

def options
  @options
end

#pathObject

Returns the value of attribute path



12
13
14
# File 'lib/twitter/rest/request.rb', line 12

def path
  @path
end

#rate_limitObject

Returns the value of attribute rate_limit



12
13
14
# File 'lib/twitter/rest/request.rb', line 12

def rate_limit
  @rate_limit
end

#request_methodObject Also known as: verb

Returns the value of attribute request_method



12
13
14
# File 'lib/twitter/rest/request.rb', line 12

def request_method
  @request_method
end

#uriObject

Returns the value of attribute uri



12
13
14
# File 'lib/twitter/rest/request.rb', line 12

def uri
  @uri
end

Instance Method Details

#performArray, Hash



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/twitter/rest/request.rb', line 30

def perform
  @headers = Twitter::Headers.new(@client, @request_method, @uri.to_s, @options).request_headers
  begin
    response = @client.connection.send(@request_method, @path, @options) { |request| request.headers.update(@headers) }.env
  rescue Faraday::Error::TimeoutError, Timeout::Error => error
    raise(Twitter::Error::RequestTimeout.new(error))
  rescue Faraday::Error::ClientError, JSON::ParserError => error
    raise(Twitter::Error.new(error))
  end
  @rate_limit = Twitter::RateLimit.new(response.response_headers)
  response.body
end