Sha256: cea8f57b6122180da617d2adbb4c2ff045912296ac1720257fb5c27524780798

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

require 'singleton'

class Iknow::Config
  include Singleton
  attr_accessor :protocol, :host, :port, :api_protocol, :api_host, :api_port, :timeout,
                :api_key, :oauth_consumer_key, :oauth_consumer_secret, :oauth_http_method, :oauth_scheme,
                :user_agent, :application_name, :application_version, :application_url, :source

  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,
      :timeout               => 30,
      :api_key               => '',
      :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

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

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

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

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
iknow-0.2.1 lib/iknow/core/config.rb