Class: Pandoru::ClientBuilders::PydoraConfigFileBuilder

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

Overview

Pydora Config Format Client Builder Builds API client for original pydora configuration format.

Constant Summary collapse

DEFAULT_CONFIG_FILE =
"~/.pydora.cfg"

Constants inherited from APIClientBuilder

APIClientBuilder::DEFAULT_CLIENT_CLASS

Instance Attribute Summary

Attributes inherited from FileBasedClientBuilder

#authenticate, #path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FileBasedClientBuilder

#build, #config, #initialize

Methods inherited from APIClientBuilder

#build_from_settings_hash, #initialize

Constructor Details

This class inherits a constructor from Pandoru::ClientBuilders::FileBasedClientBuilder

Class Method Details

.default_configObject



225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/pandoru/client_builder.rb', line 225

def self.default_config
  {
    "DECRYPTION_KEY" => "",
    "ENCRYPTION_KEY" => "",
    "PARTNER_USER" => "",
    "PARTNER_PASSWORD" => "",
    "DEVICE" => "",
    "USERNAME" => "",
    "PASSWORD" => "",
    "API_HOST" => Transport::DEFAULT_API_HOST,
    "AUDIO_QUALITY" => Client::BaseAPIClient::MED_AUDIO_QUALITY
  }
end

Instance Method Details

#parse_configObject



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/pandoru/client_builder.rb', line 239

def parse_config
  config_path = config_file_path
  
  unless File.exist?(config_path)
    raise ArgumentError, "Config file not found: #{config_path}"
  end

  config = self.class.default_config.dup
  current_section = nil
  
  File.readlines(config_path).each do |line|
    line = line.strip
    next if line.empty? || line.start_with?('#')
    
    if line.start_with?('[') && line.end_with?(']')
      current_section = line[1...-1]
      next
    end
    
    if line.include?('=')
      key, value = line.split('=', 2)
      key = key.strip.upcase
      value = value.strip
      
      # Remove quotes if present
      value = value[1...-1] if (value.start_with?('"') && value.end_with?('"')) ||
                               (value.start_with?("'") && value.end_with?("'"))
      
      config[key] = value
    end
  end
  
  # Apply any translations
  SettingsDict.new(config)
end