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
45
46
47
48
49
50
51
52
53
54
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
|
# File 'lib/amex/client.rb', line 16
def accounts
options = { :body => { "PayLoadText" => request_xml }}
response = self.class.post(
'/myca/intl/moblclient/emea/ws.do?Face=en_GB', options
)
xml = Nokogiri::XML(response.body)
xml = xml.css("XMLResponse")
if xml.css('ServiceResponse Status').text != "success"
raise "There was a problem logging in to American Express."
else
@security_token = xml.css('ClientSecurityToken').text
accounts = []
xml.css('CardAccounts CardAccount').each do |item|
account_details = {client: self} item.css('CardData param').each do |attribute|
account_details[attribute.attr('name')] = attribute.text
end
item.css('AccountSummaryData SummaryElement').each do |attribute|
account_details[attribute.attr('name')] = attribute.attr('value') ? attribute.attr('value').to_f : attribute.attr('formattedValue')
end
account = Amex::CardAccount.new(account_details)
item.css('LoyaltyProgramData LoyaltyElement').each do |element|
account.loyalty_programmes << Amex::LoyaltyProgramme.new(
element.attr('label'), element.attr('formattedValue').gsub(",", "").to_i
)
end
options = { :body => {
"PayLoadText" => statement_request_xml(account.card_index)
}}
response = self.class.post(
'/myca/intl/moblclient/emea/ws.do?Face=en_GB', options
)
xml = Nokogiri::XML(response.body)
xml = xml.css("XMLResponse")
xml.css('Transaction').each do |transaction|
account.transactions << Amex::Transaction.new(transaction)
end
accounts << account
end
accounts
end
end
|