Sha256: e63ac306244b39ef2787d945b26f39c22145e3dc083daee08dbb6d232d8f08c4

Contents?: true

Size: 788 Bytes

Versions: 3

Compression:

Stored size: 788 Bytes

Contents

module TeslaApi
  class Client
    include HTTParty
    base_uri "https://owner-api.teslamotors.com/api/1"
    format :json

    attr_reader :email

    def initialize(email, password, client_id, client_secret)
      @email = email
      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.class.headers "Authorization" => "Bearer #{response["access_token"]}"
    end

    def vehicles
      self.class.get("/vehicles")["response"].map { |v| Vehicle.new(self.class, email, v["id"], v) }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tesla_api-1.0.0 lib/tesla_api/client.rb
tesla_api-0.9.0 lib/tesla_api/client.rb
tesla_api-0.1.0 lib/tesla_api/client.rb