Class: Uber::Client
Constant Summary collapse
- ENDPOINT =
'https://api.uber.com'
Instance Attribute Summary collapse
-
#bearer_token ⇒ Object
Returns the value of attribute bearer_token.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
- #connection_options ⇒ Object
- #middleware ⇒ Object
-
#server_token ⇒ Object
Returns the value of attribute server_token.
Instance Method Summary collapse
- #bearer_token? ⇒ Boolean
- #credentials ⇒ Hash
- #credentials? ⇒ Boolean
-
#get(path, params = {}) ⇒ Object
Perform an HTTP GET request.
-
#initialize(options = {}) {|_self| ... } ⇒ Client
constructor
A new instance of Client.
-
#post(path, params = {}) ⇒ Object
Perform an HTTP POST request.
- #user_agent ⇒ String
- #user_token? ⇒ Boolean
Methods included from API::Promotions
Methods included from API::Me
Methods included from API::Activities
Methods included from API::TimeEstimates
Methods included from API::PriceEstimates
Methods included from API::Products
Methods included from Utils
#perform_with_object, #perform_with_objects
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Client
Returns a new instance of Client.
17 18 19 20 21 22 23 |
# File 'lib/uber/client.rb', line 17 def initialize( = {}) .each do |key, value| send(:"#{key}=", value) end yield(self) if block_given? validate_credential_type! end |
Instance Attribute Details
#bearer_token ⇒ Object
Returns the value of attribute bearer_token.
13 14 15 |
# File 'lib/uber/client.rb', line 13 def bearer_token @bearer_token end |
#client_id ⇒ Object
Returns the value of attribute client_id.
12 13 14 |
# File 'lib/uber/client.rb', line 12 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
12 13 14 |
# File 'lib/uber/client.rb', line 12 def client_secret @client_secret end |
#connection_options ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/uber/client.rb', line 29 def @connection_options ||= { :builder => middleware, :headers => { :accept => 'application/json', :user_agent => user_agent, }, :request => { :open_timeout => 10, :timeout => 30, }, } end |
#middleware ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/uber/client.rb', line 53 def middleware @middleware ||= Faraday::RackBuilder.new do |faraday| # Encodes as "application/x-www-form-urlencoded" if not already encoded faraday.request :url_encoded # Handle error responses faraday.response :raise_error # Parse JSON response bodies faraday.response :parse_json # Use instrumentation if available faraday.use :instrumentation if defined?(FaradayMiddleware::Instrumentation) # Set default HTTP adapter faraday.adapter Faraday.default_adapter end end |
#server_token ⇒ Object
Returns the value of attribute server_token.
12 13 14 |
# File 'lib/uber/client.rb', line 12 def server_token @server_token end |
Instance Method Details
#bearer_token? ⇒ Boolean
81 82 83 |
# File 'lib/uber/client.rb', line 81 def bearer_token? !!bearer_token end |
#credentials ⇒ Hash
86 87 88 89 90 91 92 |
# File 'lib/uber/client.rb', line 86 def credentials { server_token: server_token, client_id: client_id, client_secret: client_secret } end |
#credentials? ⇒ Boolean
95 96 97 |
# File 'lib/uber/client.rb', line 95 def credentials? credentials.values.all? end |
#get(path, params = {}) ⇒ Object
Perform an HTTP GET request
69 70 71 72 |
# File 'lib/uber/client.rb', line 69 def get(path, params = {}) headers = request_headers(:get, path, params) request(:get, path, params, headers) end |
#post(path, params = {}) ⇒ Object
Perform an HTTP POST request
75 76 77 78 |
# File 'lib/uber/client.rb', line 75 def post(path, params = {}) headers = params.values.any? { |value| value.respond_to?(:to_io) } ? request_headers(:post, path, params, {}) : request_headers(:post, path, params) request(:post, path, params, headers) end |
#user_agent ⇒ String
49 50 51 |
# File 'lib/uber/client.rb', line 49 def user_agent @user_agent ||= "Uber Ruby Gem #{Uber::Version}" end |
#user_token? ⇒ Boolean
44 45 46 |
# File 'lib/uber/client.rb', line 44 def user_token? !!(client_id && client_secret) end |