Class: Qiwi::Request::Base
- Inherits:
-
Object
- Object
- Qiwi::Request::Base
show all
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/qiwi/request.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(client, params) ⇒ Base
See concrete classes for parameters description.
29
30
31
32
|
# File 'lib/qiwi/request.rb', line 29
def initialize(client, params)
self.class.attributes.each { |attr| send(:"#{attr}=", params[attr]) }
@login, @password = client.login, client.password
end
|
Class Method Details
.attributes(*attrs) ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/qiwi/request.rb', line 15
def self.attributes(*attrs)
if attrs.empty?
@_attributes
else
@_attributes ||= []
@_attributes += attrs
attr_accessor(*attrs)
end
end
|
.inherited(klass) ⇒ Object
10
11
12
13
|
# File 'lib/qiwi/request.rb', line 10
def self.inherited(klass)
klass.attributes :login, :password
klass.validates_presence_of :login, :password
end
|
Instance Method Details
#body ⇒ Object
34
35
36
|
# File 'lib/qiwi/request.rb', line 34
def body
with_envelope { |xml| soap_body(xml) }
end
|
#method ⇒ Object
60
61
62
|
# File 'lib/qiwi/request.rb', line 60
def method
@method ||= self.class.to_s.split('::').last.camelize(:lower)
end
|
#result_from_xml(xml) ⇒ Object
Make sense of what is returned by the server
67
68
69
|
# File 'lib/qiwi/request.rb', line 67
def result_from_xml(xml)
xml.xpath("//#{method}Response/#{method}Result").text.to_i
end
|
#soap_body(xml) ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/qiwi/request.rb', line 49
def soap_body(xml)
xml['tns'].send(method) do
self.class.attributes.each do |attr|
xml.send("#{attr}_", send(attr)).instance_variable_get(:@node).namespace = nil
end
end
end
|
#with_envelope(&block) ⇒ Object
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/qiwi/request.rb', line 38
def with_envelope(&block)
Nokogiri::XML::Builder.new do |xml|
xml.Envelope("xmlns:soapenv" => "http://www.w3.org/2003/05/soap-envelope",
"xmlns:tns" => "http://server.ishop.mw.ru/") do
xml.parent.namespace = xml.parent.namespace_definitions.first
xml.Header
xml.Body(&block)
end
end
end
|