smartcar 2.1.0 → 2.2.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: 42d14a5db8893d4b26b07e273924b854c1c5970aee1a072e5d748a95a5934201
4
- data.tar.gz: 8b5c2a8c57127a1a494dc6448c84a251d8c6f2eaf0f6773255258006dcac7296
3
+ metadata.gz: 8df9188b608db089e0225bdeaad7a7e585ec19ce0c2f8e024f16055c555c48cf
4
+ data.tar.gz: e85c23cacda1e774df87a84a4d916f7675584e4cb1f8d43f20496d9e04d6c213
5
5
  SHA512:
6
- metadata.gz: 3b143db051f1009607453d86e2f034b3ad3a6a32949a0aee77ea88a6ef4db34e9d0f65d2b3e8da361eb4aee7da4cad4bcfe873aeb8079647287d488206f6fddb
7
- data.tar.gz: 47061d5c08c3db932e6d8c0b2cea7e0064c60348122ac70fb537fbf512b19b545593d9448cbc91766299c8c31ae79029088d10dab56fc5a445d47de501d635ef
6
+ metadata.gz: fcce1b264d733d8abd2c5f0bb8fd84c2edd219ac45d1303b04deb0b5b2257b6a301cdeeb4e1c415ffbf8f339fd8543095e9d5897237f68e4e43e625f1e0f49c7
7
+ data.tar.gz: 3283ea8c41227ef0d46503b2b78be6581eadd6fc9c1d2b81e0f80ae65c06a868461040f0cb260a464cd966587fb491d826efea10a557928d94fe71ce82091d8a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smartcar (2.1.0)
4
+ smartcar (2.2.0)
5
5
  oauth2 (~> 1.4)
6
6
 
7
7
  GEM
@@ -10,14 +10,16 @@ GEM
10
10
  byebug (11.1.3)
11
11
  childprocess (3.0.0)
12
12
  diff-lcs (1.3)
13
- faraday (1.2.0)
13
+ faraday (1.3.0)
14
+ faraday-net_http (~> 1.0)
14
15
  multipart-post (>= 1.2, < 3)
15
16
  ruby2_keywords
17
+ faraday-net_http (1.0.1)
16
18
  jwt (2.2.2)
17
19
  multi_json (1.15.0)
18
20
  multi_xml (0.6.0)
19
21
  multipart-post (2.1.1)
20
- oauth2 (1.4.4)
22
+ oauth2 (1.4.7)
21
23
  faraday (>= 0.8, < 2.0)
22
24
  jwt (>= 1.0, < 3.0)
23
25
  multi_json (~> 1.3)
@@ -25,7 +27,7 @@ GEM
25
27
  rack (>= 1.2, < 3)
26
28
  rack (2.2.3)
27
29
  rake (12.3.3)
28
- redcarpet (3.5.0)
30
+ redcarpet (3.5.1)
29
31
  rspec (3.9.0)
30
32
  rspec-core (~> 3.9.0)
31
33
  rspec-expectations (~> 3.9.0)
@@ -39,7 +41,7 @@ GEM
39
41
  diff-lcs (>= 1.2.0, < 2.0)
40
42
  rspec-support (~> 3.9.0)
41
43
  rspec-support (3.9.3)
42
- ruby2_keywords (0.0.2)
44
+ ruby2_keywords (0.0.4)
43
45
  rubyzip (2.3.0)
44
46
  selenium-webdriver (3.142.7)
45
47
  childprocess (>= 0.5, < 4.0)
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
19
19
 
20
20
  %i{get post patch put delete}.each do |verb|
21
21
  # meta programming and define all Restful methods.
@@ -27,7 +27,7 @@ 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
32
  complete_path = "/#{API_VERSION}#{path}"
33
33
  if verb==:get
@@ -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
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
9
-
10
- def initialize(token:)
11
- raise InvalidParameterValue.new, "Access Token(token) is a required field" if token.nil?
12
- @token = token
13
- end
8
+ attr_reader :id
14
9
 
15
10
  # Class method Used to get user id
16
- # EX : Smartcar::User.fetch
11
+ # EX : Smartcar::User.user_id
17
12
  # API - https://smartcar.com/docs/api#get-user
18
13
  # @param token [String] Access token
19
14
  #
20
- # @return [User] object
15
+ # @return [String] User ID
21
16
  def self.user_id(token:)
22
- new(token: token).get(USER_PATH)['id']
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).id
23
20
  end
24
21
 
22
+ # Class method Used to get user id
23
+ # EX : Smartcar::User.get
24
+ # API - https://smartcar.com/docs/api#get-user
25
+ # @param token [String] Access token
26
+ #
27
+ # @return [User] User object
28
+ def self.get(token:)
29
+ user = new(token: token)
30
+ body, _meta = user.fetch(path: USER_PATH)
31
+ user.instance_variable_set('@id', body['id'])
32
+ user
33
+ end
25
34
  end
26
35
  end
@@ -1,44 +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
- # Utility method to return a hash of the isntance variables
14
- #
15
- # @return [Hash] hash of all instance variables
16
- def to_hash
17
- instance_variables.each_with_object({}) do |attribute, hash|
18
- hash[attribute.to_s.delete("@").to_sym] = instance_variable_get(attribute)
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
19
21
  end
20
- end
21
22
 
22
- # gets a given env variable, checks for existence and throws exception if not present
23
- # @param config_name [String] key of the env variable
24
- #
25
- # @return [String] value of the env variable
26
- def get_config(config_name)
27
- config_name = "INTEGRATION_#{config_name}" if ENV['MODE'] == 'test'
28
- raise Smartcar::ConfigNotFound, "Environment variable #{config_name} not found !" unless ENV[config_name]
29
- ENV[config_name]
30
- end
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
31
32
 
32
- # Given the response from smartcar API, returns an error object if needed
33
- # @param response [Object] response Object with status and body
34
- #
35
- # @return [Object] nil OR Error object
36
- def get_error(response)
37
- status = response.status
38
- return nil if [200,204].include?(status)
39
- return Smartcar::ServiceUnavailableError.new("Service Unavailable - #{response.body}") if status == 404
40
- return Smartcar::BadRequestError.new("Bad Request - #{response.body}") if status == 400
41
- return Smartcar::AuthenticationError.new("Authentication error") if status == 401
42
- return Smartcar::ExternalServiceError.new("API error - #{response.body}")
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
43
45
  end
44
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,7 +15,6 @@ 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
19
  def initialize(token:, id:, unit_system: IMPERIAL)
24
20
  raise InvalidParameterValue.new, "Invalid Units provided : #{unit_system}" unless UNITS.include?(unit_system)
@@ -36,7 +32,7 @@ module Smartcar
36
32
  #
37
33
  # @return [Array] of vehicle IDs(Strings)
38
34
  def self.all_vehicle_ids(token:, options: {})
39
- response, meta = new(token: token, id: 'none').fetch(
35
+ response, _meta = new(token: token, id: 'none').fetch(
40
36
  path: PATH.call(''),
41
37
  options: options
42
38
  )
@@ -1,4 +1,4 @@
1
1
  module Smartcar
2
2
  # Gem current version number
3
- VERSION = "2.1.0"
3
+ VERSION = "2.2.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.1.0
4
+ version: 2.2.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-12-29 00:00:00.000000000 Z
11
+ date: 2021-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler