fiftyfifty 0.4.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/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.6.4)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.9.2)
10
+ rcov (0.9.10)
11
+ shoulda (2.11.3)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.0.0)
18
+ jeweler (~> 1.6.4)
19
+ rcov
20
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Peter Hamilton
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,57 @@
1
+ Fifty Fifty API Gem
2
+ ======
3
+
4
+ What is it?
5
+ -----------
6
+ A Gem for interacting with the API for the 5050 project. Read more about the project [Here](http://http://www.5050.gd/)
7
+
8
+ Simple usage session example:
9
+
10
+ Set up
11
+
12
+ ```ruby
13
+ ruby-1.9.2-p180 :001 > ff = FiftyFifty.new('XXXXXXXXXXXXXXXXXXXXXXXXXXX')
14
+ => #<FiftyFifty:0x00000101f5f6e8 @api_key="XXXXXXXXXXXXXXXXXXXXXXXXXXX">
15
+ ```
16
+
17
+ Play!
18
+
19
+ ```ruby
20
+ ruby-1.9.2-p180 :002 > ff.statistics
21
+ => <#Hashie::Mash backer_count=91 donation_count=69 donation_total=3319.2 project_count=11>
22
+ ruby-1.9.2-p180 :003 > ff.statistics.project_count
23
+ => 11
24
+ ruby-1.9.2-p180 :004 > ff.projects.length
25
+ => 11
26
+ ruby-1.9.2-p180 :005 > ff.projects.map(&:title)
27
+ => ["Give-a-gram", "The Fat Planner", "Facebook Famine", "Fight the Famine", "Hangouts for Charity", "#f*ckfamine SwearJar", "Toilet to Pocket", "4words", "Space for Change", "I give a buck, now you give a f**k!", "#AfricaNeedsYou"]
28
+ ruby-1.9.2-p180 :006 > class Array; def mean; sum / size; end; end
29
+ => nil
30
+ ruby-1.9.2-p180 :007 > ff.project_donations(ff.projects[1].id).map(&:amount)
31
+ => [2.0, 306.0, 10.0, 30.0, 2.0, 8.0, 25.0, 61.0, 61.2, 61.0, 20.0, 20.0, 100.0, 306.0, 30.0, 100.0, 10.0, 30.0, 12.0, 100.0, 18.0, 20.0, 5.0, 45.0, 10.0, 100.0, 12.0, 10.0, 609.0, 15.0, 60.0, 15.0, 30.0, 15.0, 182.0, 60.0, 60.0, 60.0, 82.0]
32
+ ruby-1.9.2-p180 :008 > ff.project_donations(ff.projects[1].id).map(&:amount).mean.round(1)
33
+ => 69.3
34
+ ruby-1.9.2-p180 :009 > ff.campaigners.each do |c| puts "#{c.name} from (#{c.location})" end
35
+ Made by Many from (London, UK)
36
+ Public House from (Manchester, UK)
37
+ Alejandro Lozada from (Mexico City)
38
+ 15 Million Elephants from (Colorado, USA)
39
+ Tom and Syd from (London & Winchester, UK)
40
+ Albion London from (London, UK)
41
+ Relax in the Air from (Switzerland)
42
+ Mint Digital from (London, UK)
43
+ Chameleon from (UK)
44
+ Unicef from (global)
45
+ Good for Nothing from (UK)
46
+ Victors & Spoils from (Colorado)
47
+ Arnold Worldwide from (Global)
48
+ The Social Practice from (London, UK)
49
+ She Says from (Global)
50
+ Independents United from (London, UK)
51
+ GFN collective from (UK)
52
+ For Love Not Money from (UK)
53
+ Because Studio from (UK)
54
+ Jack & Paul / Enjoythis from (UK)
55
+ Enjoythis from (UK)
56
+ Disrupt4Good from (London, UK)
57
+ ```
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = fiftyfifty
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to fiftyfifty
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * 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.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Peter Hamilton. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
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
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "fiftyfifty"
18
+ gem.homepage = "http://github.com/peterhamilton/fiftyfifty"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{An API Wrapper for the 5050 Project API}
21
+ gem.description = %Q{An API Wrapper for the 5050 Project API}
22
+ gem.email = "peter@inspiredpixel.net"
23
+ gem.authors = ["Peter Hamilton"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "fiftyfifty #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.4.0
@@ -0,0 +1,61 @@
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 = "fiftyfifty"
8
+ s.version = "0.4.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Peter Hamilton"]
12
+ s.date = "2011-09-12"
13
+ s.description = "An API Wrapper for the 5050 Project API"
14
+ s.email = "peter@inspiredpixel.net"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "fiftyfifty.gemspec",
30
+ "lib/fiftyfifty.rb",
31
+ "test/helper.rb",
32
+ "test/test_fiftyfifty.rb"
33
+ ]
34
+ s.homepage = "http://github.com/peterhamilton/fiftyfifty"
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = "1.8.10"
38
+ s.summary = "An API Wrapper for the 5050 Project API"
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
45
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
46
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
47
+ s.add_development_dependency(%q<rcov>, [">= 0"])
48
+ else
49
+ s.add_dependency(%q<shoulda>, [">= 0"])
50
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
51
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
52
+ s.add_dependency(%q<rcov>, [">= 0"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<shoulda>, [">= 0"])
56
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
57
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
58
+ s.add_dependency(%q<rcov>, [">= 0"])
59
+ end
60
+ end
61
+
data/lib/fiftyfifty.rb ADDED
@@ -0,0 +1,74 @@
1
+ require 'httparty'
2
+ require 'hashie'
3
+
4
+ class FiftyFifty
5
+ include HTTParty
6
+
7
+ class BadRequest < StandardError; end
8
+
9
+ format :json
10
+
11
+ def initialize(api_key)
12
+ @api_key = api_key
13
+ self.class.base_uri "5050.gd/api/#{@api_key}"
14
+ end
15
+
16
+ def statistics
17
+ return get("/statistics")
18
+ end
19
+
20
+ # Lists all current 50/50 projects.
21
+ def projects
22
+ return get("/projects/list")
23
+ end
24
+
25
+ # Show details for specific project.
26
+ def project_details(project_id)
27
+ return get("/projects/#{project_id}")
28
+ end
29
+
30
+ # List donations for a specific project.
31
+ def project_donations(project_id)
32
+ return get("/projects/#{project_id}/donations")
33
+ end
34
+
35
+ # Notify us of a new donation, i.e. one that you may have received in person,
36
+ # or from another online payment mechanism. Your API key must be associated
37
+ # with the requested project for this to be successful.
38
+ def register_project_donation(project_id, amount)
39
+ return get("/projects/#{project_id}/donations/notify/#{amount}")
40
+ end
41
+
42
+ # List of users who have pledged to take part in a specific project.
43
+ def project_pledges(project_id)
44
+ return get("/projects/#{project_id}/pledges")
45
+ end
46
+
47
+
48
+ # List all campaigners currently running projects on 50/50.
49
+ def campaigners
50
+ return get("/campaigners/list")
51
+ end
52
+
53
+ # Show details for a specific campaigner.
54
+ def campaigner_details(campaigner_id)
55
+ return get("/campaigners/#{campaigner_id}")
56
+ end
57
+ def get(url)
58
+ response = Hashie::Mash.new(self.class.get(url))
59
+
60
+ if response.status == 400
61
+ raise BadRequest
62
+ else
63
+ return response.data
64
+ end
65
+ end
66
+
67
+ def put
68
+
69
+ end
70
+
71
+ def post
72
+
73
+ end
74
+ end
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 'fiftyfifty'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestFiftyfifty < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fiftyfifty
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.4.0
6
+ platform: ruby
7
+ authors:
8
+ - Peter Hamilton
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-09-12 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: shoulda
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: :development
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: bundler
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 1.0.0
35
+ type: :development
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: jeweler
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.6.4
46
+ type: :development
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: rcov
50
+ prerelease: false
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ type: :development
58
+ version_requirements: *id004
59
+ description: An API Wrapper for the 5050 Project API
60
+ email: peter@inspiredpixel.net
61
+ executables: []
62
+
63
+ extensions: []
64
+
65
+ extra_rdoc_files:
66
+ - LICENSE.txt
67
+ - README.md
68
+ - README.rdoc
69
+ files:
70
+ - .document
71
+ - Gemfile
72
+ - Gemfile.lock
73
+ - LICENSE.txt
74
+ - README.md
75
+ - README.rdoc
76
+ - Rakefile
77
+ - VERSION
78
+ - fiftyfifty.gemspec
79
+ - lib/fiftyfifty.rb
80
+ - test/helper.rb
81
+ - test/test_fiftyfifty.rb
82
+ homepage: http://github.com/peterhamilton/fiftyfifty
83
+ licenses:
84
+ - MIT
85
+ post_install_message:
86
+ rdoc_options: []
87
+
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: "0"
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: "0"
102
+ requirements: []
103
+
104
+ rubyforge_project:
105
+ rubygems_version: 1.8.10
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: An API Wrapper for the 5050 Project API
109
+ test_files: []
110
+