Class: Iknow::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/iknow/core/config.rb

Constant Summary collapse

ATTRIBUTES =
[ :protocol, :host, :port, :api_protocol, :api_host, :api_port, :api_key, :timeout,
:oauth_consumer_key, :oauth_consumer_secret, :oauth_http_method, :oauth_scheme,
:user_agent, :application_name, :application_version, :application_url ]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.init {|conf| ... } ⇒ Object

Yields:

  • (conf)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/iknow/core/config.rb', line 10

def self.init(&block)
  conf = Iknow::Config.instance
  { :protocol              => 'http',
    :host                  => 'www.iknow.co.jp',
    :port                  => 80,
    :api_protocol          => 'http',
    :api_host              => 'api.iknow.co.jp',
    :api_port              => 80,
    :api_key               => '',
    :timeout               => 30,
    :oauth_consumer_key    => '',
    :oauth_consumer_secret => '',
    :oauth_http_method     => :post,
    :oauth_scheme          => :header,
    :user_agent            => 'default',
    :application_name      => 'iKnow! Gem',
    :application_version   => Iknow::Version.to_version,
    :application_url       => 'http://github.com/nov/iknow'
  }.each do |key, value| conf.send("#{key}=", value) end
  yield conf if block_given?
  conf
end

.method_missing(method, *args) ⇒ Object



48
49
50
# File 'lib/iknow/core/config.rb', line 48

def self.method_missing(method, *args)
  Iknow::Config.instance.send(method, *args)
end

.timeoutObject

hack: Object.timeout is already defined..



44
45
46
# File 'lib/iknow/core/config.rb', line 44

def self.timeout
  instance.timeout
end

Instance Method Details

#api_base_urlObject



38
39
40
41
# File 'lib/iknow/core/config.rb', line 38

def api_base_url
  port = self.api_port==80 ? nil : ":#{self.api_port}"
  "#{self.api_protocol}://#{self.api_host}#{port}"
end

#base_urlObject



33
34
35
36
# File 'lib/iknow/core/config.rb', line 33

def base_url
  port = self.port==80 ? nil : ":#{self.port}"
  "#{self.protocol}://#{self.host}#{port}"
end