smartcar 3.5.0 → 3.7.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: e1c4483d2719b243be93876bec15f34de1d2787308bb6a44383a9e0bbf0db00a
4
+ data.tar.gz: f4774a7225f67e3ddae7d4d935fbddf9cf772994ba5a7d236c3c2e8daf5ed222
5
5
  SHA512:
6
- metadata.gz: 61339cf13180062815aca1ed833d5761a0c3613595818526fc9f247e44a23d4e76f547f859c769a5bdd90917ef3e77f74048ad624806aefe8a060331b13eb2a7
7
- data.tar.gz: 9974454e496f5e67cb7bf121e696fea11c0b1ab22583a521293fcb42e750cfc70073efb33e63f1c8c2b11f77ddb1afc23f56904b7a6de2e8f03348c62fe6f0df
6
+ metadata.gz: 1a3c96cb014e4ad5b5797e0a8a4d74599f849f861fccee1739c916a02e77c53c105853a496a3f87b7e94e34c66046e0b49c0bc1e63b13da4a8fac6cf82c2c961
7
+ data.tar.gz: 4a3d22bb0334c947b39dcd43c2950e35c1b8453ddd3f731ae589f1dfbdbbd254cae671668f712387b455328fc0e15c25e925603e90be8fff2330ff31c9412936
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.7.0)
5
5
  oauth2 (~> 1.4)
6
6
  recursive-open-struct (~> 1.1.3)
7
7
 
@@ -20,25 +20,25 @@ GEM
20
20
  rexml
21
21
  diff-lcs (1.5.0)
22
22
  docile (1.4.0)
23
- faraday (2.4.0)
24
- faraday-net_http (~> 2.0)
23
+ faraday (2.7.10)
24
+ faraday-net_http (>= 2.0, < 3.1)
25
25
  ruby2_keywords (>= 0.0.4)
26
- faraday-net_http (2.1.0)
26
+ faraday-net_http (3.0.2)
27
27
  hashdiff (1.0.1)
28
- jwt (2.4.1)
28
+ jwt (2.7.1)
29
29
  multi_json (1.15.0)
30
30
  multi_xml (0.6.0)
31
- oauth2 (1.4.10)
31
+ oauth2 (1.4.11)
32
32
  faraday (>= 0.17.3, < 3.0)
33
33
  jwt (>= 1.0, < 3.0)
34
34
  multi_json (~> 1.3)
35
35
  multi_xml (~> 0.5)
36
- rack (>= 1.2, < 3)
36
+ rack (>= 1.2, < 4)
37
37
  parallel (1.21.0)
38
38
  parser (3.1.0.0)
39
39
  ast (~> 2.4.1)
40
40
  public_suffix (4.0.6)
41
- rack (2.2.3)
41
+ rack (3.0.8)
42
42
  rainbow (3.1.1)
43
43
  rake (12.3.3)
44
44
  readapt (1.4.3)
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
@@ -125,6 +125,8 @@ module Smartcar
125
125
  # Adding this because else it would become tires_pressure
126
126
  return :tire_pressure if path == '/tires/pressure'
127
127
 
128
+ return :lock_status if path == '/security'
129
+
128
130
  path.split('/').reject(&:empty?).join('_').to_sym
129
131
  end
130
132
 
@@ -54,6 +54,13 @@ module Smartcar
54
54
  vin: { path: proc { |id| "/vehicles/#{id}/vin" } },
55
55
  get_charge_limit: { path: proc { |id| "/vehicles/#{id}/charge/limit" } },
56
56
  disconnect!: { type: :delete, path: proc { |id| "/vehicles/#{id}/application" } },
57
+ lock_status: {
58
+ path: proc { |id| "/vehicles/#{id}/security" },
59
+ aliases: {
60
+ 'isLocked' => 'is_locked',
61
+ 'chargingPort' => 'charging_port'
62
+ }
63
+ },
57
64
  lock!: { type: :post, path: proc { |id| "/vehicles/#{id}/security" }, body: { action: 'LOCK' } },
58
65
  unlock!: { type: :post, path: proc { |id| "/vehicles/#{id}/security" }, body: { action: 'UNLOCK' } },
59
66
  start_charge!: { type: :post, path: proc { |id| "/vehicles/#{id}/charge" }, body: { action: 'START' } },
@@ -172,6 +179,17 @@ module Smartcar
172
179
  # @return [OpenStruct] And object representing the JSON response mentioned in https://smartcar.com/docs/api#get-vin
173
180
  # and a meta attribute with the relevant items from response headers.
174
181
 
182
+ # @!method lock_status()
183
+ # Returns the lock status for a vehicle and the open status of its doors, windows, storage units,
184
+ # sunroof and charging port where available. The open status array(s) will be empty if a vehicle
185
+ # has partial support. The request will error if lock status can not be retrieved from the vehicle or
186
+ # the brand is not supported.
187
+ #
188
+ # API Documentation https://smartcar.com/docs/api#get-security
189
+ #
190
+ # @return [OpenStruct] And object representing the JSON response mentioned in https://smartcar.com/docs/api#get-security
191
+ # and a meta attribute with the relevant items from response headers.
192
+
175
193
  # NOTES :
176
194
  # - We only generate the methods where there is no query string or additional options considering thats
177
195
  # the majority, for all the ones that require parameters, write them separately.
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Smartcar
4
4
  # Gem current version number
5
- VERSION = '3.5.0'
5
+ VERSION = '3.7.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.7.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-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler