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.



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_tokenObject

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_tokenObject

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

#connObject



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.authorization :Token, @server_token else conn.authorization :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

#profileObject



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