smartcar 1.0.0 → 1.0.7

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: 9d9a7ac2f2c91af854e62d5c52e799ac7948e2904a4997341847fd8845ffade3
4
- data.tar.gz: 23557ce0dbd44d4df30eae96c1ad12557ebd4514e839e3ff59e16cbc120102e4
3
+ metadata.gz: 20f8c410ca2e09b81f481f66f8790b9040688dec92973825d7a7ba72cec14a7d
4
+ data.tar.gz: 5c748df1b3c987a00df29e1f7f65ae8c89c76ad7473acfc8135c27ddad94fe15
5
5
  SHA512:
6
- metadata.gz: 4592facfcef32121f865d424bf57ac42e9954150d652f1b1183bea553df60f1d5e569e4bc2933cc5e188b26655f65fd1395e457ebad440a2bc5488d3b1a629d3
7
- data.tar.gz: 0ca054815ce5849735181bf513ff52bd8df81bc2732e185281b2257dd6ec0a879222187f95cfea410e7113406ff62fda4a87835f05a2991f46931df1cc4bcd65
6
+ metadata.gz: 4bdbd39d8887437f76f53ccea2cdc8f6ae618d5a13558713c44b74ca21ab01fbe960b8d8b66104ace8df1a4c3de2d8a2308e3fe6ec000c9a80b721abda0fca09
7
+ data.tar.gz: 71f27cea632e1578e878f9bb6c7caa921890236515facc7435f6b17aa2faa1c198c8e7bfd4064fd90ec37ee2533d31aae362b1f0c13ce867b43380d3add3fcbc
@@ -1,7 +1,29 @@
1
- ---
2
1
  sudo: false
3
2
  language: ruby
4
3
  cache: bundler
4
+ services:
5
+ - xvfb
6
+ addons:
7
+ firefox: latest
5
8
  rvm:
6
- - 2.5.5
7
- before_install: gem install bundler -v 2.0.2
9
+ - 2.5
10
+ - 2.6
11
+ - 2.7
12
+ before_install:
13
+ - gem install bundler -v 2.1.2
14
+ - wget https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz
15
+ - mkdir geckodriver
16
+ - tar -xzf geckodriver-v0.26.0-linux64.tar.gz -C geckodriver
17
+ - export PATH=$PATH:$PWD/geckodriver
18
+ # install:
19
+ # - firefox -headless &
20
+ deploy:
21
+ provider: rubygems
22
+ api_key: $RUBYGEMSAPI_KEY
23
+ gem: smartcar
24
+ gemspec: ruby-sdk.gemspec
25
+ on:
26
+ tags: true
27
+ branch: master
28
+ rvm: 2.5
29
+ skip_cleanup: 'true'
@@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
55
55
  ## Enforcement
56
56
 
57
57
  Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at Ashwin.Subramanian@ooma.com. All
58
+ reported by contacting the project team at support@smartcar.com. All
59
59
  complaints will be reviewed and investigated and will result in a response that
60
60
  is deemed necessary and appropriate to the circumstances. The project team is
61
61
  obligated to maintain confidentiality with regard to the reporter of an incident.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smartcar (1.0.0)
4
+ smartcar (1.0.7)
5
5
  oauth2 (~> 1.4)
6
6
 
7
7
  GEM
@@ -12,8 +12,8 @@ GEM
12
12
  diff-lcs (1.3)
13
13
  faraday (1.0.1)
14
14
  multipart-post (>= 1.2, < 3)
15
- jwt (2.2.1)
16
- multi_json (1.14.1)
15
+ jwt (2.2.2)
16
+ multi_json (1.15.0)
17
17
  multi_xml (0.6.0)
18
18
  multipart-post (2.1.1)
19
19
  oauth2 (1.4.4)
@@ -22,7 +22,7 @@ GEM
22
22
  multi_json (~> 1.3)
23
23
  multi_xml (~> 0.5)
24
24
  rack (>= 1.2, < 3)
25
- rack (2.2.2)
25
+ rack (2.2.3)
26
26
  rake (12.3.3)
27
27
  redcarpet (3.5.0)
28
28
  rspec (3.9.0)
@@ -50,7 +50,7 @@ DEPENDENCIES
50
50
  bundler (~> 2.0)
51
51
  byebug (~> 11.0)
52
52
  rake (~> 12.3, >= 12.3.3)
53
- redcarpet
53
+ redcarpet (~> 3.5.0)
54
54
  rspec (~> 3.0)
55
55
  selenium-webdriver (~> 3.142)
56
56
  smartcar!
data/README.md CHANGED
@@ -107,10 +107,10 @@ Smartcar::ExternalServiceError (API error - {"error":"vehicle_state_error","mess
107
107
  Example Usage for oAuth -
108
108
  ```ruby
109
109
  # To get the redirect URL :
110
- 2.5.5 :002 > options = {test_mode: true,scope: ["read_battery","read_charge","read_fuel","read_location","control_security","read_odometer","read_tires","read_vin","read_vehicle_info"]}
110
+ 2.5.5 :002 > options = {test_mode: true,scope: ["read_battery","read_charge","read_fuel","read_location","control_security","read_odometer","read_tires","read_vin","read_vehicle_info"],flags: ["country:DE"]}
111
111
  2.5.5 :003 > require 'smartcar'
112
112
  2.5.5 :004 > url = Smartcar::Oauth.authorization_url(options)
113
- => "https://connect.smartcar.com/oauth/authorize?approval_prompt=auto&client_id=2715c6b2-eba8-4fda-85b1-8d849733a344&mode=test&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fcallback&response_type=code&scope=read_battery+read_charge+read_fuel+read_location+control_security+read_odometer+read_tires+read_vin+read_vehicle_info"
113
+ => "https://connect.smartcar.com/oauth/authorize?approval_prompt=auto&client_id=2715c6b2-eba8-4fda-85b1-8d849733a344&mode=test&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fcallback&response_type=code&scope=read_battery+read_charge+read_fuel+read_location+control_security+read_odometer+read_tires+read_vin+read_vehicle_info&flags=country%3ADE"
114
114
  # Redirect user to the above URL.
115
115
  # After authentication user control reaches the callback URL with code.
116
116
  # Use the code from the parameters and request a token
@@ -123,7 +123,32 @@ Example Usage for oAuth -
123
123
 
124
124
  ## Development
125
125
 
126
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
126
+ To install this gem onto your local machine, run `bundle exec rake install`.
127
+
128
+ To run tests, make sure you have the env variables setup for client id and secret.
129
+ ```shell
130
+ export INTEGRATION_CLIENT_ID=<client id>
131
+ export INTEGRATION_CLIENT_SECRET=<client secret>
132
+ ```
133
+
134
+ Tests can be run using either default rake command OR specific rspec command.
135
+ ```ruby
136
+ bundle exec rake spec
137
+ ```
138
+
139
+ Releasing to rubygems right now cannot be automated because of MFA ([source](https://github.com/rubygems/rubygems/issues/3092)). For now the process is to run the gem build and push commands locally and manually enter in the Rubygems MFA code (available on 1password). Steps for that would be :
140
+
141
+ ```
142
+ # After merging to master, checkout to master and pull code locally, then run the following
143
+ gem build
144
+ Successfully built RubyGem
145
+ Name: smartcar
146
+ Version: <version>
147
+ File: smartcar-<version>.gem
148
+ # now push the gem built by the build command. This would ask for the MFA code
149
+ gem push smartcar-<version>.gem
150
+ ```
151
+ In general it is a good advice to create a tag for every release. If not for the above mentioned MFA bug, creating a tag for a commit on master and pushing the tag would trigger travis to deploy to rubygems automatically.
127
152
 
128
153
  ## Contributing
129
154
 
@@ -11,6 +11,7 @@ require "smartcar/location"
11
11
  require "smartcar/odometer"
12
12
  require "smartcar/tire_pressure"
13
13
  require "smartcar/vin"
14
+ require "smartcar/vehicle_attributes"
14
15
  require "smartcar/vehicle"
15
16
  require "smartcar/user"
16
17
 
@@ -12,6 +12,8 @@ module Smartcar
12
12
  BEARER = 'BEARER'.freeze
13
13
  # Constant for Basic auth type
14
14
  BASIC = 'BASIC'.freeze
15
+ # Number of seconds to wait for response
16
+ REQUEST_TIMEOUT = 310
15
17
 
16
18
  attr_accessor :token, :error, :meta
17
19
 
@@ -66,7 +68,7 @@ module Smartcar
66
68
  #
67
69
  # @return [OAuth2::AccessToken] An initialized AccessToken instance that acts as service client
68
70
  def service
69
- @service ||= Faraday.new(url: SITE)
71
+ @service ||= Faraday.new(url: SITE, request: { timeout: REQUEST_TIMEOUT })
70
72
  end
71
73
  end
72
74
  end
@@ -1,83 +1,95 @@
1
1
  module Smartcar
2
- # Oauth class to take care of the Oauth 2.0 with genomelink APIs
2
+ # Oauth class to take care of the Oauth 2.0 with Smartcar APIs
3
3
  #
4
4
  class Oauth < Base
5
5
  extend Utils
6
- class << self
7
- # Generate the OAuth authorization URL.
8
- #
9
- # By default users are not shown the permission dialog if they have already
10
- # approved the set of scopes for this application. The application can elect
11
- # to always display the permissions dialog to the user by setting
12
- # approval_prompt to `force`.
13
- #
14
- # @param options [Hash]
15
- # @option options[:state] [String] - OAuth state parameter passed to the
16
- # redirect uri. This parameter may be used for identifying the user who
17
- # initiated the request.
18
- # @option options[:test_mode] [Boolean] - Setting this to 'true' runs it in test mode.
19
- # @option options[:force_prompt] [Boolean] - Setting `force_prompt` to
20
- # `true` will show the permissions approval screen on every authentication
21
- # attempt, even if the user has previously consented to the exact scope of
22
- # permissions.
23
- # @option options[:make] [String] - `make' is an optional parameter that allows
24
- # users to bypass the car brand selection screen.
25
- # For a complete list of supported makes, please see our
26
- # [API Reference](https://smartcar.com/docs/api#authorization) documentation.
27
- # @option options[:scope] [Array of Strings] - array of scopes that specify what the user can access
28
- # EXAMPLE : ['read_odometer', 'read_vehicle_info', 'required:read_location']
29
- # For further details refer to https://smartcar.com/docs/guides/scope/
30
- #
31
- # @return [String] URL where user needs to be redirected for authorization
32
- def authorization_url(options)
33
- parameters = {
34
- redirect_uri: get_config('REDIRECT_URI'),
35
- approval_prompt: options[:force_prompt] ? FORCE : AUTO,
36
- mode: options[:test_mode] ? TEST : LIVE,
37
- response_type: CODE
38
- }
39
- parameters[:scope] = options[:scope].join(' ') if options[:scope]
40
- %I(state make).each do |parameter|
41
- parameters[:parameter] = options[:parameter] unless options[:parameter].nil?
42
- end
6
+ # By default users are not shown the permission dialog if they have already
7
+ # approved the set of scopes for this application. The application can elect
8
+ # to always display the permissions dialog to the user by setting
9
+ # approval_prompt to `force`.
10
+ #
11
+ # @param options [Hash]
12
+ # @option options[:client_id] [String] - Client ID, if not passed fallsback to ENV['CLIENT_ID']
13
+ # @option options[:client_secret] [String] - Client Secret, if not passed fallsback to ENV['CLIENT_SECRET']
14
+ # @option options[:redirect_uri] [String] - Redirect URI, if not passed fallsback to ENV['REDIRECT_URI']
15
+ # @option options[:state] [String] - OAuth state parameter passed to the
16
+ # redirect uri. This parameter may be used for identifying the user who
17
+ # initiated the request.
18
+ # @option options[:test_mode] [Boolean] - Setting this to 'true' runs it in test mode.
19
+ # @option options[:force_prompt] [Boolean] - Setting `force_prompt` to
20
+ # `true` will show the permissions approval screen on every authentication
21
+ # attempt, even if the user has previously consented to the exact scope of
22
+ # permissions.
23
+ # @option options[:make] [String] - `make' is an optional parameter that allows
24
+ # users to bypass the car brand selection screen.
25
+ # For a complete list of supported makes, please see our
26
+ # [API Reference](https://smartcar.com/docs/api#authorization) documentation.
27
+ # @option options[:scope] [Array of Strings] - array of scopes that specify what the user can access
28
+ # EXAMPLE : ['read_odometer', 'read_vehicle_info', 'required:read_location']
29
+ # For further details refer to https://smartcar.com/docs/guides/scope/
30
+ # @option options[:flags] [Array of Strings] - an optional array of early access features to enable.
31
+ #
32
+ # @return [Smartcar::Oauth] Returns a Smartcar::Oauth Object that has other methods
33
+ def initialize(options)
34
+ @redirect_uri = options[:redirect_uri] || get_config('REDIRECT_URI')
35
+ @client_id = options[:client_id] || get_config('CLIENT_ID')
36
+ @client_secret = options[:client_secret] || get_config('CLIENT_SECRET')
43
37
 
44
- client.auth_code.authorize_url(parameters)
38
+ @auth_parameters = {
39
+ redirect_uri: @redirect_uri,
40
+ approval_prompt: options[:force_prompt] ? FORCE : AUTO,
41
+ mode: options[:test_mode] ? TEST : LIVE,
42
+ response_type: CODE
43
+ }
44
+
45
+ %I(scope flags).each do |parameter|
46
+ @auth_parameters[parameter] = options[parameter].join(' ') unless options[parameter].nil?
45
47
  end
46
-
47
- # [get_token description]
48
- # @param auth_code [String] This is the code that is returned after use r
49
- # visits and authorizes on the authorization URL.
50
- #
51
- # @return [Hash] Hash of token, refresh token, expiry info and token type
52
- def get_token(auth_code)
53
- client.auth_code
54
- .get_token(
55
- auth_code,
56
- redirect_uri: get_config('REDIRECT_URI')
57
- ).to_hash
48
+ %I(state make).each do |parameter|
49
+ @auth_parameters[parameter] = options[parameter] unless options[parameter].nil?
58
50
  end
51
+ end
59
52
 
60
- # [refresh_token description]
61
- # @param token_hash [Hash] This is the hash that is returned with the
62
- # get_token method
63
- #
64
- # @return [Hash] Hash of token, refresh token, expiry info and token type
65
- def refresh_token(token_hash)
66
- token_object = OAuth2::AccessToken.from_hash(client, token_hash)
67
- token_object = token_object.refresh!
68
- token_object.to_hash
69
- end
53
+ # Generate the OAuth authorization URL.
54
+ #
55
+ # @return [String] Authorization URL string
56
+ def authorization_url
57
+ client.auth_code.authorize_url(@auth_parameters)
58
+ end
70
59
 
71
- private
72
- # gets the Oauth Client object
73
- #
74
- # @return [OAuth2::Client] A Oauth Client object.
75
- def client
76
- @client ||= OAuth2::Client.new( get_config('CLIENT_ID'),
77
- get_config('CLIENT_SECRET'),
78
- :site => OAUTH_PATH
79
- )
80
- end
60
+ # Generates the tokens hash using the code returned in oauth process.
61
+ # @param auth_code [String] This is the code that is returned after user
62
+ # visits and authorizes on the authorization URL.
63
+ #
64
+ # @return [Hash] Hash of token, refresh token, expiry info and token type
65
+ def get_token(auth_code)
66
+ client.auth_code
67
+ .get_token(
68
+ auth_code,
69
+ redirect_uri: @redirect_uri
70
+ ).to_hash
71
+ end
72
+
73
+ # Refreshing the access token
74
+ # @param token_hash [Hash] This is the hash that is returned with the
75
+ # get_token method
76
+ #
77
+ # @return [Hash] Hash of token, refresh token, expiry info and token type
78
+ def refresh_token(token_hash)
79
+ token_object = OAuth2::AccessToken.from_hash(client, token_hash)
80
+ token_object = token_object.refresh!
81
+ token_object.to_hash
82
+ end
83
+
84
+ private
85
+ # gets the Oauth Client object
86
+ #
87
+ # @return [OAuth2::Client] A Oauth Client object.
88
+ def client
89
+ @client ||= OAuth2::Client.new( @client_id,
90
+ @client_secret,
91
+ :site => OAUTH_PATH
92
+ )
81
93
  end
82
94
  end
83
95
  end
@@ -47,16 +47,20 @@ module Smartcar
47
47
  # API - https://smartcar.com/docs/api#connect-compatibility
48
48
  # @param vin [String] VIN of the vehicle to be checked
49
49
  # @param scope [Array of Strings] - array of scopes
50
+ # @param country [String] An optional country code according to
51
+ # [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).
52
+ # Defaults to US.
50
53
  #
51
54
  # @return [Boolean] true or false
52
- def self.compatible?(vin:, scope:)
55
+ def self.compatible?(vin:, scope:, country: 'US')
53
56
  raise InvalidParameterValue.new, "vin is a required field" if vin.nil?
54
57
  raise InvalidParameterValue.new, "scope is a required field" if scope.nil?
55
58
 
56
59
  response, meta = new(token: 'none', id: 'none').fetch(path: COMPATIBLITY_PATH,
57
60
  options: {
58
61
  vin: vin,
59
- scope: scope.join(' ')
62
+ scope: scope.join(' '),
63
+ country: country
60
64
  },
61
65
  auth: BASIC
62
66
  )
@@ -1,4 +1,4 @@
1
1
  module Smartcar
2
2
  # Gem current version number
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.7"
4
4
  end
@@ -12,6 +12,10 @@ Gem::Specification.new do |spec|
12
12
  spec.summary = %q{Ruby Gem to access smartcar APIs (https://smartcar.com/docs/)}
13
13
  spec.description = %q{This is a ruby gem to access the smartcar APIs. It includes the API classes and the OAuth system.}
14
14
  spec.license = "MIT"
15
+ spec.metadata = {
16
+ "source_code_uri" => "https://github.com/smartcar/ruby-sdk",
17
+ "documentation_uri" => "https://www.rubydoc.info/gems/smartcar",
18
+ }
15
19
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
16
20
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
21
  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: 1.0.0
4
+ version: 1.0.7
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-06-12 00:00:00.000000000 Z
11
+ date: 2020-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -155,7 +155,9 @@ files:
155
155
  homepage: https://rubygems.org/gems/smartcar
156
156
  licenses:
157
157
  - MIT
158
- metadata: {}
158
+ metadata:
159
+ source_code_uri: https://github.com/smartcar/ruby-sdk
160
+ documentation_uri: https://www.rubydoc.info/gems/smartcar
159
161
  post_install_message:
160
162
  rdoc_options: []
161
163
  require_paths:
@@ -171,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
173
  - !ruby/object:Gem::Version
172
174
  version: '0'
173
175
  requirements: []
174
- rubygems_version: 3.0.6
176
+ rubygems_version: 3.0.8
175
177
  signing_key:
176
178
  specification_version: 4
177
179
  summary: Ruby Gem to access smartcar APIs (https://smartcar.com/docs/)