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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +4 -0
- data/lib/smartcar/auth_client.rb +24 -14
- data/lib/smartcar/version.rb +1 -1
- data/lib/smartcar.rb +2 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe729c83b0d759f2d787090e3f815ec9d97cd0b283585f8775ebe16e61b16e56
|
4
|
+
data.tar.gz: '029284bb31e8363b2cd0fe751705749e19365fb5692cbc3054325d648440117e'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e469fcb92c39256e4a779476217fdb7cd5cce276af14d61ac9a51054e5d5e485f70e8f7886fb1852d2fb9d8128edd9b85164303f7c36fdca9d919f50bb0f4cb
|
7
|
+
data.tar.gz: faf78f8b977e3548e9f44fa45a59ce3b26cc89de53e6d85f3a8bc5391ced3031bdb2801696cb237cc2bb8c801bf85f7d2dd5bb6f15ccf2904430c65549c8ac86
|
data/Gemfile.lock
CHANGED
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
|
data/lib/smartcar/auth_client.rb
CHANGED
@@ -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, :
|
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[:
|
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
|
-
|
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 =
|
74
|
-
|
75
|
-
|
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(
|
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(
|
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
|
-
|
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
|
151
|
-
@
|
152
|
-
|
153
|
-
|
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
|
data/lib/smartcar/version.rb
CHANGED
data/lib/smartcar.rb
CHANGED
@@ -22,7 +22,8 @@ module Smartcar
|
|
22
22
|
}.freeze
|
23
23
|
|
24
24
|
# Path for smartcar oauth
|
25
|
-
|
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.
|
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:
|
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.
|
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/)
|