Class: Pandoru::ClientBuilders::APIClientBuilder

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

Overview

Abstract API Client Builder Provides the basic functions for building an API client. Expects a hash of standard configuration options.

Required values:

  • DECRYPTION_KEY - Pandora API decryption key

  • ENCRYPTION_KEY - Pandora API encryption key

  • PARTNER_USER - Pandora API partner username

  • PARTNER_PASSWORD - Pandora API partner password

  • DEVICE - Pandora API device type identifier

Optional values:

  • API_HOST - API hostname and path to API

  • PROXY - HTTP/HTTPS proxy hostname

  • AUDIO_QUALITY - A supported audio quality (see APIClient)

Direct Known Subclasses

FileBasedClientBuilder, SettingsHashBuilder

Constant Summary collapse

DEFAULT_CLIENT_CLASS =
Client::APIClient

Instance Method Summary collapse

Constructor Details

#initialize(client_class: nil) ⇒ APIClientBuilder

Returns a new instance of APIClientBuilder.



117
118
119
# File 'lib/pandoru/client_builder.rb', line 117

def initialize(client_class: nil)
  @client_class = client_class || DEFAULT_CLIENT_CLASS
end

Instance Method Details

#build_from_settings_hash(settings) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/pandoru/client_builder.rb', line 121

def build_from_settings_hash(settings)
  cryptor = Transport::Encryptor.new(
    settings["DECRYPTION_KEY"],
    settings["ENCRYPTION_KEY"]
  )

  transport = Transport::APITransport.new(
    cryptor,
    api_host: settings["API_HOST"],
    proxy: settings["PROXY"]
  )

  @client_class.new(
    transport,
    settings["PARTNER_USER"],
    settings["PARTNER_PASSWORD"], 
    settings["DEVICE"],
    default_audio_quality: settings["AUDIO_QUALITY"] || Client::BaseAPIClient::MED_AUDIO_QUALITY
  )
end