Class: AppReport::API::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/app_report/api/base.rb

Direct Known Subclasses

Jasper

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



23
24
25
# File 'lib/app_report/api/base.rb', line 23

def initialize
  @params = {}
end

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



21
22
23
# File 'lib/app_report/api/base.rb', line 21

def params
  @params
end

Instance Method Details

#params_to_signObject



27
28
29
# File 'lib/app_report/api/base.rb', line 27

def params_to_sign
  []
end

#sign_params(params) ⇒ Object



31
32
33
34
# File 'lib/app_report/api/base.rb', line 31

def sign_params params
  string = params.map { |k, v| v.to_s }.join
  SimpleSigner.sign :secret_key => AppReport.settings.secret_key, :string => string
end

#signed_paramsObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/app_report/api/base.rb', line 36

def signed_params
  params = {}

  # include params that must be signed
  params_to_sign.each { |param|
    params[param] = @params[param]#  unless params.include? param
  }

  # include configured keys
  params.merge! :app_name   => AppReport.settings.app_name,
                :expires    => Time.now.to_i + AppReport.settings.expires_signed_url_after

  # sign params
  params.merge! :signature  => sign_params(params),
                :access_key => AppReport.settings.access_key

  # include not signed params
  @params.merge params
end