Class: ActiveMerchant::Billing::PaypalPermissions::Parsers::PersonalDataNVParser

Inherits:
CommonNVParser
  • Object
show all
Defined in:
lib/paypal_permissions/parsers/personal_data.rb

Class Method Summary collapse

Methods inherited from CommonNVParser

process_envelope_pair, process_error_idx, process_error_pair

Class Method Details

.parse(nvp_response) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/paypal_permissions/parsers/personal_data.rb', line 7

def parse nvp_response
  super

  @response[:personal_data] = {}

  key = nil
  key_idx = nil
  pairs = nvp_response.split "&"
  pairs.each do |pair|
    n,v = pair.split "="
    v ||= ""
    n = CGI.unescape n
    v = CGI.unescape v

    case n

    # envelope
    when /^responseEnvelope/
      process_envelope_pair n, v

    # successful personal data response
    when /response\.personalData\((\d+)\)\.personalDataKey/
      key_idx = $1.to_i
      key = personal_data_mappings[v]

    when /response\.personalData\((\d+)\)\.personalDataValue/
      val_idx = $1.to_i
      raise unless key && val_idx == key_idx
      @response[:personal_data][key] = v

    # error with index
    when /^error\((\d+)\)/
      process_error_pair n, v

    end
  end
  @response
end