Class: Issuu::ParameterSet

Inherits:
Object
  • Object
show all
Defined in:
lib/issuu/parameter_set.rb

Instance Method Summary collapse

Constructor Details

#initialize(action, extra_params = {}) ⇒ ParameterSet

Returns a new instance of ParameterSet.



3
4
5
6
7
8
9
10
11
12
# File 'lib/issuu/parameter_set.rb', line 3

def initialize(action, extra_params={})
  extra_params = HashWithIndifferentAccess.new(extra_params)
  @api_key = extra_params.delete(:api_key) || Issuu.api_key
  @secret = extra_params.delete(:secret) || Issuu.secret
  @params = extra_params.update({
    :action => action,
    :apiKey => @api_key,
    :format => "json"
  }).hash_select{ |key, value| !value.nil? }
end

Instance Method Details

#generate_signatureObject



14
15
16
17
# File 'lib/issuu/parameter_set.rb', line 14

def generate_signature
  string_to_sign = "#{@secret}#{@params.sort_by {|k| k.to_s }.flatten.join}"
  Digest::MD5.hexdigest(string_to_sign)
end

#outputObject



19
20
21
# File 'lib/issuu/parameter_set.rb', line 19

def output
  @params.merge({:signature => generate_signature})
end