smartcar 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +7 -5
- data/lib/smartcar/base.rb +3 -3
- data/lib/smartcar/oauth.rb +1 -1
- data/lib/smartcar/user.rb +18 -9
- data/lib/smartcar/utils.rb +38 -36
- data/lib/smartcar/vehicle.rb +1 -5
- data/lib/smartcar/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8df9188b608db089e0225bdeaad7a7e585ec19ce0c2f8e024f16055c555c48cf
|
4
|
+
data.tar.gz: e85c23cacda1e774df87a84a4d916f7675584e4cb1f8d43f20496d9e04d6c213
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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.
|
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.
|
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.
|
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
|
data/lib/smartcar/oauth.rb
CHANGED
@@ -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
|
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.
|
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 [
|
15
|
+
# @return [String] User ID
|
21
16
|
def self.user_id(token:)
|
22
|
-
|
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
|
data/lib/smartcar/utils.rb
CHANGED
@@ -1,44 +1,46 @@
|
|
1
|
-
|
1
|
+
# Utils module , provides utility methods to underlying classes
|
2
|
+
module Smartcar
|
2
3
|
module Utils
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
data/lib/smartcar/vehicle.rb
CHANGED
@@ -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,
|
35
|
+
response, _meta = new(token: token, id: 'none').fetch(
|
40
36
|
path: PATH.call(''),
|
41
37
|
options: options
|
42
38
|
)
|
data/lib/smartcar/version.rb
CHANGED
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.
|
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:
|
11
|
+
date: 2021-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|