smartcar 3.0.0 → 3.0.1
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/Gemfile.lock +4 -2
- data/README.md +2 -2
- data/lib/smartcar.rb +1 -0
- data/lib/smartcar/auth_client.rb +2 -2
- data/lib/smartcar/utils.rb +14 -2
- data/lib/smartcar/version.rb +1 -1
- data/ruby-sdk.gemspec +1 -0
- metadata +16 -3
- data/lib/open_struct_extensions.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40fb835517be1ed88352e2988be1800570c3bc6a2cd46db81d20cd1430aa5391
|
4
|
+
data.tar.gz: 23137d3489c55affd34287acc0a7301c6af04cf74ab7ec2bca0bc9476a11ee0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46cdf2c55fb8213943e0e5841b91aafa4e9be4d9b24d7e6121507f341fe51871892074667774f2214329f61d299899e0b18505f9fc0d6d007f229861ae5a69de
|
7
|
+
data.tar.gz: bb650cc504f122c4adf1869f067316cb7470746fa19c33c7a81ad83c4371c9b417699d93e46ac2e35cd39a6bbcafb10f4f06cadaf06d667152c9118fff226153
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
smartcar (3.0.
|
4
|
+
smartcar (3.0.1)
|
5
5
|
oauth2 (~> 1.4)
|
6
|
+
recursive-open-struct (~> 1.1.3)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
10
|
-
addressable (2.
|
11
|
+
addressable (2.8.0)
|
11
12
|
public_suffix (>= 2.0.2, < 5.0)
|
12
13
|
ast (2.4.2)
|
13
14
|
backport (1.1.2)
|
@@ -53,6 +54,7 @@ GEM
|
|
53
54
|
readapt (1.3.0)
|
54
55
|
backport (~> 1.1)
|
55
56
|
thor (~> 1.0)
|
57
|
+
recursive-open-struct (1.1.3)
|
56
58
|
redcarpet (3.5.1)
|
57
59
|
regexp_parser (2.1.1)
|
58
60
|
rexml (3.2.5)
|
data/README.md
CHANGED
@@ -82,7 +82,7 @@ Example Usage for calling the reports API with oAuth token
|
|
82
82
|
```ruby
|
83
83
|
2.5.7 :001 > require 'smartcar'
|
84
84
|
=> true
|
85
|
-
2.5.7 :003 > ids = Smartcar
|
85
|
+
2.5.7 :003 > ids = Smartcar.get_vehicles(token: token).vehicles
|
86
86
|
=> ["4bb777b2-bde7-4305-8952-25956f8c0868"]
|
87
87
|
2.5.7 :004 > vehicle = Smartcar::Vehicle.new(token: token, id: ids.first)
|
88
88
|
=> #<Smartcar::Vehicle:0x0000558dcd7ee608 @token="c900e00e-ee8e-403d-a7bf-f992bc0ad302", @id="e31c9de6-1332-472b-b648-5d74b05b7fda", @options={:unit_system=>"metric", :version=>"2.0"}, @unit_system="metric", @version="2.0", @service=#<Faraday::Connection:0x0000558dcd7d63f0 @parallel_manager=nil, @headers={"User-Agent"=>"Faraday v1.4.2"}, @params={}, @options=#<Faraday::RequestOptions timeout=310>, @ssl=#<Faraday::SSLOptions verify=true>, @default_parallel_manager=nil, @builder=#<Faraday::RackBuilder:0x0000558dcd7c1bf8 @adapter=Faraday::Adapter::NetHttp, @handlers=[Faraday::Request::UrlEncoded], @app=#<Faraday::Request::UrlEncoded:0x0000558dcd7af048 @app=#<Faraday::Adapter::NetHttp:0x0000558dcd7af390 @ssl_cert_store=#<OpenSSL::X509::Store:0x0000558dcd7a36a8 @verify_callback=nil, @error=nil, @error_string=nil, @chain=nil, @time=nil>, @app=#<Proc:0x0000558dcd7af278 /home/ashwinsubramanian/.rvm/gems/ruby-2.7.2/gems/faraday-1.4.2/lib/faraday/adapter.rb:37 (lambda)>, @connection_options={}, @config_block=nil>, @options={}>>, @url_prefix=#<URI::HTTPS https://api.smartcar.com/>, @proxy=nil, @manual_proxy=false>>
|
@@ -165,4 +165,4 @@ To contribute, please:
|
|
165
165
|
|
166
166
|
Smartcar aims to support the SDK on all Ruby branches that have a status of "normal maintenance" or "security maintenance" as defined in the [Ruby Branches documentation](https://www.ruby-lang.org/en/downloads/branches/).
|
167
167
|
|
168
|
-
In accordance with the Semantic Versioning specification, the addition of support for new Ruby branches would result in a MINOR version bump and the removal of support for Ruby branches would result in a MAJOR version bump.
|
168
|
+
In accordance with the Semantic Versioning specification, the addition of support for new Ruby branches would result in a MINOR version bump and the removal of support for Ruby branches would result in a MAJOR version bump.
|
data/lib/smartcar.rb
CHANGED
data/lib/smartcar/auth_client.rb
CHANGED
@@ -72,7 +72,7 @@ module Smartcar
|
|
72
72
|
.get_token(code, redirect_uri: redirect_uri)
|
73
73
|
.to_hash
|
74
74
|
|
75
|
-
|
75
|
+
json_to_ostruct(token_hash)
|
76
76
|
rescue OAuth2::Error => e
|
77
77
|
raise build_error(e.response.status, e.response.body, e.response.headers)
|
78
78
|
end
|
@@ -89,7 +89,7 @@ module Smartcar
|
|
89
89
|
token_object = OAuth2::AccessToken.from_hash(client, { refresh_token: token })
|
90
90
|
token_object = token_object.refresh!
|
91
91
|
|
92
|
-
|
92
|
+
json_to_ostruct(token_object.to_hash)
|
93
93
|
rescue OAuth2::Error => e
|
94
94
|
raise build_error(e.response.status, e.response.body, e.response.headers)
|
95
95
|
end
|
data/lib/smartcar/utils.rb
CHANGED
@@ -25,6 +25,18 @@ module Smartcar
|
|
25
25
|
ENV[config_name]
|
26
26
|
end
|
27
27
|
|
28
|
+
# Converts a hash to RecursiveOpenStruct (a powered up OpenStruct object).
|
29
|
+
# NOTE - Do not replace with the more elegant looking
|
30
|
+
# JSON.parse(meta_hash.to_json, object_class: OpenStruct)
|
31
|
+
# this is because we had an app using OJ as their json parser which led to an issue using the
|
32
|
+
# above mentioned method. Source : https://github.com/ohler55/oj/issues/239
|
33
|
+
# @param hash [Hash] json object as hash
|
34
|
+
#
|
35
|
+
# @return [RecursiveOpenStruct]
|
36
|
+
def json_to_ostruct(hash)
|
37
|
+
RecursiveOpenStruct.new(hash)
|
38
|
+
end
|
39
|
+
|
28
40
|
def build_meta(headers)
|
29
41
|
meta_hash = {
|
30
42
|
'sc-data-age' => :data_age,
|
@@ -33,14 +45,14 @@ module Smartcar
|
|
33
45
|
}.each_with_object({}) do |(header_name, key), meta|
|
34
46
|
meta[key] = headers[header_name] if headers[header_name]
|
35
47
|
end
|
36
|
-
meta =
|
48
|
+
meta = json_to_ostruct(meta_hash)
|
37
49
|
meta.data_age &&= DateTime.parse(meta.data_age)
|
38
50
|
|
39
51
|
meta
|
40
52
|
end
|
41
53
|
|
42
54
|
def build_response(body, headers)
|
43
|
-
response =
|
55
|
+
response = json_to_ostruct(body)
|
44
56
|
response.meta = build_meta(headers)
|
45
57
|
response
|
46
58
|
end
|
data/lib/smartcar/version.rb
CHANGED
data/ruby-sdk.gemspec
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.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ashwin Subramanian
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -170,6 +170,20 @@ dependencies:
|
|
170
170
|
- - "~>"
|
171
171
|
- !ruby/object:Gem::Version
|
172
172
|
version: '1.4'
|
173
|
+
- !ruby/object:Gem::Dependency
|
174
|
+
name: recursive-open-struct
|
175
|
+
requirement: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - "~>"
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: 1.1.3
|
180
|
+
type: :runtime
|
181
|
+
prerelease: false
|
182
|
+
version_requirements: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - "~>"
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: 1.1.3
|
173
187
|
description: This is a ruby gem to access the smartcar APIs. It includes the API classes
|
174
188
|
and the OAuth system.
|
175
189
|
email:
|
@@ -191,7 +205,6 @@ files:
|
|
191
205
|
- Rakefile
|
192
206
|
- bin/console
|
193
207
|
- bin/setup
|
194
|
-
- lib/open_struct_extensions.rb
|
195
208
|
- lib/smartcar.rb
|
196
209
|
- lib/smartcar/auth_client.rb
|
197
210
|
- lib/smartcar/base.rb
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Extension to OpenStruct to convert a nested OpenStruct object to a hash.
|
4
|
-
# Using this method any of the API response can be converted back to hash
|
5
|
-
# or JSON (from hash) for convenience.
|
6
|
-
# Example Usage :
|
7
|
-
# response = {a: { b: {c: "test", d: [{x: 1}, {y: 3}]}}}
|
8
|
-
class OpenStruct
|
9
|
-
def deep_to_h
|
10
|
-
to_h.transform_values do |value|
|
11
|
-
case value
|
12
|
-
when is_a?(OpenStruct)
|
13
|
-
value.deep_to_h
|
14
|
-
when is_a?(Array)
|
15
|
-
value.map { |item| item.is_a?(OpenStruct) ? item.deep_to_h : item }
|
16
|
-
else
|
17
|
-
value
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|