justgiving-client 0.1.0
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.
- data/README.rdoc +0 -0
- data/lib/just_giving.rb +9 -0
- data/lib/just_giving/client.rb +22 -0
- data/lib/just_giving/donation.rb +9 -0
- data/lib/just_giving/fundraising_page.rb +9 -0
- data/lib/just_giving/http_client.rb +27 -0
- data/lib/just_giving/user.rb +19 -0
- data/spec/just_giving/client_spec.rb +48 -0
- data/spec/just_giving/user_spec.rb +47 -0
- data/spec/spec_helper.rb +11 -0
- metadata +85 -0
data/README.rdoc
ADDED
File without changes
|
data/lib/just_giving.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
module JustGiving
|
2
|
+
ROOT = File.expand_path('..', __FILE__)
|
3
|
+
|
4
|
+
autoload :Client, ROOT + '/just_giving/client'
|
5
|
+
autoload :HttpClient, ROOT + '/just_giving/http_client'
|
6
|
+
autoload :Donation, ROOT + '/just_giving/donation'
|
7
|
+
autoload :FundraisingPage, ROOT + '/just_giving/fundraising_page'
|
8
|
+
autoload :User, ROOT + '/just_giving/user'
|
9
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module JustGiving
|
2
|
+
class Client
|
3
|
+
def initialize(options)
|
4
|
+
@api_key = options[:api_key]
|
5
|
+
end
|
6
|
+
|
7
|
+
def user(email)
|
8
|
+
User.new(http, email)
|
9
|
+
end
|
10
|
+
|
11
|
+
def donation(id)
|
12
|
+
response = http.get("/donation/#{id}")
|
13
|
+
Donation.new(response)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def http
|
19
|
+
HttpClient.new
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module JustGiving
|
4
|
+
class HttpClient
|
5
|
+
include HTTParty
|
6
|
+
|
7
|
+
format :json
|
8
|
+
base_uri "http://api.justgiving.com"
|
9
|
+
|
10
|
+
def initialize(api_key, version)
|
11
|
+
@api_key = api_key
|
12
|
+
@version = version
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(path, params = {})
|
16
|
+
self.class.get(construct_uri(path), :query => params).parsed_response
|
17
|
+
end
|
18
|
+
|
19
|
+
def post(path, params = {})
|
20
|
+
self.class.post(construct_uri(path), :query => params).parsed_response
|
21
|
+
end
|
22
|
+
|
23
|
+
def construct_uri(path)
|
24
|
+
"/#{api_key}/#{version}#{path}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
module JustGiving
|
4
|
+
class User
|
5
|
+
attr_reader :email
|
6
|
+
|
7
|
+
def initialize(http_client, email)
|
8
|
+
@http_client = http_client
|
9
|
+
@email = email
|
10
|
+
end
|
11
|
+
|
12
|
+
def fundraising_pages
|
13
|
+
response = @http_client.get("/account/#{CGI.escape(@email)}/pages")
|
14
|
+
@pages = response.map do |page_hash|
|
15
|
+
FundraisingPage.new(page_hash)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe JustGiving::Client do
|
4
|
+
include SpecHelper
|
5
|
+
|
6
|
+
before do
|
7
|
+
@client = JustGiving::Client.new(:api_key => api_key)
|
8
|
+
@client.stub(:http).and_return(http_client)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe :donation do
|
12
|
+
before do
|
13
|
+
http_client.should_receive(:get).with("/donation/1234").
|
14
|
+
and_return({
|
15
|
+
"id" => 1234,
|
16
|
+
"image" => "",
|
17
|
+
"hasImage" => false,
|
18
|
+
"donationDate" => "/Date(1321720670900+0000)/",
|
19
|
+
"donorDisplayName" => "Awesome Guy",
|
20
|
+
"message" => "Hope you like my donation.",
|
21
|
+
"estimatedTaxReclaim" => 0.56,
|
22
|
+
"amount" => "2.00",
|
23
|
+
"donorRealName" => "Peter Queue",
|
24
|
+
"thirdPartyReference" => "1234-my-sdi-ref",
|
25
|
+
"status" => "Accepted",
|
26
|
+
"source" => "SponsorshipDonations"
|
27
|
+
})
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:donation) { @client.donation(1234) }
|
31
|
+
|
32
|
+
it "returns a Donation" do
|
33
|
+
donation.should be_a(JustGiving::Donation)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "exposes the donor's real name" do
|
37
|
+
donation.message.should == "Hope you like my donation."
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe :user do
|
42
|
+
it "returns a User" do
|
43
|
+
user = @client.user("bob@me.com")
|
44
|
+
user.should be_a(JustGiving::User)
|
45
|
+
user.email.should == "bob@me.com"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe JustGiving::User do
|
4
|
+
include SpecHelper
|
5
|
+
|
6
|
+
before do
|
7
|
+
@user = JustGiving::User.new(http_client, "bob@me.com")
|
8
|
+
end
|
9
|
+
|
10
|
+
describe :fundraising_pages do
|
11
|
+
before do
|
12
|
+
http_client.should_receive(:get).with("/account/bob%40me.com/pages").
|
13
|
+
and_return([
|
14
|
+
{
|
15
|
+
"pageId" => 1457423,
|
16
|
+
"pageTitle" => "My Fundraising Page!",
|
17
|
+
"pageStatus" => "Active",
|
18
|
+
"pageShortName" => "myJustGivingShortName",
|
19
|
+
"raisedAmount" => 20.0,
|
20
|
+
"designId" => 1,
|
21
|
+
"companyAppealId" => 0,
|
22
|
+
"targetAmount" => 1000.0,
|
23
|
+
"offlineDonations" => 10.0,
|
24
|
+
"totalRaisedOnline" => 50.0,
|
25
|
+
"giftAidPlusSupplement" => 1.25,
|
26
|
+
"pageImages" => [
|
27
|
+
"42010/65f56cc6-3535-436e-927d-eb9c24b82a6e.jpg"
|
28
|
+
],
|
29
|
+
"eventName" => "My Awesome Event",
|
30
|
+
"domain" => "www.justgiving.com",
|
31
|
+
"smsCode" => "PEJN76",
|
32
|
+
"charityId" => 1
|
33
|
+
}
|
34
|
+
])
|
35
|
+
end
|
36
|
+
|
37
|
+
let(:page) { @user.fundraising_pages.first }
|
38
|
+
|
39
|
+
it "returns a FundraisingPage" do
|
40
|
+
page.should be_a(JustGiving::FundraisingPage)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns the page title" do
|
44
|
+
page.title.should == "My Fundraising Page!"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require File.expand_path('../../lib/just_giving', __FILE__)
|
5
|
+
|
6
|
+
module SpecHelper
|
7
|
+
def self.included(spec)
|
8
|
+
spec.let(:api_key) { "justgivingkey" }
|
9
|
+
spec.let(:http_client) { mock JustGiving::HttpClient }
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: justgiving-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matt Gibb
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-11-19 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: httparty
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id002
|
37
|
+
description:
|
38
|
+
email: matt@mattgibb.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- README.rdoc
|
45
|
+
files:
|
46
|
+
- README.rdoc
|
47
|
+
- spec/just_giving/client_spec.rb
|
48
|
+
- spec/just_giving/user_spec.rb
|
49
|
+
- spec/spec_helper.rb
|
50
|
+
- lib/just_giving/client.rb
|
51
|
+
- lib/just_giving/donation.rb
|
52
|
+
- lib/just_giving/fundraising_page.rb
|
53
|
+
- lib/just_giving/http_client.rb
|
54
|
+
- lib/just_giving/user.rb
|
55
|
+
- lib/just_giving.rb
|
56
|
+
homepage: https://github.com/mattgibb/justgiving-client
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options:
|
61
|
+
- --main
|
62
|
+
- README.rdoc
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
requirements: []
|
78
|
+
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 1.8.7
|
81
|
+
signing_key:
|
82
|
+
specification_version: 3
|
83
|
+
summary: API client for JustGiving
|
84
|
+
test_files: []
|
85
|
+
|