smartcar 1.0.7 → 2.3.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: 20f8c410ca2e09b81f481f66f8790b9040688dec92973825d7a7ba72cec14a7d
4
- data.tar.gz: 5c748df1b3c987a00df29e1f7f65ae8c89c76ad7473acfc8135c27ddad94fe15
3
+ metadata.gz: 8b46d97dfaa2c543d0c5a5a7fbe7be668991babc0b0d35b81c432dc6ae3b3d06
4
+ data.tar.gz: 6e67faac4de5a809023fad29fba657bba0648a67978831d4c19a1a26e7bc039b
5
5
  SHA512:
6
- metadata.gz: 4bdbd39d8887437f76f53ccea2cdc8f6ae618d5a13558713c44b74ca21ab01fbe960b8d8b66104ace8df1a4c3de2d8a2308e3fe6ec000c9a80b721abda0fca09
7
- data.tar.gz: 71f27cea632e1578e878f9bb6c7caa921890236515facc7435f6b17aa2faa1c198c8e7bfd4064fd90ec37ee2533d31aae362b1f0c13ce867b43380d3add3fcbc
6
+ metadata.gz: 92f3f9cb5002eae3d5289d5e426a7954ca2f789a55f264360083f7a85a46d95279c63b516a6aa09b6661b5604afc33e38ddcf1c9d990429a8204e162930b684c
7
+ data.tar.gz: 9a33b2a71aa62207a38143383fb010b2bf557214f265d5fd2b3eb5e747d19627fc1cd5e33670e75539f34a3d9f10d6ea293818e68e239311b6ce93af3673734e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smartcar (1.0.7)
4
+ smartcar (2.3.0)
5
5
  oauth2 (~> 1.4)
6
6
 
7
7
  GEM
@@ -10,13 +10,16 @@ GEM
10
10
  byebug (11.1.3)
11
11
  childprocess (3.0.0)
12
12
  diff-lcs (1.3)
13
- faraday (1.0.1)
13
+ faraday (1.3.0)
14
+ faraday-net_http (~> 1.0)
14
15
  multipart-post (>= 1.2, < 3)
16
+ ruby2_keywords
17
+ faraday-net_http (1.0.1)
15
18
  jwt (2.2.2)
16
19
  multi_json (1.15.0)
17
20
  multi_xml (0.6.0)
18
21
  multipart-post (2.1.1)
19
- oauth2 (1.4.4)
22
+ oauth2 (1.4.7)
20
23
  faraday (>= 0.8, < 2.0)
21
24
  jwt (>= 1.0, < 3.0)
22
25
  multi_json (~> 1.3)
@@ -24,7 +27,7 @@ GEM
24
27
  rack (>= 1.2, < 3)
25
28
  rack (2.2.3)
26
29
  rake (12.3.3)
27
- redcarpet (3.5.0)
30
+ redcarpet (3.5.1)
28
31
  rspec (3.9.0)
29
32
  rspec-core (~> 3.9.0)
30
33
  rspec-expectations (~> 3.9.0)
@@ -38,6 +41,7 @@ GEM
38
41
  diff-lcs (>= 1.2.0, < 2.0)
39
42
  rspec-support (~> 3.9.0)
40
43
  rspec-support (3.9.3)
44
+ ruby2_keywords (0.0.4)
41
45
  rubyzip (2.3.0)
42
46
  selenium-webdriver (3.142.7)
43
47
  childprocess (>= 0.5, < 4.0)
@@ -56,4 +60,4 @@ DEPENDENCIES
56
60
  smartcar!
57
61
 
58
62
  BUNDLED WITH
59
- 2.1.2
63
+ 2.1.4
data/README.md CHANGED
@@ -109,12 +109,13 @@ Example Usage for oAuth -
109
109
  # To get the redirect URL :
110
110
  2.5.5 :002 > options = {test_mode: true,scope: ["read_battery","read_charge","read_fuel","read_location","control_security","read_odometer","read_tires","read_vin","read_vehicle_info"],flags: ["country:DE"]}
111
111
  2.5.5 :003 > require 'smartcar'
112
- 2.5.5 :004 > url = Smartcar::Oauth.authorization_url(options)
113
- => "https://connect.smartcar.com/oauth/authorize?approval_prompt=auto&client_id=2715c6b2-eba8-4fda-85b1-8d849733a344&mode=test&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fcallback&response_type=code&scope=read_battery+read_charge+read_fuel+read_location+control_security+read_odometer+read_tires+read_vin+read_vehicle_info&flags=country%3ADE"
112
+ 2.5.5 :004 > client = Smartcar::Oauth.new(options)
113
+ 2.5.5 :005 > url = client.authorization_url
114
+ => "https://connect.smartcar.com/oauth/authorize?approval_prompt=auto&client_id=<client id>&mode=test&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fcallback&response_type=code&scope=read_battery+read_charge+read_fuel+read_location+control_security+read_odometer+read_tires+read_vin+read_vehicle_info&flags=country%3ADE"
114
115
  # Redirect user to the above URL.
115
116
  # After authentication user control reaches the callback URL with code.
116
117
  # Use the code from the parameters and request a token
117
- 2.5.5 :006 > token_hash = Smartcar::Oauth.get_token(code)
118
+ 2.5.5 :006 > token_hash = client.get_token(code)
118
119
  => {"token_type"=>"Bearer", :access_token=>"56801a5e-6a0b-4d05-a43e-52a4d5e6648f", :refresh_token=>"4f46e7e4-28c5-47b3-ba8d-7dcef73d05dd", :expires_at=>1577875279}
119
120
  # This access_token can be used to call the Smartcar APIs as given above.
120
121
  # Store this hash and if it expired refresh the token OR use the code again to
@@ -136,19 +137,22 @@ Tests can be run using either default rake command OR specific rspec command.
136
137
  bundle exec rake spec
137
138
  ```
138
139
 
139
- Releasing to rubygems right now cannot be automated because of MFA ([source](https://github.com/rubygems/rubygems/issues/3092)). For now the process is to run the gem build and push commands locally and manually enter in the Rubygems MFA code (available on 1password). Steps for that would be :
140
+ **NOTE : Do not forget to update the version number in version.rb.**
141
+
142
+ ## Release
143
+
144
+ Deployments to Rubgygems is automated through Travis. After merging to master, create a tag on the latest commit on master and push it. That would trigger a CI job which will build, test and deploy to Rubygems. As a convention we use the version number of the gem for the release tag.
140
145
 
141
146
  ```
142
147
  # After merging to master, checkout to master and pull code locally, then run the following
143
- gem build
144
- Successfully built RubyGem
145
- Name: smartcar
146
- Version: <version>
147
- File: smartcar-<version>.gem
148
- # now push the gem built by the build command. This would ask for the MFA code
149
- gem push smartcar-<version>.gem
148
+ git tag v1.2.3
149
+ # now push the tags
150
+ git push origin --tags
151
+ Total 0 (delta 0), reused 0 (delta 0)
152
+ To github.com:smartcar/ruby-sdk.git
153
+ * [new tag] v1.2.3 -> v1.2.3
150
154
  ```
151
- In general it is a good advice to create a tag for every release. If not for the above mentioned MFA bug, creating a tag for a commit on master and pushing the tag would trigger travis to deploy to rubygems automatically.
155
+
152
156
 
153
157
  ## Contributing
154
158
 
@@ -156,7 +160,7 @@ To contribute, please:
156
160
 
157
161
  1. Open an issue for the feature (or bug) you would like to resolve.
158
162
  2. Resolve the issue and add tests in your feature branch.
159
- 3. Open a PR from your feature branch into `develop` that tags the issue.
163
+ 3. Open a PR from your feature branch into `master` that tags the issue.
160
164
 
161
165
  [gem-image]: https://badge.fury.io/rb/smartcar
162
166
  [gem-url]: https://badge.fury.io/rb/smartcar.svg
data/lib/smartcar.rb CHANGED
@@ -4,6 +4,7 @@ require "smartcar/base"
4
4
  require "smartcar/oauth"
5
5
  require "smartcar/permissions"
6
6
  require "smartcar/battery"
7
+ require "smartcar/battery_capacity"
7
8
  require "smartcar/charge"
8
9
  require "smartcar/engine_oil"
9
10
  require "smartcar/fuel"
@@ -16,8 +17,8 @@ require "smartcar/vehicle"
16
17
  require "smartcar/user"
17
18
 
18
19
 
19
- # Main Smartcar umbrella module
20
- module Smartcar
20
+ # Main Smartcar umbrella module
21
+ module Smartcar
21
22
  # Error raised when a config is not found
22
23
  class ConfigNotFound < StandardError; end
23
24
  # Error raised when Smartcar returns non 400, 404, 401, 200 or 204 response
@@ -28,8 +29,8 @@ require "smartcar/user"
28
29
  class AuthenticationError < ExternalServiceError; end
29
30
  # Error raised when Smartcar returns 400 response
30
31
  class BadRequestError < ExternalServiceError; end
31
- # Smartcar API version being used
32
- API_VERSION = "v1.0".freeze
32
+ # Smartcar API version - default version.
33
+ DEFAULT_API_VERSION = "v1.0".freeze
33
34
  # Host to connect to smartcar
34
35
  SITE = "https://api.smartcar.com/".freeze
35
36
 
data/lib/smartcar/base.rb CHANGED
@@ -4,7 +4,7 @@ module Smartcar
4
4
  # The Base class for all of the other class.
5
5
  # Let other classes inherit from here and put common methods here.
6
6
  class Base
7
- include Utils
7
+ include Smartcar::Utils
8
8
 
9
9
  # Error raised when an invalid parameter is passed.
10
10
  class InvalidParameterValue < StandardError; end
@@ -15,7 +15,7 @@ module Smartcar
15
15
  # Number of seconds to wait for response
16
16
  REQUEST_TIMEOUT = 310
17
17
 
18
- attr_accessor :token, :error, :meta
18
+ attr_accessor :token, :error, :meta, :unit_system, :version
19
19
 
20
20
  %i{get post patch put delete}.each do |verb|
21
21
  # meta programming and define all Restful methods.
@@ -27,9 +27,9 @@ module Smartcar
27
27
  response = service.send(verb) do |request|
28
28
  request.headers['Authorization'] = "BEARER #{token}"
29
29
  request.headers['Authorization'] = "BASIC #{get_basic_auth}" if data[:auth] == BASIC
30
- request.headers['sc-unit-system'] = unit_system
30
+ request.headers['sc-unit-system'] = unit_system if unit_system
31
31
  request.headers['Content-Type'] = "application/json"
32
- complete_path = "/#{API_VERSION}#{path}"
32
+ complete_path = "/#{version}#{path}"
33
33
  if verb==:get
34
34
  request.url complete_path, data
35
35
  else
@@ -0,0 +1,9 @@
1
+ module Smartcar
2
+ # class to represent Battery Capacity info
3
+ #@attr [Number] capacity Decimal value representing the battery's total capacity in kWh.
4
+ class BatteryCapacity < Base
5
+ # Path Proc for hitting battery capacity end point
6
+ PATH = Proc.new{|id| "/vehicles/#{id}/battery/capacity"}
7
+ attr_reader :capacity
8
+ end
9
+ end
@@ -2,7 +2,7 @@ module Smartcar
2
2
  # Oauth class to take care of the Oauth 2.0 with Smartcar APIs
3
3
  #
4
4
  class Oauth < Base
5
- extend Utils
5
+ extend Smartcar::Utils
6
6
  # By default users are not shown the permission dialog if they have already
7
7
  # approved the set of scopes for this application. The application can elect
8
8
  # to always display the permissions dialog to the user by setting
@@ -12,10 +12,25 @@ module Smartcar
12
12
  # @option options[:client_id] [String] - Client ID, if not passed fallsback to ENV['CLIENT_ID']
13
13
  # @option options[:client_secret] [String] - Client Secret, if not passed fallsback to ENV['CLIENT_SECRET']
14
14
  # @option options[:redirect_uri] [String] - Redirect URI, if not passed fallsback to ENV['REDIRECT_URI']
15
+ # @option options[:scope] [Array of Strings] - array of scopes that specify what the user can access
16
+ # EXAMPLE : ['read_odometer', 'read_vehicle_info', 'required:read_location']
17
+ # For further details refer to https://smartcar.com/docs/guides/scope/
18
+ # @option options[:test_mode] [Boolean] - Setting this to 'true' runs it in test mode.
19
+ #
20
+ # @return [Smartcar::Oauth] Returns a Smartcar::Oauth Object that has other methods
21
+ def initialize(options)
22
+ @redirect_uri = options[:redirect_uri] || get_config('REDIRECT_URI')
23
+ @client_id = options[:client_id] || get_config('CLIENT_ID')
24
+ @client_secret = options[:client_secret] || get_config('CLIENT_SECRET')
25
+ @scope = options[:scope]
26
+ @test_mode = !!options[:test_mode]
27
+ end
28
+
29
+ # Generate the OAuth authorization URL.
30
+ # @param options [Hash]
15
31
  # @option options[:state] [String] - OAuth state parameter passed to the
16
32
  # redirect uri. This parameter may be used for identifying the user who
17
33
  # initiated the request.
18
- # @option options[:test_mode] [Boolean] - Setting this to 'true' runs it in test mode.
19
34
  # @option options[:force_prompt] [Boolean] - Setting `force_prompt` to
20
35
  # `true` will show the permissions approval screen on every authentication
21
36
  # attempt, even if the user has previously consented to the exact scope of
@@ -24,37 +39,39 @@ module Smartcar
24
39
  # users to bypass the car brand selection screen.
25
40
  # For a complete list of supported makes, please see our
26
41
  # [API Reference](https://smartcar.com/docs/api#authorization) documentation.
27
- # @option options[:scope] [Array of Strings] - array of scopes that specify what the user can access
28
- # EXAMPLE : ['read_odometer', 'read_vehicle_info', 'required:read_location']
29
- # For further details refer to https://smartcar.com/docs/guides/scope/
42
+ # @option options[:single_select] [Boolean, Hash] - An optional value that sets the
43
+ # behavior of the grant dialog displayed to the user. If set to `true`,
44
+ # `single_select` limits the user to selecting only one vehicle. If `single_select`
45
+ # is an hash with the property `vin`, Smartcar will only authorize the vehicle
46
+ # with the specified VIN. See the
47
+ # [Single Select guide](https://smartcar.com/docs/guides/single-select/)
48
+ # for more information.
30
49
  # @option options[:flags] [Array of Strings] - an optional array of early access features to enable.
31
50
  #
32
- # @return [Smartcar::Oauth] Returns a Smartcar::Oauth Object that has other methods
33
- def initialize(options)
34
- @redirect_uri = options[:redirect_uri] || get_config('REDIRECT_URI')
35
- @client_id = options[:client_id] || get_config('CLIENT_ID')
36
- @client_secret = options[:client_secret] || get_config('CLIENT_SECRET')
37
-
38
- @auth_parameters = {
51
+ # @return [String] Authorization URL string
52
+ def authorization_url(options = {})
53
+ options[:scope] = @scope
54
+ auth_parameters = {
39
55
  redirect_uri: @redirect_uri,
40
56
  approval_prompt: options[:force_prompt] ? FORCE : AUTO,
41
- mode: options[:test_mode] ? TEST : LIVE,
42
- response_type: CODE
57
+ mode: @test_mode ? TEST : LIVE,
58
+ response_type: CODE,
43
59
  }
44
-
45
- %I(scope flags).each do |parameter|
46
- @auth_parameters[parameter] = options[parameter].join(' ') unless options[parameter].nil?
47
- end
60
+
61
+ auth_parameters[:flags] = options[:flags].join(' ') unless options[:flags].nil?
62
+ auth_parameters[:scope] = @scope.join(' ') unless @scope.nil?
63
+
48
64
  %I(state make).each do |parameter|
49
- @auth_parameters[parameter] = options[parameter] unless options[parameter].nil?
65
+ auth_parameters[parameter] = options[parameter] unless options[parameter].nil?
50
66
  end
51
- end
52
67
 
53
- # Generate the OAuth authorization URL.
54
- #
55
- # @return [String] Authorization URL string
56
- def authorization_url
57
- client.auth_code.authorize_url(@auth_parameters)
68
+ if(options[:single_select].is_a?(Hash))
69
+ auth_parameters[:single_select_vin] = options[:single_select][:vin]
70
+ auth_parameters[:single_select] = true
71
+ else
72
+ auth_parameters[:single_select] = !!options[:single_select]
73
+ end
74
+ client.auth_code.authorize_url(auth_parameters)
58
75
  end
59
76
 
60
77
  # Generates the tokens hash using the code returned in oauth process.
@@ -71,16 +88,23 @@ module Smartcar
71
88
  end
72
89
 
73
90
  # Refreshing the access token
74
- # @param token_hash [Hash] This is the hash that is returned with the
75
- # get_token method
91
+ # @param refresh_token [String] refresh_token received during token exchange
76
92
  #
77
93
  # @return [Hash] Hash of token, refresh token, expiry info and token type
78
- def refresh_token(token_hash)
79
- token_object = OAuth2::AccessToken.from_hash(client, token_hash)
94
+ def exchange_refresh_token(refresh_token)
95
+ token_object = OAuth2::AccessToken.from_hash(client, {refresh_token: refresh_token})
80
96
  token_object = token_object.refresh!
81
97
  token_object.to_hash
82
98
  end
83
99
 
100
+ # Checks if token is expired using Oauth2 classes
101
+ # @param expires_at [Number] expires_at as time since epoch
102
+ #
103
+ # @return [Boolean]
104
+ def expired?(expires_at)
105
+ OAuth2::AccessToken.from_hash(client, {expires_at: expires_at}).expired?
106
+ end
107
+
84
108
  private
85
109
  # gets the Oauth Client object
86
110
  #
data/lib/smartcar/user.rb CHANGED
@@ -5,22 +5,31 @@ module Smartcar
5
5
  class User < Base
6
6
  # Path for hitting user end point
7
7
  USER_PATH = '/user'.freeze
8
- attr_reader :id, :token
8
+ attr_reader :id
9
9
 
10
- def initialize(token:)
11
- raise InvalidParameterValue.new, "Access Token(token) is a required field" if token.nil?
12
- @token = token
10
+ # Class method Used to get user id
11
+ # EX : Smartcar::User.user_id
12
+ # API - https://smartcar.com/docs/api#get-user
13
+ # @param token [String] Access token
14
+ #
15
+ # @return [String] User ID
16
+ def self.user_id(token:, version: DEFAULT_API_VERSION)
17
+ # @deprecated Please use {#get} instead
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
+ get(token: token, version: version).id
13
20
  end
14
21
 
15
22
  # Class method Used to get user id
16
- # EX : Smartcar::User.fetch
23
+ # EX : Smartcar::User.get
17
24
  # API - https://smartcar.com/docs/api#get-user
18
25
  # @param token [String] Access token
19
26
  #
20
- # @return [User] object
21
- def self.user_id(token:)
22
- new(token: token).get(USER_PATH)['id']
27
+ # @return [User] User object
28
+ def self.get(token:, version: DEFAULT_API_VERSION)
29
+ user = new(token: token, version: version)
30
+ body, _meta = user.fetch(path: USER_PATH)
31
+ user.instance_variable_set('@id', body['id'])
32
+ user
23
33
  end
24
-
25
34
  end
26
35
  end
@@ -1,35 +1,46 @@
1
- # Utils module , provides utility methods to underlying classes
1
+ # Utils module , provides utility methods to underlying classes
2
+ module Smartcar
2
3
  module Utils
3
- # A constructor to take a hash and assign it to the instance variables
4
- # @param options = {} [Hash] Could by any class's hash, but the first level keys should be defined in the class
5
- #
6
- # @return [Subclass os Base] Returns object of any subclass like Report
7
- def initialize(options = {})
8
- options.each do |attribute, value|
9
- instance_variable_set("@#{attribute}", value)
4
+ # A constructor to take a hash and assign it to the instance variables
5
+ # @param options = {} [Hash] Could by any class's hash, but the first level keys should be defined in the class
6
+ #
7
+ # @return [Subclass os Base] Returns object of any subclass like Report
8
+ def initialize(options = {})
9
+ options.each do |attribute, value|
10
+ instance_variable_set("@#{attribute}", value)
11
+ end
10
12
  end
11
- end
12
13
 
13
- # gets a given env variable, checks for existence and throws exception if not present
14
- # @param config_name [String] key of the env variable
15
- #
16
- # @return [String] value of the env variable
17
- def get_config(config_name)
18
- config_name = "INTEGRATION_#{config_name}" if ENV['MODE'] == 'test'
19
- raise Smartcar::ConfigNotFound, "Environment variable #{config_name} not found !" unless ENV[config_name]
20
- ENV[config_name]
21
- end
14
+ # Utility method to return a hash of the isntance variables
15
+ #
16
+ # @return [Hash] hash of all instance variables
17
+ def to_hash
18
+ instance_variables.each_with_object({}) do |attribute, hash|
19
+ hash[attribute.to_s.delete("@").to_sym] = instance_variable_get(attribute)
20
+ end
21
+ end
22
22
 
23
- # Given the response from smartcar API, returns an error object if needed
24
- # @param response [Object] response Object with status and body
25
- #
26
- # @return [Object] nil OR Error object
27
- def get_error(response)
28
- status = response.status
29
- return nil if [200,204].include?(status)
30
- return Smartcar::ServiceUnavailableError.new("Service Unavailable - #{response.body}") if status == 404
31
- return Smartcar::BadRequestError.new("Bad Request - #{response.body}") if status == 400
32
- return Smartcar::AuthenticationError.new("Authentication error") if status == 401
33
- return Smartcar::ExternalServiceError.new("API error - #{response.body}")
23
+ # gets a given env variable, checks for existence and throws exception if not present
24
+ # @param config_name [String] key of the env variable
25
+ #
26
+ # @return [String] value of the env variable
27
+ def get_config(config_name)
28
+ config_name = "INTEGRATION_#{config_name}" if ENV['MODE'] == 'test'
29
+ raise Smartcar::ConfigNotFound, "Environment variable #{config_name} not found !" unless ENV[config_name]
30
+ ENV[config_name]
31
+ end
32
+
33
+ # Given the response from smartcar API, returns an error object if needed
34
+ # @param response [Object] response Object with status and body
35
+ #
36
+ # @return [Object] nil OR Error object
37
+ def get_error(response)
38
+ status = response.status
39
+ return nil if [200,204].include?(status)
40
+ return Smartcar::ServiceUnavailableError.new("Service Unavailable - #{response.body}") if status == 404
41
+ return Smartcar::BadRequestError.new("Bad Request - #{response.body}") if status == 400
42
+ return Smartcar::AuthenticationError.new("Authentication error") if status == 401
43
+ return Smartcar::ExternalServiceError.new("API error - #{response.body}")
44
+ end
34
45
  end
35
46
  end
@@ -8,9 +8,6 @@ module Smartcar
8
8
  #@attr [String] id Smartcar vehicle ID.
9
9
  #@attr [String] unit_system unit system to represent the data in.
10
10
  class Vehicle < Base
11
- include Utils
12
-
13
-
14
11
  # Path for hitting compatibility end point
15
12
  COMPATIBLITY_PATH = '/compatibility'.freeze
16
13
 
@@ -18,15 +15,15 @@ module Smartcar
18
15
  PATH = Proc.new{|id| "/vehicles/#{id}"}
19
16
 
20
17
  attr_reader :id
21
- attr_accessor :token, :unit_system
22
18
 
23
- def initialize(token:, id:, unit_system: IMPERIAL)
19
+ def initialize(token:, id:, unit_system: IMPERIAL, version: DEFAULT_API_VERSION)
24
20
  raise InvalidParameterValue.new, "Invalid Units provided : #{unit_system}" unless UNITS.include?(unit_system)
25
21
  raise InvalidParameterValue.new, "Vehicle ID (id) is a required field" if id.nil?
26
22
  raise InvalidParameterValue.new, "Access Token(token) is a required field" if token.nil?
27
23
  @token = token
28
24
  @id = id
29
25
  @unit_system = unit_system
26
+ @version = version
30
27
  end
31
28
 
32
29
  # Class method Used to get all the vehicles in the app. This only returns
@@ -35,8 +32,8 @@ module Smartcar
35
32
  # @param options [Hash] - Optional filter parameters (check documentation)
36
33
  #
37
34
  # @return [Array] of vehicle IDs(Strings)
38
- def self.all_vehicle_ids(token:, options: {})
39
- response, meta = new(token: token, id: 'none').fetch(
35
+ def self.all_vehicle_ids(token:, options: {}, version: DEFAULT_API_VERSION)
36
+ response, meta = new(token: token, id: 'none', version: version).fetch(
40
37
  path: PATH.call(''),
41
38
  options: options
42
39
  )
@@ -52,11 +49,11 @@ module Smartcar
52
49
  # Defaults to US.
53
50
  #
54
51
  # @return [Boolean] true or false
55
- def self.compatible?(vin:, scope:, country: 'US')
52
+ def self.compatible?(vin:, scope:, country: 'US', version: DEFAULT_API_VERSION)
56
53
  raise InvalidParameterValue.new, "vin is a required field" if vin.nil?
57
54
  raise InvalidParameterValue.new, "scope is a required field" if scope.nil?
58
55
 
59
- response, meta = new(token: 'none', id: 'none').fetch(path: COMPATIBLITY_PATH,
56
+ response, meta = new(token: 'none', id: 'none', version: version).fetch(path: COMPATIBLITY_PATH,
60
57
  options: {
61
58
  vin: vin,
62
59
  scope: scope.join(' '),
@@ -84,7 +81,7 @@ module Smartcar
84
81
  # EX : Smartcar::Vehicle.new(token: token, id: id).permissions
85
82
  # @param options [Hash] - Optional filter parameters (check documentation)
86
83
  #
87
- # @return [Array] of permissions (Strings)
84
+ # @return [Permissions] object
88
85
  def permissions(options: {})
89
86
  get_attribute(Permissions)
90
87
  end
@@ -147,6 +144,15 @@ module Smartcar
147
144
  get_attribute(Battery)
148
145
  end
149
146
 
147
+ # Returns the capacity of an electric or
148
+ # plug-in hybrid vehicle's battery.
149
+ # API - https://smartcar.com/docs/api#get-ev-battery-capacity
150
+ #
151
+ # @return [Battery] object
152
+ def battery_capacity
153
+ get_attribute(BatteryCapacity)
154
+ end
155
+
150
156
  # Returns the current charge status of the vehicle.
151
157
  # API - https://smartcar.com/docs/api#get-ev-battery
152
158
  #
@@ -1,4 +1,4 @@
1
1
  module Smartcar
2
2
  # Gem current version number
3
- VERSION = "1.0.7"
3
+ VERSION = "2.3.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: 1.0.7
4
+ version: 2.3.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: 2020-10-06 00:00:00.000000000 Z
11
+ date: 2021-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -137,6 +137,7 @@ files:
137
137
  - lib/smartcar.rb
138
138
  - lib/smartcar/base.rb
139
139
  - lib/smartcar/battery.rb
140
+ - lib/smartcar/battery_capacity.rb
140
141
  - lib/smartcar/charge.rb
141
142
  - lib/smartcar/engine_oil.rb
142
143
  - lib/smartcar/fuel.rb