Class: Qiwi::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/qiwi/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(login = nil, password = nil, handler = nil) ⇒ Server

Creates a new instance of Rack application

Parameters:

  • login (String) (defaults to: nil)
  • password (String) (defaults to: nil)
  • handler (Proc) (defaults to: nil)

    must return 0 on success



14
15
16
17
18
# File 'lib/qiwi/server.rb', line 14

def initialize( = nil, password = nil, handler = nil)
  @login =  || Qiwi.config.
  @password = password || Qiwi.config.password
  @handler = handler || Qiwi::Handler
end

Instance Attribute Details

#handlerObject

Returns the value of attribute handler.



7
8
9
# File 'lib/qiwi/server.rb', line 7

def handler
  @handler
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/qiwi/server.rb', line 20

def call(env)
  @logger = env['rack.logger']

  if env['QUERY_STRING'] == 'wsdl'
    body = File.read(File.join(File.dirname(__FILE__), 'IShopClientWS.wsdl'))
  else
    body = env['rack.input'].read
    result = handle_soap_body(body)
    body = <<-EOF
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:cli="http://client.ishop.mw.ru/">
   <soap:Body>
  <cli:updateBillResponse>
     <updateBillResult>#{result}</updateBillResult>
  </cli:updateBillResponse>
   </soap:Body>
</soap:Envelope>
  EOF
  end
  headers = {'Content-Type' => 'application/soap+xml', 'Cache-Control' => 'no-cache'}
  [200, headers, [body]]
end