just_giving 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.4"
12
+ gem "rcov", ">= 0"
13
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Mint Digital
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ just_giving
2
+ ===========
3
+
4
+ A ruby wrapper for the justgiving.com API
5
+
6
+ Installation
7
+ ------------
8
+
9
+ gem install just_giving
10
+
11
+ Usage
12
+ -----
13
+
14
+ Just giving provides 2 separate API's - Simple Donation Integration (SDI) for making donations and an XML API for querying and creating data.
15
+
16
+ This gem currently provides functionality to link to SDI, if you are using rails you can use view helpers like so:
17
+
18
+ <%= link_to 'Click to donate', just_giving_charity_page_url('short_name') %>
19
+ <%= link_to 'Click to donate', just_giving_charity_donation_page_url('id',
20
+ {:suggested_amount => 2..100000, :donation_id => 'JUSTGIVING-DONATION-ID', :amount => 2..100000,
21
+ :frequency => %w(single monthly), :exit_url => 'http://myredirect.com'}) %>
22
+ <%= link_to 'Click to donate', just_giving_fundraising_page_url('short_url') %>
23
+ <%= link_to 'Click to donate', just_giving_fundraising_donation_url('pageId',
24
+ {:suggested_amount => 2..100000, :amount => 2..100000, :exit_url => 'http://myredirect.com',
25
+ :donation_id => 'JUSTGIVING-DONATION-ID'}) %>)
26
+
27
+ 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
+
29
+ Contributing to just_giving
30
+ ---------------------------
31
+
32
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
33
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
34
+ * Fork the project
35
+ * Start a feature/bugfix branch
36
+ * Commit and push until you are happy with your contribution
37
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
38
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
39
+
40
+ Copyright
41
+ ---------
42
+
43
+ Copyright (c) 2011 Mint Digital. See LICENSE.txt for
44
+ further details.
45
+
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ require 'lib/just_giving/version'
16
+ Jeweler::Tasks.new do |gem|
17
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
18
+ gem.name = "just_giving"
19
+ gem.homepage = "http://github.com/mintdigital/just_giving"
20
+ gem.license = "MIT"
21
+ gem.summary = %Q{A ruby wrapper for the justgiving.com API}
22
+ gem.description = %Q{A ruby wrapper for the justgiving.com API}
23
+ gem.email = "thomas@mintdigital.com"
24
+ gem.authors = ["Thomas Pomfret"]
25
+ gem.version = JustGiving::Version::STRING
26
+ # dependencies defined in Gemfile
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rake/testtask'
31
+ Rake::TestTask.new(:test) do |test|
32
+ test.libs << 'lib' << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+
37
+ require 'rcov/rcovtask'
38
+ Rcov::RcovTask.new do |test|
39
+ test.libs << 'test'
40
+ test.pattern = 'test/**/test_*.rb'
41
+ test.verbose = true
42
+ test.rcov_opts << '--exclude "gems/*"'
43
+ end
44
+
45
+ task :default => :test
46
+
47
+ require 'rake/rdoctask'
48
+ Rake::RDocTask.new do |rdoc|
49
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "just_giving #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
@@ -0,0 +1,62 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{just_giving}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Thomas Pomfret"]
12
+ s.date = %q{2011-08-12}
13
+ s.description = %q{A ruby wrapper for the justgiving.com API}
14
+ s.email = %q{thomas@mintdigital.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "LICENSE.txt",
23
+ "README.md",
24
+ "Rakefile",
25
+ "just_giving.gemspec",
26
+ "lib/just_giving.rb",
27
+ "lib/just_giving/config.rb",
28
+ "lib/just_giving/railtie.rb",
29
+ "lib/just_giving/simple_donation_integration.rb",
30
+ "lib/just_giving/version.rb",
31
+ "lib/just_giving/view_helpers.rb",
32
+ "test/helper.rb",
33
+ "test/test_simple_donation_integration.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/mintdigital/just_giving}
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.4.1}
39
+ s.summary = %q{A ruby wrapper for the justgiving.com API}
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
46
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
47
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
48
+ s.add_development_dependency(%q<rcov>, [">= 0"])
49
+ else
50
+ s.add_dependency(%q<shoulda>, [">= 0"])
51
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
52
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
53
+ s.add_dependency(%q<rcov>, [">= 0"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<shoulda>, [">= 0"])
57
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
59
+ s.add_dependency(%q<rcov>, [">= 0"])
60
+ end
61
+ end
62
+
@@ -0,0 +1,7 @@
1
+ module JustGiving
2
+ class Config
3
+ # cattr_accessor :application_id
4
+
5
+ BASE_URI = "http://www.justgiving.com"
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ require 'just_giving/view_helpers'
2
+ module JustGiving
3
+ class Railtie < Rails::Railtie
4
+ initializer "just_giving.view_helpers" do
5
+ ActionView::Base.send :include, JustGiving::ViewHelpers
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,43 @@
1
+ require 'cgi'
2
+
3
+ module JustGiving
4
+ class SimpleDonationIntegration
5
+ def self.charity_page_url(short_name)
6
+ "#{JustGiving::Config::BASE_URI}/#{short_name}/donate"
7
+ end
8
+
9
+ def self.charity_donation_url(charity_id, options={})
10
+ options = self.parse_options(options)
11
+ url = "#{JustGiving::Config::BASE_URI}/donation/direct/charity/#{charity_id}"
12
+ url << self.options_to_query(options) if options.any?
13
+ url
14
+ end
15
+
16
+ class << self
17
+ alias :fundraising_page_url :charity_page_url
18
+ end
19
+
20
+ def self.fundraising_donation_url(page_id, options={})
21
+ options = self.parse_options(options)
22
+ url = "#{JustGiving::Config::BASE_URI}/donation/sponsor/page/#{page_id}"
23
+ url << self.options_to_query(options) if options.any?
24
+ url
25
+ end
26
+
27
+ private
28
+
29
+ def self.parse_options(options)
30
+ available_options = [:amount, :frequency, :exit_url, :donation_id]
31
+ options.delete_if{|key, value| !available_options.include?(key)}
32
+ end
33
+
34
+ # This is a pretty niave implementation but we control the input so it suffices
35
+ def self.camelize(snake_case_word)
36
+ snake_case_word.to_s.gsub(/_(.)/){$1.upcase}
37
+ end
38
+
39
+ def self.options_to_query(options)
40
+ "?#{options.collect{|k,v| "#{self.camelize(k)}=#{CGI.escape(v.to_s)}"}.join("&")}"
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,9 @@
1
+ module JustGiving
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ PATCH = 0
6
+
7
+ STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ module JustGiving
2
+ module ViewHelpers
3
+ def just_giving_charity_page_url(short_name)
4
+ SimpleDonationIntegration.charity_page_url(short_name)
5
+ end
6
+
7
+ def just_giving_charity_donation_page_url(charity_id, options={})
8
+ SimpleDonationIntegration.charity_donation_url(charity_id, options)
9
+ end
10
+
11
+ def just_giving_fundraising_page_url(short_url)
12
+ SimpleDonationIntegration.fundraising_page_url(short_url)
13
+ end
14
+
15
+ def just_giving_fundraising_donation_url(page_id, options={})
16
+ SimpleDonationIntegration.fundraising_donation_url(page_id, options)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ require 'just_giving/config'
2
+ require 'just_giving/simple_donation_integration'
3
+ require 'just_giving/railtie' if defined?(Rails)
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'just_giving'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,45 @@
1
+ require 'helper'
2
+
3
+ class TestSimpleDonationIntegration < Test::Unit::TestCase
4
+ should "return charity url" do
5
+ assert_equal "http://www.justgiving.com/short_name/donate", JustGiving::SimpleDonationIntegration.charity_page_url('short_name')
6
+ end
7
+
8
+ context "charity donation url" do
9
+ should "return charity donation url" do
10
+ assert_equal "http://www.justgiving.com/donation/direct/charity/2050", JustGiving::SimpleDonationIntegration.charity_donation_url(2050)
11
+ end
12
+
13
+ should "accept valid options" do
14
+ assert_equal "http://www.justgiving.com/donation/direct/charity/2050?amount=2", JustGiving::SimpleDonationIntegration.charity_donation_url(2050, :amount => 2)
15
+ assert_equal "http://www.justgiving.com/donation/direct/charity/2050?frequency=single",
16
+ JustGiving::SimpleDonationIntegration.charity_donation_url(2050, :frequency => 'single')
17
+ assert_equal "http://www.justgiving.com/donation/direct/charity/2050?exitUrl=http%3A%2F%2Fwww.myredirecturl.com%2Fpath",
18
+ JustGiving::SimpleDonationIntegration.charity_donation_url(2050, :exit_url => 'http://www.myredirecturl.com/path')
19
+ assert_equal "http://www.justgiving.com/donation/direct/charity/2050?donationId=JUSTGIVING-DONATION-ID",
20
+ JustGiving::SimpleDonationIntegration.charity_donation_url(2050, :donation_id => 'JUSTGIVING-DONATION-ID')
21
+ end
22
+
23
+ should "reject unknown options" do
24
+ assert_equal "http://www.justgiving.com/donation/direct/charity/2050", JustGiving::SimpleDonationIntegration.charity_donation_url(2050, :bogus => 1)
25
+ end
26
+ end
27
+
28
+ should "return fundraising url" do
29
+ assert_equal "http://www.justgiving.com/test/donate", JustGiving::SimpleDonationIntegration.fundraising_page_url('test')
30
+ end
31
+
32
+ context "fundraising donation url" do
33
+ should "return fundraising donation url" do
34
+ assert_equal "http://www.justgiving.com/donation/sponsor/page/12345", JustGiving::SimpleDonationIntegration.fundraising_donation_url(12345)
35
+ end
36
+
37
+ should "accept valid options" do
38
+ assert_equal "http://www.justgiving.com/donation/sponsor/page/12345?amount=2", JustGiving::SimpleDonationIntegration.fundraising_donation_url(12345, :amount => 2)
39
+ assert_equal "http://www.justgiving.com/donation/sponsor/page/12345?exitUrl=http%3A%2F%2Fwww.myredirecturl.com%2Fpath",
40
+ JustGiving::SimpleDonationIntegration.fundraising_donation_url(12345, :exit_url => 'http://www.myredirecturl.com/path')
41
+ assert_equal "http://www.justgiving.com/donation/sponsor/page/12345?donationId=JUSTGIVING-DONATION-ID",
42
+ JustGiving::SimpleDonationIntegration.fundraising_donation_url(12345, :donation_id => 'JUSTGIVING-DONATION-ID')
43
+ end
44
+ end
45
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: just_giving
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Thomas Pomfret
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-12 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ name: shoulda
24
+ type: :development
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ prerelease: false
37
+ name: bundler
38
+ type: :development
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 23
45
+ segments:
46
+ - 1
47
+ - 0
48
+ - 0
49
+ version: 1.0.0
50
+ requirement: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ prerelease: false
53
+ name: jeweler
54
+ type: :development
55
+ version_requirements: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 7
61
+ segments:
62
+ - 1
63
+ - 6
64
+ - 4
65
+ version: 1.6.4
66
+ requirement: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ prerelease: false
69
+ name: rcov
70
+ type: :development
71
+ version_requirements: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ requirement: *id004
81
+ description: A ruby wrapper for the justgiving.com API
82
+ email: thomas@mintdigital.com
83
+ executables: []
84
+
85
+ extensions: []
86
+
87
+ extra_rdoc_files:
88
+ - LICENSE.txt
89
+ - README.md
90
+ files:
91
+ - .document
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - just_giving.gemspec
97
+ - lib/just_giving.rb
98
+ - lib/just_giving/config.rb
99
+ - lib/just_giving/railtie.rb
100
+ - lib/just_giving/simple_donation_integration.rb
101
+ - lib/just_giving/version.rb
102
+ - lib/just_giving/view_helpers.rb
103
+ - test/helper.rb
104
+ - test/test_simple_donation_integration.rb
105
+ has_rdoc: true
106
+ homepage: http://github.com/mintdigital/just_giving
107
+ licenses:
108
+ - MIT
109
+ post_install_message:
110
+ rdoc_options: []
111
+
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ hash: 3
120
+ segments:
121
+ - 0
122
+ version: "0"
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ hash: 3
129
+ segments:
130
+ - 0
131
+ version: "0"
132
+ requirements: []
133
+
134
+ rubyforge_project:
135
+ rubygems_version: 1.4.1
136
+ signing_key:
137
+ specification_version: 3
138
+ summary: A ruby wrapper for the justgiving.com API
139
+ test_files: []
140
+