uber-ruby 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d701a94c056f2a62beda2a8fad9fbab3196b5e8e
4
- data.tar.gz: fd42a9fc46cb484ef60378052c0613b7f46f8e64
3
+ metadata.gz: 102ad031c8fea0a68a5361dcc4e4fc8a5c7147da
4
+ data.tar.gz: 5e2d6cb7363c74230ed7fa01e13ab4c9dc51982f
5
5
  SHA512:
6
- metadata.gz: 68b64d7807b28b55e6437c51322b7a8163028cab4af9e1d09a77fba8e6cb58c277a8057a802d6355b42cd80b72e66495bb89c7aed62d5a0f54cd87ed9ffbb44e
7
- data.tar.gz: d69e71aadc6d29c1ce8572b8598e3fe4e77cdcec3b902d0bead3db8443b758f14bbf0abbb8234b53f754c6a4de86fb56cba0fb2ce81f87ded4075c7c1ee23101
6
+ metadata.gz: b3146219ed1b481fc4051101e848fc0067a0913066e2fa1ca68aceaa2b13700660c4ecf66fa2bb9cf6fb790363d55e9d9155557027b6e0144cc311438e27e369
7
+ data.tar.gz: 8064f6376fbf619547e9a6e4be76e16c260e4454de6934ddd81cf8b2f9c28795c4b1e23c1668f40b2a09fc441ab44019355da8b473371cfecafd9dba9b97c70b
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # The Uber Ruby Gem
2
2
 
3
- A Ruby interface to the Uber API.
3
+ > A Ruby interface to the Uber API.
4
4
 
5
5
  ## Installation
6
6
 
@@ -80,6 +80,92 @@ end
80
80
  client.history
81
81
  ```
82
82
 
83
+ ### Request a ride
84
+
85
+ ```ruby
86
+ client = Uber::Client.new do |config|
87
+ config.client_id = "YOUR_CLIENT_ID"
88
+ config.client_secret = "YOUR_CLIENT_SECRET"
89
+ config.bearer_toekn = "USER_ACCESS_TOKEN"
90
+ end
91
+
92
+ client.trip_request(product_id: product_id, start_latitude: start_lat, start_longitude: start_lng, end_latitude: end_lat, end_longitude: end_lng)
93
+ ```
94
+
95
+ ### Simulate a ride request with surge
96
+
97
+ ```ruby
98
+ client = Uber::Client.new do |config|
99
+ config.client_id = "YOUR_CLIENT_ID"
100
+ config.client_secret = "YOUR_CLIENT_SECRET"
101
+ config.bearer_toekn = "USER_ACCESS_TOKEN"
102
+ end
103
+
104
+ # Only available in sandbox environment
105
+ # Use this to simulate a surge
106
+ # More info here https://developer.uber.com/docs/sandbox#section-product-types
107
+ client.apply_surge 'product_id', 2.0
108
+
109
+ client.trip_request(product_id: product_id, start_latitude: start_lat, start_longitude: start_lng, end_latitude: end_lat, end_longitude: end_lng, surge_confirmation_id: surge_id)
110
+ ```
111
+
112
+ ### Simulate a ride request with no drivers available
113
+
114
+ ```ruby
115
+ client = Uber::Client.new do |config|
116
+ config.client_id = "YOUR_CLIENT_ID"
117
+ config.client_secret = "YOUR_CLIENT_SECRET"
118
+ config.bearer_toekn = "USER_ACCESS_TOKEN"
119
+ end
120
+
121
+ # Only available in sandbox environment
122
+ # Use this to simulate a request with no drivers available
123
+ # More info here https://developer.uber.com/docs/sandbox#section-product-types
124
+ client.apply_availability 'product_id', false
125
+
126
+ client.trip_request(product_id: product_id, start_latitude: start_lat, start_longitude: start_lng, end_latitude: end_lat, end_longitude: end_lng)
127
+ ```
128
+
129
+ ### Update the status of a ride request
130
+
131
+ ```ruby
132
+ client = Uber::Client.new do |config|
133
+ config.client_id = "YOUR_CLIENT_ID"
134
+ config.client_secret = "YOUR_CLIENT_SECRET"
135
+ config.bearer_toekn = "USER_ACCESS_TOKEN"
136
+ end
137
+
138
+ # Only available in sandbox environment
139
+ # Use this to simulate the status change of a ride request
140
+ # More info here https://developer.uber.com/docs/sandbox#section-request
141
+
142
+ client.trip_update('request_id', 'accepted')
143
+ ```
144
+
145
+ ### Retrieve a ride request details
146
+
147
+ ```ruby
148
+ client = Uber::Client.new do |config|
149
+ config.client_id = "YOUR_CLIENT_ID"
150
+ config.client_secret = "YOUR_CLIENT_SECRET"
151
+ config.bearer_toekn = "USER_ACCESS_TOKEN"
152
+ end
153
+
154
+ client.trip_details 'request_id'
155
+ ```
156
+
157
+ ### Cancel a ride request
158
+
159
+ ```ruby
160
+ client = Uber::Client.new do |config|
161
+ config.client_id = "YOUR_CLIENT_ID"
162
+ config.client_secret = "YOUR_CLIENT_SECRET"
163
+ config.bearer_toekn = "USER_ACCESS_TOKEN"
164
+ end
165
+
166
+ client.trip_cancel 'request_id'
167
+ ```
168
+
83
169
  ## Contributors
84
170
 
85
171
  * [Arun Thampi](https://github.com/arunthampi)
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: "spec"
@@ -9,6 +9,14 @@ module Uber
9
9
  arguments = Uber::Arguments.new(args)
10
10
  perform_with_objects(:get, "/v1/products", arguments.options, Product)
11
11
  end
12
+
13
+ def apply_surge(product_id, surge_multiplier)
14
+ perform_with_object(:put, "/v1/sandbox/products/#{product_id}", {surge_multiplier: surge_multiplier}, Product)
15
+ end
16
+
17
+ def apply_availability(product_id, value)
18
+ perform_with_object(:put, "/v1/sandbox/products/#{product_id}", {drivers_available: value}, Product)
19
+ end
12
20
  end
13
21
  end
14
22
  end
@@ -1,11 +1,17 @@
1
1
  require 'uber/arguments'
2
2
  require 'uber/api_request'
3
3
  require 'uber/models/request'
4
+ require 'uber/models/estimate'
4
5
  require 'uber/models/map'
5
6
 
6
7
  module Uber
7
8
  module API
8
9
  module Requests
10
+ def trip_estimate(*args)
11
+ arguments = Uber::Arguments.new(args)
12
+ perform_with_object(:post, "v1/requests/estimate", arguments.options, Estimate)
13
+ end
14
+
9
15
  def trip_request(*args)
10
16
  arguments = Uber::Arguments.new(args)
11
17
  perform_with_object(:post, "v1/requests", arguments.options, Request)
@@ -22,6 +28,10 @@ module Uber
22
28
  def trip_update(request_id, status)
23
29
  perform_with_object(:put, "v1/sandbox/requests/#{request_id}", {status: status}, Request)
24
30
  end
31
+
32
+ def trip_cancel(request_id)
33
+ perform_with_object(:delete, "v1/requests/#{request_id}", {}, Request)
34
+ end
25
35
  end
26
36
  end
27
37
  end
data/lib/uber/client.rb CHANGED
@@ -84,6 +84,12 @@ module Uber
84
84
  request(:put, path, params.to_json, headers)
85
85
  end
86
86
 
87
+ # Perform an HTTP DELETE request
88
+ def delete(path, params = {})
89
+ headers = request_headers(:delete, path, params)
90
+ request(:delete, path, params, headers)
91
+ end
92
+
87
93
  # @return [Boolean]
88
94
  def bearer_token?
89
95
  !!bearer_token
@@ -0,0 +1,29 @@
1
+ module Uber
2
+ class Estimate < Base
3
+ attr_accessor :pickup_estimate, :price, :trip, :errors
4
+
5
+ def price=(value)
6
+ @price = value.nil? ? nil : Price.new(value)
7
+ end
8
+
9
+ def trip=(value)
10
+ @trip = value.nil? ? nil : Trip.new(value)
11
+ end
12
+
13
+ def humanized_estimate
14
+ unless pickup_estimate.nil?
15
+ pickup_estimate.to_i == 1 ? "#{pickup_estimate} minute" : "#{pickup_estimate} minutes"
16
+ end
17
+ end
18
+ end
19
+
20
+ class Price < Base
21
+ attr_accessor :surge_confirmation_href, :surge_confirmation_id, :high_estimate, :low_estimate, :minimum, :surge_multiplier, :display, :currency_code
22
+ end
23
+
24
+ class Trip < Base
25
+ attr_accessor :distance_unit, :duration_estimate, :distance_estimate
26
+ end
27
+
28
+ end
29
+
data/lib/uber/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Uber
2
2
  class Version
3
3
  MAJOR = 0
4
- MINOR = 5
4
+ MINOR = 6
5
5
  PATCH = 0
6
6
 
7
7
  class << self
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uber-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dingding Ye
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-09 00:00:00.000000000 Z
11
+ date: 2016-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -119,6 +119,7 @@ files:
119
119
  - lib/uber/client.rb
120
120
  - lib/uber/error.rb
121
121
  - lib/uber/models/activity.rb
122
+ - lib/uber/models/estimate.rb
122
123
  - lib/uber/models/map.rb
123
124
  - lib/uber/models/price.rb
124
125
  - lib/uber/models/product.rb