smartcar 2.3.0 → 2.4.0

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: 8b46d97dfaa2c543d0c5a5a7fbe7be668991babc0b0d35b81c432dc6ae3b3d06
4
- data.tar.gz: 6e67faac4de5a809023fad29fba657bba0648a67978831d4c19a1a26e7bc039b
3
+ metadata.gz: 4d9d54665fb1e1c644ec917708c8f702d6eec0afec4b7bc14e5504a717da92d9
4
+ data.tar.gz: 31d22b73a4406d512a738c694bc250b9eeab7e60ba1e137fbd11c221d05206fa
5
5
  SHA512:
6
- metadata.gz: 92f3f9cb5002eae3d5289d5e426a7954ca2f789a55f264360083f7a85a46d95279c63b516a6aa09b6661b5604afc33e38ddcf1c9d990429a8204e162930b684c
7
- data.tar.gz: 9a33b2a71aa62207a38143383fb010b2bf557214f265d5fd2b3eb5e747d19627fc1cd5e33670e75539f34a3d9f10d6ea293818e68e239311b6ce93af3673734e
6
+ metadata.gz: 950dccc0e0ae5e801bd24d8516a11258ef386bbc706e13b7ed323cbd032bf4e61d45f32ba7ec49136e022777d700611838548a73e7b339e7d668b01d3a64266a
7
+ data.tar.gz: 979f5ee0f0bb62255aec3f5c11c844b787da1a9710f025f18d9f6d99d95dd80dd5d4ce4ae681743583d4a50ea8d251184ed31a4fdcd8073d056dc3d9fd654da6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smartcar (2.3.0)
4
+ smartcar (2.4.0)
5
5
  oauth2 (~> 1.4)
6
6
 
7
7
  GEM
data/lib/smartcar.rb CHANGED
@@ -29,8 +29,7 @@ module Smartcar
29
29
  class AuthenticationError < ExternalServiceError; end
30
30
  # Error raised when Smartcar returns 400 response
31
31
  class BadRequestError < ExternalServiceError; end
32
- # Smartcar API version - default version.
33
- DEFAULT_API_VERSION = "v1.0".freeze
32
+
34
33
  # Host to connect to smartcar
35
34
  SITE = "https://api.smartcar.com/".freeze
36
35
 
@@ -51,4 +50,24 @@ module Smartcar
51
50
  STOP_CHARGE = "STOP".freeze
52
51
  # Constant for units
53
52
  UNITS = [IMPERIAL,METRIC]
53
+
54
+ # Smartcar API version variable - defaulted to 1.0
55
+ @api_version = "1.0"
56
+
57
+ # Module method Used to set api version to be used.
58
+ # This method can be used at the top to set the version and any
59
+ # following request will use the version set here unless overridden
60
+ # separately.
61
+ # @param version [String] version to be set without 'v' prefix.
62
+ def self.set_api_version(version)
63
+ instance_variable_set('@api_version', version)
64
+ end
65
+
66
+ # Module method Used to get api version to be used.
67
+ # This is the getter for the class instance variable @api_version
68
+ #
69
+ # @return [String] api version number without 'v' prefix
70
+ def self.get_api_version
71
+ instance_variable_get('@api_version')
72
+ end
54
73
  end
data/lib/smartcar/base.rb CHANGED
@@ -29,7 +29,7 @@ module Smartcar
29
29
  request.headers['Authorization'] = "BASIC #{get_basic_auth}" if data[:auth] == BASIC
30
30
  request.headers['sc-unit-system'] = unit_system if unit_system
31
31
  request.headers['Content-Type'] = "application/json"
32
- complete_path = "/#{version}#{path}"
32
+ complete_path = "/v#{version}#{path}"
33
33
  if verb==:get
34
34
  request.url complete_path, data
35
35
  else
data/lib/smartcar/user.rb CHANGED
@@ -13,7 +13,7 @@ module Smartcar
13
13
  # @param token [String] Access token
14
14
  #
15
15
  # @return [String] User ID
16
- def self.user_id(token:, version: DEFAULT_API_VERSION)
16
+ def self.user_id(token:, version: Smartcar.get_api_version)
17
17
  # @deprecated Please use {#get} instead
18
18
  warn "[DEPRECATION] `Smartcar::User.user_id` is deprecated and will be removed in next major version update. Please use `Smartcar::User.get` instead."
19
19
  get(token: token, version: version).id
@@ -25,7 +25,7 @@ module Smartcar
25
25
  # @param token [String] Access token
26
26
  #
27
27
  # @return [User] User object
28
- def self.get(token:, version: DEFAULT_API_VERSION)
28
+ def self.get(token:, version: Smartcar.get_api_version)
29
29
  user = new(token: token, version: version)
30
30
  body, _meta = user.fetch(path: USER_PATH)
31
31
  user.instance_variable_set('@id', body['id'])
@@ -16,7 +16,7 @@ module Smartcar
16
16
 
17
17
  attr_reader :id
18
18
 
19
- def initialize(token:, id:, unit_system: IMPERIAL, version: DEFAULT_API_VERSION)
19
+ def initialize(token:, id:, unit_system: IMPERIAL, version: Smartcar.get_api_version)
20
20
  raise InvalidParameterValue.new, "Invalid Units provided : #{unit_system}" unless UNITS.include?(unit_system)
21
21
  raise InvalidParameterValue.new, "Vehicle ID (id) is a required field" if id.nil?
22
22
  raise InvalidParameterValue.new, "Access Token(token) is a required field" if token.nil?
@@ -32,7 +32,7 @@ module Smartcar
32
32
  # @param options [Hash] - Optional filter parameters (check documentation)
33
33
  #
34
34
  # @return [Array] of vehicle IDs(Strings)
35
- def self.all_vehicle_ids(token:, options: {}, version: DEFAULT_API_VERSION)
35
+ def self.all_vehicle_ids(token:, options: {}, version: Smartcar.get_api_version)
36
36
  response, meta = new(token: token, id: 'none', version: version).fetch(
37
37
  path: PATH.call(''),
38
38
  options: options
@@ -49,7 +49,7 @@ module Smartcar
49
49
  # Defaults to US.
50
50
  #
51
51
  # @return [Boolean] true or false
52
- def self.compatible?(vin:, scope:, country: 'US', version: DEFAULT_API_VERSION)
52
+ def self.compatible?(vin:, scope:, country: 'US', version: Smartcar.get_api_version)
53
53
  raise InvalidParameterValue.new, "vin is a required field" if vin.nil?
54
54
  raise InvalidParameterValue.new, "scope is a required field" if scope.nil?
55
55
 
@@ -1,4 +1,4 @@
1
1
  module Smartcar
2
2
  # Gem current version number
3
- VERSION = "2.3.0"
3
+ VERSION = "2.4.0"
4
4
  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: 2.3.0
4
+ version: 2.4.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: 2021-04-24 00:00:00.000000000 Z
11
+ date: 2021-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler