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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b57225d3763fbbe7c577b89697ea80af48c4de44dcb39efdbb3a4811bfcfc27d
4
- data.tar.gz: 5b7915fd5b5686909ddc01a63725287ed1771efa53b48b4c5c7327a6079449e1
3
+ metadata.gz: 3848d46ccf722b908e7b42acc1afebccc24fbf1362c36bd0b0a867cd8bdd5b85
4
+ data.tar.gz: 3cfbf110c26177478a4ffad5373aeffcb73411b85f014c7af98293ea42739601
5
5
  SHA512:
6
- metadata.gz: f792bda809f5a3be1e89f775877f3ce11495b2416c8ec3d0767e8e0ed744333203a0defeb95beca33ba6f0f42d93bcaf7fd40cd6e6dc86ebcdf5fbb066487efa
7
- data.tar.gz: cd9e6ac196300057dc0e704aab9a75bb65c0475273cf60b62872c92a07d7d7975f316e5e7c7bdab3424c866af1eac710492db538cd94b29e72dfd3678fcad73f
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
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
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.0.0)
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.1.0)
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.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.0)
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
- ruby2_keywords (0.0.2)
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.2
84
+ 2.1.4
data/Rakefile CHANGED
@@ -1,6 +1,14 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
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
- task :default => :spec
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 "bundler/setup"
4
- require "smartcar"
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 "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
data/lib/smartcar.rb CHANGED
@@ -1,53 +1,83 @@
1
- require "smartcar/utils"
2
- require "smartcar/version"
3
- require "smartcar/base"
4
- require "smartcar/oauth"
5
- require "smartcar/permissions"
6
- require "smartcar/battery"
7
- require "smartcar/charge"
8
- require "smartcar/engine_oil"
9
- require "smartcar/fuel"
10
- require "smartcar/location"
11
- require "smartcar/odometer"
12
- require "smartcar/tire_pressure"
13
- require "smartcar/vin"
14
- require "smartcar/vehicle_attributes"
15
- require "smartcar/vehicle"
16
- require "smartcar/user"
17
-
18
-
19
- # Main Smartcar umbrella module
20
- module Smartcar
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
- # Smartcar API version being used
32
- API_VERSION = "v1.0".freeze
40
+
33
41
  # Host to connect to smartcar
34
- SITE = "https://api.smartcar.com/".freeze
42
+ SITE = 'https://api.smartcar.com/'
35
43
 
36
44
  # Path for smartcar oauth
37
- OAUTH_PATH = "https://connect.smartcar.com/oauth/authorize".freeze
38
- %w(success code test live force auto metric imperial).each do |constant|
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 = "LOCK".freeze
52
+ LOCK = 'LOCK'
45
53
  # Unlock value sent in request body
46
- UNLOCK = "UNLOCK".freeze
54
+ UNLOCK = 'UNLOCK'
47
55
  # Start charge value sent in request body
48
- START_CHARGE = "START".freeze
56
+ START_CHARGE = 'START'
49
57
  # Stop charge value sent in request body
50
- STOP_CHARGE = "STOP".freeze
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'.freeze
14
+ BEARER = 'BEARER'
13
15
  # Constant for Basic auth type
14
- BASIC = 'BASIC'.freeze
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{get post patch put delete}.each do |verb|
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 #{get_basic_auth}" if data[:auth] == BASIC
30
- request.headers['sc-unit-system'] = unit_system
31
- request.headers['Content-Type'] = "application/json"
32
- complete_path = "/#{API_VERSION}#{path}"
33
- if verb==:get
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: , options: {}, auth: 'BEARER')
53
- _path = path
54
- _path += "?#{URI.encode_www_form(options)}" unless options.empty?
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 get_basic_auth
65
+ def generate_basic_auth
64
66
  Base64.strict_encode64("#{get_config('CLIENT_ID')}:#{get_config('CLIENT_SECRET')}")
65
67
  end
66
68
 
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Smartcar
2
4
  # class to represent Battery info
3
- #@attr [Number] percentRemaining Decimal value representing the remaining charge percent.
4
- #@attr [Number] range Remaining range of the vehicle.
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 = Proc.new{|id| "/vehicles/#{id}/battery"}
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
- alias_method :percentage_remaining, :percentRemaining
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
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Smartcar
2
4
  # class to represent Charge info
3
- #@attr [Boolean] isPluggedIn Specifies if the vehicle is plugged in.
4
- #@attr [String] state Charging state of the vehicle.
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 = Proc.new{|id| "/vehicles/#{id}/charge"}
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
- alias_method :is_plugged_in?, :isPluggedIn
13
+ alias is_plugged_in? isPluggedIn
12
14
  end
13
15
  end
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Smartcar
2
4
  # class to represent Engine oil info
3
- #@attr [Number] lifeRemaining Remaining life of the engine oil
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 = Proc.new{|id| "/vehicles/#{id}/engine/oil"}
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
- alias_method :life_remaining, :lifeRemaining
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
- #@attr [Number] amountRemaining Amount of fuel remaining.
4
- #@attr [Number] percentageRemaining Decimal value representing the remaining fuel percent.
5
- #@attr [Number] range Remaining range of the vehicle.
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 = Proc.new{|id| "/vehicles/#{id}/fuel"}
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
- alias_method :amount_remaining, :amountRemaining
13
- alias_method :percent_remaining, :percentRemaining
14
+ alias amount_remaining amountRemaining
15
+ alias percent_remaining percentRemaining
14
16
  end
15
17
  end