Class: RenaultZE::Client
- Inherits:
-
Object
- Object
- RenaultZE::Client
- Defined in:
- lib/renault_ze/renault_ze_connect.rb
Instance Method Summary collapse
- #get_battery(creds) ⇒ Object
-
#initialize(username, password) ⇒ Client
constructor
A new instance of Client.
- #login ⇒ Object
Constructor Details
#initialize(username, password) ⇒ Client
Returns a new instance of Client.
3 4 5 6 |
# File 'lib/renault_ze/renault_ze_connect.rb', line 3 def initialize(username, password) @username = username @password = password end |
Instance Method Details
#get_battery(creds) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/renault_ze/renault_ze_connect.rb', line 23 def get_battery(creds) raise "Battery - Missing token in input: #{creds}" if creds[:token].nil? raise "Battery - Missing VIN in input: #{creds}" if creds[:vin].nil? response = HTTParty.get( "https://www.services.renault-ze.com/api/vehicle/#{creds[:vin]}/battery", headers: {"Authorization": "Bearer #{creds[:token]}"} ) raise "Battery - Unexpected response code: #{response}" unless response.code == 200 result = JSON.parse response.body unless result["last_update"].nil? epoch = result["last_update"] / 1000 result["last_update"] = epoch result["last_update_hours_ago"] = (Time.now - Time.at(epoch)) / 3600 end return result end |
#login ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/renault_ze/renault_ze_connect.rb', line 8 def login response = HTTParty.post( "https://www.services.renault-ze.com/api/user/login", headers: {"Content-Type": "application/json"}, body: {username: @username, password: @password}.to_json ) raise "Login - Unexpected response code: #{response}" unless response.code == 200 content = JSON.parse response.body return { token: content["token"], vin: content["user"]["vehicle_details"]["VIN"] } end |