huginn_renault_ze_agent 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/renault_ze/renault_ze_connect.rb +14 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6c82cb1b7fc09ef9a5b74fcf21d53554d286782deffd642f1e1c822963860ba
|
4
|
+
data.tar.gz: a92a61ef98519fb37eba57be92e13109d0804fa30f173cda8fb93311c46b6325
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bae069a3481e4396fbbec077bf3b400d03a7ea9b6280af4296f648be08240d07a989f421e466e0197e8b0d644a49655eef22f9a417a6df6add04e5ad5962da6
|
7
|
+
data.tar.gz: edbaabe68939e7054a9123a5c7cd5a466d8357f7ef55ef9abc63e77fc299ab792d9a0e0abaafac2a9288966d1c477db51c85e73cc33829799a95c0327bc1f52c
|
@@ -7,9 +7,12 @@ module RenaultZE
|
|
7
7
|
|
8
8
|
def login
|
9
9
|
response = HTTParty.post(
|
10
|
-
"https://www.services.renault-ze.com/api/user/login",
|
10
|
+
"https://www.services.renault-ze.com/api/user/login",
|
11
|
+
headers: {"Content-Type": "application/json"},
|
11
12
|
body: {username: @username, password: @password}.to_json
|
12
13
|
)
|
14
|
+
raise 'Unexpected response code: #{response}' unless response.code == 200
|
15
|
+
|
13
16
|
content = JSON.parse response.body
|
14
17
|
return {
|
15
18
|
token: content["token"],
|
@@ -18,13 +21,21 @@ module RenaultZE
|
|
18
21
|
end
|
19
22
|
|
20
23
|
def get_battery(creds)
|
24
|
+
raise 'Missing token in input: #{creds}' if creds[:token].nil?
|
25
|
+
raise 'Missing VIN in input: #{creds}' if creds[:vin].nil?
|
26
|
+
|
21
27
|
response = HTTParty.get(
|
22
28
|
"https://www.services.renault-ze.com/api/vehicle/#{creds[:vin]}/battery",
|
23
|
-
headers: {"Authorization": "Bearer #{creds[
|
29
|
+
headers: {"Authorization": "Bearer #{creds[:token]}"}
|
24
30
|
)
|
31
|
+
raise 'Unexpected response code: #{response}' unless response.code == 200
|
25
32
|
|
26
33
|
result = JSON.parse response.body
|
27
|
-
|
34
|
+
unless result["last_update"].nil?
|
35
|
+
epoch = result["last_update"] / 1000
|
36
|
+
result["last_update"] = epoch
|
37
|
+
result["last_update_hours_ago"] = (Time.now - Time.at(epoch)) / 3600
|
38
|
+
end
|
28
39
|
return result
|
29
40
|
end
|
30
41
|
end
|