Class: RubyUber::Client
- Inherits:
-
Object
- Object
- RubyUber::Client
- Defined in:
- lib/ruby_uber/client.rb
Instance Attribute Summary collapse
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#secret ⇒ Object
Returns the value of attribute secret.
-
#server_token ⇒ Object
Returns the value of attribute server_token.
Instance Method Summary collapse
- #base_url ⇒ Object
- #connection ⇒ Object
- #get(url, params) ⇒ Object
- #host ⇒ Object
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
- #price_estimates ⇒ Object
- #products ⇒ Object
- #time_estimates ⇒ Object
- #user_activity ⇒ Object
- #user_profile ⇒ Object
Constructor Details
#initialize(options) ⇒ Client
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ruby_uber/client.rb', line 9 def initialize() @server_token = [:server_token] @client_id = [:client_id] @secret = [:secret] if !server_token && !oauthable? raise AuthenticationError, "Must provide either :server_token or :client_id and :secret to initialize Ruber::Client" end end |
Instance Attribute Details
#client_id ⇒ Object
Returns the value of attribute client_id.
7 8 9 |
# File 'lib/ruby_uber/client.rb', line 7 def client_id @client_id end |
#secret ⇒ Object
Returns the value of attribute secret.
7 8 9 |
# File 'lib/ruby_uber/client.rb', line 7 def secret @secret end |
#server_token ⇒ Object
Returns the value of attribute server_token.
7 8 9 |
# File 'lib/ruby_uber/client.rb', line 7 def server_token @server_token end |
Instance Method Details
#base_url ⇒ Object
24 25 26 |
# File 'lib/ruby_uber/client.rb', line 24 def base_url "https://#{host}/v1" end |
#connection ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/ruby_uber/client.rb', line 28 def connection @connection ||= Faraday.new(url: base_url) do |conn| conn.request :json conn.response :json conn.adapter Faraday.default_adapter end end |
#get(url, params) ⇒ Object
36 37 38 39 40 |
# File 'lib/ruby_uber/client.rb', line 36 def get(url, params) connection.get(url, params) do |req| req.headers['Authorization'] = "Token #{server_token}" end end |
#host ⇒ Object
20 21 22 |
# File 'lib/ruby_uber/client.rb', line 20 def host 'api.uber.com' end |
#price_estimates ⇒ Object
42 43 44 |
# File 'lib/ruby_uber/client.rb', line 42 def price_estimates V1::PriceEstimates.new(client: self) end |
#products ⇒ Object
46 47 48 |
# File 'lib/ruby_uber/client.rb', line 46 def products V1::Products.new(client: self) end |
#time_estimates ⇒ Object
50 51 52 |
# File 'lib/ruby_uber/client.rb', line 50 def time_estimates V1::TimeEstimates.new(client: self) end |
#user_activity ⇒ Object
54 55 56 |
# File 'lib/ruby_uber/client.rb', line 54 def user_activity V1::UserActivity.new(client: self) end |
#user_profile ⇒ Object
58 59 60 |
# File 'lib/ruby_uber/client.rb', line 58 def user_profile V1::UserProfile.new(client: self) end |