class PagSeguro::Authorization::Response

Attributes

response[R]

The request response.

Public Class Methods

new(response, object) click to toggle source
# File lib/pagseguro/authorization/response.rb, line 4
def initialize(response, object)
  @response = response
  @object = object
end

Public Instance Methods

serialize() click to toggle source
# File lib/pagseguro/authorization/response.rb, line 9
def serialize
  if success?
    xml = Nokogiri::XML(response.body).css('authorization').first
    serializer = ResponseSerializer.new(xml).serialize
    object.update_attributes(serializer)
  else
    object.errors.add(response)
  end

  object
end
serialize_collection() click to toggle source
# File lib/pagseguro/authorization/response.rb, line 21
def serialize_collection
  if success?
    object.authorizations = serialize_authorizations
  else
    object.errors.add(response)
  end

  object
end
success?() click to toggle source
# File lib/pagseguro/authorization/response.rb, line 31
def success?
  response.success? && response.xml?
end

Private Instance Methods

serialize_authorizations() click to toggle source
# File lib/pagseguro/authorization/response.rb, line 42
def serialize_authorizations
  Nokogiri::XML(response.body).css('authorizations > authorization').map do |node|
    Authorization.new(ResponseSerializer.new(node).serialize)
  end
end