smartcar 3.0.5 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/Gemfile.lock +1 -1
- data/lib/smartcar/base.rb +9 -4
- data/lib/smartcar/vehicle.rb +18 -1
- data/lib/smartcar/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32c5b37d833b0951c08a33faa9e4c3af4cc02a5032b46fdd22ee80418aaa23ec
|
4
|
+
data.tar.gz: e89526a99861483111ef3fb8af353d64e2444f32641772e34a78f66524f66a7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc82965cdba424926a2929cc8c6ba9e9e9c957939b60fde968485ba04985dc50542372d7c42dbb6621fbda362f2666a8a67ee93b0665548f7806b6d46f85efc0
|
7
|
+
data.tar.gz: 0faa6f47b0242ec99b5d3752a7ae2507bea41da3bb1b9a41880dc22dd6ebcf50292456f00586f489095dc00c2f86924e76eef8170acfa48e410d0b4d13d46156
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/lib/smartcar/base.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'oauth2'
|
4
4
|
require 'base64'
|
5
|
+
require 'rbconfig'
|
5
6
|
module Smartcar
|
6
7
|
# The Base class for all of the other class.
|
7
8
|
# Let other classes inherit from here and put common methods here.
|
@@ -23,11 +24,15 @@ module Smartcar
|
|
23
24
|
# @param data [Hash] request body if needed.
|
24
25
|
#
|
25
26
|
# @return [Hash] The response Json parsed as a hash.
|
26
|
-
define_method verb do |path, data = nil|
|
27
|
+
define_method verb do |path, data = nil, headers = {}|
|
27
28
|
response = service.send(verb) do |request|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
request_headers = {}
|
30
|
+
request_headers['Authorization'] = auth_type == BASIC ? "Basic #{token}" : "Bearer #{token}"
|
31
|
+
request_headers['sc-unit-system'] = unit_system if unit_system
|
32
|
+
request_headers['Content-Type'] = 'application/json'
|
33
|
+
request_headers['User-Agent'] =
|
34
|
+
"Smartcar/#{VERSION} (#{RbConfig::CONFIG['host_os']}; #{RbConfig::CONFIG['arch']}) Ruby v#{RUBY_VERSION}"
|
35
|
+
request.headers = request_headers.merge(headers)
|
31
36
|
complete_path = "/v#{version}#{path}"
|
32
37
|
if verb == :get
|
33
38
|
request.url complete_path, data
|
data/lib/smartcar/vehicle.rb
CHANGED
@@ -201,7 +201,7 @@ module Smartcar
|
|
201
201
|
#
|
202
202
|
# @param webhook_id [String] Webhook id to subscribe to
|
203
203
|
#
|
204
|
-
# @return [OpenStruct]
|
204
|
+
# @return [OpenStruct] An object representing the JSON response and a meta attribute
|
205
205
|
# with the relevant items from response headers.
|
206
206
|
def subscribe!(webhook_id)
|
207
207
|
response, headers = post(METHODS.dig(:subscribe!, :path).call(id, webhook_id), {})
|
@@ -234,5 +234,22 @@ module Smartcar
|
|
234
234
|
response, headers = post("/vehicles/#{id}/batch", request_body)
|
235
235
|
process_batch_response(response, headers)
|
236
236
|
end
|
237
|
+
|
238
|
+
# General purpose method to make requests to the Smartcar API - can be
|
239
|
+
# used to make requests to brand specific endpoints.
|
240
|
+
#
|
241
|
+
# @param method [String] The HTTP request method to use.
|
242
|
+
# @param path [String] The path to make the request to.
|
243
|
+
# @param body [Hash] The request body.
|
244
|
+
# @param headers [Hash] The headers to inlcude in the request.
|
245
|
+
#
|
246
|
+
# @return [OpenStruct] An object with a "body" attribute that contains the
|
247
|
+
# response body and a "meta" attribute with the relevant items from response headers.
|
248
|
+
def request(method, path, body = {}, headers = {})
|
249
|
+
path = "/vehicles/#{id}/#{path}"
|
250
|
+
raw_response, headers = send(method, path, body, headers)
|
251
|
+
meta = build_meta(headers)
|
252
|
+
json_to_ostruct({ body: raw_response, meta: meta })
|
253
|
+
end
|
237
254
|
end
|
238
255
|
end
|
data/lib/smartcar/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smartcar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ashwin Subramanian
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|