uber-ruby 0.2.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/uber/api.rb +8 -6
- data/lib/uber/{activities.rb → api/activities.rb} +2 -2
- data/lib/uber/{me.rb → api/me.rb} +2 -2
- data/lib/uber/{price_estimates.rb → api/price_estimates.rb} +2 -2
- data/lib/uber/{products.rb → api/products.rb} +2 -2
- data/lib/uber/{promotions.rb → api/promotions.rb} +2 -2
- data/lib/uber/api/requests.rb +27 -0
- data/lib/uber/{time_estimates.rb → api/time_estimates.rb} +2 -2
- data/lib/uber/{request.rb → api_request.rb} +3 -3
- data/lib/uber/base.rb +5 -3
- data/lib/uber/client.rb +12 -5
- data/lib/uber/{activity.rb → models/activity.rb} +0 -0
- data/lib/uber/models/map.rb +5 -0
- data/lib/uber/{price.rb → models/price.rb} +0 -0
- data/lib/uber/{product.rb → models/product.rb} +0 -0
- data/lib/uber/{promotion.rb → models/promotion.rb} +0 -0
- data/lib/uber/models/request.rb +55 -0
- data/lib/uber/{time.rb → models/time.rb} +0 -0
- data/lib/uber/{user.rb → models/user.rb} +1 -1
- data/lib/uber/utils.rb +3 -3
- data/lib/uber/version.rb +2 -2
- data/uber-ruby.gemspec +4 -2
- metadata +57 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b110234300659f7056d22ff62ad5aa7d943f78f
|
4
|
+
data.tar.gz: 3b241992c3341246329bfd2e72efa0cee30b7a11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b24e742d27c346d71a8fbb3f6e9b95dc14ebb928b57512f7da5d032af426137193a8ec6b7044a0863149c0f8f9ac45aafa42f0ad79aa3b43735d80ae89ba31a4
|
7
|
+
data.tar.gz: f278ed4c63d1866a86ab96c3102c09eb93cbc9c5094d01588ce36b89f49244074b667beca3329d63cb3c7c0a95130d72945629d7016a902d87df27bae4cebece
|
data/lib/uber/api.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
require 'uber/products'
|
2
|
-
require 'uber/price_estimates'
|
3
|
-
require 'uber/time_estimates'
|
4
|
-
require 'uber/activities'
|
5
|
-
require 'uber/me'
|
6
|
-
require 'uber/promotions'
|
1
|
+
require 'uber/api/products'
|
2
|
+
require 'uber/api/price_estimates'
|
3
|
+
require 'uber/api/time_estimates'
|
4
|
+
require 'uber/api/activities'
|
5
|
+
require 'uber/api/me'
|
6
|
+
require 'uber/api/promotions'
|
7
|
+
require 'uber/api/requests'
|
7
8
|
|
8
9
|
module Uber
|
9
10
|
module API
|
@@ -14,5 +15,6 @@ module Uber
|
|
14
15
|
include Uber::API::Activities
|
15
16
|
include Uber::API::Me
|
16
17
|
include Uber::API::Promotions
|
18
|
+
include Uber::API::Requests
|
17
19
|
end
|
18
20
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'uber/arguments'
|
2
|
+
require 'uber/api_request'
|
3
|
+
require 'uber/models/request'
|
4
|
+
require 'uber/models/map'
|
5
|
+
|
6
|
+
module Uber
|
7
|
+
module API
|
8
|
+
module Requests
|
9
|
+
def trip_request(*args)
|
10
|
+
arguments = Uber::Arguments.new(args)
|
11
|
+
perform_with_object(:post, "v1/requests", arguments.options, Request)
|
12
|
+
end
|
13
|
+
|
14
|
+
def trip_details(request_id)
|
15
|
+
perform_with_object(:get, "v1/requests/#{request_id}", {}, Request)
|
16
|
+
end
|
17
|
+
|
18
|
+
def trip_map(request_id)
|
19
|
+
perform_with_object(:get, "v1/requests/#{request_id}/map", {}, Map)
|
20
|
+
end
|
21
|
+
|
22
|
+
def trip_update(request_id, status)
|
23
|
+
perform_with_object(:put, "v1/sandbox/requests/#{request_id}", {status: status}, Request)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Uber
|
2
|
-
class
|
2
|
+
class ApiRequest
|
3
3
|
attr_accessor :client, :request_method, :path, :options
|
4
4
|
alias_method :verb, :request_method
|
5
5
|
|
@@ -7,7 +7,7 @@ module Uber
|
|
7
7
|
# @param request_method [String, Symbol]
|
8
8
|
# @param path [String]
|
9
9
|
# @param options [Hash]
|
10
|
-
# @return [Uber::
|
10
|
+
# @return [Uber::ApiRequest]
|
11
11
|
def initialize(client, request_method, path, options = {})
|
12
12
|
@client = client
|
13
13
|
@request_method = request_method.to_sym
|
@@ -21,7 +21,7 @@ module Uber
|
|
21
21
|
end
|
22
22
|
|
23
23
|
# @param klass [Class]
|
24
|
-
# @param request [Uber::
|
24
|
+
# @param request [Uber::ApiRequest]
|
25
25
|
# @return [Object]
|
26
26
|
def perform_with_object(klass)
|
27
27
|
klass.new(perform)
|
data/lib/uber/base.rb
CHANGED
@@ -8,9 +8,11 @@ module Uber
|
|
8
8
|
# @param attrs [Hash]
|
9
9
|
# @return [Uber::Base]
|
10
10
|
def initialize(attrs = {})
|
11
|
-
attrs.
|
12
|
-
|
13
|
-
|
11
|
+
if !(attrs.nil? || attrs == "")
|
12
|
+
attrs.each do |key, value|
|
13
|
+
if respond_to?(:"#{key}=")
|
14
|
+
send(:"#{key}=", value)
|
15
|
+
end
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
data/lib/uber/client.rb
CHANGED
@@ -11,8 +11,11 @@ module Uber
|
|
11
11
|
|
12
12
|
attr_accessor :server_token, :client_id, :client_secret
|
13
13
|
attr_accessor :bearer_token
|
14
|
+
attr_accessor :sandbox
|
15
|
+
|
14
16
|
attr_writer :connection_options, :middleware
|
15
17
|
ENDPOINT = 'https://api.uber.com'
|
18
|
+
SANDBOX_ENDPOINT = 'https://sandbox-api.uber.com'
|
16
19
|
|
17
20
|
def initialize(options = {})
|
18
21
|
options.each do |key, value|
|
@@ -54,8 +57,6 @@ module Uber
|
|
54
57
|
@middleware ||= Faraday::RackBuilder.new do |faraday|
|
55
58
|
# Encodes as "application/x-www-form-urlencoded" if not already encoded
|
56
59
|
faraday.request :url_encoded
|
57
|
-
# Handle error responses
|
58
|
-
faraday.response :raise_error
|
59
60
|
# Parse JSON response bodies
|
60
61
|
faraday.response :parse_json
|
61
62
|
# Use instrumentation if available
|
@@ -74,7 +75,13 @@ module Uber
|
|
74
75
|
# Perform an HTTP POST request
|
75
76
|
def post(path, params = {})
|
76
77
|
headers = params.values.any? { |value| value.respond_to?(:to_io) } ? request_headers(:post, path, params, {}) : request_headers(:post, path, params)
|
77
|
-
request(:post, path, params, headers)
|
78
|
+
request(:post, path, params.to_json, headers)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Perform an HTTP PUT request
|
82
|
+
def put(path, params = {})
|
83
|
+
headers = params.values.any? { |value| value.respond_to?(:to_io) } ? request_headers(:post, path, params, {}) : request_headers(:put, path, params)
|
84
|
+
request(:put, path, params.to_json, headers)
|
78
85
|
end
|
79
86
|
|
80
87
|
# @return [Boolean]
|
@@ -114,7 +121,7 @@ module Uber
|
|
114
121
|
#
|
115
122
|
# @return [Faraday::Connection]
|
116
123
|
def connection
|
117
|
-
@connection ||= Faraday.new(ENDPOINT, connection_options)
|
124
|
+
@connection ||= Faraday.new(self.sandbox ? SANDBOX_ENDPOINT : ENDPOINT, connection_options)
|
118
125
|
end
|
119
126
|
|
120
127
|
def request(method, path, params = {}, headers = {})
|
@@ -128,7 +135,7 @@ module Uber
|
|
128
135
|
def request_headers(method, path, params = {}, signature_params = params)
|
129
136
|
headers = {}
|
130
137
|
headers[:accept] = '*/*'
|
131
|
-
headers[:content_type] = 'application/
|
138
|
+
headers[:content_type] = 'application/json; charset=UTF-8'
|
132
139
|
if bearer_token?
|
133
140
|
headers[:authorization] = bearer_auth_header
|
134
141
|
else
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Uber
|
2
|
+
class Request < Base
|
3
|
+
attr_accessor :request_id, :status, :vehicle, :driver, :location, :eta, :surge_multiplier, :meta, :errors
|
4
|
+
|
5
|
+
def driver=(value)
|
6
|
+
@driver = value.nil? ? nil : Driver.new(value)
|
7
|
+
end
|
8
|
+
|
9
|
+
def vehicle=(value)
|
10
|
+
@vehicle = value.nil? ? nil : Vehicle.new(value)
|
11
|
+
end
|
12
|
+
|
13
|
+
def location=(value)
|
14
|
+
@location = value.nil? ? nil : Location.new(value)
|
15
|
+
end
|
16
|
+
|
17
|
+
def errors=(values)
|
18
|
+
@errors = values.map { |v| RequestError.new(v) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def vehicle_name
|
22
|
+
vehicle.nil? ? nil : "#{vehicle.make} #{vehicle.model}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def vehicle_image_url
|
26
|
+
vehicle.nil? ? nil : "#{vehicle.picture_url}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def driver_image_url
|
30
|
+
driver.nil? ? nil : "#{driver.picture_url}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def humanized_eta
|
34
|
+
unless eta.nil?
|
35
|
+
eta.to_i == 1 ? "#{eta} minute" : "#{eta} minutes"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class RequestError < Base
|
41
|
+
attr_accessor :status, :code, :title
|
42
|
+
end
|
43
|
+
|
44
|
+
class Driver < Base
|
45
|
+
attr_accessor :phone_number, :rating, :picture_url, :name
|
46
|
+
end
|
47
|
+
|
48
|
+
class Vehicle < Base
|
49
|
+
attr_accessor :make, :model, :license_plate, :picture_url
|
50
|
+
end
|
51
|
+
|
52
|
+
class Location < Base
|
53
|
+
attr_accessor :latitude, :longitude, :bearing
|
54
|
+
end
|
55
|
+
end
|
File without changes
|
data/lib/uber/utils.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'uber/arguments'
|
2
|
-
require 'uber/
|
2
|
+
require 'uber/api_request'
|
3
3
|
|
4
4
|
module Uber
|
5
5
|
module Utils
|
@@ -8,7 +8,7 @@ module Uber
|
|
8
8
|
# @param options [Hash]
|
9
9
|
# @param klass [Class]
|
10
10
|
def perform_with_object(request_method, path, options, klass)
|
11
|
-
request = Uber::
|
11
|
+
request = Uber::ApiRequest.new(self, request_method, path, options)
|
12
12
|
request.perform_with_object(klass)
|
13
13
|
end
|
14
14
|
|
@@ -17,7 +17,7 @@ module Uber
|
|
17
17
|
# @param options [Hash]
|
18
18
|
# @param klass [Class]
|
19
19
|
def perform_with_objects(request_method, path, options, klass)
|
20
|
-
request = Uber::
|
20
|
+
request = Uber::ApiRequest.new(self, request_method, path, options)
|
21
21
|
request.perform_with_objects(klass)
|
22
22
|
end
|
23
23
|
end
|
data/lib/uber/version.rb
CHANGED
data/uber-ruby.gemspec
CHANGED
@@ -21,8 +21,10 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
spec.required_rubygems_version = '>= 1.3.5'
|
23
23
|
|
24
|
-
spec.add_development_dependency "bundler",
|
25
|
-
spec.add_development_dependency "rake",
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
25
|
+
spec.add_development_dependency "rake", "~> 0"
|
26
|
+
spec.add_development_dependency "webmock", "~> 1.21.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.3.0"
|
26
28
|
|
27
29
|
spec.add_dependency 'faraday', '~> 0.9.0'
|
28
30
|
spec.add_dependency 'json', '~> 1.8'
|
metadata
CHANGED
@@ -1,69 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uber-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.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: 2015-
|
11
|
+
date: 2015-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.5'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: webmock
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.21.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.21.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.3.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.3.0
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: faraday
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
44
72
|
requirements:
|
45
|
-
- - ~>
|
73
|
+
- - "~>"
|
46
74
|
- !ruby/object:Gem::Version
|
47
75
|
version: 0.9.0
|
48
76
|
type: :runtime
|
49
77
|
prerelease: false
|
50
78
|
version_requirements: !ruby/object:Gem::Requirement
|
51
79
|
requirements:
|
52
|
-
- - ~>
|
80
|
+
- - "~>"
|
53
81
|
- !ruby/object:Gem::Version
|
54
82
|
version: 0.9.0
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: json
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
58
86
|
requirements:
|
59
|
-
- - ~>
|
87
|
+
- - "~>"
|
60
88
|
- !ruby/object:Gem::Version
|
61
89
|
version: '1.8'
|
62
90
|
type: :runtime
|
63
91
|
prerelease: false
|
64
92
|
version_requirements: !ruby/object:Gem::Requirement
|
65
93
|
requirements:
|
66
|
-
- - ~>
|
94
|
+
- - "~>"
|
67
95
|
- !ruby/object:Gem::Version
|
68
96
|
version: '1.8'
|
69
97
|
description: A Ruby interface to the Uber API.
|
@@ -77,27 +105,30 @@ files:
|
|
77
105
|
- README.md
|
78
106
|
- Rakefile
|
79
107
|
- lib/uber.rb
|
80
|
-
- lib/uber/activities.rb
|
81
|
-
- lib/uber/activity.rb
|
82
108
|
- lib/uber/api.rb
|
109
|
+
- lib/uber/api/activities.rb
|
110
|
+
- lib/uber/api/me.rb
|
111
|
+
- lib/uber/api/price_estimates.rb
|
112
|
+
- lib/uber/api/products.rb
|
113
|
+
- lib/uber/api/promotions.rb
|
114
|
+
- lib/uber/api/requests.rb
|
115
|
+
- lib/uber/api/time_estimates.rb
|
116
|
+
- lib/uber/api_request.rb
|
83
117
|
- lib/uber/arguments.rb
|
84
118
|
- lib/uber/base.rb
|
85
119
|
- lib/uber/client.rb
|
86
120
|
- lib/uber/error.rb
|
87
|
-
- lib/uber/
|
121
|
+
- lib/uber/models/activity.rb
|
122
|
+
- lib/uber/models/map.rb
|
123
|
+
- lib/uber/models/price.rb
|
124
|
+
- lib/uber/models/product.rb
|
125
|
+
- lib/uber/models/promotion.rb
|
126
|
+
- lib/uber/models/request.rb
|
127
|
+
- lib/uber/models/time.rb
|
128
|
+
- lib/uber/models/user.rb
|
88
129
|
- lib/uber/parse_json.rb
|
89
|
-
- lib/uber/price.rb
|
90
|
-
- lib/uber/price_estimates.rb
|
91
|
-
- lib/uber/product.rb
|
92
|
-
- lib/uber/products.rb
|
93
|
-
- lib/uber/promotion.rb
|
94
|
-
- lib/uber/promotions.rb
|
95
130
|
- lib/uber/rate_limit.rb
|
96
|
-
- lib/uber/request.rb
|
97
|
-
- lib/uber/time.rb
|
98
|
-
- lib/uber/time_estimates.rb
|
99
131
|
- lib/uber/token.rb
|
100
|
-
- lib/uber/user.rb
|
101
132
|
- lib/uber/utils.rb
|
102
133
|
- lib/uber/version.rb
|
103
134
|
- uber-ruby.gemspec
|
@@ -111,17 +142,17 @@ require_paths:
|
|
111
142
|
- lib
|
112
143
|
required_ruby_version: !ruby/object:Gem::Requirement
|
113
144
|
requirements:
|
114
|
-
- -
|
145
|
+
- - ">="
|
115
146
|
- !ruby/object:Gem::Version
|
116
147
|
version: '0'
|
117
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
149
|
requirements:
|
119
|
-
- -
|
150
|
+
- - ">="
|
120
151
|
- !ruby/object:Gem::Version
|
121
152
|
version: 1.3.5
|
122
153
|
requirements: []
|
123
154
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.4.
|
155
|
+
rubygems_version: 2.4.5
|
125
156
|
signing_key:
|
126
157
|
specification_version: 4
|
127
158
|
summary: The Uber Ruby Gem.
|