Class: Ruze::Kamereon

Inherits:
Object
  • Object
show all
Defined in:
lib/ruze/kamereon.rb

Constant Summary collapse

BASE_URL =
'https://api-wired-prod-1-euw1.wrd-aws.com/commerce/v1'.freeze
COUNTRY =
'DE'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(person_id, gigya_token, vin = nil) ⇒ Kamereon

Returns a new instance of Kamereon.

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
# File 'lib/ruze/kamereon.rb', line 9

def initialize(person_id, gigya_token, vin = nil)
  raise ArgumentError unless person_id.is_a?(String) && gigya_token.is_a?(String)

  @person_id = person_id
  @gigya_token = gigya_token
  @vin = vin
end

Instance Attribute Details

#gigya_tokenObject (readonly)

Returns the value of attribute gigya_token.



16
17
18
# File 'lib/ruze/kamereon.rb', line 16

def gigya_token
  @gigya_token
end

#person_idObject (readonly)

Returns the value of attribute person_id.



16
17
18
# File 'lib/ruze/kamereon.rb', line 16

def person_id
  @person_id
end

Instance Method Details

#account_idObject



18
19
20
# File 'lib/ruze/kamereon.rb', line 18

def 
  accounts.first['accountId']
end

#accountsObject



22
23
24
25
26
27
# File 'lib/ruze/kamereon.rb', line 22

def accounts
  @accounts ||= return_from get(
    uri("/persons/#{person_id}?country=#{COUNTRY}"),
    headers
  ), keys: %w[accounts]
end

#batteryObject



40
41
42
43
44
45
# File 'lib/ruze/kamereon.rb', line 40

def battery
  @battery ||= return_from get(
    uri("/accounts/#{}/kamereon/kca/car-adapter/v2/cars/#{vin}/battery-status?country=#{COUNTRY}"),
    headers
  ), keys: %w[data attributes]
end

#cockpitObject



47
48
49
50
51
52
# File 'lib/ruze/kamereon.rb', line 47

def cockpit
  @cockpit ||= return_from get(
    uri("/accounts/#{}/kamereon/kca/car-adapter/v1/cars/#{vin}/cockpit?country=#{COUNTRY}"),
    headers
  ), keys: %w[data attributes]
end

#locationObject



54
55
56
57
58
59
60
61
62
63
# File 'lib/ruze/kamereon.rb', line 54

def location
  @location ||= return_from get(
    uri("/accounts/#{}/kamereon/kca/car-adapter/v1/cars/#{vin}/location?country=#{COUNTRY}"),
    headers
  ), keys: %w[data attributes]
rescue Error => e
  raise e unless e.message.include?('404')

  {}
end

#vehiclesObject



29
30
31
32
33
34
# File 'lib/ruze/kamereon.rb', line 29

def vehicles
  @vehicles ||= return_from get(
    uri("/accounts/#{}/vehicles?country=#{COUNTRY}"),
    headers
  ), keys: %w[vehicleLinks]
end

#vinObject



36
37
38
# File 'lib/ruze/kamereon.rb', line 36

def vin
  @vin ||= vehicles.first.dig('vehicleDetails', 'vin')
end