Sha256: cbd085ad81600326958c14781cf9a8c228e9c81385f1be07741feb96fa87ab73

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

require 'erb'
require 'yaml'

module Hatenablog
  class Configuration
    # For OAuth authorization.
    attr_reader :consumer_key, :consumer_secret, :access_token, :access_token_secret

    attr_reader :user_id, :blog_id

    # Create a new configuration.
    # @param [String] config_file configuration file path
    # @return [Hatenablog::Configuration]
    def initialize(config_file)
      config = YAML.load(ERB.new(File.read(config_file)).result)
      unless config.has_key?('consumer_key') && config.has_key?('consumer_secret')     &&
             config.has_key?('access_token') && config.has_key?('access_token_secret') &&
             config.has_key?('user_id')      && config.has_key?('blog_id')
        raise ConfigurationError, 'the configure file is incorrect'
      end

      @consumer_key        = config['consumer_key']
      @consumer_secret     = config['consumer_secret']
      @access_token        = config['access_token']
      @access_token_secret = config['access_token_secret']
      @user_id             = config['user_id']
      @blog_id             = config['blog_id']
    end
  end

  class ConfigurationError < StandardError; end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hatenablog-0.3.0 lib/hatenablog/configuration.rb