Class: Pandoru::Client::BaseAPIClient

Inherits:
Object
  • Object
show all
Defined in:
lib/pandoru/client.rb

Overview

Base Pandora API Client The base API client has lower level methods that are composed together to provide higher level functionality.

Direct Known Subclasses

APIClient

Constant Summary collapse

LOW_AUDIO_QUALITY =
"lowQuality"
MED_AUDIO_QUALITY =
"mediumQuality"
HIGH_AUDIO_QUALITY =
"highQuality"
ALL_QUALITIES =
[LOW_AUDIO_QUALITY, MED_AUDIO_QUALITY, HIGH_AUDIO_QUALITY].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transport, partner_user = nil, partner_password = nil, device = nil, default_audio_quality: MED_AUDIO_QUALITY) ⇒ BaseAPIClient

Returns a new instance of BaseAPIClient.



30
31
32
33
34
35
36
37
38
# File 'lib/pandoru/client.rb', line 30

def initialize(transport, partner_user = nil, partner_password = nil, device = nil, default_audio_quality: MED_AUDIO_QUALITY)
  @transport = transport
  @partner_user = partner_user
  @partner_password = partner_password
  @device = device
  @default_audio_quality = default_audio_quality
  @username = nil
  @password = nil
end

Instance Attribute Details

#default_audio_qualityObject (readonly)

Returns the value of attribute default_audio_quality.



27
28
29
# File 'lib/pandoru/client.rb', line 27

def default_audio_quality
  @default_audio_quality
end

#deviceObject (readonly)

Returns the value of attribute device.



27
28
29
# File 'lib/pandoru/client.rb', line 27

def device
  @device
end

#partner_passwordObject (readonly)

Returns the value of attribute partner_password.



27
28
29
# File 'lib/pandoru/client.rb', line 27

def partner_password
  @partner_password
end

#partner_userObject (readonly)

Returns the value of attribute partner_user.



27
28
29
# File 'lib/pandoru/client.rb', line 27

def partner_user
  @partner_user
end

#passwordObject

Returns the value of attribute password.



28
29
30
# File 'lib/pandoru/client.rb', line 28

def password
  @password
end

#transportObject (readonly)

Returns the value of attribute transport.



27
28
29
# File 'lib/pandoru/client.rb', line 27

def transport
  @transport
end

#usernameObject

Returns the value of attribute username.



28
29
30
# File 'lib/pandoru/client.rb', line 28

def username
  @username
end

Class Method Details

.get_qualities(start_at, return_all_if_invalid: true) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/pandoru/client.rb', line 55

def self.get_qualities(start_at, return_all_if_invalid: true)
  begin
    idx = ALL_QUALITIES.index(start_at)
    ALL_QUALITIES[0..idx]
  rescue ArgumentError
    return_all_if_invalid ? ALL_QUALITIES.dup : []
  end
end

Instance Method Details

#call(method, **kwargs) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/pandoru/client.rb', line 46

def call(method, **kwargs)
  begin
    @transport.call(method, **kwargs)
  rescue Errors::InvalidAuthToken
    authenticate
    @transport.call(method, **kwargs)
  end
end

#login(username, password) ⇒ Object



40
41
42
43
44
# File 'lib/pandoru/client.rb', line 40

def (username, password)
  @username = username
  @password = password
  authenticate
end