smartcar 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +24 -3
- data/CODE_OF_CONDUCT.md +1 -1
- data/Gemfile.lock +3 -3
- data/README.md +11 -1
- data/lib/smartcar/oauth.rb +79 -71
- data/lib/smartcar/version.rb +1 -1
- data/ruby-sdk.gemspec +4 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6edb5e52f0934476c62ad8dd9c8851c4e65e8e2b38023b54ccf1d9b584ad75b1
|
4
|
+
data.tar.gz: 7dcf139e66ede5b2ab77b3c2c90ef5645776bcedcb72537402326da6d3be6eb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47a1bbb0152d2ab79e2e15f85094d28bacdea30e9f18003ae0e2b2e25f3f7475885e94eced22b568536ae043bb3f1c3f8cdf13e1cc9a29cb777f6420ad2f2964
|
7
|
+
data.tar.gz: 928aa7165e2af3a3a1c0a2402c7ea0f57467aa1cd2b3aaa7ff5aa2acf5662603c07eebe7e96121b0e432f81002147785b0cfbc3775ead59da9cbbfc6efc97634
|
data/.travis.yml
CHANGED
@@ -1,7 +1,28 @@
|
|
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
|
-
|
7
|
-
|
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
|
+
on:
|
25
|
+
tags: true
|
26
|
+
branch: master
|
27
|
+
rvm: 2.5
|
28
|
+
skip_cleanup: 'true'
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -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
|
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.
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
smartcar (1.0.
|
4
|
+
smartcar (1.0.3)
|
5
5
|
oauth2 (~> 1.4)
|
6
6
|
|
7
7
|
GEM
|
@@ -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.
|
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
@@ -123,8 +123,18 @@ 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
|
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 create a git tag for the version, push git commits and tags. When merging to master if it finds the tag it will deploy to rubygems automatically
|
127
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
|
+
```
|
128
138
|
## Contributing
|
129
139
|
|
130
140
|
To contribute, please:
|
data/lib/smartcar/oauth.rb
CHANGED
@@ -1,83 +1,91 @@
|
|
1
1
|
module Smartcar
|
2
|
-
# Oauth class to take care of the Oauth 2.0 with
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
+
#
|
31
|
+
# @return [Smartcar::Oauth] Returns a Smartcar::Oauth Object that has other methods
|
32
|
+
def initialize(options)
|
33
|
+
@redirect_uri = options[:redirect_uri] || get_config('REDIRECT_URI')
|
34
|
+
@client_id = options[:client_id] || get_config('CLIENT_ID')
|
35
|
+
@client_secret = options[:client_secret] || get_config('CLIENT_SECRET')
|
43
36
|
|
44
|
-
|
37
|
+
@auth_parameters = {
|
38
|
+
redirect_uri: @redirect_uri,
|
39
|
+
approval_prompt: options[:force_prompt] ? FORCE : AUTO,
|
40
|
+
mode: options[:test_mode] ? TEST : LIVE,
|
41
|
+
response_type: CODE
|
42
|
+
}
|
43
|
+
@auth_parameters[:scope] = options[:scope].join(' ') if options[:scope]
|
44
|
+
%I(state make).each do |parameter|
|
45
|
+
parameters[:parameter] = options[:parameter] unless options[:parameter].nil?
|
45
46
|
end
|
47
|
+
end
|
46
48
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
client.auth_code
|
54
|
-
.get_token(
|
55
|
-
auth_code,
|
56
|
-
redirect_uri: get_config('REDIRECT_URI')
|
57
|
-
).to_hash
|
58
|
-
end
|
49
|
+
# Generate the OAuth authorization URL.
|
50
|
+
#
|
51
|
+
# @return [String] Authorization URL string
|
52
|
+
def authorization_url
|
53
|
+
client.auth_code.authorize_url(@auth_parameters)
|
54
|
+
end
|
59
55
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
56
|
+
# Generates the tokens hash using the code returned in oauth process.
|
57
|
+
# @param auth_code [String] This is the code that is returned after user
|
58
|
+
# visits and authorizes on the authorization URL.
|
59
|
+
#
|
60
|
+
# @return [Hash] Hash of token, refresh token, expiry info and token type
|
61
|
+
def get_token(auth_code)
|
62
|
+
client.auth_code
|
63
|
+
.get_token(
|
64
|
+
auth_code,
|
65
|
+
redirect_uri: @redirect_uri
|
66
|
+
).to_hash
|
67
|
+
end
|
70
68
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
69
|
+
# Refreshing the access token
|
70
|
+
# @param token_hash [Hash] This is the hash that is returned with the
|
71
|
+
# get_token method
|
72
|
+
#
|
73
|
+
# @return [Hash] Hash of token, refresh token, expiry info and token type
|
74
|
+
def refresh_token(token_hash)
|
75
|
+
token_object = OAuth2::AccessToken.from_hash(client, token_hash)
|
76
|
+
token_object = token_object.refresh!
|
77
|
+
token_object.to_hash
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
# gets the Oauth Client object
|
82
|
+
#
|
83
|
+
# @return [OAuth2::Client] A Oauth Client object.
|
84
|
+
def client
|
85
|
+
@client ||= OAuth2::Client.new( @client_id,
|
86
|
+
@client_secret,
|
87
|
+
:site => OAUTH_PATH
|
88
|
+
)
|
81
89
|
end
|
82
90
|
end
|
83
91
|
end
|
data/lib/smartcar/version.rb
CHANGED
data/ruby-sdk.gemspec
CHANGED
@@ -12,7 +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 = {
|
15
|
+
spec.metadata = {
|
16
|
+
"source_code_uri" => "https://github.com/smartcar/ruby-sdk",
|
17
|
+
"documentation_uri" => "https://www.rubydoc.info/gems/smartcar",
|
18
|
+
}
|
16
19
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
17
20
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
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.
|
4
|
+
version: 1.0.3
|
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-
|
11
|
+
date: 2020-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -157,6 +157,7 @@ licenses:
|
|
157
157
|
- MIT
|
158
158
|
metadata:
|
159
159
|
source_code_uri: https://github.com/smartcar/ruby-sdk
|
160
|
+
documentation_uri: https://www.rubydoc.info/gems/smartcar
|
160
161
|
post_install_message:
|
161
162
|
rdoc_options: []
|
162
163
|
require_paths:
|
@@ -172,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
173
|
- !ruby/object:Gem::Version
|
173
174
|
version: '0'
|
174
175
|
requirements: []
|
175
|
-
rubygems_version: 3.
|
176
|
+
rubygems_version: 3.1.2
|
176
177
|
signing_key:
|
177
178
|
specification_version: 4
|
178
179
|
summary: Ruby Gem to access smartcar APIs (https://smartcar.com/docs/)
|