Class: TeslaApi::Client
- Inherits:
-
Object
- Object
- TeslaApi::Client
- Includes:
- HTTParty
- Defined in:
- lib/tesla_api/client.rb
Instance Attribute Summary collapse
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
-
#initialize(email, client_id = ENV["TESLA_CLIENT_ID"], client_secret = ENV["TESLA_CLIENT_SECRET"]) ⇒ Client
constructor
A new instance of Client.
- #login!(password) ⇒ Object
- #vehicles ⇒ Object
Constructor Details
#initialize(email, client_id = ENV["TESLA_CLIENT_ID"], client_secret = ENV["TESLA_CLIENT_SECRET"]) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 |
# File 'lib/tesla_api/client.rb', line 9 def initialize(email, client_id = ENV["TESLA_CLIENT_ID"], client_secret = ENV["TESLA_CLIENT_SECRET"]) @email = email @client_id = client_id @client_secret = client_secret end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
7 8 9 |
# File 'lib/tesla_api/client.rb', line 7 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
7 8 9 |
# File 'lib/tesla_api/client.rb', line 7 def client_secret @client_secret end |
#email ⇒ Object (readonly)
Returns the value of attribute email.
7 8 9 |
# File 'lib/tesla_api/client.rb', line 7 def email @email end |
#token ⇒ Object
Returns the value of attribute token.
7 8 9 |
# File 'lib/tesla_api/client.rb', line 7 def token @token end |
Instance Method Details
#login!(password) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tesla_api/client.rb', line 20 def login!(password) response = self.class.post( "https://owner-api.teslamotors.com/oauth/token", body: { "grant_type" => "password", "client_id" => client_id, "client_secret" => client_secret, "email" => email, "password" => password } ) self.token = response["access_token"] end |