smartcar 1.0.1 → 1.0.8
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/.travis.yml +25 -3
 - data/CODE_OF_CONDUCT.md +1 -1
 - data/Gemfile.lock +8 -6
 - data/README.md +35 -6
 - data/lib/smartcar.rb +1 -0
 - data/lib/smartcar/base.rb +3 -1
 - data/lib/smartcar/oauth.rb +83 -71
 - data/lib/smartcar/vehicle.rb +7 -3
 - 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: a3f5f753c2493733b16502aa5d2cbd3957ed073a1caf9dbcd032241febbe75b7
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 2f639abde820c99a2ea91a80518dd95ffba94dbfc1915dd5ddb53578189fdb5e
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 2abac7e475acd840ba72e98367857abed3ea53c1df739179cbaf1a9c6751542bdfc3871cd8f1fc908a428fa603839f68ec0a82c13f0bf9f985f462ee3bf32fa5
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: e7352fd756b8c969eb50450e6fa7024e4196e86511b9630afe1db0ba46cdf8d6ca71d342402b2e891bfcfe0ec6d88ba70a1f17dcf7ac3481ea169d12106ad5cc
         
     | 
    
        data/.travis.yml
    CHANGED
    
    | 
         @@ -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 
     | 
    
         
            -
             
     | 
| 
       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 
     | 
    
         
            +
              gemspec: ruby-sdk.gemspec
         
     | 
| 
      
 25 
     | 
    
         
            +
              on:
         
     | 
| 
      
 26 
     | 
    
         
            +
                tags: true
         
     | 
| 
      
 27 
     | 
    
         
            +
                branch: master
         
     | 
| 
      
 28 
     | 
    
         
            +
                rvm: 2.5
         
     | 
| 
      
 29 
     | 
    
         
            +
              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.8)
         
     | 
| 
       5 
5 
     | 
    
         
             
                  oauth2 (~> 1.4)
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
            GEM
         
     | 
| 
         @@ -10,10 +10,11 @@ GEM 
     | 
|
| 
       10 
10 
     | 
    
         
             
                byebug (11.1.3)
         
     | 
| 
       11 
11 
     | 
    
         
             
                childprocess (3.0.0)
         
     | 
| 
       12 
12 
     | 
    
         
             
                diff-lcs (1.3)
         
     | 
| 
       13 
     | 
    
         
            -
                faraday (1.0 
     | 
| 
      
 13 
     | 
    
         
            +
                faraday (1.1.0)
         
     | 
| 
       14 
14 
     | 
    
         
             
                  multipart-post (>= 1.2, < 3)
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
                 
     | 
| 
      
 15 
     | 
    
         
            +
                  ruby2_keywords
         
     | 
| 
      
 16 
     | 
    
         
            +
                jwt (2.2.2)
         
     | 
| 
      
 17 
     | 
    
         
            +
                multi_json (1.15.0)
         
     | 
| 
       17 
18 
     | 
    
         
             
                multi_xml (0.6.0)
         
     | 
| 
       18 
19 
     | 
    
         
             
                multipart-post (2.1.1)
         
     | 
| 
       19 
20 
     | 
    
         
             
                oauth2 (1.4.4)
         
     | 
| 
         @@ -22,7 +23,7 @@ GEM 
     | 
|
| 
       22 
23 
     | 
    
         
             
                  multi_json (~> 1.3)
         
     | 
| 
       23 
24 
     | 
    
         
             
                  multi_xml (~> 0.5)
         
     | 
| 
       24 
25 
     | 
    
         
             
                  rack (>= 1.2, < 3)
         
     | 
| 
       25 
     | 
    
         
            -
                rack (2.2. 
     | 
| 
      
 26 
     | 
    
         
            +
                rack (2.2.3)
         
     | 
| 
       26 
27 
     | 
    
         
             
                rake (12.3.3)
         
     | 
| 
       27 
28 
     | 
    
         
             
                redcarpet (3.5.0)
         
     | 
| 
       28 
29 
     | 
    
         
             
                rspec (3.9.0)
         
     | 
| 
         @@ -38,6 +39,7 @@ GEM 
     | 
|
| 
       38 
39 
     | 
    
         
             
                  diff-lcs (>= 1.2.0, < 2.0)
         
     | 
| 
       39 
40 
     | 
    
         
             
                  rspec-support (~> 3.9.0)
         
     | 
| 
       40 
41 
     | 
    
         
             
                rspec-support (3.9.3)
         
     | 
| 
      
 42 
     | 
    
         
            +
                ruby2_keywords (0.0.2)
         
     | 
| 
       41 
43 
     | 
    
         
             
                rubyzip (2.3.0)
         
     | 
| 
       42 
44 
     | 
    
         
             
                selenium-webdriver (3.142.7)
         
     | 
| 
       43 
45 
     | 
    
         
             
                  childprocess (>= 0.5, < 4.0)
         
     | 
| 
         @@ -50,7 +52,7 @@ DEPENDENCIES 
     | 
|
| 
       50 
52 
     | 
    
         
             
              bundler (~> 2.0)
         
     | 
| 
       51 
53 
     | 
    
         
             
              byebug (~> 11.0)
         
     | 
| 
       52 
54 
     | 
    
         
             
              rake (~> 12.3, >= 12.3.3)
         
     | 
| 
       53 
     | 
    
         
            -
              redcarpet
         
     | 
| 
      
 55 
     | 
    
         
            +
              redcarpet (~> 3.5.0)
         
     | 
| 
       54 
56 
     | 
    
         
             
              rspec (~> 3.0)
         
     | 
| 
       55 
57 
     | 
    
         
             
              selenium-webdriver (~> 3.142)
         
     | 
| 
       56 
58 
     | 
    
         
             
              smartcar!
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -107,14 +107,15 @@ 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 
     | 
    
         
            -
            2.5.5 :004 >  
     | 
| 
       113 
     | 
    
         
            -
              
     | 
| 
      
 112 
     | 
    
         
            +
            2.5.5 :004 > client = Smartcar::Oauth.new(options)
         
     | 
| 
      
 113 
     | 
    
         
            +
            2.5.5 :005 > url = client.authorization_url
         
     | 
| 
      
 114 
     | 
    
         
            +
             => "https://connect.smartcar.com/oauth/authorize?approval_prompt=auto&client_id=<client id>&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 
115 
     | 
    
         
             
            # Redirect user to the above URL.
         
     | 
| 
       115 
116 
     | 
    
         
             
            # After authentication user control reaches the callback URL with code.
         
     | 
| 
       116 
117 
     | 
    
         
             
            # Use the code from the parameters and request a token
         
     | 
| 
       117 
     | 
    
         
            -
            2.5.5 :006 > token_hash =  
     | 
| 
      
 118 
     | 
    
         
            +
            2.5.5 :006 > token_hash = client.get_token(code)
         
     | 
| 
       118 
119 
     | 
    
         
             
             => {"token_type"=>"Bearer", :access_token=>"56801a5e-6a0b-4d05-a43e-52a4d5e6648f", :refresh_token=>"4f46e7e4-28c5-47b3-ba8d-7dcef73d05dd", :expires_at=>1577875279}
         
     | 
| 
       119 
120 
     | 
    
         
             
            # This access_token can be used to call the Smartcar APIs as given above.
         
     | 
| 
       120 
121 
     | 
    
         
             
            # Store this hash and if it expired refresh the token OR use the code again to
         
     | 
| 
         @@ -123,7 +124,35 @@ Example Usage for oAuth - 
     | 
|
| 
       123 
124 
     | 
    
         | 
| 
       124 
125 
     | 
    
         
             
            ## Development
         
     | 
| 
       125 
126 
     | 
    
         | 
| 
       126 
     | 
    
         
            -
            To install this gem onto your local machine, run `bundle exec rake install`. 
     | 
| 
      
 127 
     | 
    
         
            +
            To install this gem onto your local machine, run `bundle exec rake install`.
         
     | 
| 
      
 128 
     | 
    
         
            +
             
     | 
| 
      
 129 
     | 
    
         
            +
            To run tests, make sure you have the env variables setup for client id and secret.
         
     | 
| 
      
 130 
     | 
    
         
            +
            ```shell
         
     | 
| 
      
 131 
     | 
    
         
            +
            export INTEGRATION_CLIENT_ID=<client id>
         
     | 
| 
      
 132 
     | 
    
         
            +
            export INTEGRATION_CLIENT_SECRET=<client secret>
         
     | 
| 
      
 133 
     | 
    
         
            +
            ```
         
     | 
| 
      
 134 
     | 
    
         
            +
             
     | 
| 
      
 135 
     | 
    
         
            +
            Tests can be run using either default rake command OR specific rspec command.
         
     | 
| 
      
 136 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 137 
     | 
    
         
            +
            bundle exec rake spec
         
     | 
| 
      
 138 
     | 
    
         
            +
            ```
         
     | 
| 
      
 139 
     | 
    
         
            +
             
     | 
| 
      
 140 
     | 
    
         
            +
            **NOTE : Do not forget to update the version number in version.rb.**
         
     | 
| 
      
 141 
     | 
    
         
            +
             
     | 
| 
      
 142 
     | 
    
         
            +
            ## Release
         
     | 
| 
      
 143 
     | 
    
         
            +
             
     | 
| 
      
 144 
     | 
    
         
            +
            Deployments to Rubgygems is automated through Travis. After merging to master, create a tag on the latest commit on master and push it. That would trigger a CI job which will build, test and deploy to Rubygems. As a convention we use the version number of the gem for the release tag.
         
     | 
| 
      
 145 
     | 
    
         
            +
             
     | 
| 
      
 146 
     | 
    
         
            +
            ```
         
     | 
| 
      
 147 
     | 
    
         
            +
            # After merging to master, checkout to master and pull code locally, then run the following
         
     | 
| 
      
 148 
     | 
    
         
            +
            git tag v1.2.3
         
     | 
| 
      
 149 
     | 
    
         
            +
            # now push the tags
         
     | 
| 
      
 150 
     | 
    
         
            +
            git push origin --tags
         
     | 
| 
      
 151 
     | 
    
         
            +
            Total 0 (delta 0), reused 0 (delta 0)
         
     | 
| 
      
 152 
     | 
    
         
            +
            To github.com:smartcar/ruby-sdk.git
         
     | 
| 
      
 153 
     | 
    
         
            +
             * [new tag]         v1.2.3 -> v1.2.3
         
     | 
| 
      
 154 
     | 
    
         
            +
            ```
         
     | 
| 
      
 155 
     | 
    
         
            +
             
     | 
| 
       127 
156 
     | 
    
         | 
| 
       128 
157 
     | 
    
         
             
            ## Contributing
         
     | 
| 
       129 
158 
     | 
    
         | 
| 
         @@ -131,7 +160,7 @@ To contribute, please: 
     | 
|
| 
       131 
160 
     | 
    
         | 
| 
       132 
161 
     | 
    
         
             
            1. Open an issue for the feature (or bug) you would like to resolve.
         
     | 
| 
       133 
162 
     | 
    
         
             
            2. Resolve the issue and add tests in your feature branch.
         
     | 
| 
       134 
     | 
    
         
            -
            3. Open a PR from your feature branch into ` 
     | 
| 
      
 163 
     | 
    
         
            +
            3. Open a PR from your feature branch into `master` that tags the issue.
         
     | 
| 
       135 
164 
     | 
    
         | 
| 
       136 
165 
     | 
    
         
             
            [gem-image]: https://badge.fury.io/rb/smartcar
         
     | 
| 
       137 
166 
     | 
    
         
             
            [gem-url]: https://badge.fury.io/rb/smartcar.svg
         
     | 
    
        data/lib/smartcar.rb
    CHANGED
    
    
    
        data/lib/smartcar/base.rb
    CHANGED
    
    | 
         @@ -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
         
     | 
    
        data/lib/smartcar/oauth.rb
    CHANGED
    
    | 
         @@ -1,83 +1,95 @@ 
     | 
|
| 
       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 
     | 
    
         
            -
             
     | 
| 
       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 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       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 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
                   
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       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 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     | 
    
        data/lib/smartcar/vehicle.rb
    CHANGED
    
    | 
         @@ -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 
     | 
    
         
             
                  )
         
     | 
| 
         @@ -80,7 +84,7 @@ module Smartcar 
     | 
|
| 
       80 
84 
     | 
    
         
             
                # EX : Smartcar::Vehicle.new(token: token, id: id).permissions
         
     | 
| 
       81 
85 
     | 
    
         
             
                # @param options [Hash] - Optional filter parameters (check documentation)
         
     | 
| 
       82 
86 
     | 
    
         
             
                #
         
     | 
| 
       83 
     | 
    
         
            -
                # @return [ 
     | 
| 
      
 87 
     | 
    
         
            +
                # @return [Permissions] object
         
     | 
| 
       84 
88 
     | 
    
         
             
                def permissions(options: {})
         
     | 
| 
       85 
89 
     | 
    
         
             
                  get_attribute(Permissions)
         
     | 
| 
       86 
90 
     | 
    
         
             
                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.8
         
     | 
| 
       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- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2020-11-04 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.0. 
     | 
| 
      
 176 
     | 
    
         
            +
            rubygems_version: 3.0.8
         
     | 
| 
       176 
177 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       177 
178 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       178 
179 
     | 
    
         
             
            summary: Ruby Gem to access smartcar APIs (https://smartcar.com/docs/)
         
     |