uber-ruby 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +94 -0
- data/lib/uber/api.rb +4 -0
- data/lib/uber/api/places.rb +19 -0
- data/lib/uber/api/reminders.rb +43 -0
- data/lib/uber/client.rb +8 -0
- data/lib/uber/error.rb +3 -0
- data/lib/uber/models/place.rb +5 -0
- data/lib/uber/models/product.rb +6 -1
- data/lib/uber/models/reminder.rb +30 -0
- data/lib/uber/models/user.rb +5 -1
- data/lib/uber/version.rb +2 -2
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4c9bf4cb4b8f0ced763b3702bb943a90ae36327
|
4
|
+
data.tar.gz: 2e123aa2989f454b0f0e3e88a908e11e38aa7c95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9ec68f21a3ebb754e11df5d7559d222dfcb41552578697583110299dfa1c1130c45bf66afc23ca40bb8d6780fbd5babcc04f543414d0267d8a1a814dadd7d82
|
7
|
+
data.tar.gz: d3c849532fe23d3f62ac85493fb4f92f1c6747c7aee8c88afe89f8162f316419960ffd376b643d7c089c659ca103e832e3d2b24002c2a0cc4001384c52dae9c0
|
data/README.md
CHANGED
@@ -26,6 +26,22 @@ client = Uber::Client.new do |config|
|
|
26
26
|
end
|
27
27
|
```
|
28
28
|
|
29
|
+
### Sandbox mode
|
30
|
+
The Uber API Sandbox provides development endpoints for testing the functionality of an application without making calls to the production Uber platform. All requests made to the Sandbox environment will be ephemeral.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
client = Uber::Client.new do |config|
|
34
|
+
config.server_token = "YOUR_SERVER_TOKEN"
|
35
|
+
config.client_id = "YOUR_CLIENT_ID"
|
36
|
+
config.client_secret = "YOUR_CLIENT_SECRET"
|
37
|
+
config.sandbox = true
|
38
|
+
end
|
39
|
+
# More info here https://developer.uber.com/docs/sandbox#section-product-types
|
40
|
+
```
|
41
|
+
|
42
|
+
## Debug mode
|
43
|
+
Add `config.debug = true` to log HTTP request-response headers while making API requests.
|
44
|
+
|
29
45
|
## Usage
|
30
46
|
|
31
47
|
### Request Products
|
@@ -166,9 +182,87 @@ end
|
|
166
182
|
client.trip_cancel 'request_id'
|
167
183
|
```
|
168
184
|
|
185
|
+
### Retrieve addresses
|
186
|
+
Retrieves address information of _home_ or _work_.
|
187
|
+
|
188
|
+
```ruby
|
189
|
+
client = Uber::Client.new do |config|
|
190
|
+
config.client_id = "YOUR_CLIENT_ID"
|
191
|
+
config.client_secret = "YOUR_CLIENT_SECRET"
|
192
|
+
config.bearer_token = "USER_ACCESS_TOKEN"
|
193
|
+
end
|
194
|
+
|
195
|
+
place = client.places 'home'
|
196
|
+
place.address #=> retuns fully qualified address of location
|
197
|
+
```
|
198
|
+
|
199
|
+
### Update addresses
|
200
|
+
Updates address information of _home_ or _work_.
|
201
|
+
```ruby
|
202
|
+
client = Uber::Client.new do |config|
|
203
|
+
config.client_id = "YOUR_CLIENT_ID"
|
204
|
+
config.client_secret = "YOUR_CLIENT_SECRET"
|
205
|
+
config.bearer_token = "USER_ACCESS_TOKEN"
|
206
|
+
end
|
207
|
+
|
208
|
+
place = client.place_update 'home', 'my address'
|
209
|
+
place.address #=> retuns fully qualified address of location
|
210
|
+
```
|
211
|
+
|
212
|
+
### Retrieve a reminder
|
213
|
+
This allows you to get the status of an existing ride reminder.
|
214
|
+
**Note**: It only supports _server_token_.
|
215
|
+
```ruby
|
216
|
+
client = Uber::Client.new do |config|
|
217
|
+
config.client_id = "YOUR_CLIENT_ID"
|
218
|
+
config.client_secret = "YOUR_CLIENT_SECRET"
|
219
|
+
client.server_token = "YOUR_SERVER_TOKEN"
|
220
|
+
end
|
221
|
+
client.reminder 'reminder_id'
|
222
|
+
#=> Uber::Reminder
|
223
|
+
```
|
224
|
+
|
225
|
+
### Add a reminder
|
226
|
+
This allows developers to set a reminder for a future trip. You can pass object of `Time` or _unixtime_ in `reminder_time` and `event.time`.
|
227
|
+
```ruby
|
228
|
+
reminder = client.add_reminder({reminder_time: Time.local(2016, 9, 8, 23, 23, 23),
|
229
|
+
phone_number: '+91-9999999999',
|
230
|
+
trip_branding: {link_text: 'My first reminder'},
|
231
|
+
event: {time: Time.now + 234234},
|
232
|
+
reminder_id: 'rem1' })
|
233
|
+
reminder.event.time
|
234
|
+
#=> 2016-09-11 11:02:06 UTC
|
235
|
+
reminder.reminder_time
|
236
|
+
#=> 2016-09-08 17:53:23 UTC
|
237
|
+
reminder.reminder_status
|
238
|
+
#=> "pending"
|
239
|
+
```
|
240
|
+
|
241
|
+
### Update a reminder
|
242
|
+
This allows you to update an existing reminder.
|
243
|
+
```ruby
|
244
|
+
reminder = client.add_reminder('rem1', {reminder_time: Time.local(2016, 9, 10, 23, 23, 23),
|
245
|
+
phone_number: '+91-9999999999',
|
246
|
+
trip_branding: {link_text: 'My edited reminder'},
|
247
|
+
event: {time: Time.now + 234234},
|
248
|
+
reminder_id: 'rem1' })
|
249
|
+
reminder.trip_branding.link_text
|
250
|
+
#=> "My edited reminder"
|
251
|
+
|
252
|
+
```
|
253
|
+
|
254
|
+
### Delete a reminder
|
255
|
+
This allows you to remove any reminder in the pending state from being sent.
|
256
|
+
```ruby
|
257
|
+
reminder.delete_reminder 'rem1'
|
258
|
+
#=> Uber::Reminder
|
259
|
+
```
|
260
|
+
|
261
|
+
|
169
262
|
## Contributors
|
170
263
|
|
171
264
|
* [Arun Thampi](https://github.com/arunthampi)
|
265
|
+
* [Ankur Goel](https://github.com/AnkurGel)
|
172
266
|
|
173
267
|
## Contributing
|
174
268
|
|
data/lib/uber/api.rb
CHANGED
@@ -4,7 +4,9 @@ require 'uber/api/time_estimates'
|
|
4
4
|
require 'uber/api/activities'
|
5
5
|
require 'uber/api/me'
|
6
6
|
require 'uber/api/promotions'
|
7
|
+
require 'uber/api/reminders.rb'
|
7
8
|
require 'uber/api/requests'
|
9
|
+
require 'uber/api/places'
|
8
10
|
|
9
11
|
module Uber
|
10
12
|
module API
|
@@ -15,6 +17,8 @@ module Uber
|
|
15
17
|
include Uber::API::Activities
|
16
18
|
include Uber::API::Me
|
17
19
|
include Uber::API::Promotions
|
20
|
+
include Uber::API::Places
|
21
|
+
include Uber::API::Reminders
|
18
22
|
include Uber::API::Requests
|
19
23
|
end
|
20
24
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'uber/arguments'
|
2
|
+
require 'uber/api_request'
|
3
|
+
require 'uber/models/place'
|
4
|
+
|
5
|
+
module Uber
|
6
|
+
module API
|
7
|
+
module Places
|
8
|
+
def place(place_id)
|
9
|
+
perform_with_object(:get, "/v1/places/#{place_id}", {}, Place)
|
10
|
+
end
|
11
|
+
|
12
|
+
def place_update(place_id, address)
|
13
|
+
perform_with_object(:put, "/v1/places/#{place_id}", {address: address}, Place)
|
14
|
+
end
|
15
|
+
|
16
|
+
alias_method :place_detail, :place
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'uber/arguments'
|
2
|
+
require 'uber/api_request'
|
3
|
+
require 'uber/models/reminder'
|
4
|
+
|
5
|
+
module Uber
|
6
|
+
module API
|
7
|
+
module Reminders
|
8
|
+
|
9
|
+
def reminder(reminder_id)
|
10
|
+
perform_with_object(:get, "/v1/reminders/#{reminder_id}", {}, Reminder)
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_reminder(*args)
|
14
|
+
arguments = sanitize_time(Uber::Arguments.new(args))
|
15
|
+
perform_with_object(:post, "/v1/reminders", arguments.options, Reminder)
|
16
|
+
end
|
17
|
+
|
18
|
+
def update_reminder(reminder_id, *args)
|
19
|
+
arguments = sanitize_time(Uber::Arguments.new(args))
|
20
|
+
perform_with_object(:patch, "/v1/reminders/#{reminder_id}", arguments.options, Reminder)
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete_reminder(reminder_id)
|
24
|
+
perform_with_object(:delete, "/v1/reminders/#{reminder_id}", {}, Reminder)
|
25
|
+
end
|
26
|
+
|
27
|
+
alias_method :reminder_detail, :reminder
|
28
|
+
|
29
|
+
private
|
30
|
+
def sanitize_time(arguments)
|
31
|
+
options = arguments.options
|
32
|
+
options[:reminder_time] = to_unix_time(options[:reminder_time])
|
33
|
+
options[:event][:time] = to_unix_time(options[:event][:time]) if options[:event]
|
34
|
+
arguments
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_unix_time(attr)
|
38
|
+
attr && attr.instance_of?(::Time) ? attr.to_i : attr
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/uber/client.rb
CHANGED
@@ -12,6 +12,7 @@ module Uber
|
|
12
12
|
attr_accessor :server_token, :client_id, :client_secret
|
13
13
|
attr_accessor :bearer_token
|
14
14
|
attr_accessor :sandbox
|
15
|
+
attr_accessor :debug
|
15
16
|
|
16
17
|
attr_writer :connection_options, :middleware
|
17
18
|
ENDPOINT = 'https://api.uber.com'
|
@@ -59,6 +60,7 @@ module Uber
|
|
59
60
|
faraday.request :url_encoded
|
60
61
|
# Parse JSON response bodies
|
61
62
|
faraday.response :parse_json
|
63
|
+
faraday.response :logger if self.debug
|
62
64
|
# Use instrumentation if available
|
63
65
|
faraday.use :instrumentation if defined?(FaradayMiddleware::Instrumentation)
|
64
66
|
# Set default HTTP adapter
|
@@ -90,6 +92,12 @@ module Uber
|
|
90
92
|
request(:delete, path, params, headers)
|
91
93
|
end
|
92
94
|
|
95
|
+
# Perform an HTTP PATCH request
|
96
|
+
def patch(path, params={})
|
97
|
+
headers = params.values.any? { |value| value.respond_to?(:to_io) } ? request_headers(:post, path, params, {}) : request_headers(:patch, path, params)
|
98
|
+
request(:patch, path, params.to_json, headers)
|
99
|
+
end
|
100
|
+
|
93
101
|
# @return [Boolean]
|
94
102
|
def bearer_token?
|
95
103
|
!!bearer_token
|
data/lib/uber/error.rb
CHANGED
data/lib/uber/models/product.rb
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
module Uber
|
2
2
|
class Product < Base
|
3
|
-
attr_accessor :product_id, :description, :display_name, :capacity, :image
|
3
|
+
attr_accessor :product_id, :description, :display_name, :capacity, :image,
|
4
|
+
:cash_enabled, :shared, :price_details
|
5
|
+
|
6
|
+
[:cash_enabled, :shared].each do |m|
|
7
|
+
define_method("#{m}?") { instance_variable_get("@#{m}") }
|
8
|
+
end
|
4
9
|
end
|
5
10
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Uber
|
2
|
+
class Reminder < Base
|
3
|
+
attr_accessor :event, :product_id, :reminder_id, :reminder_time, :reminder_status, :trip_branding
|
4
|
+
|
5
|
+
def event=(value)
|
6
|
+
@event = value && Event.new(value)
|
7
|
+
end
|
8
|
+
|
9
|
+
def trip_branding=(value)
|
10
|
+
@trip_branding = value && TripBranding.new(value)
|
11
|
+
end
|
12
|
+
|
13
|
+
def reminder_time
|
14
|
+
@reminder_time && ::Time.at(@reminder_time)
|
15
|
+
end
|
16
|
+
|
17
|
+
class Event < Base
|
18
|
+
attr_accessor :name, :location, :latitude, :longitude, :time
|
19
|
+
|
20
|
+
def time
|
21
|
+
@time && ::Time.at(@time)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class TripBranding < Base
|
26
|
+
attr_accessor :link_text, :partner_deeplink
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/lib/uber/models/user.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
module Uber
|
2
2
|
class User < Base
|
3
|
-
attr_accessor :first_name, :last_name, :email, :picture, :promo_code, :uuid
|
3
|
+
attr_accessor :first_name, :last_name, :email, :picture, :promo_code, :mobile_verified, :uuid
|
4
|
+
|
5
|
+
def mobile_verified?
|
6
|
+
!!self.mobile_verified
|
7
|
+
end
|
4
8
|
end
|
5
9
|
end
|
data/lib/uber/version.rb
CHANGED
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.
|
4
|
+
version: 0.7.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-
|
11
|
+
date: 2016-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,9 +108,11 @@ files:
|
|
108
108
|
- lib/uber/api.rb
|
109
109
|
- lib/uber/api/activities.rb
|
110
110
|
- lib/uber/api/me.rb
|
111
|
+
- lib/uber/api/places.rb
|
111
112
|
- lib/uber/api/price_estimates.rb
|
112
113
|
- lib/uber/api/products.rb
|
113
114
|
- lib/uber/api/promotions.rb
|
115
|
+
- lib/uber/api/reminders.rb
|
114
116
|
- lib/uber/api/requests.rb
|
115
117
|
- lib/uber/api/time_estimates.rb
|
116
118
|
- lib/uber/api_request.rb
|
@@ -121,9 +123,11 @@ files:
|
|
121
123
|
- lib/uber/models/activity.rb
|
122
124
|
- lib/uber/models/estimate.rb
|
123
125
|
- lib/uber/models/map.rb
|
126
|
+
- lib/uber/models/place.rb
|
124
127
|
- lib/uber/models/price.rb
|
125
128
|
- lib/uber/models/product.rb
|
126
129
|
- lib/uber/models/promotion.rb
|
130
|
+
- lib/uber/models/reminder.rb
|
127
131
|
- lib/uber/models/request.rb
|
128
132
|
- lib/uber/models/time.rb
|
129
133
|
- lib/uber/models/user.rb
|