class Qiwi::Client

Constants

ENDPOINT
HEADERS

Attributes

endpoint[R]
login[R]
password[R]

Public Class Methods

new(login = nil, password = nil, endpoint = nil) click to toggle source
# File lib/qiwi/client.rb, line 15
def initialize(login = nil, password = nil, endpoint = nil)
  @login = login || Qiwi.config.login
  @password = password || Qiwi.config.password
  @endpoint = endpoint || Qiwi.config.endpoint || ENDPOINT
  raise ArgumentError.new("Missing login or password") unless @login and @password
end

Private Instance Methods

handle_error(response) click to toggle source
# File lib/qiwi/client.rb, line 56
def handle_error(response)
  el = nil
  begin
    xml = Nokogiri::XML(response.body).remove_namespaces!
    xpath = '/Envelope/Body/Fault'
    el = xml.at(xpath)
  rescue
    # If it's an invalid XML response
    raise ServerError.new(response)
  end

  raise ServerError.new(response) unless el
  code = el.xpath('Code/Value').text
  string = el.xpath('Reason/Text').text
  raise SOAPError.new(code, string)
end
perform(request) click to toggle source

Advanced methods :create_bill_ccy :cancel_bill_payed_amount :create_bill_ext

# File lib/qiwi/client.rb, line 42
def perform(request)
  body = request.body
  conn = Faraday.new
  response = conn.post(@endpoint, body.to_xml, HEADERS)
  unless response.success?
    handle_error(response)
    return
  end
  xml = Nokogiri::XML(response.body).remove_namespaces!
  request.result_from_xml(xml)
# rescue
#   raise ServerError.new(response)
end