smartcar 2.0.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +28 -0
- data/Gemfile +4 -2
- data/Gemfile.lock +29 -6
- data/Rakefile +11 -3
- data/bin/console +4 -3
- data/lib/smartcar.rb +60 -30
- data/lib/smartcar/base.rb +18 -16
- data/lib/smartcar/battery.rb +6 -4
- data/lib/smartcar/battery_capacity.rb +11 -0
- data/lib/smartcar/charge.rb +6 -4
- data/lib/smartcar/engine_oil.rb +5 -3
- data/lib/smartcar/fuel.rb +8 -6
- data/lib/smartcar/location.rb +5 -3
- data/lib/smartcar/oauth.rb +46 -38
- data/lib/smartcar/odometer.rb +4 -2
- data/lib/smartcar/permissions.rb +4 -2
- data/lib/smartcar/tire_pressure.rb +11 -10
- data/lib/smartcar/user.rb +24 -12
- data/lib/smartcar/utils.rb +46 -35
- data/lib/smartcar/vehicle.rb +23 -240
- data/lib/smartcar/vehicle_attributes.rb +7 -5
- data/lib/smartcar/vehicle_utils/actions.rb +61 -0
- data/lib/smartcar/vehicle_utils/batch.rb +83 -0
- data/lib/smartcar/vehicle_utils/data.rb +110 -0
- data/lib/smartcar/version.rb +3 -1
- data/lib/smartcar/vin.rb +4 -2
- data/ruby-sdk.gemspec +24 -21
- metadata +30 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3848d46ccf722b908e7b42acc1afebccc24fbf1362c36bd0b0a867cd8bdd5b85
|
4
|
+
data.tar.gz: 3cfbf110c26177478a4ffad5373aeffcb73411b85f014c7af98293ea42739601
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f46fc77b3eafb462cfbd210d7509293368d9d2306ce8d16dbfbd4aad7a76339e53b689f06c2e50b3cc6eb56be5a390c805f8ae88384f6cfcdfa7e1ce27b34e91
|
7
|
+
data.tar.gz: ee615279dc5c61e75ba1afd3ffa640b2df9ffafd4ea459cf22558d145e434b117814bd4279fcfd418643146eec4386911735f8f1066babd3ce494df44d15cfba
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Prevent messages for libraries of rubocop
|
2
|
+
AllCops:
|
3
|
+
NewCops: enable
|
4
|
+
SuggestExtensions: false
|
5
|
+
|
6
|
+
# Disabling ABC size for now as refactoring few places seems pointless for now
|
7
|
+
Metrics/AbcSize:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Metrics/BlockLength:
|
11
|
+
Exclude:
|
12
|
+
- '**/*.gemspec'
|
13
|
+
- 'spec/**/*'
|
14
|
+
|
15
|
+
# Just ignoring test helper for headless auth.
|
16
|
+
Metrics/MethodLength:
|
17
|
+
Max: 20
|
18
|
+
Exclude:
|
19
|
+
- 'spec/smartcar/helpers/auth_helper.rb'
|
20
|
+
|
21
|
+
# Parameters in data from json API comes in as camelCase, ignoring those files to avoid snake_case enforcement
|
22
|
+
Naming/MethodName:
|
23
|
+
Exclude:
|
24
|
+
- 'lib/smartcar/battery.rb'
|
25
|
+
- 'lib/smartcar/charge.rb'
|
26
|
+
- 'lib/smartcar/engine_oil.rb'
|
27
|
+
- 'lib/smartcar/fuel.rb'
|
28
|
+
- 'lib/smartcar/tire_pressure.rb'
|
data/Gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
6
|
|
5
7
|
# Specify your gem's dependencies in smartcar.gemspec
|
6
8
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,31 +1,40 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
smartcar (2.
|
4
|
+
smartcar (2.5.0)
|
5
5
|
oauth2 (~> 1.4)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
+
ast (2.4.2)
|
10
11
|
byebug (11.1.3)
|
11
12
|
childprocess (3.0.0)
|
12
13
|
diff-lcs (1.3)
|
13
|
-
faraday (1.
|
14
|
+
faraday (1.3.0)
|
15
|
+
faraday-net_http (~> 1.0)
|
14
16
|
multipart-post (>= 1.2, < 3)
|
15
17
|
ruby2_keywords
|
18
|
+
faraday-net_http (1.0.1)
|
16
19
|
jwt (2.2.2)
|
17
20
|
multi_json (1.15.0)
|
18
21
|
multi_xml (0.6.0)
|
19
22
|
multipart-post (2.1.1)
|
20
|
-
oauth2 (1.4.
|
23
|
+
oauth2 (1.4.7)
|
21
24
|
faraday (>= 0.8, < 2.0)
|
22
25
|
jwt (>= 1.0, < 3.0)
|
23
26
|
multi_json (~> 1.3)
|
24
27
|
multi_xml (~> 0.5)
|
25
28
|
rack (>= 1.2, < 3)
|
29
|
+
parallel (1.20.1)
|
30
|
+
parser (3.0.0.0)
|
31
|
+
ast (~> 2.4.1)
|
26
32
|
rack (2.2.3)
|
33
|
+
rainbow (3.0.0)
|
27
34
|
rake (12.3.3)
|
28
|
-
redcarpet (3.5.
|
35
|
+
redcarpet (3.5.1)
|
36
|
+
regexp_parser (2.1.1)
|
37
|
+
rexml (3.2.5)
|
29
38
|
rspec (3.9.0)
|
30
39
|
rspec-core (~> 3.9.0)
|
31
40
|
rspec-expectations (~> 3.9.0)
|
@@ -39,11 +48,24 @@ GEM
|
|
39
48
|
diff-lcs (>= 1.2.0, < 2.0)
|
40
49
|
rspec-support (~> 3.9.0)
|
41
50
|
rspec-support (3.9.3)
|
42
|
-
|
51
|
+
rubocop (1.12.0)
|
52
|
+
parallel (~> 1.10)
|
53
|
+
parser (>= 3.0.0.0)
|
54
|
+
rainbow (>= 2.2.2, < 4.0)
|
55
|
+
regexp_parser (>= 1.8, < 3.0)
|
56
|
+
rexml
|
57
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
58
|
+
ruby-progressbar (~> 1.7)
|
59
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
60
|
+
rubocop-ast (1.4.1)
|
61
|
+
parser (>= 2.7.1.5)
|
62
|
+
ruby-progressbar (1.11.0)
|
63
|
+
ruby2_keywords (0.0.4)
|
43
64
|
rubyzip (2.3.0)
|
44
65
|
selenium-webdriver (3.142.7)
|
45
66
|
childprocess (>= 0.5, < 4.0)
|
46
67
|
rubyzip (>= 1.2.2)
|
68
|
+
unicode-display_width (2.0.0)
|
47
69
|
|
48
70
|
PLATFORMS
|
49
71
|
ruby
|
@@ -54,8 +76,9 @@ DEPENDENCIES
|
|
54
76
|
rake (~> 12.3, >= 12.3.3)
|
55
77
|
redcarpet (~> 3.5.0)
|
56
78
|
rspec (~> 3.0)
|
79
|
+
rubocop (~> 1.12)
|
57
80
|
selenium-webdriver (~> 3.142)
|
58
81
|
smartcar!
|
59
82
|
|
60
83
|
BUNDLED WITH
|
61
|
-
2.1.
|
84
|
+
2.1.4
|
data/Rakefile
CHANGED
@@ -1,6 +1,14 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
3
5
|
|
4
6
|
RSpec::Core::RakeTask.new(:spec)
|
5
7
|
|
6
|
-
|
8
|
+
require 'rubocop/rake_task'
|
9
|
+
|
10
|
+
RuboCop::RakeTask.new(:rubocop) do |t|
|
11
|
+
t.options = ['--display-cop-names']
|
12
|
+
end
|
13
|
+
|
14
|
+
task default: %i[rubocop spec]
|
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'smartcar'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "smartcar"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start(__FILE__)
|
data/lib/smartcar.rb
CHANGED
@@ -1,53 +1,83 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'smartcar/utils'
|
4
|
+
require 'smartcar/version'
|
5
|
+
require 'smartcar/base'
|
6
|
+
require 'smartcar/oauth'
|
7
|
+
require 'smartcar/permissions'
|
8
|
+
require 'smartcar/battery'
|
9
|
+
require 'smartcar/battery_capacity'
|
10
|
+
require 'smartcar/charge'
|
11
|
+
require 'smartcar/engine_oil'
|
12
|
+
require 'smartcar/fuel'
|
13
|
+
require 'smartcar/location'
|
14
|
+
require 'smartcar/odometer'
|
15
|
+
require 'smartcar/tire_pressure'
|
16
|
+
require 'smartcar/vin'
|
17
|
+
require 'smartcar/vehicle_attributes'
|
18
|
+
require 'smartcar/vehicle_utils/batch'
|
19
|
+
require 'smartcar/vehicle_utils/data'
|
20
|
+
require 'smartcar/vehicle_utils/actions'
|
21
|
+
require 'smartcar/vehicle'
|
22
|
+
require 'smartcar/user'
|
23
|
+
|
24
|
+
# Main Smartcar umbrella module
|
25
|
+
module Smartcar
|
21
26
|
# Error raised when a config is not found
|
22
27
|
class ConfigNotFound < StandardError; end
|
28
|
+
|
23
29
|
# Error raised when Smartcar returns non 400, 404, 401, 200 or 204 response
|
24
30
|
class ExternalServiceError < StandardError; end
|
31
|
+
|
25
32
|
# Error raised when Smartcar returns 404
|
26
33
|
class ServiceUnavailableError < ExternalServiceError; end
|
34
|
+
|
27
35
|
# Error raised when Smartcar returns Authentication Error with status 401
|
28
36
|
class AuthenticationError < ExternalServiceError; end
|
37
|
+
|
29
38
|
# Error raised when Smartcar returns 400 response
|
30
39
|
class BadRequestError < ExternalServiceError; end
|
31
|
-
|
32
|
-
API_VERSION = "v1.0".freeze
|
40
|
+
|
33
41
|
# Host to connect to smartcar
|
34
|
-
SITE =
|
42
|
+
SITE = 'https://api.smartcar.com/'
|
35
43
|
|
36
44
|
# Path for smartcar oauth
|
37
|
-
OAUTH_PATH =
|
38
|
-
%w
|
45
|
+
OAUTH_PATH = 'https://connect.smartcar.com/oauth/authorize'
|
46
|
+
%w[success code test live force auto metric imperial].each do |constant|
|
39
47
|
# Constant to represent the value
|
40
48
|
const_set(constant.upcase, constant.freeze)
|
41
49
|
end
|
42
50
|
|
43
51
|
# Lock value sent in request body
|
44
|
-
LOCK =
|
52
|
+
LOCK = 'LOCK'
|
45
53
|
# Unlock value sent in request body
|
46
|
-
UNLOCK =
|
54
|
+
UNLOCK = 'UNLOCK'
|
47
55
|
# Start charge value sent in request body
|
48
|
-
START_CHARGE =
|
56
|
+
START_CHARGE = 'START'
|
49
57
|
# Stop charge value sent in request body
|
50
|
-
STOP_CHARGE =
|
58
|
+
STOP_CHARGE = 'STOP'
|
51
59
|
# Constant for units
|
52
|
-
UNITS = [IMPERIAL,METRIC]
|
60
|
+
UNITS = [IMPERIAL, METRIC].freeze
|
61
|
+
|
62
|
+
# Smartcar API version variable - defaulted to 1.0
|
63
|
+
@api_version = '1.0'
|
64
|
+
|
65
|
+
# rubocop:disable Naming/AccessorMethodName
|
66
|
+
# Module method Used to set api version to be used.
|
67
|
+
# This method can be used at the top to set the version and any
|
68
|
+
# following request will use the version set here unless overridden
|
69
|
+
# separately.
|
70
|
+
# @param version [String] version to be set without 'v' prefix.
|
71
|
+
def self.set_api_version(version)
|
72
|
+
instance_variable_set('@api_version', version)
|
73
|
+
end
|
74
|
+
|
75
|
+
# Module method Used to get api version to be used.
|
76
|
+
# This is the getter for the class instance variable @api_version
|
77
|
+
#
|
78
|
+
# @return [String] api version number without 'v' prefix
|
79
|
+
def self.get_api_version
|
80
|
+
instance_variable_get('@api_version')
|
81
|
+
end
|
82
|
+
# rubocop:enable Naming/AccessorMethodName
|
53
83
|
end
|
data/lib/smartcar/base.rb
CHANGED
@@ -1,36 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'oauth2'
|
2
4
|
require 'base64'
|
3
5
|
module Smartcar
|
4
6
|
# The Base class for all of the other class.
|
5
7
|
# Let other classes inherit from here and put common methods here.
|
6
8
|
class Base
|
7
|
-
include Utils
|
9
|
+
include Smartcar::Utils
|
8
10
|
|
9
11
|
# Error raised when an invalid parameter is passed.
|
10
12
|
class InvalidParameterValue < StandardError; end
|
11
13
|
# Constant for Bearer auth type
|
12
|
-
BEARER = 'BEARER'
|
14
|
+
BEARER = 'BEARER'
|
13
15
|
# Constant for Basic auth type
|
14
|
-
BASIC = 'BASIC'
|
16
|
+
BASIC = 'BASIC'
|
15
17
|
# Number of seconds to wait for response
|
16
18
|
REQUEST_TIMEOUT = 310
|
17
19
|
|
18
|
-
attr_accessor :token, :error, :meta
|
20
|
+
attr_accessor :token, :error, :meta, :unit_system, :version
|
19
21
|
|
20
|
-
%i
|
22
|
+
%i[get post patch put delete].each do |verb|
|
21
23
|
# meta programming and define all Restful methods.
|
22
24
|
# @param path [String] the path to hit for the request.
|
23
25
|
# @param data [Hash] request body if needed.
|
24
26
|
#
|
25
27
|
# @return [Hash] The response Json parsed as a hash.
|
26
|
-
define_method verb do |path, data=nil|
|
28
|
+
define_method verb do |path, data = nil|
|
27
29
|
response = service.send(verb) do |request|
|
28
30
|
request.headers['Authorization'] = "BEARER #{token}"
|
29
|
-
request.headers['Authorization'] = "BASIC #{
|
30
|
-
request.headers['sc-unit-system'] = unit_system
|
31
|
-
request.headers['Content-Type'] =
|
32
|
-
complete_path = "
|
33
|
-
if verb
|
31
|
+
request.headers['Authorization'] = "BASIC #{generate_basic_auth}" if data && data[:auth] == BASIC
|
32
|
+
request.headers['sc-unit-system'] = unit_system if unit_system
|
33
|
+
request.headers['Content-Type'] = 'application/json'
|
34
|
+
complete_path = "/v#{version}#{path}"
|
35
|
+
if verb == :get
|
34
36
|
request.url complete_path, data
|
35
37
|
else
|
36
38
|
request.url complete_path
|
@@ -39,6 +41,7 @@ module Smartcar
|
|
39
41
|
end
|
40
42
|
error = get_error(response)
|
41
43
|
raise error if error
|
44
|
+
|
42
45
|
[JSON.parse(response.body), response.headers]
|
43
46
|
end
|
44
47
|
end
|
@@ -49,10 +52,9 @@ module Smartcar
|
|
49
52
|
# @param auth [String] type of auth
|
50
53
|
#
|
51
54
|
# @return [Object]
|
52
|
-
def fetch(path
|
53
|
-
|
54
|
-
|
55
|
-
get(_path, {auth: auth})
|
55
|
+
def fetch(path:, options: {}, auth: 'BEARER')
|
56
|
+
path += "?#{URI.encode_www_form(options)}" unless options.empty?
|
57
|
+
get(path, { auth: auth })
|
56
58
|
end
|
57
59
|
|
58
60
|
private
|
@@ -60,7 +62,7 @@ module Smartcar
|
|
60
62
|
# returns auth token for BASIC auth
|
61
63
|
#
|
62
64
|
# @return [String] Base64 encoding of CLIENT:SECRET
|
63
|
-
def
|
65
|
+
def generate_basic_auth
|
64
66
|
Base64.strict_encode64("#{get_config('CLIENT_ID')}:#{get_config('CLIENT_SECRET')}")
|
65
67
|
end
|
66
68
|
|
data/lib/smartcar/battery.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Smartcar
|
2
4
|
# class to represent Battery info
|
3
|
-
|
4
|
-
|
5
|
+
# @attr [Number] percentRemaining Decimal value representing the remaining charge percent.
|
6
|
+
# @attr [Number] range Remaining range of the vehicle.
|
5
7
|
class Battery < Base
|
6
8
|
# Path Proc for hitting battery end point
|
7
|
-
PATH =
|
9
|
+
PATH = proc { |id| "/vehicles/#{id}/battery" }
|
8
10
|
attr_reader :percentRemaining, :range
|
9
11
|
|
10
12
|
# just to have Ruby-esque method names
|
11
|
-
|
13
|
+
alias percentage_remaining percentRemaining
|
12
14
|
end
|
13
15
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Smartcar
|
4
|
+
# class to represent Battery Capacity info
|
5
|
+
# @attr [Number] capacity Decimal value representing the battery's total capacity in kWh.
|
6
|
+
class BatteryCapacity < Base
|
7
|
+
# Path Proc for hitting battery capacity end point
|
8
|
+
PATH = proc { |id| "/vehicles/#{id}/battery/capacity" }
|
9
|
+
attr_reader :capacity
|
10
|
+
end
|
11
|
+
end
|
data/lib/smartcar/charge.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Smartcar
|
2
4
|
# class to represent Charge info
|
3
|
-
|
4
|
-
|
5
|
+
# @attr [Boolean] isPluggedIn Specifies if the vehicle is plugged in.
|
6
|
+
# @attr [String] state Charging state of the vehicle.
|
5
7
|
class Charge < Base
|
6
8
|
# Path Proc for hitting charge end point
|
7
|
-
PATH =
|
9
|
+
PATH = proc { |id| "/vehicles/#{id}/charge" }
|
8
10
|
attr_reader :isPluggedIn, :state
|
9
11
|
|
10
12
|
# just to have Ruby-esque method names
|
11
|
-
|
13
|
+
alias is_plugged_in? isPluggedIn
|
12
14
|
end
|
13
15
|
end
|
data/lib/smartcar/engine_oil.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Smartcar
|
2
4
|
# class to represent Engine oil info
|
3
|
-
|
5
|
+
# @attr [Number] lifeRemaining Remaining life of the engine oil
|
4
6
|
class EngineOil < Base
|
5
7
|
# Path Proc for hitting engine oil end point
|
6
|
-
PATH =
|
8
|
+
PATH = proc { |id| "/vehicles/#{id}/engine/oil" }
|
7
9
|
attr_reader :lifeRemaining
|
8
10
|
|
9
11
|
# just to have Ruby-esque method names
|
10
|
-
|
12
|
+
alias life_remaining lifeRemaining
|
11
13
|
end
|
12
14
|
end
|
data/lib/smartcar/fuel.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Smartcar
|
2
4
|
# class to represent Fuel info
|
3
|
-
|
4
|
-
|
5
|
-
|
5
|
+
# @attr [Number] amountRemaining Amount of fuel remaining.
|
6
|
+
# @attr [Number] percentageRemaining Decimal value representing the remaining fuel percent.
|
7
|
+
# @attr [Number] range Remaining range of the vehicle.
|
6
8
|
class Fuel < Base
|
7
9
|
# Path Proc for hitting fuel end point
|
8
|
-
PATH =
|
10
|
+
PATH = proc { |id| "/vehicles/#{id}/fuel" }
|
9
11
|
attr_reader :amountRemaining, :percentRemaining, :range
|
10
12
|
|
11
13
|
# just to have Ruby-esque method names
|
12
|
-
|
13
|
-
|
14
|
+
alias amount_remaining amountRemaining
|
15
|
+
alias percent_remaining percentRemaining
|
14
16
|
end
|
15
17
|
end
|