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.
- data/Gemfile +8 -0
- data/README.md +40 -1
- data/just_giving.gemspec +58 -7
- data/lib/faraday/raise_http_4xx.rb +29 -0
- data/lib/faraday/raise_http_5xx.rb +28 -0
- data/lib/just_giving.rb +11 -2
- data/lib/just_giving/account.rb +43 -0
- data/lib/just_giving/api.rb +9 -0
- data/lib/just_giving/charity.rb +13 -0
- data/lib/just_giving/configuration.rb +59 -0
- data/lib/just_giving/connection.rb +28 -0
- data/lib/just_giving/donation.rb +17 -0
- data/lib/just_giving/error.rb +9 -0
- data/lib/just_giving/event.rb +17 -0
- data/lib/just_giving/fundraising.rb +51 -0
- data/lib/just_giving/request.rb +40 -0
- data/lib/just_giving/response.rb +9 -0
- data/lib/just_giving/search.rb +13 -0
- data/lib/just_giving/simple_donation_integration.rb +7 -3
- data/lib/just_giving/version.rb +1 -1
- data/test/fixtures/account_create_fail.json +1 -0
- data/test/fixtures/account_create_success.json +3 -0
- data/test/fixtures/account_list_all_pages.json +21 -0
- data/test/fixtures/charity_auth_success.json +5 -0
- data/test/fixtures/charity_get_success.json +1 -0
- data/test/fixtures/donation_status_success.json +7 -0
- data/test/fixtures/event_get_success.json +8 -0
- data/test/fixtures/event_pages_success.json +26 -0
- data/test/fixtures/fundraising_donations_success.json +1 -0
- data/test/fixtures/fundraising_get_page_success.json +1 -0
- data/test/fixtures/fundraising_pages_success.json +1 -0
- data/test/fixtures/fundraising_update_story_success.json +1 -0
- data/test/fixtures/search_success.json +1 -0
- data/test/helper.rb +29 -0
- data/test/test_account.rb +110 -0
- data/test/test_charity.rb +31 -0
- data/test/test_configuration.rb +37 -0
- data/test/test_donation.rb +26 -0
- data/test/test_event.rb +30 -0
- data/test/test_fundraising.rb +75 -0
- data/test/test_search.rb +32 -0
- metadata +139 -22
- data/lib/just_giving/config.rb +0 -7
data/Gemfile
CHANGED
@@ -3,6 +3,13 @@ source "http://rubygems.org"
|
|
3
3
|
# Example:
|
4
4
|
# gem "activesupport", ">= 2.3.5"
|
5
5
|
|
6
|
+
gem "faraday"
|
7
|
+
gem "faraday_middleware"
|
8
|
+
gem "hashie"
|
9
|
+
gem "multi_json", "~> 1.0.1"
|
10
|
+
gem "yajl-ruby"
|
11
|
+
|
12
|
+
|
6
13
|
# Add dependencies to develop your gem here.
|
7
14
|
# Include everything needed to run rake, tests, features, etc.
|
8
15
|
group :development do
|
@@ -10,4 +17,5 @@ group :development do
|
|
10
17
|
gem "bundler", "~> 1.0.0"
|
11
18
|
gem "jeweler", "~> 1.6.4"
|
12
19
|
gem "rcov", ">= 0"
|
20
|
+
gem "webmock"
|
13
21
|
end
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
just_giving
|
2
2
|
===========
|
3
3
|
|
4
|
-
A ruby wrapper for the justgiving.com API
|
4
|
+
A ruby wrapper for the justgiving.com API (https://api.justgiving.com/docs)
|
5
5
|
|
6
6
|
Installation
|
7
7
|
------------
|
@@ -11,6 +11,8 @@ Installation
|
|
11
11
|
Usage
|
12
12
|
-----
|
13
13
|
|
14
|
+
### Simple Donation Integration
|
15
|
+
|
14
16
|
Just giving provides 2 separate API's - Simple Donation Integration (SDI) for making donations and an XML API for querying and creating data.
|
15
17
|
|
16
18
|
This gem currently provides functionality to link to SDI, if you are using rails you can use view helpers like so:
|
@@ -26,6 +28,43 @@ This gem currently provides functionality to link to SDI, if you are using rails
|
|
26
28
|
|
27
29
|
As you can see just_giving_charity_donation_page_url and just_giving_fundraising_donation_url take and optional options hash - supply as many or as few of these as you need.
|
28
30
|
|
31
|
+
### API
|
32
|
+
|
33
|
+
#### Configure
|
34
|
+
|
35
|
+
JustGiving::Configuration.application_id = YOUR_APP_ID
|
36
|
+
|
37
|
+
JustGiving::Configuration.ca_path = "/System/Library/OpenSSL/certs" # (defaults to "/usr/lib/ssl/certs")
|
38
|
+
|
39
|
+
JustGiving::Configuration.environment = :production (defaults to :staging)
|
40
|
+
|
41
|
+
JustGiving::Configuration.username = 'test@example.com' # Needed for actions that require auth
|
42
|
+
|
43
|
+
JustGiving::Configuration.password = 'secret' # Needed for actions that require auth
|
44
|
+
|
45
|
+
#### Account calls
|
46
|
+
JustGiving::Account.new(YOUR_EMAIL).pages
|
47
|
+
|
48
|
+
JustGiving::Account.new.create({:title => 'Mr', :firstName => 'Test', :lastName => 'McTest', :address => {:line1 => 'Unit 100', :townOrCity => 'London', :country => 'UK', :postcodeOrZipcode => 'ec1r 0jh'}, :email => 'test@example.com', :password => 'password', :acceptTermsAndConditions => true})
|
49
|
+
|
50
|
+
#### Fundraising calls
|
51
|
+
JustGiving::Fundraising.new('short-name').donations
|
52
|
+
|
53
|
+
For further examples please check the tests
|
54
|
+
|
55
|
+
Note that a 404 will raise a JustGiving::NotFound error
|
56
|
+
|
57
|
+
A 400 response means the params supplied are wrong - this will return an errors collection with the details, eg:
|
58
|
+
|
59
|
+
response = JustGiving::Account.new('unkown@unkown.com').password_reminder
|
60
|
+
|
61
|
+
response.errors # errors array
|
62
|
+
|
63
|
+
TODO
|
64
|
+
----
|
65
|
+
|
66
|
+
* Finish off all calls
|
67
|
+
|
29
68
|
Contributing to just_giving
|
30
69
|
---------------------------
|
31
70
|
|
data/just_giving.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{just_giving}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = [
|
12
|
-
s.date = %q{2011-08-
|
11
|
+
s.authors = [%q{Thomas Pomfret}]
|
12
|
+
s.date = %q{2011-08-23}
|
13
13
|
s.description = %q{A ruby wrapper for the justgiving.com API}
|
14
14
|
s.email = %q{thomas@mintdigital.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -23,40 +23,91 @@ Gem::Specification.new do |s|
|
|
23
23
|
"README.md",
|
24
24
|
"Rakefile",
|
25
25
|
"just_giving.gemspec",
|
26
|
+
"lib/faraday/raise_http_4xx.rb",
|
27
|
+
"lib/faraday/raise_http_5xx.rb",
|
26
28
|
"lib/just_giving.rb",
|
27
|
-
"lib/just_giving/
|
29
|
+
"lib/just_giving/account.rb",
|
30
|
+
"lib/just_giving/api.rb",
|
31
|
+
"lib/just_giving/charity.rb",
|
32
|
+
"lib/just_giving/configuration.rb",
|
33
|
+
"lib/just_giving/connection.rb",
|
34
|
+
"lib/just_giving/donation.rb",
|
35
|
+
"lib/just_giving/error.rb",
|
36
|
+
"lib/just_giving/event.rb",
|
37
|
+
"lib/just_giving/fundraising.rb",
|
28
38
|
"lib/just_giving/railtie.rb",
|
39
|
+
"lib/just_giving/request.rb",
|
40
|
+
"lib/just_giving/response.rb",
|
41
|
+
"lib/just_giving/search.rb",
|
29
42
|
"lib/just_giving/simple_donation_integration.rb",
|
30
43
|
"lib/just_giving/version.rb",
|
31
44
|
"lib/just_giving/view_helpers.rb",
|
45
|
+
"test/fixtures/account_create_fail.json",
|
46
|
+
"test/fixtures/account_create_success.json",
|
47
|
+
"test/fixtures/account_list_all_pages.json",
|
48
|
+
"test/fixtures/charity_auth_success.json",
|
49
|
+
"test/fixtures/charity_get_success.json",
|
50
|
+
"test/fixtures/donation_status_success.json",
|
51
|
+
"test/fixtures/event_get_success.json",
|
52
|
+
"test/fixtures/event_pages_success.json",
|
53
|
+
"test/fixtures/fundraising_donations_success.json",
|
54
|
+
"test/fixtures/fundraising_get_page_success.json",
|
55
|
+
"test/fixtures/fundraising_pages_success.json",
|
56
|
+
"test/fixtures/fundraising_update_story_success.json",
|
57
|
+
"test/fixtures/search_success.json",
|
32
58
|
"test/helper.rb",
|
59
|
+
"test/test_account.rb",
|
60
|
+
"test/test_charity.rb",
|
61
|
+
"test/test_configuration.rb",
|
62
|
+
"test/test_donation.rb",
|
63
|
+
"test/test_event.rb",
|
64
|
+
"test/test_fundraising.rb",
|
65
|
+
"test/test_search.rb",
|
33
66
|
"test/test_simple_donation_integration.rb"
|
34
67
|
]
|
35
68
|
s.homepage = %q{http://github.com/mintdigital/just_giving}
|
36
|
-
s.licenses = [
|
37
|
-
s.require_paths = [
|
38
|
-
s.rubygems_version = %q{1.
|
69
|
+
s.licenses = [%q{MIT}]
|
70
|
+
s.require_paths = [%q{lib}]
|
71
|
+
s.rubygems_version = %q{1.8.8}
|
39
72
|
s.summary = %q{A ruby wrapper for the justgiving.com API}
|
40
73
|
|
41
74
|
if s.respond_to? :specification_version then
|
42
75
|
s.specification_version = 3
|
43
76
|
|
44
77
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
78
|
+
s.add_runtime_dependency(%q<faraday>, [">= 0"])
|
79
|
+
s.add_runtime_dependency(%q<faraday_middleware>, [">= 0"])
|
80
|
+
s.add_runtime_dependency(%q<hashie>, [">= 0"])
|
81
|
+
s.add_runtime_dependency(%q<multi_json>, ["~> 1.0.1"])
|
82
|
+
s.add_runtime_dependency(%q<yajl-ruby>, [">= 0"])
|
45
83
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
46
84
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
47
85
|
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
48
86
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
87
|
+
s.add_development_dependency(%q<webmock>, [">= 0"])
|
49
88
|
else
|
89
|
+
s.add_dependency(%q<faraday>, [">= 0"])
|
90
|
+
s.add_dependency(%q<faraday_middleware>, [">= 0"])
|
91
|
+
s.add_dependency(%q<hashie>, [">= 0"])
|
92
|
+
s.add_dependency(%q<multi_json>, ["~> 1.0.1"])
|
93
|
+
s.add_dependency(%q<yajl-ruby>, [">= 0"])
|
50
94
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
51
95
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
52
96
|
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
53
97
|
s.add_dependency(%q<rcov>, [">= 0"])
|
98
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
54
99
|
end
|
55
100
|
else
|
101
|
+
s.add_dependency(%q<faraday>, [">= 0"])
|
102
|
+
s.add_dependency(%q<faraday_middleware>, [">= 0"])
|
103
|
+
s.add_dependency(%q<hashie>, [">= 0"])
|
104
|
+
s.add_dependency(%q<multi_json>, ["~> 1.0.1"])
|
105
|
+
s.add_dependency(%q<yajl-ruby>, [">= 0"])
|
56
106
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
57
107
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
58
108
|
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
59
109
|
s.add_dependency(%q<rcov>, [">= 0"])
|
110
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
60
111
|
end
|
61
112
|
end
|
62
113
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
class Response::RaiseHttp4xx < Response::Middleware
|
5
|
+
def on_complete(env)
|
6
|
+
env[:response].on_complete do |response|
|
7
|
+
case response[:status].to_i
|
8
|
+
when 404
|
9
|
+
raise JustGiving::NotFound, error_message(response)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def error_message(response)
|
17
|
+
"#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]} #{error_body(response[:body])}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def error_body(body)
|
21
|
+
body = MultiJson.decode(body)
|
22
|
+
if body.nil?
|
23
|
+
nil
|
24
|
+
elsif body.any?
|
25
|
+
body.collect{|error| "#{error['id']} #{error['desc']}"}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
class Response::RaiseHttp5xx < Response::Middleware
|
5
|
+
def on_complete(env)
|
6
|
+
env[:response].on_complete do |response|
|
7
|
+
case response[:status].to_i
|
8
|
+
when 500
|
9
|
+
raise JustGiving::InternalServerError, error_message(response)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def error_message(response)
|
17
|
+
"#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]} #{error_body(response[:body])}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def error_body(body)
|
21
|
+
if body.nil?
|
22
|
+
nil
|
23
|
+
elsif body['error']
|
24
|
+
body['error']['id']
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/just_giving.rb
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
-
require 'just_giving/
|
1
|
+
require 'just_giving/error'
|
2
|
+
require 'just_giving/response'
|
3
|
+
require 'just_giving/configuration'
|
2
4
|
require 'just_giving/simple_donation_integration'
|
3
|
-
require 'just_giving/
|
5
|
+
require 'just_giving/api'
|
6
|
+
require 'just_giving/account'
|
7
|
+
require 'just_giving/charity'
|
8
|
+
require 'just_giving/event'
|
9
|
+
require 'just_giving/fundraising'
|
10
|
+
require 'just_giving/search'
|
11
|
+
require 'just_giving/donation'
|
12
|
+
require 'just_giving/railtie' if defined?(Rails)
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module JustGiving
|
2
|
+
class Account < API
|
3
|
+
def initialize(email=nil)
|
4
|
+
@email = email
|
5
|
+
end
|
6
|
+
|
7
|
+
# This lists all the fundraising pages for the supplied email
|
8
|
+
def pages
|
9
|
+
get("v1/account/#{@email}/pages")
|
10
|
+
end
|
11
|
+
|
12
|
+
# This creates an user account with Just Giving
|
13
|
+
def create(params)
|
14
|
+
put('v1/account', params)
|
15
|
+
end
|
16
|
+
|
17
|
+
# This validates a username/password
|
18
|
+
def validate(params)
|
19
|
+
post('v1/account/validate', params)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Confirm if an email is available or not
|
23
|
+
def available?
|
24
|
+
begin
|
25
|
+
head("v1/account/#{@email}")
|
26
|
+
return false
|
27
|
+
rescue JustGiving::NotFound
|
28
|
+
return true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Update password
|
33
|
+
def change_password(params)
|
34
|
+
post('v1/account/changePassword', params)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Send password reminder
|
38
|
+
def password_reminder
|
39
|
+
response = get("v1/account/#{@email}/requestpasswordreminder")
|
40
|
+
(response && response.errors) ? response : true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module JustGiving
|
2
|
+
class Configuration
|
3
|
+
BASE_URI = "http://www.justgiving.com"
|
4
|
+
|
5
|
+
@@application_id = nil
|
6
|
+
@@environment = :staging
|
7
|
+
@@ca_path = "/usr/lib/ssl/certs"
|
8
|
+
|
9
|
+
## This is your Just Giving application id
|
10
|
+
def self.application_id
|
11
|
+
@@application_id
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.application_id=(id)
|
15
|
+
@@application_id = id
|
16
|
+
end
|
17
|
+
|
18
|
+
## This can be either :staging or :production and sets what endpoint to use
|
19
|
+
def self.environment=(env)
|
20
|
+
@@environment = env
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.environment
|
24
|
+
@@environment
|
25
|
+
end
|
26
|
+
|
27
|
+
## The API endpoint
|
28
|
+
def self.api_endpoint
|
29
|
+
raise JustGiving::InvalidApplicationId.new if !application_id
|
30
|
+
environment == :staging ? "https://api.staging.justgiving.com/#{application_id}" : "https://api.justgiving.com/#{application_id}"
|
31
|
+
end
|
32
|
+
|
33
|
+
## Path to the systems CA cert bundles
|
34
|
+
def self.ca_path=(path)
|
35
|
+
@@ca_path = path
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.ca_path
|
39
|
+
@@ca_path
|
40
|
+
end
|
41
|
+
|
42
|
+
## Username/password for basic auth
|
43
|
+
def self.username
|
44
|
+
@@username
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.username=(username)
|
48
|
+
@@username = username
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.password=(password)
|
52
|
+
@@password = password
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.password
|
56
|
+
@@password
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
require 'faraday/raise_http_4xx'
|
3
|
+
require 'faraday/raise_http_5xx'
|
4
|
+
|
5
|
+
module JustGiving
|
6
|
+
module Connection
|
7
|
+
private
|
8
|
+
|
9
|
+
def connection(basic_auth=false)
|
10
|
+
options = {
|
11
|
+
:headers => {'Accept' => "application/json"},
|
12
|
+
:url => JustGiving::Configuration.api_endpoint,
|
13
|
+
:ssl => {:ca_path => JustGiving::Configuration.ca_path, :verify => false}
|
14
|
+
}
|
15
|
+
|
16
|
+
connection = Faraday::Connection.new(options) do |connection|
|
17
|
+
connection.use Faraday::Request::JSON
|
18
|
+
connection.use Faraday::Adapter::NetHttp
|
19
|
+
connection.use Faraday::Response::ParseJson
|
20
|
+
connection.use Faraday::Response::RaiseHttp4xx
|
21
|
+
connection.use Faraday::Response::RaiseHttp5xx
|
22
|
+
connection.use Faraday::Response::Mashify
|
23
|
+
end
|
24
|
+
connection.basic_auth(JustGiving::Configuration.username, JustGiving::Configuration.password) if basic_auth
|
25
|
+
connection
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module JustGiving
|
2
|
+
class Donation < API
|
3
|
+
def initialize(id)
|
4
|
+
@id = id
|
5
|
+
end
|
6
|
+
|
7
|
+
# Get the details of a specific donation
|
8
|
+
def details
|
9
|
+
get("v1/donation/#{@id}")
|
10
|
+
end
|
11
|
+
|
12
|
+
# Get the status of a specific donation
|
13
|
+
def status
|
14
|
+
get("v1/donation/#{@id}/status")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|