Class: Pandoru::ClientBuilder

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

Overview

Main ClientBuilder class for external API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_data = {}) ⇒ ClientBuilder

Returns a new instance of ClientBuilder.



353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# File 'lib/pandoru/client_builder.rb', line 353

def initialize(config_data = {})
  base_defaults = {
    device: 'android-generic',
    encrypt_password: true,
    rpc_host: 'tuner.pandora.com',
    rpc_path: '/services/json/',
    rpc_tls_port: 443
  }
  
  if config_data.is_a?(String)
    # File path provided
    loaded_config = load_config_file(config_data)
    @config = base_defaults.merge(loaded_config)
  elsif config_data.is_a?(Hash)
    # Hash data provided
    @config = base_defaults.merge(config_data.transform_keys(&:to_sym))
  else
    @config = base_defaults.dup
  end
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



351
352
353
# File 'lib/pandoru/client_builder.rb', line 351

def config
  @config
end

Instance Method Details

#buildObject



374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
# File 'lib/pandoru/client_builder.rb', line 374

def build
  # Convert config to string keys for the internal builders
  string_config = @config.transform_keys(&:to_s).transform_keys(&:upcase)
  
  # Map common config keys to the expected API format
  mapped_config = {
    'ENCRYPTION_KEY' => string_config['ENCRYPTION_KEY'] || '6#26FRL$ZWD',
    'DECRYPTION_KEY' => string_config['DECRYPTION_KEY'] || 'R=U!LH$O2B#',
    'PARTNER_USER' => string_config['PARTNER_USER'] || 'android',
    'PARTNER_PASSWORD' => string_config['PARTNER_PASSWORD'] || 'AC7IBG09A3DTSYM4R41UJWL07VLN8JI7',
    'DEVICE' => string_config['DEVICE'] || 'android-generic',
    'API_HOST' => (string_config['RPC_HOST'] || string_config['HOST'] || 'tuner.pandora.com'),
    'PROXY' => string_config['CONTROL_PROXY'],
    'AUDIO_QUALITY' => string_config['AUDIO_QUALITY'] || Client::BaseAPIClient::MED_AUDIO_QUALITY
  }.compact
  
  # Handle custom port
  if string_config['RPC_TLS_PORT']
    port = string_config['RPC_TLS_PORT'].to_i
    if port > 0
      mapped_config['API_HOST'] = "https://#{mapped_config['API_HOST']}:#{port}/services/json/"
    end
  elsif mapped_config['API_HOST'] == 'tuner.pandora.com'
    # Only add HTTPS and path for the default tuner.pandora.com to enable TLS
    mapped_config['API_HOST'] = 'https://tuner.pandora.com/services/json/'
  end
  
  # Build using the simple approach
  ClientBuilders.from_settings_hash(mapped_config)
end