mercedes 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0ae65dcab047268243b2235f846f7e67f88595a1e2baf867df589e8d3c362587
4
+ data.tar.gz: 109d922e054a8846d6ef0fb0a8794a63bdfe444d63f6edacee69938415d96458
5
+ SHA512:
6
+ metadata.gz: 3ed8a793e354c1ffbcfb19b582b84c621778b9ab135ab010bdd6fe84d1654d706b62f8275dced2b2387ac7438934be61867e57acf1c1dc4c18e6a9bd40f7397c
7
+ data.tar.gz: 7d4b20ec975180c85576486f245bbc9a4dc733c5a35786da3b5228e65dc7c1d13e5a4672f3e8b1b0f4c860da33bf5d37a4a4fd6e0b03334e4e0845fa259d3f04
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .rspec_status
10
+ .byebug_history
11
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.3
5
+ before_install: gem install bundler -v 1.16.2
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development, :test do
6
+ gem 'byebug', '~> 10.0'
7
+ gem 'launchy', '~> 2.4.3'
8
+ gem 'pry', '~> 0.12'
9
+ end
10
+
11
+ group :test do
12
+ gem 'rspec', '~> 3.8'
13
+ gem 'webmock', '~> 3.4.2'
14
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Alfonso Jiménez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,380 @@
1
+ # mercedes
2
+
3
+ <img src="https://user-images.githubusercontent.com/204811/49523343-dc100900-f8a9-11e8-86ff-f1a89e630c8f.png" width="500" alt="Mercedes-Benz logo">
4
+
5
+ This gem is a Ruby client for interacting with Mercedes-Benz Connected Vehicle API. This API allows to access to relevant information about Mercedes-Benz vehicles and also modify its state such as locking/unlocking doors.
6
+
7
+ Notice that this API is still experimental. You can find out more information at: https://developer.mercedes-benz.com/apis/connected_vehicle_experimental_api/
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'mercedes'
15
+ ```
16
+
17
+ or install it yourself as:
18
+
19
+ $ gem install mercedes
20
+
21
+ ## Usage
22
+
23
+ ### Initializing a client
24
+
25
+ The client can be configured globally:
26
+
27
+ ```ruby
28
+ Mercedes.configure do |config|
29
+ config.token = '7dca6d45-0415-4732-a93d-d3514e2c8605'
30
+ end
31
+
32
+ Mercedes::Client.new
33
+ ```
34
+
35
+ or by instance:
36
+
37
+ ```ruby
38
+ Mercedes::Client.new(token: '7dca6d45-0415-4732-a93d-d3514e2c8605')
39
+ ```
40
+
41
+ ### Client methods
42
+
43
+ Clients methods returns a `Mercedes::Response` object. This kind of objects contain methods to get the status of the request (ie: `#ok?`, `#created?`, ...) and a method called `#json` which returns a JSON representation of the response.
44
+
45
+ #### Vehicle
46
+ ##### #vehicles
47
+
48
+ It lists the available vehicles associated to the account, including their `id` (useful for retrieving other information), license plate number and VIN number
49
+
50
+ ```ruby
51
+ client.vehicles.json
52
+ ```
53
+
54
+ Response
55
+ ```ruby
56
+ [
57
+ {
58
+ 'id' => 'AA178E8213TBC9CABA',
59
+ 'licenseplate' => '8594FNC',
60
+ 'finorvin' => '1HM5F7F9XHD7C0861'
61
+ }
62
+ ]
63
+ ```
64
+
65
+ ##### #vehicle(vehicle_id)
66
+ It returns relevant information about a specific vehicle
67
+
68
+ ```ruby
69
+ client.vehicle("AA178E8213TBC9CABA").json
70
+ ```
71
+
72
+ Response
73
+ ```ruby
74
+ {
75
+ 'id' => 'AA178E8213TBC9CABA',
76
+ 'licenseplate' => '8594FNC',
77
+ 'salesdesignation' => 'A Klass W177',
78
+ 'finorvin' => '1HM5F7F9XHD7C0861',
79
+ 'nickname' => 'mmueller',
80
+ 'modelyear' => '2018',
81
+ 'colorname' => 'black',
82
+ 'fueltype' => 'Benzin',
83
+ 'powerhp' => '163',
84
+ 'powerkw' => '122',
85
+ 'numberofdoors' => '5',
86
+ 'numberofseats' => '5'
87
+ }
88
+ ```
89
+
90
+ #### Charge status
91
+
92
+ ##### #charge(vehicle_id:)
93
+
94
+ It returns vehicle charge information
95
+
96
+ ```ruby
97
+ client.charge(vehicle_id: 'ABCD123').json
98
+ ```
99
+
100
+ Response
101
+ ```ruby
102
+ {
103
+ 'stateofcharge' => {
104
+ 'value' => 80,
105
+ 'retrievalstatus' => 'VALID',
106
+ 'timestamp' => 1544019051,
107
+ 'unit' => 'PERCENT'
108
+ }
109
+ }
110
+ ```
111
+
112
+ #### Doors handling
113
+
114
+ ##### #doors(vehicle_id:)
115
+
116
+ It returns vehicle doors status information
117
+
118
+ ```ruby
119
+ client.doors(vehicle_id: 'ABCD123').json
120
+ ```
121
+
122
+ Response
123
+ ```ruby
124
+ {
125
+ 'doorstatusrearleft' => {
126
+ 'value' => 'CLOSED',
127
+ 'retrievalstatus' => 'VALID',
128
+ 'timestamp' => 1544018685
129
+ },
130
+ 'doorlockstatusrearleft' => {
131
+ 'value' => 'LOCKED',
132
+ 'retrievalstatus' => 'VALID',
133
+ 'timestamp' => 1544018685
134
+ },
135
+ 'doorstatusrearright' => {
136
+ 'value' => 'CLOSED',
137
+ 'retrievalstatus' => 'VALID',
138
+ 'timestamp' => 1544018685
139
+ },
140
+ 'doorlockstatusrearright' => {
141
+ 'value' => 'LOCKED',
142
+ 'retrievalstatus' => 'VALID',
143
+ 'timestamp' => 1544018685
144
+ },
145
+ 'doorstatusfrontright' => {
146
+ 'value' => 'CLOSED',
147
+ 'retrievalstatus' => 'VALID',
148
+ 'timestamp' => 1544018685
149
+ },
150
+ 'doorlockstatusfrontright' => {
151
+ 'value' => 'LOCKED',
152
+ 'retrievalstatus' => 'VALID',
153
+ 'timestamp' => 1544018685
154
+ },
155
+ 'doorstatusfrontleft' => {
156
+ 'value' =>' CLOSED',
157
+ 'retrievalstatus' => 'VALID',
158
+ 'timestamp' => 1544018685
159
+ },
160
+ 'doorlockstatusfrontleft' => {
161
+ 'value' => 'LOCKED',
162
+ 'retrievalstatus' => 'VALID',
163
+ 'timestamp' => 1544018685
164
+ },
165
+ 'doorlockstatusdecklid' => {
166
+ 'value' =>'UNLOCKED',
167
+ 'retrievalstatus' => 'VALID',
168
+ 'timestamp' => 1544018685
169
+ },
170
+ 'doorlockstatusgas' => {
171
+ 'value' => 'UNLOCKED',
172
+ 'retrievalstatus' => 'VALID',
173
+ 'timestamp' => 1544018685
174
+ },
175
+ 'doorlockstatusvehicle' => {
176
+ 'value' => 'LOCKED',
177
+ 'retrievalstatus' => 'VALID',
178
+ 'timestamp' => 1544018685
179
+ }
180
+ }
181
+ ```
182
+
183
+ ##### #lock_doors(vehicle_id:)
184
+
185
+ It locks vehicle doors
186
+
187
+ ```ruby
188
+ client.lock_doors(vehicle_id: 'ABCD123').ok?
189
+ #=> true
190
+ ```
191
+
192
+ ##### #unlock_doors(vehicle_id:)
193
+
194
+ It unlocks vehicle doors
195
+
196
+ ```ruby
197
+ client.unlock_doors(vehicle_id: 'ABCD123').ok?
198
+ #=> true
199
+ ```
200
+
201
+ #### Fuel status
202
+
203
+ ##### #fuel(vehicle_id:)
204
+
205
+ It returns vehicle fuel information
206
+
207
+ ```ruby
208
+ client.fuel(vehicle_id: 'ABCD123').json
209
+ ```
210
+
211
+ Response
212
+ ```ruby
213
+ {
214
+ 'fuellevelpercent' => {
215
+ 'value' => 80,
216
+ 'retrievalstatus' => 'VALID',
217
+ 'timestamp' => 1544019329,
218
+ 'unit' => 'PERCENT'
219
+ }
220
+ }
221
+ ```
222
+
223
+ #### Location
224
+ ##### #location(vehicle_id:)
225
+
226
+ It returns current vehicle location
227
+
228
+ ```ruby
229
+ client.location(vehicle_id: 'ABCD123').json
230
+ ```
231
+
232
+ Response
233
+ ```ruby
234
+ {
235
+ 'longitude' => {
236
+ 'value' => 13.381815,
237
+ 'retrievalstatus' => 'VALID',
238
+ 'timestamp' => 1544019449
239
+ },
240
+ 'latitude' => {
241
+ 'value' => 52.516506,
242
+ 'retrievalstatus' => 'VALID',
243
+ 'timestamp' => 1544019449
244
+ },
245
+ 'heading' => {
246
+ 'value' => 52.520008,
247
+ 'retrievalstatus' => 'VALID',
248
+ 'timestamp' =>1544019449
249
+ }
250
+ }
251
+ ```
252
+
253
+ #### Odometer
254
+ ##### #odometer(vehicle_id:)
255
+
256
+ It returns relevant vehicle information such as mileage
257
+
258
+ ```ruby
259
+ client.odometer(vehicle_id: 'ABCD123').json
260
+ ```
261
+
262
+ Response
263
+ ```ruby
264
+ {
265
+ 'odometer' => {
266
+ 'value' => 3000,
267
+ 'retrievalstatus' => 'VALID',
268
+ 'timestamp' => 1544019575,
269
+ 'unit' =>'KILOMETERS'
270
+ },
271
+ 'distancesincereset' => {
272
+ 'value' => 1234,
273
+ 'retrievalstatus' => 'VALID',
274
+ 'timestamp' => 1544019575,
275
+ 'unit' => 'KILOMETERS'
276
+ },
277
+ 'distancesincestart' => {
278
+ 'value' => 276,
279
+ 'retrievalstatus' => 'VALID',
280
+ 'timestamp' => 1544019575,
281
+ 'unit' => 'KILOMETERS'
282
+ }
283
+ }
284
+ ```
285
+
286
+ #### Tires status
287
+ ##### #tires(vehicle_id:)
288
+
289
+ It returns vehicle tires information
290
+
291
+ ```ruby
292
+ client.tires(vehicle_id: 'ABCD123').json
293
+ ```
294
+
295
+ Response
296
+ ```ruby
297
+ {
298
+ 'tirepressurerearleft' => {
299
+ 'value' => 230,
300
+ 'retrievalstatus' => 'VALID',
301
+ 'timestamp' => 1544019784,
302
+ 'unit' => 'KILOPASCAL'
303
+ },
304
+ 'tirepressurerearright' => {
305
+ 'value' => 230,
306
+ 'retrievalstatus' =>'VALID',
307
+ 'timestamp' => 1544019784,
308
+ 'unit' => 'KILOPASCAL'
309
+ },
310
+ 'tirepressurefrontright' => {
311
+ 'value' => 230,
312
+ 'retrievalstatus' => 'VALID',
313
+ 'timestamp' => 1544019784,
314
+ 'unit' => 'KILOPASCAL'
315
+ },
316
+ 'tirepressurefrontleft' => {
317
+ 'value' => 231,
318
+ 'retrievalstatus' => 'VALID',
319
+ 'timestamp' => 1544019784,
320
+ 'unit' => 'KILOPASCAL'
321
+ }
322
+ }
323
+ ```
324
+
325
+ ### Client errors
326
+
327
+ `Mercedes::Client` methods can raise several exceptions when performing requests:
328
+
329
+ * `Mercedes::Client::CarNotAvailable`: Car is not available because it is not connected to the simulator. In order to fix that, go to https://car-simulator.developer.mercedes-benz.com
330
+ * `Mercedes::Client::Unauthorized`: Request is not properly authenticated
331
+ * `Mercedes::Client::ServerError`: Mercedes API is not responding
332
+ * `Mercedes::Client::NotFound`: Resource is not found (`404`)
333
+
334
+ ### How to retrieve the authentication token
335
+
336
+ Mercedes API is secured with OAuth 2. `Mercedes::Client` need a valid access token to be able to perform requests against Mercedes API.
337
+
338
+ You can get a Client ID and a Client Secret at https://developer.mercedes-benz.com/console
339
+
340
+ Then you need to follow the OAuth workflow as described at: https://developer.mercedes-benz.com/content-page/oauth-documentation#_authorization_code_flow
341
+
342
+ Alternatively, this repository contains a small utility which can help to retrieve the access token.
343
+
344
+ You can either pass `CLIENT_ID` and `CLIENT_SECRET` as environment vars or just insert them when the script ask for them:
345
+
346
+ ```shell
347
+ ./bin/get_token
348
+ ```
349
+
350
+ or
351
+
352
+ ```shell
353
+ CLIENT_ID=**** CLIENT_SECRET=**** ./bin/get_token
354
+ ```
355
+
356
+ The script will open the browser where you will need to sign in by using your Mercedes account. Mercedes site will redirect you to something like:
357
+
358
+ ```
359
+ http://localhost/?code=355c72c1-821c-4378-88f0-2230a361d599
360
+ ````
361
+
362
+ That URL contains the `code` that you need to insert back into the script. Then you will obtain the `access_token`:
363
+
364
+ ```js
365
+ {
366
+ "access_token":"91890431-0cf8-433f-8c68-64727db14554",
367
+ "token_type":"Bearer",
368
+ "expires_in":3600,
369
+ "refresh_token":"ede733e3-d076-4cb0-89f1-48568ae9c21e",
370
+ "scope":"mb:vehicle:status:general mb:user:pool:reader"
371
+ }
372
+ ```
373
+
374
+ ## Contributing
375
+
376
+ Bug reports and pull requests are welcome on GitHub at https://github.com/alfonsojimenez/mercedes. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
377
+
378
+ ## License
379
+
380
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $stdout.sync = true
4
+
5
+ require 'bundler/setup'
6
+ require 'mercedes'
7
+ require 'pry'
8
+
9
+ ARGV.clear
10
+ Pry.start
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'patron'
5
+ require 'launchy'
6
+ require 'base64'
7
+
8
+ client = Patron::Session.new do |config|
9
+ config.base_url = 'https://api.secure.mercedes-benz.com/oidc10/auth/oauth/v2/'
10
+ end
11
+
12
+ client_id = ENV.fetch('CLIENT_ID') do
13
+ print 'Insert Client ID: '
14
+ gets.strip
15
+ end
16
+
17
+ client_secret = ENV.fetch('CLIENT_SECRET') do
18
+ print 'Insert Client Secret: '
19
+ gets.strip
20
+ end
21
+
22
+ Launchy.open("https://api.secure.mercedes-benz.com/oidc10/auth/oauth/v2/authorize"\
23
+ "?response_type=code&client_id=#{client_id}&redirect_uri=http://localhost"\
24
+ "&scope=mb:user:pool:reader mb:vehicle:status:general")
25
+
26
+ print 'Insert code: '
27
+
28
+ code = gets.strip
29
+
30
+ headers = {
31
+ 'content-type' => 'application/x-www-form-urlencoded',
32
+ 'authorization' => "Basic #{Base64.strict_encode64("#{client_id}:#{client_secret}")}"
33
+ }
34
+
35
+ puts client.post('token',
36
+ "grant_type=authorization_code&code=#{code}&redirect_uri=http://localhost",
37
+ headers).body
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,10 @@
1
+ require 'mercedes/configurable'
2
+ require 'mercedes/version'
3
+
4
+ module Mercedes
5
+ class << self
6
+ include Mercedes::Configurable
7
+ end
8
+ end
9
+
10
+ require 'mercedes/client'
@@ -0,0 +1,72 @@
1
+ require 'mercedes/response'
2
+ require 'mercedes/client/charge'
3
+ require 'mercedes/client/door'
4
+ require 'mercedes/client/fuel'
5
+ require 'mercedes/client/location'
6
+ require 'mercedes/client/odometer'
7
+ require 'mercedes/client/tire'
8
+ require 'mercedes/client/vehicle'
9
+ require 'patron'
10
+
11
+ module Mercedes
12
+ class Client
13
+ include Client::Charge
14
+ include Client::Door
15
+ include Client::Fuel
16
+ include Client::Location
17
+ include Client::Odometer
18
+ include Client::Tire
19
+ include Client::Vehicle
20
+
21
+ CarNotAvailable = Class.new(RuntimeError)
22
+ NotFound = Class.new(RuntimeError)
23
+ ServerError = Class.new(RuntimeError)
24
+ Unauthorized = Class.new(RuntimeError)
25
+
26
+ BASE_URL = 'https://api.mercedes-benz.com/experimental/connectedvehicle/v1/'
27
+ TIMEOUT = 10
28
+
29
+ attr_reader(*Configurable::OPTIONS)
30
+
31
+ def initialize(options = {})
32
+ Configurable::OPTIONS.each do |key|
33
+ instance_variable_set(:"@#{key}", options[key] || Mercedes.send(key))
34
+ end
35
+
36
+ http_client.base_url = BASE_URL
37
+ end
38
+
39
+ private
40
+
41
+ def http_client
42
+ @http_client ||= Patron::Session.new do |config|
43
+ config.timeout = TIMEOUT
44
+ config.headers = {
45
+ 'Content-Type' => 'application/json',
46
+ 'Accept' => 'application/json',
47
+ 'authorization' => "Bearer #{@token}"
48
+ }
49
+ end
50
+ end
51
+
52
+ def perform_request(method, url, params = {})
53
+ handle_errors do
54
+ Response.new(http_client.request(method, url, {}, params))
55
+ end
56
+ end
57
+
58
+ def handle_errors
59
+ yield.tap do |response|
60
+ if response.request_timeout?
61
+ raise CarNotAvailable, 'Car is not available because it is not connected to simulator'
62
+ elsif response.unauthorized?
63
+ raise Unauthorized, 'Unauthorized'
64
+ elsif response.server_error?
65
+ raise ServerError, 'Server is not available'
66
+ elsif response.not_found?
67
+ raise NotFound, 'Resource not found'
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,9 @@
1
+ module Mercedes
2
+ class Client
3
+ module Charge
4
+ def charge(vehicle_id:)
5
+ perform_request(:get, "vehicles/#{vehicle_id}/stateofcharge")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ module Mercedes
2
+ class Client
3
+ module Door
4
+ def doors(vehicle_id:)
5
+ perform_request(:get, "vehicles/#{vehicle_id}/doors")
6
+ end
7
+
8
+ def lock_doors(vehicle_id:)
9
+ perform_request(:post, "vehicles/#{vehicle_id}/doors", data: { command: 'LOCK' }.to_json)
10
+ end
11
+
12
+ def unlock_doors(vehicle_id:)
13
+ perform_request(:post, "vehicles/#{vehicle_id}/doors", data: { command: 'UNLOCK' }.to_json)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module Mercedes
2
+ class Client
3
+ module Fuel
4
+ def fuel(vehicle_id:)
5
+ perform_request(:get, "vehicles/#{vehicle_id}/fuel")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Mercedes
2
+ class Client
3
+ module Location
4
+ def location(vehicle_id:)
5
+ perform_request(:get, "vehicles/#{vehicle_id}/location")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Mercedes
2
+ class Client
3
+ module Odometer
4
+ def odometer(vehicle_id:)
5
+ perform_request(:get, "vehicles/#{vehicle_id}/odometer")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Mercedes
2
+ class Client
3
+ module Tire
4
+ def tires(vehicle_id:)
5
+ perform_request(:get, "vehicles/#{vehicle_id}/tires")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module Mercedes
2
+ class Client
3
+ module Vehicle
4
+ def vehicles
5
+ perform_request(:get, 'vehicles')
6
+ end
7
+
8
+ def vehicle(id)
9
+ perform_request(:get, "vehicles/#{id}")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ module Mercedes
2
+ module Configurable
3
+ OPTIONS = %i[token].freeze
4
+
5
+ attr_accessor(*OPTIONS)
6
+
7
+ def configure
8
+ yield self
9
+ end
10
+
11
+ def auth(opts = {})
12
+ "authorization #{opts[:token] || token}"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,40 @@
1
+ require 'delegate'
2
+ require 'oj'
3
+
4
+ module Mercedes
5
+ class Response < SimpleDelegator
6
+ alias_method :object, :__getobj__
7
+
8
+ def json
9
+ Oj.load(object.body)
10
+ end
11
+
12
+ def ok?
13
+ object.status == 200
14
+ end
15
+
16
+ def created?
17
+ object.status == 201
18
+ end
19
+
20
+ def no_content?
21
+ object.status == 204
22
+ end
23
+
24
+ def unauthorized?
25
+ object.status == 401
26
+ end
27
+
28
+ def not_found?
29
+ object.status == 404
30
+ end
31
+
32
+ def request_timeout?
33
+ object.status == 408
34
+ end
35
+
36
+ def server_error?
37
+ object.status >= 500
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module Mercedes
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'mercedes/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'mercedes'
7
+ spec.version = Mercedes::VERSION
8
+ spec.authors = ['Alfonso Jiménez']
9
+ spec.email = ['me@alfie.cat']
10
+
11
+ spec.summary = %q{Ruby client for interacting with Mercedes-Benz Connected Vehicle API}
12
+ spec.description = %q{This client allows to access to relevant information about Mercedes-Benz vehicles and modify its state such as locking/unlocking doors}
13
+ spec.homepage = 'https://github.com/alfonsojimenez/mercedes'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
18
+ end
19
+ spec.bindir = 'bin'
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'patron', '~> 0.13.1'
24
+ spec.add_dependency 'oj', '~> 3.7.4'
25
+ spec.add_development_dependency 'bundler', '~> 1.16'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mercedes
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Alfonso Jiménez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-12-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: patron
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.13.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.13.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: oj
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.7.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.7.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: This client allows to access to relevant information about Mercedes-Benz
70
+ vehicles and modify its state such as locking/unlocking doors
71
+ email:
72
+ - me@alfie.cat
73
+ executables:
74
+ - console
75
+ - get_token
76
+ - setup
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - ".gitignore"
81
+ - ".rspec"
82
+ - ".travis.yml"
83
+ - Gemfile
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - bin/console
88
+ - bin/get_token
89
+ - bin/setup
90
+ - lib/mercedes.rb
91
+ - lib/mercedes/client.rb
92
+ - lib/mercedes/client/charge.rb
93
+ - lib/mercedes/client/door.rb
94
+ - lib/mercedes/client/fuel.rb
95
+ - lib/mercedes/client/location.rb
96
+ - lib/mercedes/client/odometer.rb
97
+ - lib/mercedes/client/tire.rb
98
+ - lib/mercedes/client/vehicle.rb
99
+ - lib/mercedes/configurable.rb
100
+ - lib/mercedes/response.rb
101
+ - lib/mercedes/version.rb
102
+ - mercedes.gemspec
103
+ homepage: https://github.com/alfonsojimenez/mercedes
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.7.6
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Ruby client for interacting with Mercedes-Benz Connected Vehicle API
127
+ test_files: []