Sha256: ef788fd1ce5f2c115025e0ca8aa7e08b9e0d6e4c33f676b0c97be2bdceb21939
Contents?: true
Size: 1.27 KB
Versions: 8
Compression:
Stored size: 1.27 KB
Contents
module Mashery class Config DEFAULT_HOSTS = { test: 'api.sandbox.mashery.com', production: 'api.mashery.com' } attr_accessor :config def initialize(yaml_file) @config ||= YAML.load_file(yaml_file) check_config! end def check_config! if config["site_id"].blank? raise ParamMissing.new("site_id") end if config["key"].blank? raise ParamMissing.new("key") end if config["secret"].blank? raise ParamMissing.new("secret") end find_host! end def site_id @site_id ||= config["site_id"] end def key @key ||= config["key"] end alias :api_key :key def secret @secret ||= config["secret"] end def host @host ||= find_host! end def signature Digest::MD5.hexdigest(key + secret + Time.now.to_f.to_i.to_s) end protected def find_host! if config["host"].present? config["host"] else if defined?(Rails) if Rails.env.test? || Rails.env.development? DEFAULT_HOSTS[:test] elsif Rails.env.production? DEFAULT_HOSTS[:production] end end raise ParamMissing.new("host") end end end end
Version data entries
8 entries across 8 versions & 1 rubygems