Class: Uber::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/uber_api/client.rb

Constant Summary collapse

API_LOCATION =
'https://api.uber.com'
API_VERSION =
'/v1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Client

Returns a new instance of Client.



11
12
13
# File 'lib/uber_api/client.rb', line 11

def initialize(params={})
	params.each { |k,v| instance_variable_set("@#{k}", v) }
end

Instance Attribute Details

#bearer_tokenObject

Returns the value of attribute bearer_token.



9
10
11
# File 'lib/uber_api/client.rb', line 9

def bearer_token
  @bearer_token
end

#client_idObject

Returns the value of attribute client_id.



9
10
11
# File 'lib/uber_api/client.rb', line 9

def client_id
  @client_id
end

#secretObject

Returns the value of attribute secret.



9
10
11
# File 'lib/uber_api/client.rb', line 9

def secret
  @secret
end

#server_tokenObject

Returns the value of attribute server_token.



9
10
11
# File 'lib/uber_api/client.rb', line 9

def server_token
  @server_token
end

Instance Method Details

#get(endpoint, params) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/uber_api/client.rb', line 15

def get(endpoint, params)
	conn = Faraday.new API_LOCATION do |conn|
		conn.request :json
		conn.response :json, :content_type => /\bjson$/
		conn.authorization :Token, @server_token
		conn.adapter Faraday.default_adapter
	end
	response = conn.get API_VERSION.concat(endpoint) , params
	response_hash = JSON.parse(response.body.to_json)
end

#prices(start_latitude, start_longitude, end_latitude, end_longitude) ⇒ Object



32
33
34
35
36
37
# File 'lib/uber_api/client.rb', line 32

def prices(start_latitude, start_longitude, end_latitude, end_longitude)
	params = {:start_latitude => start_latitude.to_s, :start_longitude => start_longitude.to_s,
				:end_latitude => end_latitude.to_s, :end_longitude => end_longitude.to_s}
	response = get("/estimates/price", params)
	response["prices"]
end

#products(latitude, longitude) ⇒ Object



26
27
28
29
30
# File 'lib/uber_api/client.rb', line 26

def products(latitude, longitude)
	params = {:latitude => latitude.to_s, :longitude => longitude.to_s}
	response = get("/products", params)
	response["products"]		
end

#times(start_latitude, start_longitude, customer_uuid, product_id) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/uber_api/client.rb', line 39

def times(start_latitude, start_longitude, customer_uuid, product_id)
	params = {
		:start_longitude => start_longitude.to_s, :start_longitude => start_longitude.to_s,
		:customer_uuid => customer_uuid.to_s, :product_id => product_id.to_s
	}
	response = get("/estimates/time", params)
	response["times"]
end