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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f96ead76c474cc7bd2f579c79ae5457437b7826ea5738fc939e78e7fd15ad9a
4
- data.tar.gz: 4ca101d8945328f524a4c4fe525eef8c0fa9ed5828a6d7fc1e7d96bccc299015
3
+ metadata.gz: 40fb835517be1ed88352e2988be1800570c3bc6a2cd46db81d20cd1430aa5391
4
+ data.tar.gz: 23137d3489c55affd34287acc0a7301c6af04cf74ab7ec2bca0bc9476a11ee0b
5
5
  SHA512:
6
- metadata.gz: c944b360628c97f3e78e6d1f7287e91c136a33cd8c696c0e8246c18839f97d790aea5457dc402ace57eda565f4937dbc72a51e5c66e70b12d24a1850674f6bcf
7
- data.tar.gz: 73646b1545692c60714bd7581abef94f6271907587dc1ed2564dbae30adafb63b3c3d546b46f2188933fd2f4035a1eb8922fa4ef0c7e09a4fbd48a5d69c1cb11
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.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.7.0)
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::Vehicle.get_vehicles(token: token).vehicles
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
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'recursive_open_struct'
3
4
  require 'smartcar_error'
4
5
  require 'smartcar/utils'
5
6
  require 'smartcar/version'
@@ -72,7 +72,7 @@ module Smartcar
72
72
  .get_token(code, redirect_uri: redirect_uri)
73
73
  .to_hash
74
74
 
75
- JSON.parse(token_hash.to_json, object_class: OpenStruct)
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
- JSON.parse(token_object.to_hash.to_json, object_class: OpenStruct)
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
@@ -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 = JSON.parse(meta_hash.to_json, object_class: OpenStruct)
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 = JSON.parse(body.to_json, object_class: OpenStruct)
55
+ response = json_to_ostruct(body)
44
56
  response.meta = build_meta(headers)
45
57
  response
46
58
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Smartcar
4
4
  # Gem current version number
5
- VERSION = '3.0.0'
5
+ VERSION = '3.0.1'
6
6
  end
data/ruby-sdk.gemspec CHANGED
@@ -36,4 +36,5 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency 'selenium-webdriver', '~> 3.142'
37
37
  spec.add_development_dependency 'webmock', '~> 3.13'
38
38
  spec.add_dependency 'oauth2', '~> 1.4'
39
+ spec.add_dependency 'recursive-open-struct', '~> 1.1.3'
39
40
  end
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.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-12 00:00:00.000000000 Z
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