Class: Uber::Client
Constant Summary collapse
- ENDPOINT =
'https://api.uber.com'
- SANDBOX_ENDPOINT =
'https://sandbox-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
-
#debug ⇒ Object
Returns the value of attribute debug.
- #middleware ⇒ Object
-
#sandbox ⇒ Object
Returns the value of attribute sandbox.
-
#server_token ⇒ Object
Returns the value of attribute server_token.
Instance Method Summary collapse
- #bearer_token? ⇒ Boolean
- #credentials ⇒ Hash
- #credentials? ⇒ Boolean
-
#delete(path, params = {}) ⇒ Object
Perform an HTTP DELETE request.
- #deliveries ⇒ Object
-
#get(path, params = {}) ⇒ Object
Perform an HTTP GET request.
-
#initialize(options = {}) {|_self| ... } ⇒ Client
constructor
A new instance of Client.
- #partners ⇒ Object
-
#patch(path, params = {}) ⇒ Object
Perform an HTTP PATCH request.
-
#post(path, params = {}) ⇒ Object
Perform an HTTP POST request.
-
#put(path, params = {}) ⇒ Object
Perform an HTTP PUT request.
- #user_agent ⇒ String
- #user_token? ⇒ Boolean
Methods included from API::Requests
#trip_cancel, #trip_details, #trip_estimate, #trip_map, #trip_receipt, #trip_request, #trip_update
Methods included from API::Reminders
#add_reminder, #delete_reminder, #reminder, #update_reminder
Methods included from API::Places
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
#apply_availability, #apply_surge, #products
Methods included from Utils
#perform_with_object, #perform_with_objects, #perform_without_object
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Client
Returns a new instance of Client.
21 22 23 24 25 26 27 |
# File 'lib/uber/client.rb', line 21 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
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/uber/client.rb', line 33 def @connection_options ||= { :builder => middleware, :headers => { :accept => 'application/json', :user_agent => user_agent, }, :request => { :open_timeout => 10, :timeout => 30, }, } end |
#debug ⇒ Object
Returns the value of attribute debug.
15 16 17 |
# File 'lib/uber/client.rb', line 15 def debug @debug end |
#middleware ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/uber/client.rb', line 57 def middleware @middleware ||= Faraday::RackBuilder.new do |faraday| # Encodes as "application/x-www-form-urlencoded" if not already encoded faraday.request :url_encoded # Parse JSON response bodies faraday.response :parse_json faraday.response :logger if self.debug # Use instrumentation if available faraday.use :instrumentation if defined?(FaradayMiddleware::Instrumentation) # Set default HTTP adapter faraday.adapter Faraday.default_adapter end end |
#sandbox ⇒ Object
Returns the value of attribute sandbox.
14 15 16 |
# File 'lib/uber/client.rb', line 14 def sandbox @sandbox 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
102 103 104 |
# File 'lib/uber/client.rb', line 102 def bearer_token? !!bearer_token end |
#credentials ⇒ Hash
107 108 109 110 111 112 113 |
# File 'lib/uber/client.rb', line 107 def credentials { server_token: server_token, client_id: client_id, client_secret: client_secret } end |
#credentials? ⇒ Boolean
116 117 118 |
# File 'lib/uber/client.rb', line 116 def credentials? credentials.values.all? end |
#delete(path, params = {}) ⇒ Object
Perform an HTTP DELETE request
90 91 92 93 |
# File 'lib/uber/client.rb', line 90 def delete(path, params = {}) headers = request_headers(:delete, path, params) request(:delete, path, params, headers) end |
#deliveries ⇒ Object
124 125 126 |
# File 'lib/uber/client.rb', line 124 def deliveries @deliveries ||= Uber::Delivery::Client.new self end |
#get(path, params = {}) ⇒ Object
Perform an HTTP GET request
72 73 74 75 |
# File 'lib/uber/client.rb', line 72 def get(path, params = {}) headers = request_headers(:get, path, params) request(:get, path, params, headers) end |
#partners ⇒ Object
120 121 122 |
# File 'lib/uber/client.rb', line 120 def partners @partners ||= Uber::Partner::Client.new self end |
#patch(path, params = {}) ⇒ Object
Perform an HTTP PATCH request
96 97 98 99 |
# File 'lib/uber/client.rb', line 96 def patch(path, params={}) headers = params.values.any? { |value| value.respond_to?(:to_io) } ? request_headers(:post, path, params, {}) : request_headers(:patch, path, params) request(:patch, path, params.to_json, headers) end |
#post(path, params = {}) ⇒ Object
Perform an HTTP POST request
78 79 80 81 |
# File 'lib/uber/client.rb', line 78 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.to_json, headers) end |
#put(path, params = {}) ⇒ Object
Perform an HTTP PUT request
84 85 86 87 |
# File 'lib/uber/client.rb', line 84 def put(path, params = {}) headers = params.values.any? { |value| value.respond_to?(:to_io) } ? request_headers(:post, path, params, {}) : request_headers(:put, path, params) request(:put, path, params.to_json, headers) end |
#user_agent ⇒ String
53 54 55 |
# File 'lib/uber/client.rb', line 53 def user_agent @user_agent ||= "Uber Ruby Gem #{Uber::Version}" end |
#user_token? ⇒ Boolean
48 49 50 |
# File 'lib/uber/client.rb', line 48 def user_token? !!(client_id && client_secret) end |