Sha256: 02340166dcbf91b30b08a491d82a40dc2196368c7c529759241f30c325895751

Contents?: true

Size: 852 Bytes

Versions: 2

Compression:

Stored size: 852 Bytes

Contents

require 'json'
require 'net/http'
require 'remotransmission/version'
require 'remotransmission/remote'
require 'remotransmission/client'

module RemoTransmission
  DEFAULT_OPTIONS = {
    host: "localhost",
    port: 9091,
    user: "freebox",
    password: "",
    debug: false
  }.freeze

  # Returns the default options hash, optionnaly pulled from the given
  # configuration file.
  #
  # Arguments:
  #   file: path to JSON configuration file
  def self.default_options(file = nil)
    defaults = DEFAULT_OPTIONS

    if file and file = File.expand_path(file) and File.exists?(file)
      config = JSON.parse(File.read(file))

      # symbolize keys
      config = config.inject({}) do |options, (key, value)|
        options[key.to_sym] = value
        options
      end

      defaults = defaults.merge(config)
    end

    defaults
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
remotransmission-1.0.2 lib/remotransmission.rb
remotransmission-1.0.1 lib/remotransmission.rb