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: {})


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

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.



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

def client
  @client
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

#request_methodObject Also known as: verb

Returns the value of attribute request_method.



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

def request_method
  @request_method
end

Instance Method Details

#performHash

Returns:

  • (Hash)


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

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

#perform_with_object(klass) ⇒ Object

Parameters:

Returns:

  • (Object)


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

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

#perform_with_objects(klass) ⇒ Array

Parameters:

  • klass (Class)

Returns:

  • (Array)


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

def perform_with_objects(klass)
  perform.values.flatten.map do |element|
    klass.new(element)
  end
end