just_giving 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/Gemfile +8 -0
  2. data/README.md +40 -1
  3. data/just_giving.gemspec +58 -7
  4. data/lib/faraday/raise_http_4xx.rb +29 -0
  5. data/lib/faraday/raise_http_5xx.rb +28 -0
  6. data/lib/just_giving.rb +11 -2
  7. data/lib/just_giving/account.rb +43 -0
  8. data/lib/just_giving/api.rb +9 -0
  9. data/lib/just_giving/charity.rb +13 -0
  10. data/lib/just_giving/configuration.rb +59 -0
  11. data/lib/just_giving/connection.rb +28 -0
  12. data/lib/just_giving/donation.rb +17 -0
  13. data/lib/just_giving/error.rb +9 -0
  14. data/lib/just_giving/event.rb +17 -0
  15. data/lib/just_giving/fundraising.rb +51 -0
  16. data/lib/just_giving/request.rb +40 -0
  17. data/lib/just_giving/response.rb +9 -0
  18. data/lib/just_giving/search.rb +13 -0
  19. data/lib/just_giving/simple_donation_integration.rb +7 -3
  20. data/lib/just_giving/version.rb +1 -1
  21. data/test/fixtures/account_create_fail.json +1 -0
  22. data/test/fixtures/account_create_success.json +3 -0
  23. data/test/fixtures/account_list_all_pages.json +21 -0
  24. data/test/fixtures/charity_auth_success.json +5 -0
  25. data/test/fixtures/charity_get_success.json +1 -0
  26. data/test/fixtures/donation_status_success.json +7 -0
  27. data/test/fixtures/event_get_success.json +8 -0
  28. data/test/fixtures/event_pages_success.json +26 -0
  29. data/test/fixtures/fundraising_donations_success.json +1 -0
  30. data/test/fixtures/fundraising_get_page_success.json +1 -0
  31. data/test/fixtures/fundraising_pages_success.json +1 -0
  32. data/test/fixtures/fundraising_update_story_success.json +1 -0
  33. data/test/fixtures/search_success.json +1 -0
  34. data/test/helper.rb +29 -0
  35. data/test/test_account.rb +110 -0
  36. data/test/test_charity.rb +31 -0
  37. data/test/test_configuration.rb +37 -0
  38. data/test/test_donation.rb +26 -0
  39. data/test/test_event.rb +30 -0
  40. data/test/test_fundraising.rb +75 -0
  41. data/test/test_search.rb +32 -0
  42. metadata +139 -22
  43. data/lib/just_giving/config.rb +0 -7
@@ -0,0 +1,31 @@
1
+ require 'helper'
2
+
3
+ class TestCharity < Test::Unit::TestCase
4
+ def setup
5
+ JustGiving::Configuration.application_id = '2345'
6
+ end
7
+
8
+ context 'fetching a charity' do
9
+ should 'get a charity by id' do
10
+ stub_get('/v1/charity/2050').with(:headers => {'Accept'=>'application/json'}).to_return(
11
+ :body => fixture('charity_get_success.json'),
12
+ :headers => {:content_type => 'application/json; charset=utf-8'})
13
+ charity = JustGiving::Charity.new.get_charity(2050)
14
+ assert_equal 2050, charity["id"]
15
+ assert_equal "The Demo Charity", charity["smsShortName"]
16
+ end
17
+ end
18
+
19
+ context 'validate a charity' do
20
+ should '' do
21
+ stub_post('/v1/charity/authenticate').with(:headers => {'Accept'=>'application/json'}).to_return(
22
+ :body => fixture('charity_auth_success.json'),
23
+ :headers => {:content_type => 'application/json; charset=utf-8'})
24
+ auth = JustGiving::Charity.new.validate({:username => "MyCharityUsername",
25
+ :password => "MyPassword", :pin => "MyPin"})
26
+ assert auth["isValid"]
27
+ assert !auth["error"]
28
+ assert_equal 1235, auth["charityId"]
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,37 @@
1
+ require 'helper'
2
+
3
+ class TestConfiguration < Test::Unit::TestCase
4
+ should 'allow setting/getting of application_id' do
5
+ JustGiving::Configuration.application_id = '1234'
6
+ assert_equal '1234', JustGiving::Configuration.application_id
7
+ JustGiving::Configuration.application_id = '5678'
8
+ assert_equal '5678', JustGiving::Configuration.application_id
9
+ end
10
+
11
+ should 'allow setting the enviroment' do
12
+ assert_equal :staging, JustGiving::Configuration.environment
13
+ JustGiving::Configuration.environment = :production
14
+ assert_equal :production, JustGiving::Configuration.environment
15
+ end
16
+
17
+ should 'return the api endpoint' do
18
+ JustGiving::Configuration.environment = :staging
19
+ JustGiving::Configuration.application_id = '5678'
20
+ assert_equal 'https://api.staging.justgiving.com/5678', JustGiving::Configuration.api_endpoint
21
+ JustGiving::Configuration.environment = :production
22
+ assert_equal 'https://api.justgiving.com/5678', JustGiving::Configuration.api_endpoint
23
+ end
24
+
25
+ should 'raise if application id is not set' do
26
+ JustGiving::Configuration.application_id = nil
27
+ assert_raise JustGiving::InvalidApplicationId do
28
+ JustGiving::Configuration.api_endpoint
29
+ end
30
+ end
31
+
32
+ should 'return the ca_path' do
33
+ assert_equal '/usr/lib/ssl/certs', JustGiving::Configuration.ca_path
34
+ JustGiving::Configuration.ca_path = '/System/Library/OpenSSL/certs'
35
+ assert_equal '/System/Library/OpenSSL/certs', JustGiving::Configuration.ca_path
36
+ end
37
+ end
@@ -0,0 +1,26 @@
1
+ require 'helper'
2
+
3
+ class TestDonation < Test::Unit::TestCase
4
+ def setup
5
+ JustGiving::Configuration.application_id = '2345'
6
+ end
7
+
8
+ context 'getting a donation' do
9
+ should 'return known donation' do
10
+ stub_get('/v1/donation/1/status').to_return(
11
+ :body => fixture('donation_status_success.json'),
12
+ :headers => {:content_type => 'application/json; charset=utf-8'})
13
+ donation = JustGiving::Donation.new(1).status
14
+ assert_equal 2.0, donation['amount']
15
+ assert_equal 1234, donation['donationId']
16
+ assert_equal "Accepted", donation['status']
17
+ end
18
+
19
+ should 'not return unkown donation' do
20
+ stub_get('/v1/donation/1/status').to_raise(JustGiving::NotFound)
21
+ assert_raise JustGiving::NotFound do
22
+ donation = JustGiving::Donation.new(1).status
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ require 'helper'
2
+
3
+ class TestEvent < Test::Unit::TestCase
4
+ def setup
5
+ JustGiving::Configuration.application_id = '2345'
6
+ end
7
+ context 'with an event' do
8
+ setup do
9
+ @event = JustGiving::Event.new(1)
10
+ end
11
+
12
+ should 'get details' do
13
+ stub_get('/v1/event/1').with(:headers => {'Accept'=>'application/json'}).to_return(
14
+ :body => fixture('event_get_success.json'),
15
+ :headers => {:content_type => 'application/json; charset=utf-8'})
16
+ details = @event.details
17
+ assert_equal 12356, details["id"]
18
+ assert_equal "Playing Mario for charity", details["description"]
19
+ end
20
+
21
+ should 'get pages' do
22
+ stub_get('/v1/event/1/pages').with(:headers => {'Accept'=>'application/json'}).to_return(
23
+ :body => fixture('event_pages_success.json'),
24
+ :headers => {:content_type => 'application/json; charset=utf-8'})
25
+ pages = @event.pages
26
+ assert_equal 1234, pages["eventId"]
27
+ assert_equal 1457423, pages["fundraisingPages"].first["pageId"]
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,75 @@
1
+ require 'helper'
2
+
3
+ class TestFundraising < Test::Unit::TestCase
4
+ def setup
5
+ JustGiving::Configuration.application_id = '2345'
6
+ end
7
+
8
+ context 'using basic auth' do
9
+ setup do
10
+ JustGiving::Configuration.username = 'test'
11
+ JustGiving::Configuration.password = 'secret'
12
+ end
13
+
14
+ should 'get pages' do
15
+ stub_get('/v1/fundraising/pages', 'test:secret').with(:headers => {'Accept'=>'application/json'}).to_return(
16
+ :body => fixture('fundraising_pages_success.json'),
17
+ :headers => {:content_type => 'application/json; charset=utf-8'})
18
+ pages = JustGiving::Fundraising.new.pages
19
+ end
20
+
21
+ should 'get donations' do
22
+ stub_get('/v1/fundraising/pages/test/donations?pageNum=1&page_size=50', 'test:secret').with(
23
+ :headers => {'Accept'=>'application/json'}).to_return(
24
+ :body => fixture('fundraising_donations_success.json'),
25
+ :headers => {:content_type => 'application/json; charset=utf-8'})
26
+ pages = JustGiving::Fundraising.new('test').donations
27
+ end
28
+
29
+ should 'set pagination options for donations' do
30
+ stub_get('/v1/fundraising/pages/test/donations?pageNum=2&page_size=10', 'test:secret').with(
31
+ :headers => {'Accept'=>'application/json'}).to_return(
32
+ :body => fixture('fundraising_donations_success.json'),
33
+ :headers => {:content_type => 'application/json; charset=utf-8'})
34
+ pages = JustGiving::Fundraising.new('test').donations(2, 10)
35
+ end
36
+
37
+ should 'create page' do
38
+ stub_put('/v1/fundraising/pages', 'test:secret').with(:headers => {'Accept'=>'application/json'}).to_return(
39
+ :body => fixture('fundraising_pages_success.json'),
40
+ :headers => {:content_type => 'application/json; charset=utf-8'}, :status => 201)
41
+ page = JustGiving::Fundraising.new.create({})
42
+ end
43
+
44
+ should 'update story' do
45
+ stub_post('/v1/fundraising/pages/test', 'test:secret').with(:headers => {'Accept'=>'application/json',
46
+ 'Content-Type'=>'application/json'}, :body => '{"storySupplement":"new story"}').to_return(
47
+ :body => fixture('fundraising_update_story_success.json'),
48
+ :headers => {:content_type => 'application/json; charset=utf-8'}, :status => 200)
49
+ page = JustGiving::Fundraising.new('test').update_story('new story')
50
+ end
51
+ end
52
+
53
+ context 'with no basic auth' do
54
+ should 'check if short name is registered' do
55
+ stub_head('/v1/fundraising/pages/test').with(:headers => {'Accept'=>'application/json'}).to_return(
56
+ :status => 200, :headers => {:content_type => 'application/json; charset=utf-8'})
57
+ assert JustGiving::Fundraising.new('test').short_name_registered?
58
+ end
59
+
60
+ should 'check if short name is registered when not found' do
61
+ stub_head('/v1/fundraising/pages/test').with(:headers => {'Accept'=>'application/json'}).to_return(
62
+ :status => 404, :headers => {:content_type => 'application/json; charset=utf-8'})
63
+ assert !JustGiving::Fundraising.new('test').short_name_registered?
64
+ end
65
+
66
+ should 'get fundraising page' do
67
+ stub_get('/v1/fundraising/pages/test').with(:headers => {'Accept'=>'application/json'}).to_return(
68
+ :body => fixture('fundraising_get_page_success.json'), :status => 200,
69
+ :headers => {:content_type => 'application/json; charset=utf-8'})
70
+ page = JustGiving::Fundraising.new('test').page
71
+ assert_equal "00A246", page["branding"]["buttonColour"]
72
+ assert_equal "261017", page["charity"]["registrationNumber"]
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,32 @@
1
+ require 'helper'
2
+
3
+ class TestSearch < Test::Unit::TestCase
4
+ def setup
5
+ JustGiving::Configuration.application_id = '2345'
6
+ end
7
+
8
+ context 'searching' do
9
+ should 'search with default options' do
10
+ stub_get('/v1/charity/search?q=test&page=1&pageSize=10').to_return(
11
+ :body => fixture('search_success.json'),
12
+ :headers => {:content_type => 'application/json; charset=utf-8'})
13
+ search = JustGiving::Search.new.search_charities('test')
14
+ assert_equal "311", search['charitySearchResults'].first['charityId']
15
+ end
16
+
17
+ should 'use supplied page/per_page' do
18
+ stub_get('/v1/charity/search?q=test&page=2&pageSize=1').to_return(
19
+ :body => fixture('search_success.json'),
20
+ :headers => {:content_type => 'application/json; charset=utf-8'})
21
+ search = JustGiving::Search.new.search_charities('test', 2, 1)
22
+ assert_equal "311", search['charitySearchResults'].first['charityId']
23
+ end
24
+
25
+ should 'not search with invalid options' do
26
+ stub_get('/v1/charity/search?q=&page=2&pageSize=1').to_raise(JustGiving::NotFound)
27
+ assert_raise JustGiving::NotFound do
28
+ search = JustGiving::Search.new.search_charities('', 2, 1)
29
+ end
30
+ end
31
+ end
32
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: just_giving
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Thomas Pomfret
@@ -15,14 +15,24 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-12 00:00:00 +01:00
19
- default_executable:
18
+ date: 2011-08-23 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
21
+ requirement: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ version_requirements: *id001
31
+ name: faraday
22
32
  prerelease: false
23
- name: shoulda
24
- type: :development
25
- version_requirements: &id001 !ruby/object:Gem::Requirement
33
+ type: :runtime
34
+ - !ruby/object:Gem::Dependency
35
+ requirement: &id002 !ruby/object:Gem::Requirement
26
36
  none: false
27
37
  requirements:
28
38
  - - ">="
@@ -31,12 +41,70 @@ dependencies:
31
41
  segments:
32
42
  - 0
33
43
  version: "0"
34
- requirement: *id001
44
+ version_requirements: *id002
45
+ name: faraday_middleware
46
+ prerelease: false
47
+ type: :runtime
35
48
  - !ruby/object:Gem::Dependency
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ version_requirements: *id003
59
+ name: hashie
60
+ prerelease: false
61
+ type: :runtime
62
+ - !ruby/object:Gem::Dependency
63
+ requirement: &id004 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ hash: 21
69
+ segments:
70
+ - 1
71
+ - 0
72
+ - 1
73
+ version: 1.0.1
74
+ version_requirements: *id004
75
+ name: multi_json
76
+ prerelease: false
77
+ type: :runtime
78
+ - !ruby/object:Gem::Dependency
79
+ requirement: &id005 !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ version_requirements: *id005
89
+ name: yajl-ruby
90
+ prerelease: false
91
+ type: :runtime
92
+ - !ruby/object:Gem::Dependency
93
+ requirement: &id006 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ version_requirements: *id006
103
+ name: shoulda
36
104
  prerelease: false
37
- name: bundler
38
105
  type: :development
39
- version_requirements: &id002 !ruby/object:Gem::Requirement
106
+ - !ruby/object:Gem::Dependency
107
+ requirement: &id007 !ruby/object:Gem::Requirement
40
108
  none: false
41
109
  requirements:
42
110
  - - ~>
@@ -47,12 +115,12 @@ dependencies:
47
115
  - 0
48
116
  - 0
49
117
  version: 1.0.0
50
- requirement: *id002
51
- - !ruby/object:Gem::Dependency
118
+ version_requirements: *id007
119
+ name: bundler
52
120
  prerelease: false
53
- name: jeweler
54
121
  type: :development
55
- version_requirements: &id003 !ruby/object:Gem::Requirement
122
+ - !ruby/object:Gem::Dependency
123
+ requirement: &id008 !ruby/object:Gem::Requirement
56
124
  none: false
57
125
  requirements:
58
126
  - - ~>
@@ -63,12 +131,26 @@ dependencies:
63
131
  - 6
64
132
  - 4
65
133
  version: 1.6.4
66
- requirement: *id003
67
- - !ruby/object:Gem::Dependency
134
+ version_requirements: *id008
135
+ name: jeweler
68
136
  prerelease: false
137
+ type: :development
138
+ - !ruby/object:Gem::Dependency
139
+ requirement: &id009 !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ hash: 3
145
+ segments:
146
+ - 0
147
+ version: "0"
148
+ version_requirements: *id009
69
149
  name: rcov
150
+ prerelease: false
70
151
  type: :development
71
- version_requirements: &id004 !ruby/object:Gem::Requirement
152
+ - !ruby/object:Gem::Dependency
153
+ requirement: &id010 !ruby/object:Gem::Requirement
72
154
  none: false
73
155
  requirements:
74
156
  - - ">="
@@ -77,7 +159,10 @@ dependencies:
77
159
  segments:
78
160
  - 0
79
161
  version: "0"
80
- requirement: *id004
162
+ version_requirements: *id010
163
+ name: webmock
164
+ prerelease: false
165
+ type: :development
81
166
  description: A ruby wrapper for the justgiving.com API
82
167
  email: thomas@mintdigital.com
83
168
  executables: []
@@ -94,15 +179,47 @@ files:
94
179
  - README.md
95
180
  - Rakefile
96
181
  - just_giving.gemspec
182
+ - lib/faraday/raise_http_4xx.rb
183
+ - lib/faraday/raise_http_5xx.rb
97
184
  - lib/just_giving.rb
98
- - lib/just_giving/config.rb
185
+ - lib/just_giving/account.rb
186
+ - lib/just_giving/api.rb
187
+ - lib/just_giving/charity.rb
188
+ - lib/just_giving/configuration.rb
189
+ - lib/just_giving/connection.rb
190
+ - lib/just_giving/donation.rb
191
+ - lib/just_giving/error.rb
192
+ - lib/just_giving/event.rb
193
+ - lib/just_giving/fundraising.rb
99
194
  - lib/just_giving/railtie.rb
195
+ - lib/just_giving/request.rb
196
+ - lib/just_giving/response.rb
197
+ - lib/just_giving/search.rb
100
198
  - lib/just_giving/simple_donation_integration.rb
101
199
  - lib/just_giving/version.rb
102
200
  - lib/just_giving/view_helpers.rb
201
+ - test/fixtures/account_create_fail.json
202
+ - test/fixtures/account_create_success.json
203
+ - test/fixtures/account_list_all_pages.json
204
+ - test/fixtures/charity_auth_success.json
205
+ - test/fixtures/charity_get_success.json
206
+ - test/fixtures/donation_status_success.json
207
+ - test/fixtures/event_get_success.json
208
+ - test/fixtures/event_pages_success.json
209
+ - test/fixtures/fundraising_donations_success.json
210
+ - test/fixtures/fundraising_get_page_success.json
211
+ - test/fixtures/fundraising_pages_success.json
212
+ - test/fixtures/fundraising_update_story_success.json
213
+ - test/fixtures/search_success.json
103
214
  - test/helper.rb
215
+ - test/test_account.rb
216
+ - test/test_charity.rb
217
+ - test/test_configuration.rb
218
+ - test/test_donation.rb
219
+ - test/test_event.rb
220
+ - test/test_fundraising.rb
221
+ - test/test_search.rb
104
222
  - test/test_simple_donation_integration.rb
105
- has_rdoc: true
106
223
  homepage: http://github.com/mintdigital/just_giving
107
224
  licenses:
108
225
  - MIT
@@ -132,7 +249,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
249
  requirements: []
133
250
 
134
251
  rubyforge_project:
135
- rubygems_version: 1.4.1
252
+ rubygems_version: 1.8.8
136
253
  signing_key:
137
254
  specification_version: 3
138
255
  summary: A ruby wrapper for the justgiving.com API