Class: OFX::OFX102::Serializer

Inherits:
Object
  • Object
show all
Defined in:
lib/ofx/1.0.2/serializer.rb

Instance Method Summary collapse

Instance Method Details

#from_http_response_body(body) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ofx/1.0.2/serializer.rb', line 55

def from_http_response_body(body)
    body = body.lstrip

    end_of_header_index = body.index("<OFX>")

    header_str = body[0...end_of_header_index].strip
    body = body[end_of_header_index..-1]

    if header_str.nil? || header_str == ""
      raise NotImplementedError, "OFX server returned unmatched ASCII"
    end

    header = Header.from_ofx_102_s(header_str)

    parser = OFX::OFX102::Parser.new

    parser.scan_str body

    if parser.documents.length > 1
        raise NotImplementedError, "Multiple response documents"
    end

    # require 'pp'
    # pp parser.ofx_hashes[0]

    document = parser.documents[0]
    document.header = header
    document
end

#to_http_post_body(document) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ofx/1.0.2/serializer.rb', line 41

def to_http_post_body(document)
    body = ""

    body += document.header.to_ofx_102_s
    body += "\n"
    body += "<OFX>\n"
    document.message_sets.each do |message_set|
        body += message_set.to_ofx_102_s
    end
    body += "</OFX>\n"

    body
end