tesla_api 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 004b8279c80ca07b37c054941a16a1d342e9542f
4
- data.tar.gz: fd9ae6cdfafad753f98f6ce263dd8877ed520eaa
3
+ metadata.gz: 127d7079cd952af550adb8cb746fb43826ee2eb7
4
+ data.tar.gz: 46c4218838c49fed63508d853c41a97a3537b532
5
5
  SHA512:
6
- metadata.gz: 7f26680c9e17dfbb291f4bf8ccbe0a0ab33d7c8081a354d2d11eafde143c304ba30fac527daaf1880a1308bc92ca51b9641ca728c3d83a2240971bec12789046
7
- data.tar.gz: 245de6504dd0690402da5d03aa0da0042a06d944abdb11e8e5cb934cf734b1a25a5f648f70c800771c9d3bc22e6b0a20203da52b9368fee3f29f31b9e7f2373f
6
+ metadata.gz: 96efd5588a8bccd85e094a1a03d3df6b777115557d9d457577330ecf61c2f4c638fbc1de895a28e4ca03ed4a98fe766019c4119d08c1dbbe316173473c6d6935
7
+ data.tar.gz: 9d679267752007f77ba51e6eec82a128bdc4cb8d81c7bba405faaad840a6ec288937818618305a9a38c93e74bb817dd90dabafedf1392bffb2d6b0e5086298aa
@@ -4,10 +4,20 @@ module TeslaApi
4
4
  base_uri "https://owner-api.teslamotors.com/api/1"
5
5
  format :json
6
6
 
7
- attr_reader :email
7
+ attr_reader :email, :token, :client_id, :client_secret
8
8
 
9
- def initialize(email, password, client_id, client_secret)
9
+ def initialize(email, client_id = ENV["TESLA_CLIENT_ID"], client_secret = ENV["TESLA_CLIENT_SECRET"])
10
10
  @email = email
11
+ @client_id = client_id
12
+ @client_secret = client_secret
13
+ end
14
+
15
+ def token=(token)
16
+ @token = token
17
+ self.class.headers "Authorization" => "Bearer #{token}"
18
+ end
19
+
20
+ def login!(password)
11
21
  response = self.class.post(
12
22
  "https://owner-api.teslamotors.com/oauth/token",
13
23
  body: {
@@ -18,7 +28,8 @@ module TeslaApi
18
28
  "password" => password
19
29
  }
20
30
  )
21
- self.class.headers "Authorization" => "Bearer #{response["access_token"]}"
31
+
32
+ self.token = response["access_token"]
22
33
  end
23
34
 
24
35
  def vehicles
@@ -1,3 +1,3 @@
1
1
  module TeslaApi
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -1,50 +1,5 @@
1
1
  ---
2
2
  http_interactions:
3
- - request:
4
- method: post
5
- uri: https://owner-api.teslamotors.com/oauth/token
6
- body:
7
- encoding: UTF-8
8
- string: grant_type=password&client_id=<TESLA_CLIENT_ID>&client_secret=<TESLA_CLIENT_SECRET>&email=<TESLA_EMAIL>&password=<TESLA_PASS>
9
- headers:
10
- Accept-Encoding:
11
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
- Accept:
13
- - "*/*"
14
- User-Agent:
15
- - Ruby
16
- response:
17
- status:
18
- code: 200
19
- message: OK
20
- headers:
21
- Server:
22
- - nginx
23
- Date:
24
- - Mon, 15 Dec 2014 03:28:30 GMT
25
- Content-Type:
26
- - application/json; charset=utf-8
27
- Transfer-Encoding:
28
- - chunked
29
- Connection:
30
- - keep-alive
31
- Status:
32
- - 200 OK
33
- Cache-Control:
34
- - no-store
35
- Pragma:
36
- - no-cache
37
- X-Ua-Compatible:
38
- - IE=Edge,chrome=1
39
- X-Request-Id:
40
- - 2716f7fd5f4ee1239d044ddfba838d70
41
- X-Runtime:
42
- - '0.372092'
43
- body:
44
- encoding: UTF-8
45
- string: '{"access_token":"53514fcfea416c9dd77b50d0a1c1dc681960002d23c22b1a9cf2681e8cbec8da","token_type":"bearer","expires_in":7776000}'
46
- http_version:
47
- recorded_at: Mon, 15 Dec 2014 03:28:30 GMT
48
3
  - request:
49
4
  method: get
50
5
  uri: https://owner-api.teslamotors.com/api/1/vehicles
@@ -1,17 +1,30 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe TeslaApi::Client do
4
- subject(:tesla_api) { TeslaApi::Client.new(ENV["TESLA_EMAIL"], ENV["TESLA_PASS"], ENV["TESLA_CLIENT_ID"], ENV["TESLA_CLIENT_SECRET"]) }
4
+ subject(:tesla_api) { TeslaApi::Client.new(ENV["TESLA_EMAIL"]) }
5
5
 
6
- describe "#initialize", vcr: { cassette_name: "client-initialize" } do
6
+ describe "#token=" do
7
+ it "sets a Bearer token" do
8
+ tesla_api.token = Faker::Lorem.characters(32)
9
+ expect(tesla_api.class.headers).to include({"Authorization" => /Bearer [a-z0-9]{32}/})
10
+ end
11
+ end
12
+
13
+ describe "#login!", vcr: { cassette_name: "client-login" } do
7
14
  it { is_expected.to be_a(TeslaApi::Client) }
8
15
 
9
16
  it "logs into the API" do
10
- base_uri = URI.parse(tesla_api.class.base_uri)
11
- expect(a_request(:post, "https://#{base_uri.host}/oauth/token")).to have_been_made.once
17
+ tesla_api.login!(ENV["TESLA_PASS"])
18
+ expect(a_request(:post, "https://#{URI.parse(tesla_api.class.base_uri).host}/oauth/token")).to have_been_made.once
12
19
  end
13
20
 
14
- it "sets a Bearer token" do
21
+ it "obtains a Bearer token" do
22
+ tesla_api.login!(ENV["TESLA_PASS"])
23
+ expect(tesla_api.token).to match(/[a-z0-9]{32}/)
24
+ end
25
+
26
+ it "sets a Bearer token header" do
27
+ tesla_api.login!(ENV["TESLA_PASS"])
15
28
  expect(tesla_api.class.headers).to include({"Authorization" => /Bearer [a-z0-9]{32}/})
16
29
  end
17
30
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe TeslaApi::Vehicle do
4
- let(:tesla_api) { TeslaApi::Client.new(ENV["TESLA_EMAIL"], ENV["TESLA_PASS"], ENV["TESLA_CLIENT_ID"], ENV["TESLA_CLIENT_SECRET"]) }
4
+ let(:tesla_api) { TeslaApi::Client.new(ENV["TESLA_EMAIL"]) }
5
5
 
6
6
  subject(:vehicle) { tesla_api.vehicles.first }
7
7
 
@@ -11,6 +11,7 @@ end
11
11
  Coveralls::Output.silent = true
12
12
 
13
13
  require 'dotenv'
14
+ require 'faker'
14
15
  require 'vcr'
15
16
  require 'webmock/rspec'
16
17
 
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 1.7"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
25
  spec.add_development_dependency "rspec", "~> 3.1"
26
+ spec.add_development_dependency "faker", "~> 1.4"
26
27
  spec.add_development_dependency "vcr", "~> 2.9"
27
28
  spec.add_development_dependency "webmock", "~> 1.20"
28
29
  spec.add_development_dependency "dotenv", "~> 1.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tesla_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Dorr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-17 00:00:00.000000000 Z
11
+ date: 2014-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faker
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.4'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: vcr
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -170,7 +184,7 @@ files:
170
184
  - lib/tesla_api/client.rb
171
185
  - lib/tesla_api/vehicle.rb
172
186
  - lib/tesla_api/version.rb
173
- - spec/cassettes/client-initialize.yml
187
+ - spec/cassettes/client-login.yml
174
188
  - spec/cassettes/client-vehicles.yml
175
189
  - spec/cassettes/vehicle-auto_conditioning_start.yml
176
190
  - spec/cassettes/vehicle-auto_conditioning_stop.yml
@@ -238,7 +252,7 @@ signing_key:
238
252
  specification_version: 4
239
253
  summary: A wrapper for the Tesla API
240
254
  test_files:
241
- - spec/cassettes/client-initialize.yml
255
+ - spec/cassettes/client-login.yml
242
256
  - spec/cassettes/client-vehicles.yml
243
257
  - spec/cassettes/vehicle-auto_conditioning_start.yml
244
258
  - spec/cassettes/vehicle-auto_conditioning_stop.yml