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 +4 -4
- data/lib/tesla_api/client.rb +14 -3
- data/lib/tesla_api/version.rb +1 -1
- data/spec/cassettes/{client-initialize.yml → client-login.yml} +0 -0
- data/spec/cassettes/client-vehicles.yml +0 -45
- data/spec/lib/tesla_api/client_spec.rb +18 -5
- data/spec/lib/tesla_api/vehicle_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/tesla_api.gemspec +1 -0
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 127d7079cd952af550adb8cb746fb43826ee2eb7
|
4
|
+
data.tar.gz: 46c4218838c49fed63508d853c41a97a3537b532
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96efd5588a8bccd85e094a1a03d3df6b777115557d9d457577330ecf61c2f4c638fbc1de895a28e4ca03ed4a98fe766019c4119d08c1dbbe316173473c6d6935
|
7
|
+
data.tar.gz: 9d679267752007f77ba51e6eec82a128bdc4cb8d81c7bba405faaad840a6ec288937818618305a9a38c93e74bb817dd90dabafedf1392bffb2d6b0e5086298aa
|
data/lib/tesla_api/client.rb
CHANGED
@@ -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,
|
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
|
-
|
31
|
+
|
32
|
+
self.token = response["access_token"]
|
22
33
|
end
|
23
34
|
|
24
35
|
def vehicles
|
data/lib/tesla_api/version.rb
CHANGED
File without changes
|
@@ -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"]
|
4
|
+
subject(:tesla_api) { TeslaApi::Client.new(ENV["TESLA_EMAIL"]) }
|
5
5
|
|
6
|
-
describe "#
|
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
|
-
|
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 "
|
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"]
|
4
|
+
let(:tesla_api) { TeslaApi::Client.new(ENV["TESLA_EMAIL"]) }
|
5
5
|
|
6
6
|
subject(:vehicle) { tesla_api.vehicles.first }
|
7
7
|
|
data/spec/spec_helper.rb
CHANGED
data/tesla_api.gemspec
CHANGED
@@ -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.
|
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-
|
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-
|
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-
|
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
|