smartcar 3.3.0 → 3.3.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: 93454e55a42ab20160c545c9bda459e98c85fe5596519f704ffa001bcef5896f
4
- data.tar.gz: 0a8148c0f6678079467ee10d58b8564b2dec7e08127a3e7691e734503fc4128b
3
+ metadata.gz: fe729c83b0d759f2d787090e3f815ec9d97cd0b283585f8775ebe16e61b16e56
4
+ data.tar.gz: '029284bb31e8363b2cd0fe751705749e19365fb5692cbc3054325d648440117e'
5
5
  SHA512:
6
- metadata.gz: a5fb72f2ee3aab427c7eefd12628947eb3f5e8644f40f898acea27cdc1b6c47d7d1085b936b7661df699a31baa59e162efa7641cce7b18b823796cd6d392bc3b
7
- data.tar.gz: dc0ab7c95a537ea9a87c7e8f11ef13de8f8bd752625e0ec0418896de573a05d635837499e2744f53f7881a13c42cf9265e6799727bb68e424c4f57dccdd62370
6
+ metadata.gz: 6e469fcb92c39256e4a779476217fdb7cd5cce276af14d61ac9a51054e5d5e485f70e8f7886fb1852d2fb9d8128edd9b85164303f7c36fdca9d919f50bb0f4cb
7
+ data.tar.gz: faf78f8b977e3548e9f44fa45a59ce3b26cc89de53e6d85f3a8bc5391ced3031bdb2801696cb237cc2bb8c801bf85f7d2dd5bb6f15ccf2904430c65549c8ac86
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smartcar (3.3.0)
4
+ smartcar (3.3.1)
5
5
  oauth2 (~> 1.4)
6
6
  recursive-open-struct (~> 1.1.3)
7
7
 
data/README.md CHANGED
@@ -31,6 +31,7 @@ not have access to the dashboard, please
31
31
 
32
32
  - Create a new `AuthClient` object with your `client_id`, `client_secret`,
33
33
  `redirect_uri`.
34
+ -
34
35
  - Redirect the user to Smartcar Connect using `get_auth_url` with required `scope` or with one
35
36
  of our frontend SDKs.
36
37
  - The user will login, and then accept or deny your `scope`'s permissions.
@@ -76,6 +77,9 @@ Setup the environment variables for SMARTCAR_CLIENT_ID, SMARTCAR_CLIENT_SECRET a
76
77
  export SMARTCAR_CLIENT_ID=<client id>
77
78
  export SMARTCAR_CLIENT_SECRET=<client secret>
78
79
  export SMARTCAR_REDIRECT_URI=<redirect URI>
80
+ # Optional ENV variables
81
+ export SMARTCAR_CONNECT_ORIGIN=(default_value: connect.smartcar.com): Used as the host for the URL that starts the Connect/OAuth2 flow
82
+ export SMARTCAR_AUTH_ORIGIN=(default_value: auth.smartcar.com): Used as the host for the token exchange requests
79
83
  ```
80
84
 
81
85
  Example Usage for calling the reports API with oAuth token
@@ -6,7 +6,7 @@ module Smartcar
6
6
  class AuthClient
7
7
  include Smartcar::Utils
8
8
 
9
- attr_reader :redirect_uri, :client_id, :client_secret, :scope, :mode, :flags, :origin
9
+ attr_reader :redirect_uri, :client_id, :client_secret, :scope, :mode, :flags, :auth_origin, :connect_origin
10
10
 
11
11
  # Constructor for a client object
12
12
  #
@@ -23,7 +23,8 @@ module Smartcar
23
23
  options[:redirect_uri] ||= get_config('SMARTCAR_REDIRECT_URI')
24
24
  options[:client_id] ||= get_config('SMARTCAR_CLIENT_ID')
25
25
  options[:client_secret] ||= get_config('SMARTCAR_CLIENT_SECRET')
26
- options[:origin] = ENV['SMARTCAR_AUTH_ORIGIN'] || AUTH_ORIGIN
26
+ options[:auth_origin] = ENV['SMARTCAR_AUTH_ORIGIN'] || AUTH_ORIGIN
27
+ options[:connect_origin] = ENV['SMARTCAR_CONNECT_ORIGIN'] || CONNECT_ORIGIN
27
28
  options[:mode] = determine_mode(options[:test_mode], options[:mode]) || 'live'
28
29
  super
29
30
  end
@@ -57,7 +58,7 @@ module Smartcar
57
58
  def get_auth_url(scope, options = {})
58
59
  initialize_auth_parameters(scope, options)
59
60
  add_single_select_options(options[:single_select])
60
- client.auth_code.authorize_url(@auth_parameters)
61
+ connect_client.auth_code.authorize_url(@auth_parameters)
61
62
  end
62
63
 
63
64
  # Generates the tokens hash using the code returned in oauth process.
@@ -70,9 +71,9 @@ module Smartcar
70
71
  def exchange_code(code, options = {})
71
72
  set_token_url(options[:flags])
72
73
 
73
- token_hash = client.auth_code
74
- .get_token(code, redirect_uri: redirect_uri)
75
- .to_hash
74
+ token_hash = auth_client.auth_code
75
+ .get_token(code, redirect_uri: redirect_uri)
76
+ .to_hash
76
77
 
77
78
  json_to_ostruct(token_hash)
78
79
  rescue OAuth2::Error => e
@@ -88,7 +89,7 @@ module Smartcar
88
89
  def exchange_refresh_token(token, options = {})
89
90
  set_token_url(options[:flags])
90
91
 
91
- token_object = OAuth2::AccessToken.from_hash(client, { refresh_token: token })
92
+ token_object = OAuth2::AccessToken.from_hash(auth_client, { refresh_token: token })
92
93
  token_object = token_object.refresh!
93
94
 
94
95
  json_to_ostruct(token_object.to_hash)
@@ -101,7 +102,7 @@ module Smartcar
101
102
  #
102
103
  # @return [Boolean]
103
104
  def expired?(expires_at)
104
- OAuth2::AccessToken.from_hash(client, { expires_at: expires_at }).expired?
105
+ OAuth2::AccessToken.from_hash(auth_client, { expires_at: expires_at }).expired?
105
106
  end
106
107
 
107
108
  private
@@ -117,7 +118,7 @@ module Smartcar
117
118
  params[:flags] = build_flags(flags) if flags
118
119
  # Note - The inbuild interface to get the token does not allow any way to pass additional
119
120
  # URL params. Hence building the token URL with the flags and setting it in client.
120
- client.options[:token_url] = client.connection.build_url('/oauth/token', params).request_uri
121
+ auth_client.options[:token_url] = auth_client.connection.build_url('/oauth/token', params).request_uri
121
122
  end
122
123
 
123
124
  def initialize_auth_parameters(scope, options)
@@ -144,13 +145,22 @@ module Smartcar
144
145
  end
145
146
  end
146
147
 
147
- # gets the Oauth Client object
148
+ # gets the Oauth Client object configured with auth.connect.smartcar.com
148
149
  #
149
150
  # @return [OAuth2::Client] A Oauth Client object.
150
- def client
151
- @client ||= OAuth2::Client.new(client_id,
152
- client_secret,
153
- site: origin)
151
+ def auth_client
152
+ @auth_client ||= OAuth2::Client.new(client_id,
153
+ client_secret,
154
+ site: auth_origin)
155
+ end
156
+
157
+ # gets the Oauth Client object configured with connect.smartcar.com
158
+ #
159
+ # @return [OAuth2::Client] A Oauth Client object.
160
+ def connect_client
161
+ @connect_client ||= OAuth2::Client.new(client_id,
162
+ client_secret,
163
+ site: connect_origin)
154
164
  end
155
165
  end
156
166
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Smartcar
4
4
  # Gem current version number
5
- VERSION = '3.3.0'
5
+ VERSION = '3.3.1'
6
6
  end
data/lib/smartcar.rb CHANGED
@@ -22,7 +22,8 @@ module Smartcar
22
22
  }.freeze
23
23
 
24
24
  # Path for smartcar oauth
25
- AUTH_ORIGIN = 'https://connect.smartcar.com'
25
+ CONNECT_ORIGIN = 'https://connect.smartcar.com'
26
+ AUTH_ORIGIN = 'https://auth.smartcar.com'
26
27
  %w[success code test live force auto metric imperial].each do |constant|
27
28
  # Constant to represent the value
28
29
  const_set(constant.upcase, constant.freeze)
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.3.0
4
+ version: 3.3.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: 2022-08-03 00:00:00.000000000 Z
11
+ date: 2023-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -235,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
235
235
  - !ruby/object:Gem::Version
236
236
  version: '0'
237
237
  requirements: []
238
- rubygems_version: 3.0.8
238
+ rubygems_version: 3.1.6
239
239
  signing_key:
240
240
  specification_version: 4
241
241
  summary: Ruby Gem to access smartcar APIs (https://smartcar.com/docs/)