justgiving_client 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
File without changes
@@ -0,0 +1,9 @@
1
+ module JustGiving
2
+ ROOT = File.expand_path('..', __FILE__)
3
+
4
+ autoload :Client, ROOT + '/justgiving_client/client'
5
+ autoload :HttpClient, ROOT + '/justgiving_client/http_client'
6
+ autoload :Donation, ROOT + '/justgiving_client/donation'
7
+ autoload :FundraisingPage, ROOT + '/justgiving_client/fundraising_page'
8
+ autoload :User, ROOT + '/justgiving_client/user'
9
+ end
@@ -0,0 +1,30 @@
1
+ module JustGiving
2
+ # The main client, through which you interact with JustGiving
3
+ class Client
4
+ # Create a spangly new client instance
5
+ #
6
+ # Example:
7
+ # >> client = JustGiving::Client.new(:api_key => "my_key")
8
+ # => #<JustGiving::Client:0x000001009c6f98 @api_key="my_key">
9
+ def initialize(options)
10
+ @api_key = options[:api_key]
11
+ end
12
+
13
+ # Get a user by their email
14
+ def user(email)
15
+ User.new(http, email)
16
+ end
17
+
18
+ # Get a donation by it's id
19
+ def donation(id)
20
+ response = http.get("/donation/#{id}")
21
+ Donation.new(response)
22
+ end
23
+
24
+ private
25
+ # A class to handle all the nitty-gritty of the web interface
26
+ def http
27
+ HttpClient.new
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,9 @@
1
+ module JustGiving
2
+ class Donation
3
+ attr_reader :message
4
+
5
+ def initialize(response)
6
+ @message = response["message"]
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module JustGiving
2
+ class FundraisingPage
3
+ attr_reader :title
4
+
5
+ def initialize(hash)
6
+ @title = hash["pageTitle"]
7
+ end
8
+ end
9
+ 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,3 @@
1
+ module JustGiving
2
+ VERSION = "0.2.0"
3
+ 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
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require File.expand_path('../../lib/justgiving_client', __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,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: justgiving_client
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.2.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: An object-graph interpretation of the JustGiving API in Ruby
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/justgiving_client/client_spec.rb
48
+ - spec/justgiving_client/user_spec.rb
49
+ - spec/spec_helper.rb
50
+ - lib/justgiving_client/client.rb
51
+ - lib/justgiving_client/donation.rb
52
+ - lib/justgiving_client/fundraising_page.rb
53
+ - lib/justgiving_client/http_client.rb
54
+ - lib/justgiving_client/user.rb
55
+ - lib/justgiving_client/version.rb
56
+ - lib/justgiving_client.rb
57
+ homepage: https://github.com/mattgibb/justgiving_client
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options:
62
+ - --main
63
+ - README.rdoc
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 1.8.7
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: API client for JustGiving
85
+ test_files: []
86
+