smartcar 0.0.0 → 1.0.3

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
- SHA1:
3
- metadata.gz: 8fd8a3a8c8239d87ed360d17d3683525c64c0662
4
- data.tar.gz: f72f37a1d07b31bcec3d14691b9f4b5f466f6963
2
+ SHA256:
3
+ metadata.gz: 6edb5e52f0934476c62ad8dd9c8851c4e65e8e2b38023b54ccf1d9b584ad75b1
4
+ data.tar.gz: 7dcf139e66ede5b2ab77b3c2c90ef5645776bcedcb72537402326da6d3be6eb8
5
5
  SHA512:
6
- metadata.gz: d3e8b86b26a86136e2f9644f011aff83d25f22193e1cc8d9cb39192d2c663b07524ebbc11feafb0559e4b5465ee94be59185f9d76debc8ca3d6b95b02601fdab
7
- data.tar.gz: 2a1257fe53d9635d82b80ddcc1722308969cd6b1b89fd161d7d0627eca5d49cb6d31182d323375b887e29d52fb27635f51740ff4e22eb9d001825bd282ef07d6
6
+ metadata.gz: 47a1bbb0152d2ab79e2e15f85094d28bacdea30e9f18003ae0e2b2e25f3f7475885e94eced22b568536ae043bb3f1c3f8cdf13e1cc9a29cb777f6420ad2f2964
7
+ data.tar.gz: 928aa7165e2af3a3a1c0a2402c7ea0f57467aa1cd2b3aaa7ff5aa2acf5662603c07eebe7e96121b0e432f81002147785b0cfbc3775ead59da9cbbfc6efc97634
@@ -0,0 +1,20 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ # byebug files
14
+ .byebug*
15
+
16
+ # ctags
17
+ .tags*
18
+
19
+ #idea files
20
+ .idea
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,28 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ services:
5
+ - xvfb
6
+ addons:
7
+ firefox: latest
8
+ rvm:
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'
@@ -0,0 +1,2 @@
1
+ --markup=markdown
2
+ --no-private
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at support@smartcar.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in smartcar.gemspec
6
+ gemspec
@@ -0,0 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ smartcar (1.0.3)
5
+ oauth2 (~> 1.4)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ byebug (11.1.3)
11
+ childprocess (3.0.0)
12
+ diff-lcs (1.3)
13
+ faraday (1.0.1)
14
+ multipart-post (>= 1.2, < 3)
15
+ jwt (2.2.1)
16
+ multi_json (1.14.1)
17
+ multi_xml (0.6.0)
18
+ multipart-post (2.1.1)
19
+ oauth2 (1.4.4)
20
+ faraday (>= 0.8, < 2.0)
21
+ jwt (>= 1.0, < 3.0)
22
+ multi_json (~> 1.3)
23
+ multi_xml (~> 0.5)
24
+ rack (>= 1.2, < 3)
25
+ rack (2.2.3)
26
+ rake (12.3.3)
27
+ redcarpet (3.5.0)
28
+ rspec (3.9.0)
29
+ rspec-core (~> 3.9.0)
30
+ rspec-expectations (~> 3.9.0)
31
+ rspec-mocks (~> 3.9.0)
32
+ rspec-core (3.9.2)
33
+ rspec-support (~> 3.9.3)
34
+ rspec-expectations (3.9.2)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.9.0)
37
+ rspec-mocks (3.9.1)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.9.0)
40
+ rspec-support (3.9.3)
41
+ rubyzip (2.3.0)
42
+ selenium-webdriver (3.142.7)
43
+ childprocess (>= 0.5, < 4.0)
44
+ rubyzip (>= 1.2.2)
45
+
46
+ PLATFORMS
47
+ ruby
48
+
49
+ DEPENDENCIES
50
+ bundler (~> 2.0)
51
+ byebug (~> 11.0)
52
+ rake (~> 12.3, >= 12.3.3)
53
+ redcarpet (~> 3.5.0)
54
+ rspec (~> 3.0)
55
+ selenium-webdriver (~> 3.142)
56
+ smartcar!
57
+
58
+ BUNDLED WITH
59
+ 2.1.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Ashwin Subramanian
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,147 @@
1
+
2
+ # Smartcar Ruby SDK [![Gem Version][gem-url]][gem-image]
3
+
4
+ Ruby gem library to quickly get started with the Smartcar API.
5
+
6
+ ## Overview
7
+
8
+ The [Smartcar API](https://smartcar.com/docs) lets you read vehicle data
9
+ (location, odometer) and send commands to vehicles (lock, unlock) using HTTP requests.
10
+
11
+ To make requests to a vehicle from a web or mobile application, the end user
12
+ must connect their vehicle using
13
+ [Smartcar Connect](https://smartcar.com/docs/api#smartcar-connect).
14
+ This flow follows the OAuth spec and will return a `code` which can be used to
15
+ obtain an access token from Smartcar.
16
+
17
+ The Smartcar Ruby Gem provides methods to:
18
+
19
+ 1. Generate the link to redirect to Connect.
20
+ 2. Make a request to Smartcar with the `code` obtained from Connect to obtain an
21
+ access and refresh token
22
+ 3. Make requests to the Smartcar API to read vehicle data and send commands to
23
+ vehicles using the access token obtained in step 2.
24
+
25
+ Before integrating with Smartcar's SDK, you'll need to register an application
26
+ in the [Smartcar Developer portal](https://developer.smartcar.com). If you do
27
+ not have access to the dashboard, please
28
+ [request access](https://smartcar.com/subscribe).
29
+
30
+ ### Flow
31
+
32
+ - Create a new `AuthClient` object with your `clientId`, `clientSecret`,
33
+ `redirectUri`, and required `scope`.
34
+ - Redirect the user to Smartcar Connect using `getAuthUrl` or one
35
+ of our frontend SDKs.
36
+ - The user will login, and then accept or deny your `scope`'s permissions.
37
+ - Handle the get request to `redirectUri`.
38
+ - If the user accepted your permissions, `req.query.code` will contain an
39
+ authorization code.
40
+ - Use `exchangeCode` with this code to obtain an access object
41
+ containing an access token (lasting 2 hours) and a refresh token
42
+ (lasting 60 days).
43
+ - Save this access object.
44
+ - If the user denied your permissions, `req.query.error` will be set
45
+ to `"access_denied"`.
46
+ - If you passed a state parameter to `getAuthUrl`, `req.query.state` will
47
+ contain the state value.
48
+ - Get the user's vehicles with `getVehicleIds`.
49
+ - Create a new `Vehicle` object using a `vehicleId` from the previous response,
50
+ and the `access_token`.
51
+ - Make requests to the Smartcar API.
52
+ - Use `exchangeRefreshToken` on your saved `refreshToken` to retrieve a new token
53
+ when your `accessToken` expires.
54
+
55
+ ## Installation
56
+
57
+ Add this line to your application's Gemfile:
58
+
59
+ ```ruby
60
+ gem 'smartcar'
61
+ ```
62
+
63
+ And then execute:
64
+
65
+ $ bundle
66
+
67
+ Or install it yourself as:
68
+
69
+ $ gem install smartcar
70
+
71
+ ## Usage
72
+
73
+ Setup the environment variables for CLIENT_ID and CLIENT_SECRET.
74
+ ```bash
75
+ # Get your API keys from https://dashboard.smartcar.com/signup
76
+ export CLIENT_ID=<client id>
77
+ export CLIENT_SECRET=<client secret>
78
+ ```
79
+
80
+ Example Usage for calling the reports API with oAuth token
81
+ ```ruby
82
+ 2.5.7 :001 > require 'smartcar'
83
+ => true
84
+ 2.5.7 :003 > ids = Smartcar::Vehicle.all_vehicle_ids(token: token)
85
+ => ["4bb777b2-bde7-4305-8952-25956f8c0868"]
86
+ 2.5.7 :004 > vehicle = Smartcar::Vehicle.new(token: token, id: ids.first)
87
+ => #<Smartcar::Vehicle:0x00005564211a7c48 @token="5ae77cb0-7c1a-486a-ac20-00c76d2fd1aa", @id="4bb777b2-bde7-4305-8952-25956f8c0868", @unit_system="imperial">
88
+ 2.5.7 :006 > vehicle.odometer
89
+ => #<Smartcar::Odometer:0x00005564211330f0 @distance=17966.94802354251, @meta={"date"=>"Fri, 12 Jun 2020 06:04:32 GMT", "content-type"=>"application/json; charset=utf-8", "content-length"=>"30", "connection"=>"keep-alive", "access-control-allow-origin"=>"*", "sc-data-age"=>"2020-06-12T06:04:28.843Z", "sc-unit-system"=>"imperial", "sc-request-id"=>"3c447e9e-4cf7-43cb-b688-fba8db3d3582"}>
90
+ 2.5.7 :007 > vehicle.battery
91
+ => #<Smartcar::Battery:0x00005564210fcb18 @range=105.63, @percentRemaining=0.98, @meta={"date"=>"Fri, 12 Jun 2020 06:04:44 GMT", "content-type"=>"application/json; charset=utf-8", "content-length"=>"40", "connection"=>"keep-alive", "access-control-allow-origin"=>"*", "sc-data-age"=>"2020-06-12T06:04:28.843Z", "sc-unit-system"=>"imperial", "sc-request-id"=>"455ed4b0-b768-4961-86d7-436ad71cf0fa"}>
92
+ 2.5.7 :009 > vehicle.lock!
93
+ => true
94
+ 2.5.7 :010 > vehicle.batch(["charge","battery"])
95
+ => {:charge=>#<Smartcar::Charge:0x000055853d1fd7c8 @state="NOT_CHARGING", @isPluggedIn=false, @meta={"sc-data-age"=>"2020-06-12T06:18:50.581Z"}>, :battery=>#<Smartcar::Battery:0x000055853d1fd638 @range=105.63, @percentRemaining=0.98, @meta={"sc-data-age"=>"2020-06-12T06:18:50.581Z", "sc-unit-system"=>"imperial"}>}
96
+ 2.5.7 :011 > vehicle.start_charge!
97
+ Traceback (most recent call last):
98
+ 5: from /usr/share/rvm/rubies/ruby-2.5.7/bin/irb:11:in `<main>'
99
+ 4: from (irb):5
100
+ 3: from /home/st-2vgpnn2/.rvm/gems/ruby-2.5.7/gems/smartcar-1.0.0/lib/smartcar/vehicle.rb:118:in `start_charge!'
101
+ 2: from /home/st-2vgpnn2/.rvm/gems/ruby-2.5.7/gems/smartcar-1.0.0/lib/smartcar/vehicle.rb:290:in `start_or_stop_charge!'
102
+ 1: from /home/st-2vgpnn2/.rvm/gems/ruby-2.5.7/gems/smartcar-1.0.0/lib/smartcar/base.rb:39:in `block (2 levels) in <class:Base>'
103
+ Smartcar::ExternalServiceError (API error - {"error":"vehicle_state_error","message":"Charging plug is not connected to the vehicle.","code":"VS_004"})
104
+
105
+ ```
106
+
107
+ Example Usage for oAuth -
108
+ ```ruby
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"]}
111
+ 2.5.5 :003 > require 'smartcar'
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"
114
+ # Redirect user to the above URL.
115
+ # After authentication user control reaches the callback URL with code.
116
+ # Use the code from the parameters and request a token
117
+ 2.5.5 :006 > token_hash = Smartcar::Oauth.get_token(code)
118
+ => {"token_type"=>"Bearer", :access_token=>"56801a5e-6a0b-4d05-a43e-52a4d5e6648f", :refresh_token=>"4f46e7e4-28c5-47b3-ba8d-7dcef73d05dd", :expires_at=>1577875279}
119
+ # This access_token can be used to call the Smartcar APIs as given above.
120
+ # Store this hash and if it expired refresh the token OR use the code again to
121
+ # get a new token or use .
122
+ ```
123
+
124
+ ## Development
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 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
+
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
+ ## Contributing
139
+
140
+ To contribute, please:
141
+
142
+ 1. Open an issue for the feature (or bug) you would like to resolve.
143
+ 2. Resolve the issue and add tests in your feature branch.
144
+ 3. Open a PR from your feature branch into `develop` that tags the issue.
145
+
146
+ [gem-image]: https://badge.fury.io/rb/smartcar
147
+ [gem-url]: https://badge.fury.io/rb/smartcar.svg
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "smartcar"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,53 @@
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
21
+ # Error raised when a config is not found
22
+ class ConfigNotFound < StandardError; end
23
+ # Error raised when Smartcar returns non 400, 404, 401, 200 or 204 response
24
+ class ExternalServiceError < StandardError; end
25
+ # Error raised when Smartcar returns 404
26
+ class ServiceUnavailableError < ExternalServiceError; end
27
+ # Error raised when Smartcar returns Authentication Error with status 401
28
+ class AuthenticationError < ExternalServiceError; end
29
+ # Error raised when Smartcar returns 400 response
30
+ class BadRequestError < ExternalServiceError; end
31
+ # Smartcar API version being used
32
+ API_VERSION = "v1.0".freeze
33
+ # Host to connect to smartcar
34
+ SITE = "https://api.smartcar.com/".freeze
35
+
36
+ # 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|
39
+ # Constant to represent the value
40
+ const_set(constant.upcase, constant.freeze)
41
+ end
42
+
43
+ # Lock value sent in request body
44
+ LOCK = "LOCK".freeze
45
+ # Unlock value sent in request body
46
+ UNLOCK = "UNLOCK".freeze
47
+ # Start charge value sent in request body
48
+ START_CHARGE = "START".freeze
49
+ # Stop charge value sent in request body
50
+ STOP_CHARGE = "STOP".freeze
51
+ # Constant for units
52
+ UNITS = [IMPERIAL,METRIC]
53
+ end