nfg-client 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/nfg-client/utils.rb +30 -19
- data/lib/nfg-client/version.rb +1 -1
- data/spec/remote/nfg-client_remote_spec.rb +3 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OGRmZDY3ZDM3OTM0ODdkM2RjNmY2NDhkOTNkZTgzMThkNTI1MjJhMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YWVlNjNkZWUxNzNiN2E2ZmNhMTMxNDRiMDFiMWRmYzI5NDY1MWUwOQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjFhYjcwN2E0NDkyYjU5NGY4MTM4YWQzYzk0YzIwYjg2YjlmYTlmNDk0ZTY4
|
10
|
+
NGJkOTQ5N2VjMjlmNDJhMWI3YjM3ZmQ3ZDVjODE5ODUzZTUyM2U2YTY2NjRl
|
11
|
+
ZTkxMjFlNzhhZTFjNjFhYjI0OWUzZDBmOTE1NjJkYjM1ZDBmNjU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Y2M3ZGIzMjk2ZjE0YmZkNTBkNWIyYzZhMjc4OTk4MDUyZmE4MjI3ODU3ZTRm
|
14
|
+
NzY0MTc5NTRkYWZhZmFkODU2NzExMTM5ZmRlMTNjYjBmNTdlZWY3YWVjYjQ2
|
15
|
+
ODc2YjgzZWM5YzVmNmIyZWFmNTNkYmMyZTAxN2U5ZTkxYTE0NDc=
|
data/lib/nfg-client/utils.rb
CHANGED
@@ -23,34 +23,18 @@ module NFGClient
|
|
23
23
|
# params: (Hash)
|
24
24
|
def nfg_soap_request(nfg_method, params)
|
25
25
|
if (nfg_method.is_a? String) && (params.is_a? Hash)
|
26
|
-
|
26
|
+
|
27
27
|
# Build SOAP 1.2 request
|
28
28
|
soap_request = build_nfg_soap_request(nfg_method, params)
|
29
29
|
|
30
30
|
headers = format_headers(nfg_method, soap_request)
|
31
31
|
|
32
|
-
return_value = Hash.new
|
33
|
-
|
34
32
|
# Being HTTP Post
|
35
33
|
begin
|
36
34
|
response = ssl_post(soap_request, headers)
|
37
|
-
|
38
|
-
parsed = REXML::Document.new(response.body)
|
39
|
-
# Build return hash parsing XML response
|
40
|
-
if parsed.root.nil?
|
41
|
-
return_value['StatusCode'] = 'MissingParameter'
|
42
|
-
return_value['Message'] = response.body
|
43
|
-
return_value['ErrorDetails'] = nil
|
44
|
-
else
|
45
|
-
return_value = parsed.root.elements['soap:Body'].elements["#{nfg_method}Response"].elements["#{nfg_method}Result"]
|
46
|
-
end
|
47
|
-
else
|
48
|
-
return_value['StatusCode'] = 'UnexpectedError'
|
49
|
-
return_value['Message'] = response.message
|
50
|
-
return_value['ErrorDetails'] = response.body
|
51
|
-
end
|
35
|
+
return_value = parse_result(response.code, response.body, response.message, nfg_method)
|
52
36
|
rescue StandardError => e
|
53
|
-
|
37
|
+
return_value = Hash.new
|
54
38
|
return_value['StatusCode'] = 'UnexpectedError'
|
55
39
|
return_value['Message'] = e
|
56
40
|
return_value['ErrorDetails'] = e.backtrace.join(' ')
|
@@ -67,6 +51,33 @@ module NFGClient
|
|
67
51
|
get_nfg_soap_request_template.gsub('|body|',"<#{nfg_method} xmlns=\"http://api.networkforgood.org/partnerdonationservice\">#{hash_to_xml(params)}</#{nfg_method}>")
|
68
52
|
end
|
69
53
|
|
54
|
+
# Parses the response code and body and returns and appropriate result hash
|
55
|
+
#
|
56
|
+
# Arguments:
|
57
|
+
# code: (String)
|
58
|
+
# body: (XML string)
|
59
|
+
# message: string
|
60
|
+
# nfg_method: string
|
61
|
+
def parse_result(code, body, message, nfg_method)
|
62
|
+
return_value = Hash.new
|
63
|
+
if code == '200'
|
64
|
+
parsed = REXML::Document.new(body)
|
65
|
+
# Build return hash parsing XML response
|
66
|
+
if parsed.root.nil?
|
67
|
+
return_value['StatusCode'] = 'MissingParameter'
|
68
|
+
return_value['Message'] = body
|
69
|
+
return_value['ErrorDetails'] = nil
|
70
|
+
else
|
71
|
+
return_value = parsed.root.elements['soap:Body'].elements["#{nfg_method}Response"].elements["#{nfg_method}Result"]
|
72
|
+
end
|
73
|
+
else
|
74
|
+
return_value['StatusCode'] = 'UnexpectedError'
|
75
|
+
return_value['Message'] = message
|
76
|
+
return_value['ErrorDetails'] = body
|
77
|
+
end
|
78
|
+
return_value
|
79
|
+
end
|
80
|
+
|
70
81
|
# Returns a SOAP template with no body
|
71
82
|
def get_nfg_soap_request_template
|
72
83
|
"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\"><soap12:Body>|body|</soap12:Body></soap12:Envelope>"
|
data/lib/nfg-client/version.rb
CHANGED
@@ -101,14 +101,15 @@ describe NFGClient do
|
|
101
101
|
end
|
102
102
|
|
103
103
|
describe "get_donor_donation_history" do
|
104
|
-
it "should return
|
104
|
+
it "should return the donation history for the donor" do
|
105
105
|
result = nfg_client.create_cof(create_cof_params)
|
106
106
|
params = make_donation_add_cof_params
|
107
107
|
result = nfg_client.make_donation_add_cof(params)
|
108
108
|
result = nfg_client.get_donor_donation_history(DonorToken: params[:DonorToken])
|
109
109
|
|
110
110
|
expect(result["StatusCode"]).to eql('Success')
|
111
|
-
expect(result["Donations"]).to eql(
|
111
|
+
expect(result["Donations"].length).to eql(1)
|
112
|
+
expect(result["Donations"].first["ChargeId"]).to_not be_empty
|
112
113
|
end
|
113
114
|
end
|
114
115
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nfg-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Antonio Ruano Cuesta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: andand
|