Class: WirecardCheckoutPage::Request
- Inherits:
-
Object
- Object
- WirecardCheckoutPage::Request
show all
- Defined in:
- lib/wirecard_checkout_page/request.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(url: nil, params: {}) ⇒ Request
Returns a new instance of Request.
18
19
20
21
|
# File 'lib/wirecard_checkout_page/request.rb', line 18
def initialize(url: nil, params: {})
@url = url
params.each { |param, value| send "#{param}=", value }
end
|
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
27
28
29
|
# File 'lib/wirecard_checkout_page/request.rb', line 27
def errors
@errors
end
|
#params ⇒ Object
Returns the value of attribute params.
25
26
27
|
# File 'lib/wirecard_checkout_page/request.rb', line 25
def params
@params
end
|
#url ⇒ Object
Returns the value of attribute url.
23
24
25
|
# File 'lib/wirecard_checkout_page/request.rb', line 23
def url
@url
end
|
Class Method Details
.param(name, options = {}) ⇒ Object
3
4
5
6
7
8
|
# File 'lib/wirecard_checkout_page/request.rb', line 3
def self.param(name, options = {})
name = name.to_sym
params_order << name
params[name] = options
attr_accessor name
end
|
.params ⇒ Object
10
11
12
|
# File 'lib/wirecard_checkout_page/request.rb', line 10
def self.params
@params ||= {}
end
|
.params_order ⇒ Object
14
15
16
|
# File 'lib/wirecard_checkout_page/request.rb', line 14
def self.params_order
@params_order ||= []
end
|
Instance Method Details
#body ⇒ Object
39
40
41
|
# File 'lib/wirecard_checkout_page/request.rb', line 39
def body
fingerprinted_request_params
end
|
#call ⇒ Object
43
44
45
|
# File 'lib/wirecard_checkout_page/request.rb', line 43
def call
raise NotImplementedError, '#call not implemented'
end
|
#fingerprint ⇒ Object
51
52
53
|
# File 'lib/wirecard_checkout_page/request.rb', line 51
def fingerprint
Digest::MD5.hexdigest fingerprint_string
end
|
#fingerprint_order ⇒ Object
55
56
57
58
59
|
# File 'lib/wirecard_checkout_page/request.rb', line 55
def fingerprint_order
self.class.params_order.select do |param|
attributes[param][:required] || send(param).to_s != ''
end
end
|
#fingerprint_string ⇒ Object
47
48
49
|
# File 'lib/wirecard_checkout_page/request.rb', line 47
def fingerprint_string
fingerprint_order.each_with_object('') { |param, str| str << send(param).to_s }
end
|
#fingerprinted_request_params ⇒ Object
72
73
74
75
76
77
|
# File 'lib/wirecard_checkout_page/request.rb', line 72
def fingerprinted_request_params
request_params.merge(
'requestFingerprint' => fingerprint,
'requestFingerprintOrder' => fingerprint_order.join(',')
)
end
|
#request_params ⇒ Object
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/wirecard_checkout_page/request.rb', line 61
def request_params
rp = {}
attributes.keys.each do |param|
next if param == :secret
val = send(param).to_s
next if val == ''
rp[param.to_s] = val
end
rp
end
|
#valid? ⇒ Boolean
29
30
31
32
33
34
35
36
37
|
# File 'lib/wirecard_checkout_page/request.rb', line 29
def valid?
@errors = []
attributes.each do |param, options|
next unless options[:required] == true
val = send param
@errors << "#{param} is required" if val.nil? || val == ''
end
@errors.empty?
end
|