Class: PagSeguro::Subscription::ResponseSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/pagseguro/subscription/response_serializer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ ResponseSerializer

Returns a new instance of ResponseSerializer.



6
7
8
# File 'lib/pagseguro/subscription/response_serializer.rb', line 6

def initialize(xml)
  @xml = xml
end

Instance Attribute Details

#xmlObject (readonly)

Returns the value of attribute xml.



4
5
6
# File 'lib/pagseguro/subscription/response_serializer.rb', line 4

def xml
  @xml
end

Instance Method Details

#serializeObject



10
11
12
13
14
# File 'lib/pagseguro/subscription/response_serializer.rb', line 10

def serialize
  {}.tap do |data|
    data[:code] = xml.css('directPreApproval > code').text
  end
end

#serialize_from_searchObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pagseguro/subscription/response_serializer.rb', line 16

def serialize_from_search
  {}.tap do |data|
    data[:name] = xml.at_css('name').text
    data[:code] = xml.css('code').text
    data[:date] = xml.css('date').text
    data[:tracker] = xml.css('tracker').text
    data[:status] = xml.css('status').text
    data[:reference] = xml.css('reference').text
    data[:last_event_date] = xml.css('lastEventDate').text
    data[:charge] = xml.css('charge').text
    data[:sender] = serialize_sender if xml.at_css('sender')
  end
end