Class: Uber::ApiRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/uber/api_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, request_method, path, options = {}) ⇒ Uber::ApiRequest

Parameters:

  • client (Uber::Client)
  • request_method (String, Symbol)
  • path (String)
  • options (Hash) (defaults to: {})


11
12
13
14
15
16
# File 'lib/uber/api_request.rb', line 11

def initialize(client, request_method, path, options = {})
  @client = client
  @request_method = request_method.to_sym
  @path = path
  @options = options
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



3
4
5
# File 'lib/uber/api_request.rb', line 3

def client
  @client
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/uber/api_request.rb', line 3

def options
  @options
end

#pathObject

Returns the value of attribute path.



3
4
5
# File 'lib/uber/api_request.rb', line 3

def path
  @path
end

#request_methodObject Also known as: verb

Returns the value of attribute request_method.



3
4
5
# File 'lib/uber/api_request.rb', line 3

def request_method
  @request_method
end

Instance Method Details

#performHash

Returns:

  • (Hash)


19
20
21
# File 'lib/uber/api_request.rb', line 19

def perform
  @client.send(@request_method, @path, @options).body
end

#perform_with_object(klass) ⇒ Object

Parameters:

Returns:

  • (Object)


26
27
28
# File 'lib/uber/api_request.rb', line 26

def perform_with_object(klass)
  klass.new(perform)
end

#perform_with_objects(klass) ⇒ Array

Parameters:

  • klass (Class)

Returns:

  • (Array)


32
33
34
35
36
# File 'lib/uber/api_request.rb', line 32

def perform_with_objects(klass)
  ((perform.values.find { |v| v.is_a?(Array) }) || []).collect do |element|
    klass.new(element)
  end
end

#perform_without_objectObject



39
40
41
# File 'lib/uber/api_request.rb', line 39

def perform_without_object
  @client.send(@request_method, @path, @options).status
end