Sha256: d0a3c05e005d597298444b086c8a319ea0ffd7f1abaffa2f682a55e4f6de6ecf
Contents?: true
Size: 1.27 KB
Versions: 14
Compression:
Stored size: 1.27 KB
Contents
module Masheri 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
14 entries across 14 versions & 1 rubygems