Class: Mashery::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/mashery/config.rb

Constant Summary collapse

DEFAULT_HOSTS =
{
  test:       'api.sandbox.mashery.com',
  production: 'api.mashery.com'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(yaml_file) ⇒ Config

Returns a new instance of Config.



10
11
12
13
# File 'lib/mashery/config.rb', line 10

def initialize(yaml_file)
  @config ||= YAML.load_file(yaml_file)
  check_config!
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



8
9
10
# File 'lib/mashery/config.rb', line 8

def config
  @config
end

Instance Method Details

#check_config!Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mashery/config.rb', line 15

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

#hostObject



45
46
47
# File 'lib/mashery/config.rb', line 45

def host
  @host    ||= find_host!
end

#keyObject Also known as: api_key



35
36
37
# File 'lib/mashery/config.rb', line 35

def key
  @key     ||= config["key"]
end

#secretObject



41
42
43
# File 'lib/mashery/config.rb', line 41

def secret
  @secret  ||= config["secret"]
end

#signatureObject



49
50
51
# File 'lib/mashery/config.rb', line 49

def signature
  Digest::MD5.hexdigest(key + secret + Time.now.to_f.to_i.to_s)
end

#site_idObject



31
32
33
# File 'lib/mashery/config.rb', line 31

def site_id
  @site_id ||= config["site_id"]
end