Module: Johac

Defined in:
lib/johac.rb,
lib/johac/error.rb,
lib/johac/client.rb,
lib/johac/version.rb,
lib/johac/response.rb,
lib/johac/connection.rb

Defined Under Namespace

Modules: Connection Classes: Client, Config, Error, Response

Constant Summary collapse

Version =
'0.9.4'

Class Method Summary collapse

Class Method Details

.configJohac::Config

Return the config object for the global Client instance.

Returns:



47
48
49
50
51
52
# File 'lib/johac.rb', line 47

def config
  unless defined? @config
    raise "#{self.name} not configured. Configure via #{self.name}.configure { |cfg| ... }, or via client constructor"
  end
  @config
end

.defaults {|config| ... } ⇒ Johac::Config

Configure the global defaults for all clients built.

Examples:

Johac.defaults do |config|
  config.base_uri = 'http://api.myservice.com'
  config.auth_scheme = :basic
  config.access_key = 'user'
  config.secret_key = 'password'
end

Yields:

  • (config)

    Passes a config object to the block.

Yield Parameters:

Returns:



38
39
40
41
42
43
# File 'lib/johac.rb', line 38

def defaults(&block)
  c = @config ||= Config.new
  c.env = environment || 'production'
  yield c
  c
end

.merged_config(overrides) ⇒ Object

Merge the new config with defaults



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/johac.rb', line 55

def merged_config(overrides)
  case overrides
  when Hash
    dup_config.tap do |conf|
      overrides.each do |k, v|
        conf[k] = v
      end
    end
  when Struct
    dup_config.tap do |conf|
      overrides.each_pair do |k, v|
        conf[k] = v
      end
    end
  else
    config
  end
end