bolseragency-just-giving 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README +27 -0
- data/Rakefile +47 -0
- data/VERSION +1 -0
- data/lib/just-giving.rb +39 -0
- data/spec/just-giving_spec.rb +16 -0
- data/spec/spec_helper.rb +9 -0
- metadata +63 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 mattfawcett
|
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
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
just-giving
|
2
|
+
|
3
|
+
#Install the gem
|
4
|
+
gem sources -a http://gems.github.com
|
5
|
+
gem install bolseragency-just-giving
|
6
|
+
|
7
|
+
#To get the donations from the just giving page http://www.justgiving.com/abac2c
|
8
|
+
donations = JustGiving::Donations.new(event_name = "abac2c")
|
9
|
+
|
10
|
+
#get a count
|
11
|
+
donations.length #=> 49
|
12
|
+
|
13
|
+
#get details of of donation with index 5
|
14
|
+
donations[5] #=> {:date=>#<Date: 4909905/2,0,2299161>, :name=>"Laura", :amount=>10.0, :comment=>"Good Luck team ABA!!!!"}
|
15
|
+
|
16
|
+
#loop through each and diplay details
|
17
|
+
donations.each do |donation|
|
18
|
+
puts "name is #{donation[:name]}"
|
19
|
+
puts "date is #{donation[:date]}"
|
20
|
+
puts "amount is #{donation[:amout]}"
|
21
|
+
puts "comment is #{donation[:comment]}"
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
== Copyright
|
26
|
+
|
27
|
+
Copyright (c) 2009 Ashley Bolser Agency. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "just-giving"
|
8
|
+
gem.summary = "Just giving donations parser"
|
9
|
+
gem.email = "matt@bolseragency.com"
|
10
|
+
gem.homepage = "http://github.com/bolseragency/just-giving"
|
11
|
+
gem.authors = ["mattfawcett"]
|
12
|
+
end
|
13
|
+
|
14
|
+
rescue LoadError
|
15
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'spec/rake/spectask'
|
19
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
20
|
+
spec.libs << 'lib' << 'spec'
|
21
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
22
|
+
end
|
23
|
+
|
24
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
25
|
+
spec.libs << 'lib' << 'spec'
|
26
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
27
|
+
spec.rcov = true
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
task :default => :spec
|
32
|
+
|
33
|
+
require 'rake/rdoctask'
|
34
|
+
Rake::RDocTask.new do |rdoc|
|
35
|
+
if File.exist?('VERSION.yml')
|
36
|
+
config = YAML.load(File.read('VERSION.yml'))
|
37
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
38
|
+
else
|
39
|
+
version = ""
|
40
|
+
end
|
41
|
+
|
42
|
+
rdoc.rdoc_dir = 'rdoc'
|
43
|
+
rdoc.title = "just-giving #{version}"
|
44
|
+
rdoc.rdoc_files.include('README*')
|
45
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
+
end
|
47
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/lib/just-giving.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module JustGiving
|
2
|
+
require 'rubygems'
|
3
|
+
require 'hpricot'
|
4
|
+
require 'open-uri'
|
5
|
+
|
6
|
+
class Donations
|
7
|
+
attr_accessor :doc
|
8
|
+
|
9
|
+
def initialize(event_name)
|
10
|
+
self.doc = Hpricot(open("http://www.justgiving.com/#{event_name}"))
|
11
|
+
end
|
12
|
+
|
13
|
+
def each
|
14
|
+
(doc/"tr[@class='sponsorRowEven']|tr[@class='sponsorRowOdd']").each do |table_row|
|
15
|
+
name = (table_row/"td")[0].inner_html.strip.gsub(" ", "")
|
16
|
+
date = Date.strptime( (table_row/"td")[1].inner_html.strip, format = '%d/%m/%Y' )
|
17
|
+
amount = (table_row/"td")[2].inner_html.strip.gsub(/£|\$/, "").to_f
|
18
|
+
comment = (table_row/"td")[4].inner_html.strip.gsub(" ", "")
|
19
|
+
yield({:name => name, :date => date, :amount => amount, :comment => comment})
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def length
|
24
|
+
counter = 0
|
25
|
+
self.each {counter += 1}
|
26
|
+
return counter
|
27
|
+
end
|
28
|
+
|
29
|
+
def [](index)
|
30
|
+
counter = 0
|
31
|
+
self.each do |row|
|
32
|
+
return row if counter == index
|
33
|
+
counter +=1
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "JustGiving" do
|
4
|
+
it "should parse get the correct number of donations" do
|
5
|
+
donations = JustGiving::Donations.new("abac2c")
|
6
|
+
donations.length.should eql(49)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should have name, date, amount and comment" do
|
10
|
+
donations = JustGiving::Donations.new("abac2c")
|
11
|
+
donations[5][:name].should eql("Laura")
|
12
|
+
donations[5][:date].to_s.should eql("2009-05-01")
|
13
|
+
donations[5][:amount].should eql(10.0)
|
14
|
+
donations[5][:comment].should eql("Good Luck team ABA!!!!")
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bolseragency-just-giving
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mattfawcett
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-19 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: matt@bolseragency.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README
|
25
|
+
files:
|
26
|
+
- .document
|
27
|
+
- .gitignore
|
28
|
+
- LICENSE
|
29
|
+
- README
|
30
|
+
- Rakefile
|
31
|
+
- VERSION
|
32
|
+
- lib/just-giving.rb
|
33
|
+
- spec/just-giving_spec.rb
|
34
|
+
- spec/spec_helper.rb
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: http://github.com/bolseragency/just-giving
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options:
|
39
|
+
- --charset=UTF-8
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.2.0
|
58
|
+
signing_key:
|
59
|
+
specification_version: 2
|
60
|
+
summary: Just giving donations parser
|
61
|
+
test_files:
|
62
|
+
- spec/just-giving_spec.rb
|
63
|
+
- spec/spec_helper.rb
|