smartcar 2.4.0 → 2.5.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 +4 -4
- data/.rubocop.yml +28 -0
- data/Gemfile +4 -2
- data/Gemfile.lock +22 -1
- data/Rakefile +11 -3
- data/bin/console +4 -3
- data/lib/smartcar.rb +36 -26
- data/lib/smartcar/base.rb +14 -12
- data/lib/smartcar/battery.rb +6 -4
- data/lib/smartcar/battery_capacity.rb +4 -2
- 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 +45 -37
- 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 +7 -4
- data/lib/smartcar/utils.rb +14 -5
- data/lib/smartcar/vehicle.rb +19 -242
- 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 +29 -11
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Smartcar
|
4
|
+
module VehicleUtils
|
5
|
+
# Actions module has all the action methods here to declutter Vehicle class
|
6
|
+
module Actions
|
7
|
+
# Method Used toRevoke access for the current requesting application
|
8
|
+
# API - https://smartcar.com/docs/api#delete-disconnect
|
9
|
+
#
|
10
|
+
# @return [Boolean] true if success
|
11
|
+
def disconnect!
|
12
|
+
response, = delete("#{Smartcar::Vehicle::PATH.call(id)}/application")
|
13
|
+
response['status'] == SUCCESS
|
14
|
+
end
|
15
|
+
|
16
|
+
# Methods Used to lock car
|
17
|
+
# API - https://smartcar.com/docs/api#post-security
|
18
|
+
#
|
19
|
+
# @return [Boolean] true if success
|
20
|
+
def lock!
|
21
|
+
lock_or_unlock!(action: Smartcar::LOCK)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Methods Used to unlock car
|
25
|
+
# API - https://smartcar.com/docs/api#post-security
|
26
|
+
#
|
27
|
+
# @return [Boolean] true if success
|
28
|
+
def unlock!
|
29
|
+
lock_or_unlock!(action: Smartcar::UNLOCK)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Method used to start charging a car
|
33
|
+
#
|
34
|
+
#
|
35
|
+
# @return [Boolean] true if success
|
36
|
+
def start_charge!
|
37
|
+
start_or_stop_charge!(action: Smartcar::START_CHARGE)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Method used to stop charging a car
|
41
|
+
#
|
42
|
+
#
|
43
|
+
# @return [Boolean] true if success
|
44
|
+
def stop_charge!
|
45
|
+
start_or_stop_charge!(action: Smartcar::STOP_CHARGE)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def lock_or_unlock!(action:)
|
51
|
+
response, = post("#{Smartcar::Vehicle::PATH.call(id)}/security", { action: action })
|
52
|
+
response['status'] == SUCCESS
|
53
|
+
end
|
54
|
+
|
55
|
+
def start_or_stop_charge!(action:)
|
56
|
+
response, = post("#{Smartcar::Vehicle::PATH.call(id)}/charge", { action: action })
|
57
|
+
response['status'] == SUCCESS
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Smartcar
|
4
|
+
module VehicleUtils
|
5
|
+
# Batch module , has all the batch related methods here to declutter Vehicle class
|
6
|
+
module Batch
|
7
|
+
DATA_CLASSES = {
|
8
|
+
battery: Smartcar::Battery,
|
9
|
+
charge: Smartcar::Charge,
|
10
|
+
engine_oil: Smartcar::EngineOil,
|
11
|
+
fuel: Smartcar::Fuel,
|
12
|
+
location: Smartcar::Location,
|
13
|
+
odometer: Smartcar::Odometer,
|
14
|
+
permissions: Smartcar::Permissions,
|
15
|
+
tire_pressure: Smartcar::TirePressure,
|
16
|
+
vin: Smartcar::Vin
|
17
|
+
}.freeze
|
18
|
+
# Method to get batch requests
|
19
|
+
# API - https://smartcar.com/docs/api#post-batch-request
|
20
|
+
# @param attributes [Array] Array of strings or symbols of attributes to be fetched together
|
21
|
+
#
|
22
|
+
# @return [Hash] Hash with key as requested attribute(symbol)
|
23
|
+
# and value as Error OR Object of the requested attribute
|
24
|
+
def batch(attributes = [])
|
25
|
+
raise InvalidParameterValue.new, 'vin is a required field' if attributes.nil?
|
26
|
+
|
27
|
+
request_body = get_batch_request_body(attributes)
|
28
|
+
response, _meta = post("#{Smartcar::Vehicle::PATH.call(id)}/batch", request_body)
|
29
|
+
process_batch_response(response)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def allowed_attributes
|
35
|
+
@allowed_attributes ||= DATA_CLASSES.transform_values { |klass| get_path(klass) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def path_to_class
|
39
|
+
@path_to_class ||= DATA_CLASSES.transform_keys { |key| get_path(DATA_CLASSES[key]) }
|
40
|
+
end
|
41
|
+
|
42
|
+
# @private
|
43
|
+
BatchItemResponse = Struct.new(:body, :status, :headers) do
|
44
|
+
def body_with_meta
|
45
|
+
body.merge(meta: headers)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_batch_request_body(attributes)
|
50
|
+
attributes = validated_attributes(attributes)
|
51
|
+
requests = attributes.each_with_object([]) do |item, all_requests|
|
52
|
+
all_requests << { path: allowed_attributes[item] }
|
53
|
+
end
|
54
|
+
{ requests: requests }
|
55
|
+
end
|
56
|
+
|
57
|
+
def process_batch_response(responses)
|
58
|
+
inverted_map = allowed_attributes.invert
|
59
|
+
responses['responses'].each_with_object({}) do |response, result|
|
60
|
+
item_response = BatchItemResponse.new(response['body'], response['code'], response['headers'])
|
61
|
+
error = get_error(item_response)
|
62
|
+
path = response['path']
|
63
|
+
result[inverted_map[path]] = error || path_to_class[path].new(item_response.body_with_meta)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def validated_attributes(attributes)
|
68
|
+
attributes.map!(&:to_sym)
|
69
|
+
unsupported_attributes = (attributes - allowed_attributes.keys) || []
|
70
|
+
unless unsupported_attributes.empty?
|
71
|
+
message = "Unsupported attribute(s) requested in batch - #{unsupported_attributes.join(',')}"
|
72
|
+
raise Smartcar::Base::InvalidParameterValue.new, message
|
73
|
+
end
|
74
|
+
attributes
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_path(klass)
|
78
|
+
path = klass::PATH.call(id)
|
79
|
+
path.split("/vehicles/#{id}").last
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Smartcar
|
4
|
+
module VehicleUtils
|
5
|
+
# Data module has all the data accessor methods here to declutter Vehicle class
|
6
|
+
module Data
|
7
|
+
# Fetch the list of permissions that this application has been granted for
|
8
|
+
# this vehicle
|
9
|
+
# EX : Smartcar::Vehicle.new(token: token, id: id).permissions
|
10
|
+
# @param options [Hash] - Optional filter parameters (check documentation)
|
11
|
+
#
|
12
|
+
# @return [Permissions] object
|
13
|
+
def permissions(options: {})
|
14
|
+
get_attribute(klass: Permissions, options: options)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns make model year and id of the vehicle
|
18
|
+
# API - https://smartcar.com/api#get-vehicle-attributes
|
19
|
+
#
|
20
|
+
# @return [VehicleAttributes] object
|
21
|
+
def vehicle_attributes
|
22
|
+
get_attribute(klass: VehicleAttributes)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns the state of charge (SOC) and remaining range of an electric or
|
26
|
+
# plug-in hybrid vehicle's battery.
|
27
|
+
# API - https://smartcar.com/docs/api#get-ev-battery
|
28
|
+
#
|
29
|
+
# @return [Battery] object
|
30
|
+
def battery
|
31
|
+
get_attribute(klass: Battery)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns the capacity of an electric or
|
35
|
+
# plug-in hybrid vehicle's battery.
|
36
|
+
# API - https://smartcar.com/docs/api#get-ev-battery-capacity
|
37
|
+
#
|
38
|
+
# @return [Battery] object
|
39
|
+
def battery_capacity
|
40
|
+
get_attribute(klass: BatteryCapacity)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns the current charge status of the vehicle.
|
44
|
+
# API - https://smartcar.com/docs/api#get-ev-battery
|
45
|
+
#
|
46
|
+
# @return [Charge] object
|
47
|
+
def charge
|
48
|
+
get_attribute(klass: Charge)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns the remaining life span of a vehicle's engine oil
|
52
|
+
# API - https://smartcar.com/docs/api#get-engine-oil-life
|
53
|
+
#
|
54
|
+
# @return [EngineOil] object
|
55
|
+
def engine_oil
|
56
|
+
get_attribute(klass: EngineOil)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Returns the status of the fuel remaining in the vehicle's gas tank.
|
60
|
+
# API - https://smartcar.com/docs/api#get-fuel-tank
|
61
|
+
#
|
62
|
+
# @return [Fuel] object
|
63
|
+
def fuel
|
64
|
+
get_attribute(klass: Fuel)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Returns the last known location of the vehicle in geographic coordinates.
|
68
|
+
# API - https://smartcar.com/docs/api#get-location
|
69
|
+
#
|
70
|
+
# @return [Location] object
|
71
|
+
def location
|
72
|
+
get_attribute(klass: Location)
|
73
|
+
end
|
74
|
+
|
75
|
+
# Returns the vehicle's last known odometer reading.
|
76
|
+
# API - https://smartcar.com/docs/api#get-odometer
|
77
|
+
#
|
78
|
+
# @return [Odometer] object
|
79
|
+
def odometer
|
80
|
+
get_attribute(klass: Odometer)
|
81
|
+
end
|
82
|
+
|
83
|
+
# Returns the air pressure of each of the vehicle's tires.
|
84
|
+
# API - https://smartcar.com/docs/api#get-tire-pressure
|
85
|
+
#
|
86
|
+
# @return [TirePressure] object
|
87
|
+
def tire_pressure
|
88
|
+
get_attribute(klass: TirePressure)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Returns the vehicle's manufacturer identifier (VIN).
|
92
|
+
# API - https://smartcar.com/docs/api#get-vin
|
93
|
+
#
|
94
|
+
# @return [String] Vin of the vehicle.
|
95
|
+
def vin
|
96
|
+
@vin ||= get_attribute(klass: Vin).vin
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
def get_attribute(klass:, options: {})
|
102
|
+
body, meta = fetch(
|
103
|
+
path: klass::PATH.call(id),
|
104
|
+
options: options
|
105
|
+
)
|
106
|
+
klass.new(body.merge(meta: meta))
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
data/lib/smartcar/version.rb
CHANGED
data/lib/smartcar/vin.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Smartcar
|
2
4
|
# Hidden class to represent vin
|
3
5
|
#
|
4
|
-
|
6
|
+
# @attr [String] vin Vin of the vehicle
|
5
7
|
class Vin < Base
|
6
8
|
# Path Proc for hitting vin end point
|
7
|
-
PATH =
|
9
|
+
PATH = proc { |id| "/vehicles/#{id}/vin" }
|
8
10
|
attr_reader :vin
|
9
11
|
end
|
10
12
|
end
|
data/ruby-sdk.gemspec
CHANGED
@@ -1,33 +1,36 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require
|
5
|
+
require 'smartcar/version'
|
4
6
|
|
5
7
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name =
|
8
|
+
spec.name = 'smartcar'
|
7
9
|
spec.version = Smartcar::VERSION
|
8
|
-
spec.required_ruby_version =
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
10
|
+
spec.required_ruby_version = '>= 2.5.0'
|
11
|
+
spec.authors = ['Ashwin Subramanian']
|
12
|
+
spec.email = ['ashwin.subramanian@smartcar.com']
|
11
13
|
spec.homepage = 'https://rubygems.org/gems/smartcar'
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.license =
|
15
|
-
spec.metadata
|
16
|
-
|
17
|
-
|
14
|
+
spec.summary = 'Ruby Gem to access smartcar APIs (https://smartcar.com/docs/)'
|
15
|
+
spec.description = 'This is a ruby gem to access the smartcar APIs. It includes the API classes and the OAuth system.'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
spec.metadata = {
|
18
|
+
'source_code_uri' => 'https://github.com/smartcar/ruby-sdk',
|
19
|
+
'documentation_uri' => 'https://www.rubydoc.info/gems/smartcar'
|
18
20
|
}
|
19
|
-
spec.files = Dir.chdir(File.expand_path(
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
20
22
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
23
|
end
|
22
|
-
spec.bindir =
|
24
|
+
spec.bindir = 'exe'
|
23
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
-
spec.require_paths = [
|
26
|
+
spec.require_paths = ['lib']
|
25
27
|
|
26
|
-
spec.add_development_dependency
|
28
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
29
|
+
spec.add_development_dependency 'byebug', '~> 11.0'
|
27
30
|
spec.add_development_dependency 'rake', '~> 12.3', '>= 12.3.3'
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_dependency
|
31
|
+
spec.add_development_dependency 'redcarpet', '~> 3.5.0'
|
32
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
33
|
+
spec.add_development_dependency 'rubocop', '~> 1.12'
|
34
|
+
spec.add_development_dependency 'selenium-webdriver', '~> 3.142'
|
35
|
+
spec.add_dependency 'oauth2', '~> 1.4'
|
33
36
|
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.
|
4
|
+
version: 2.5.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-
|
11
|
+
date: 2021-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: byebug
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '11.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '11.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -45,47 +59,47 @@ dependencies:
|
|
45
59
|
- !ruby/object:Gem::Version
|
46
60
|
version: 12.3.3
|
47
61
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
62
|
+
name: redcarpet
|
49
63
|
requirement: !ruby/object:Gem::Requirement
|
50
64
|
requirements:
|
51
65
|
- - "~>"
|
52
66
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
67
|
+
version: 3.5.0
|
54
68
|
type: :development
|
55
69
|
prerelease: false
|
56
70
|
version_requirements: !ruby/object:Gem::Requirement
|
57
71
|
requirements:
|
58
72
|
- - "~>"
|
59
73
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
74
|
+
version: 3.5.0
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
76
|
+
name: rspec
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
64
78
|
requirements:
|
65
79
|
- - "~>"
|
66
80
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
81
|
+
version: '3.0'
|
68
82
|
type: :development
|
69
83
|
prerelease: false
|
70
84
|
version_requirements: !ruby/object:Gem::Requirement
|
71
85
|
requirements:
|
72
86
|
- - "~>"
|
73
87
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
88
|
+
version: '3.0'
|
75
89
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
90
|
+
name: rubocop
|
77
91
|
requirement: !ruby/object:Gem::Requirement
|
78
92
|
requirements:
|
79
93
|
- - "~>"
|
80
94
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
95
|
+
version: '1.12'
|
82
96
|
type: :development
|
83
97
|
prerelease: false
|
84
98
|
version_requirements: !ruby/object:Gem::Requirement
|
85
99
|
requirements:
|
86
100
|
- - "~>"
|
87
101
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
102
|
+
version: '1.12'
|
89
103
|
- !ruby/object:Gem::Dependency
|
90
104
|
name: selenium-webdriver
|
91
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,6 +138,7 @@ extra_rdoc_files: []
|
|
124
138
|
files:
|
125
139
|
- ".gitignore"
|
126
140
|
- ".rspec"
|
141
|
+
- ".rubocop.yml"
|
127
142
|
- ".travis.yml"
|
128
143
|
- ".yardopts"
|
129
144
|
- CODE_OF_CONDUCT.md
|
@@ -150,6 +165,9 @@ files:
|
|
150
165
|
- lib/smartcar/utils.rb
|
151
166
|
- lib/smartcar/vehicle.rb
|
152
167
|
- lib/smartcar/vehicle_attributes.rb
|
168
|
+
- lib/smartcar/vehicle_utils/actions.rb
|
169
|
+
- lib/smartcar/vehicle_utils/batch.rb
|
170
|
+
- lib/smartcar/vehicle_utils/data.rb
|
153
171
|
- lib/smartcar/version.rb
|
154
172
|
- lib/smartcar/vin.rb
|
155
173
|
- ruby-sdk.gemspec
|