class BMWConnectedDrive::Client
Constants
- USER_AGENT
Attributes
access_token[R]
auth_basic[R]
expires_in[R]
password[R]
username[R]
Public Class Methods
new(params={username:nil, password:nil, auth_basic:nil})
click to toggle source
# File lib/bmw-connected-drive/client.rb, line 10 def initialize(params={username:nil, password:nil, auth_basic:nil}) @username = params[:username] @password = params[:password] @auth_basic = params[:auth_basic] end
Public Instance Methods
access_token=(access_token)
click to toggle source
# File lib/bmw-connected-drive/client.rb, line 16 def access_token=(access_token) @access_token = access_token self.class.headers "User-Agent" => USER_AGENT self.class.headers "Authorization" => "Bearer #{access_token}" end
call(path)
click to toggle source
# File lib/bmw-connected-drive/client.rb, line 45 def call(path) self.class.get(path) end
expires_in=(seconds)
click to toggle source
# File lib/bmw-connected-drive/client.rb, line 22 def expires_in=(seconds) @expires_in = seconds.to_f end
login()
click to toggle source
# File lib/bmw-connected-drive/client.rb, line 26 def login response = self.class.post( "/oauth/token", body: { "grant_type" => "password", "username" => self.username, "password" => self.password, "scope" => "remote_services vehicle_data" }, headers: { "Authorization" => "Basic " + self.auth_basic, "Content-Type" => "application/x-www-form-urlencoded", "User-Agent" => USER_AGENT } ) self.expires_in = response["expires_in"] self.access_token = response["access_token"] end
vehicles()
click to toggle source
# File lib/bmw-connected-drive/client.rb, line 49 def vehicles self.class.get("/v1/user/vehicles/")["vehicles"].map { |vehicle| Vehicle.new(self.class, vehicle) } end