firstgiving 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTBmYmNjYzNmNGMwODhjN2QzMTE1ZWIyZjU4MGIyYmRhMGM4ZmRiOA==
4
+ MmIwOTM3NTI3MjY3ZmRlM2YxZTU2OTlmODk4YWUwZjI1NDJiM2Q4ZA==
5
5
  data.tar.gz: !binary |-
6
- NmNhYTY2YTA5OGY4ZWQxZTIzZmMwNmFiMDMwNzQzNjllNTM5ZGQ1ZQ==
6
+ MGYwZDhjNGQ3N2I4MjQ0ZmYyOTNmZGU4OTU1NWU2NDkyNjg4ZTBlOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjM2NjBjMDQ4ZDkzOTc3MGYyNzg5MDcxZTEzNjNjM2IxODJmMzk0N2ZiMjFi
10
- NTNlZTRmZjM1YzVkMzQ1NDNhMzIzOWQzZWNlYjA1ZjA2YzBiMmIzMTAyM2Ri
11
- NjU4ZDE4NzZmOWM2MGU5ZDMxMTQ5NDhkNGI0ZWM4OGViOTc0MTE=
9
+ MTllMWRhYWZlNjFmY2QzNjdkNGRkY2EyN2Y3Y2VhYzA4ODhmZmQ3M2M0YjZm
10
+ ZTQyMGNlZjI5ZTA4NGZjODJiMjgyNDU1NGU1ZDkyM2NiOGNiZTMyNWQ5Njcx
11
+ ODc2ZTllMzQ2YjBlOTQzZTAzYTY1NTFkN2Y2MmVlY2RlMTljODE=
12
12
  data.tar.gz: !binary |-
13
- ZWY4YjNlMTZkMjQ5NzRmNGFiYjc2NGMzZmI0MzM5MWU1NjMwZTQzYTU2ODUw
14
- MTYwNDM4ZDBlYzg4Y2QwM2FiZTBjODAwMTg2YTljM2I0MWY1MTZhNDQyNGVm
15
- MGVkYTc0ZDJhYTI0YjJiNjllMDU3YTFjZGE1ZTcyMGQ1MThkOTQ=
13
+ YjJjZWRlMDkwODAzNmI0YjQ4NWVkYWFhNWYwOGIzNDc2ZmExNTc3OGVkOGY0
14
+ YTZiNWUwYWE4ODA4MzQ3ZTc3ZDk2NWM3MjFjYzgwZDk1NzU4ZGNkYWRjMTBh
15
+ N2ZhMjdhMWVlZDcxYjZhNjhkNjZiNzA1Zjk3ZjdjNTk2YTJjYjM=
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # FirstGiving
2
2
 
3
+ [![Code Climate](https://codeclimate.com/github/boosterllc/firstgiving_ruby.png)](https://codeclimate.com/github/boosterllc/firstgiving_ruby)
4
+ [![Gem Version](https://badge.fury.io/rb/firstgiving.svg)](http://badge.fury.io/rb/firstgiving)
5
+
3
6
  FirstGiving Ruby Client Open Source.
4
7
 
5
8
  ## Installation
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'firstgiving/version'
3
3
  require 'firstgiving/base'
4
+ require 'firstgiving/response'
4
5
  require 'firstgiving/donation'
5
6
  require 'firstgiving/lookup'
6
7
  require 'firstgiving/search'
@@ -20,29 +20,18 @@ module FirstGiving
20
20
  }
21
21
  end
22
22
 
23
- def post_call(api_endpoint, action, params, headers)
24
- conn = Faraday.new(url: api_endpoint) do |faraday|
25
- faraday.request :url_encoded
26
- faraday.adapter Faraday.default_adapter
27
- end
28
-
29
- conn.post do |req|
30
- req.url action
31
- req.params = params
32
- req.headers = headers
33
- end
34
- end
35
-
36
- def get_call(api_endpoint, action, params, headers)
37
- conn = Faraday.new(url: api_endpoint) do |faraday|
38
- faraday.request :url_encoded # form-encode POST params
39
- faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
40
- end
41
-
42
- conn.get do |req|
43
- req.url action
44
- req.params = params
45
- req.headers = headers
23
+ [:post, :get].each do |method|
24
+ define_method "#{method}_call" do |api_endpoint, action, params, headers|
25
+ conn = Faraday.new(url: api_endpoint) do |faraday|
26
+ faraday.request :url_encoded
27
+ faraday.adapter Faraday.default_adapter
28
+ end
29
+
30
+ conn.send("#{method}") do |req|
31
+ req.url action
32
+ req.params = params
33
+ req.headers = headers
34
+ end
46
35
  end
47
36
  end
48
37
 
@@ -32,8 +32,23 @@ module FirstGiving
32
32
  call(Actions::TRANSACTION_LIST, params, headers)
33
33
  end
34
34
 
35
+ def success_from(response)
36
+ ack = response['firstGivingDonationApi']['firstGivingResponse']['acknowledgement']
37
+ ack == 'Success' ? true : false
38
+ end
39
+
40
+ def params_from(response)
41
+ params = response['firstGivingDonationApi']['firstGivingResponse']['transaction']
42
+ params ||= response['firstGivingDonationApi']['firstGivingResponse']['transactions']
43
+ end
44
+
45
+ def message_from(response)
46
+ response['firstGivingDonationApi']['firstGivingResponse']['verboseErrorMessage']
47
+ end
48
+
35
49
  def parse(body)
36
- Crack::XML.parse(body)
50
+ response = Crack::XML.parse(body)
51
+ response = Response.new(success_from(response), message_from(response), params_from(response))
37
52
  end
38
53
  end
39
54
  end
@@ -0,0 +1,15 @@
1
+ module FirstGiving
2
+ class Response
3
+
4
+ attr_reader :params, :message
5
+
6
+ def success?
7
+ @success
8
+ end
9
+
10
+ def initialize(success, message, params, options = {})
11
+ @success, @message, @params = success, message, params
12
+ end
13
+
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module FirstGiving
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  end
@@ -72,13 +72,15 @@ describe FirstGiving do
72
72
 
73
73
  it 'should return a list of transactions' do
74
74
  params = {
75
- page_size: 10,
75
+ page_size: 40,
76
76
  date_from: '1388707200',
77
77
  count: 10,
78
78
  page: 1
79
79
  }
80
80
  resp = FG.lookup.list(params)
81
- assert_acknowledgement(resp)
81
+ expect(resp.is_a? FirstGiving::Response).to be_true
82
+ expect(resp.success?).to be_true
83
+ expect(resp.params).to_not be_nil
82
84
  end
83
85
 
84
86
  it 'should return a transaction detail' do
@@ -86,7 +88,19 @@ describe FirstGiving do
86
88
  transactionId: 'a-0070dde28ca48048a1fc24'
87
89
  }
88
90
  resp = FG.lookup.detail(params)
89
- assert_acknowledgement(resp)
91
+ expect(resp.is_a? FirstGiving::Response).to be_true
92
+ expect(resp.success?).to be_true
93
+ expect(resp.params).to_not be_nil
94
+ end
95
+
96
+ it 'should return unsuccesful lookup transaction' do
97
+ params = {
98
+ transactionId: 'a-123'
99
+ }
100
+ resp = FG.lookup.detail(params)
101
+ expect(resp.is_a? FirstGiving::Response).to be_true
102
+ expect(resp.success?).to be_false
103
+ expect(resp.params).to be_nil
90
104
  end
91
105
 
92
106
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firstgiving
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Faizal Zakaria
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-26 00:00:00.000000000 Z
11
+ date: 2014-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -112,6 +112,7 @@ files:
112
112
  - lib/firstgiving/base.rb
113
113
  - lib/firstgiving/donation.rb
114
114
  - lib/firstgiving/lookup.rb
115
+ - lib/firstgiving/response.rb
115
116
  - lib/firstgiving/search.rb
116
117
  - lib/firstgiving/version.rb
117
118
  - spec/first_giving_spec.rb