Class: Uber::Client
- Inherits:
-
Object
- Object
- Uber::Client
- Defined in:
- lib/uber_api/client.rb
Constant Summary collapse
- API_LOCATION =
'https://api.uber.com'- API_VERSION =
'/v1'
Instance Attribute Summary collapse
-
#bearer_token ⇒ Object
Returns the value of attribute bearer_token.
-
#server_token ⇒ Object
Returns the value of attribute server_token.
Instance Method Summary collapse
- #conn ⇒ Object
- #get(endpoint, params) ⇒ Object
- #history(offset, limit) ⇒ Object
-
#initialize(params = {}) ⇒ Client
constructor
A new instance of Client.
- #prices(start_latitude, start_longitude, end_latitude, end_longitude) ⇒ Object
- #products(latitude, longitude) ⇒ Object
- #profile ⇒ Object
- #times(start_latitude, start_longitude, customer_uuid, product_id) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Client
Returns a new instance of Client.
17 18 19 |
# File 'lib/uber_api/client.rb', line 17 def initialize(params={}) params.each { |k,v| instance_variable_set("@#{k}", v) } end |
Instance Attribute Details
#bearer_token ⇒ Object
Returns the value of attribute bearer_token.
15 16 17 |
# File 'lib/uber_api/client.rb', line 15 def bearer_token @bearer_token end |
#server_token ⇒ Object
Returns the value of attribute server_token.
15 16 17 |
# File 'lib/uber_api/client.rb', line 15 def server_token @server_token end |
Instance Method Details
#conn ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/uber_api/client.rb', line 21 def conn @conn = Faraday.new API_LOCATION do |conn| conn.request :json conn.response :json, :content_type => /\bjson$/ if !@bearer_token then conn. :Token, @server_token else conn. :Bearer , @bearer_token end conn.adapter Faraday.default_adapter end end |
#get(endpoint, params) ⇒ Object
30 31 32 33 34 |
# File 'lib/uber_api/client.rb', line 30 def get(endpoint, params) query_string = API_VERSION + endpoint response = conn.get query_string, params response_hash = JSON.parse(response.body.to_json) end |
#history(offset, limit) ⇒ Object
56 57 58 59 |
# File 'lib/uber_api/client.rb', line 56 def history(offset, limit) params = {:offset => offset.to_s, :limit => limit.to_s} response = get("/history", params) end |
#prices(start_latitude, start_longitude, end_latitude, end_longitude) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/uber_api/client.rb', line 42 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
36 37 38 39 40 |
# File 'lib/uber_api/client.rb', line 36 def products(latitude, longitude) params = {:latitude => latitude.to_s, :longitude => longitude.to_s} response = get("/products", params) response["products"] end |
#profile ⇒ Object
61 62 63 64 |
# File 'lib/uber_api/client.rb', line 61 def profile params = {} response = get("/me", params) end |
#times(start_latitude, start_longitude, customer_uuid, product_id) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/uber_api/client.rb', line 49 def times(start_latitude, start_longitude, customer_uuid, product_id) params = {:start_latitude => start_latitude.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 |