smartcar 3.5.0 → 3.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c3ad3ad7082e2d27def7f0ee201f1b8f8b20eb25d3f17fffe71aecbb666dab87
4
- data.tar.gz: ce9c4420338126a9cd6a22b2ae2da01f2ef9b469aaeb7df5a160377e54d939ce
3
+ metadata.gz: 8b73275a395285b7814ea6a00e15ba722b34c04e93f04f911558243cd906fb85
4
+ data.tar.gz: 46a585c74ab00a8c61fb3493a1f4cff476cbbbcae525be27124c5fdffb5be64b
5
5
  SHA512:
6
- metadata.gz: 61339cf13180062815aca1ed833d5761a0c3613595818526fc9f247e44a23d4e76f547f859c769a5bdd90917ef3e77f74048ad624806aefe8a060331b13eb2a7
7
- data.tar.gz: 9974454e496f5e67cb7bf121e696fea11c0b1ab22583a521293fcb42e750cfc70073efb33e63f1c8c2b11f77ddb1afc23f56904b7a6de2e8f03348c62fe6f0df
6
+ metadata.gz: 448a25c995db755a1b5d198d4843bb46da8c58512c8c42d83e9efcd81c68b8e57e8586fc0eba401936da85b64392aa95f8f05f3d9b1d80843764cae42ee6cd04
7
+ data.tar.gz: 4a3aa2472759eec45741c9d842cb336fccb5e1b4fc98859400aba6f526ac6a89c8ae0f1aedb9f87486e18e15e34c80a15855361aa1f909d9d83bebb21bc7ada6
data/.rubocop.yml CHANGED
@@ -7,6 +7,10 @@ AllCops:
7
7
  Metrics/AbcSize:
8
8
  Enabled: false
9
9
 
10
+ # Lengthen module line length
11
+ Metrics/ModuleLength:
12
+ Max: 200
13
+
10
14
  # Disabling this becuase we are using `set` and `get` prefixed methods to keep some commonality across SDKs
11
15
  Naming/AccessorMethodName:
12
16
  Enabled: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smartcar (3.5.0)
4
+ smartcar (3.6.0)
5
5
  oauth2 (~> 1.4)
6
6
  recursive-open-struct (~> 1.1.3)
7
7
 
data/README.md CHANGED
@@ -144,6 +144,8 @@ Example of providing a custom Faraday connection to various methods:
144
144
 
145
145
  # Passing the custom service into a Smartcar::Vehicle object
146
146
  vehicle = Smartcar::Vehicle.new(token: token, id: id, options: { service: service })
147
+
148
+ connections = Smartcar.get_connections(amt: 'amt', filter: {userId: 'user-id'}, options: {service: service})
147
149
  ```
148
150
 
149
151
  ## Development
data/lib/smartcar/base.rb CHANGED
@@ -14,7 +14,7 @@ module Smartcar
14
14
  # Constant for Basic auth type
15
15
  BASIC = 'Basic'
16
16
 
17
- attr_accessor :token, :error, :unit_system, :version, :auth_type
17
+ attr_accessor :token, :error, :unit_system, :version, :auth_type, :url
18
18
 
19
19
  %i[get post patch put delete].each do |verb|
20
20
  # meta programming and define all Restful methods.
@@ -54,7 +54,7 @@ module Smartcar
54
54
  # @return [OAuth2::AccessToken] An initialized AccessToken instance that acts as service client
55
55
  def service
56
56
  @service ||= Faraday.new(
57
- url: ENV['SMARTCAR_API_ORIGIN'] || API_ORIGIN,
57
+ url: url || ENV['SMARTCAR_API_ORIGIN'] || API_ORIGIN,
58
58
  request: { timeout: DEFAULT_REQUEST_TIMEOUT }
59
59
  )
60
60
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Smartcar
4
4
  # Gem current version number
5
- VERSION = '3.5.0'
5
+ VERSION = '3.6.0'
6
6
  end
data/lib/smartcar.rb CHANGED
@@ -15,10 +15,12 @@ module Smartcar
15
15
 
16
16
  # Host to connect to smartcar
17
17
  API_ORIGIN = 'https://api.smartcar.com/'
18
+ MANAGEMENT_API_ORIGIN = 'https://management.smartcar.com'
18
19
  PATHS = {
19
20
  compatibility: '/compatibility',
20
21
  user: '/user',
21
- vehicles: '/vehicles'
22
+ vehicles: '/vehicles',
23
+ connections: '/management/connections'
22
24
  }.freeze
23
25
 
24
26
  # Path for smartcar oauth
@@ -80,8 +82,8 @@ module Smartcar
80
82
  # @return [OpenStruct] And object representing the JSON response mentioned in https://smartcar.com/docs/api#compatibility-api
81
83
  # and a meta attribute with the relevant items from response headers.
82
84
  def get_compatibility(vin:, scope:, country: 'US', options: {})
83
- raise InvalidParameterValue.new, 'vin is a required field' if vin.nil?
84
- raise InvalidParameterValue.new, 'scope is a required field' if scope.nil?
85
+ raise Base::InvalidParameterValue.new, 'vin is a required field' if vin.nil?
86
+ raise Base::InvalidParameterValue.new, 'scope is a required field' if scope.nil? || scope.empty?
85
87
 
86
88
  base_object = Base.new(
87
89
  {
@@ -166,6 +168,70 @@ module Smartcar
166
168
  hash_challenge(amt, body.to_json) == signature
167
169
  end
168
170
 
171
+ # Module method Returns a paged list of all vehicle connections connected to the application.
172
+ #
173
+ # API Documentation - https://smartcar.com/docs/api#get-connections
174
+ # @param amt [String] - Application Management token
175
+ # @param filters [Hash] - Optional filter parameters (check documentation)
176
+ # @param paging [Hash] - Pass a cursor for paginated results
177
+ # @param options [Hash] Other optional parameters including overrides
178
+ # @option options [Faraday::Connection] :service Optional connection object to be used for requests
179
+ # @option options [String] :version Optional API version to use, defaults to what is globally set
180
+ #
181
+ # @return [OpenStruct] And object representing the JSON response mentioned in https://smartcar.com/docs/api#get-connections
182
+ # and a meta attribute with the relevant items from response headers.
183
+ def get_connections(amt:, filter: {}, paging: {}, options: {})
184
+ paging[:limit] ||= 10
185
+ base_object = Base.new(
186
+ token: generate_basic_management_auth(amt, options),
187
+ version: options[:version] || Smartcar.get_api_version,
188
+ service: options[:service],
189
+ auth_type: Base::BASIC,
190
+ url: ENV['SMARTCAR_MANAGEMENT_API_ORIGIN'] || MANAGEMENT_API_ORIGIN
191
+ )
192
+ query_params = filter.merge(paging).compact
193
+
194
+ base_object.build_response(*base_object.get(
195
+ PATHS[:connections],
196
+ query_params
197
+ ))
198
+ end
199
+
200
+ def delete_connections(amt:, filter: {}, options: {})
201
+ user_id = filter[:user_id]
202
+ vehicle_id = filter[:vehicle_id]
203
+ error_message = nil
204
+ error_message = 'Filter can contain EITHER user_id OR vehicle_id, not both.' if user_id && vehicle_id
205
+ error_message = 'Filter needs one of user_id OR vehicle_id.' unless user_id || vehicle_id
206
+
207
+ raise Base::InvalidParameterValue.new, error_message if error_message
208
+
209
+ query_params = {}
210
+ query_params['user_id'] = user_id if user_id
211
+ query_params['vehicle_id'] = vehicle_id if vehicle_id
212
+
213
+ base_object = Base.new(
214
+ url: ENV['SMARTCAR_MANAGEMENT_API_ORIGIN'] || MANAGEMENT_API_ORIGIN,
215
+ auth_type: Base::BASIC,
216
+ token: generate_basic_management_auth(amt, options),
217
+ version: options[:version] || Smartcar.get_api_version,
218
+ service: options[:service]
219
+ )
220
+
221
+ base_object.build_response(*base_object.delete(
222
+ PATHS[:connections],
223
+ query_params
224
+ ))
225
+ end
226
+
227
+ # returns auth token for Basic vehicle management auth
228
+ #
229
+ # @return [String] Base64 encoding of default:amt
230
+ def generate_basic_management_auth(amt, options = {})
231
+ username = options[:username] || 'default'
232
+ Base64.strict_encode64("#{username}:#{amt}")
233
+ end
234
+
169
235
  private
170
236
 
171
237
  def build_compatibility_params(vin, scope, country, options)
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.5.0
4
+ version: 3.6.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: 2023-04-19 00:00:00.000000000 Z
11
+ date: 2023-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler