sunlightlabs-tcorps 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,10 @@
1
+ Copyright © 2009, Sunlight Foundation
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+ * Neither the name of Sunlight Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9
+
10
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ ## Introduction
2
+
3
+ This is a wrapper for the [TransparencyCorps](http://transparencycorps.org) API. TransparencyCorps is a microtask directory that integrates with external applications to encourage and reward volunteer activity.
4
+
5
+ You would use this in your TransparencyCorps campaign application to notify TransparencyCorps when a user has completed a task, and they should receive points for their effort.
6
+
7
+ ## Usage
8
+
9
+ Your campaign will receive a unique task key for each user when they land on your page from TransparencyCorps. You should hold this key until the task is completed, perhaps in hidden input fields on your forms, or in whatever session store your application might use.
10
+
11
+ To complete a task and nothing more:
12
+
13
+ TransparencyCorps.complete_task "the_actual_task_key"
14
+ # => #<Net::HTTPOK 200 OK readbody=true>
15
+
16
+ Your application may want to seamlessly direct users to a new task once they've completed one. TransparencyCorps can generate a new task for you at the same time as you mark the current task complete, and will return the URL for the app to redirect itself to as the response body. You can do this with this wrapper by:
17
+
18
+ TransparencyCorps.complete_task_and_reassign "the_actual_task_key"
19
+ # => "http://yoursite.com/yourcampaign?task_key=new_task_key&username=testuser&points=500
20
+
21
+ # or you can get the response body and pull the URL yourself:
22
+ response = TransparencyCorps.complete_task "the_actual_task_key", true
23
+ response.body
24
+ # => "http://yoursite.com/yourcampaign?task_key=new_task_key&username=testuser&points=500
25
+
26
+
27
+ By default, the wrapper directs requests to http://transparencycorps.org. If you want to use a different URL, (for testing in a local or staging environment, for instance), assign it a different one.
28
+
29
+ TransparencyCorps.url = "http://localhost:3000"
data/lib/tcorps.rb ADDED
@@ -0,0 +1 @@
1
+ require 'transparency_corps'
@@ -0,0 +1,33 @@
1
+ require 'open-uri'
2
+ require 'net/http'
3
+
4
+ class TransparencyCorps
5
+
6
+ @@url = 'http://transparencycorps.org'
7
+ COMPLETE_PATH = '/tasks/complete'
8
+ NEW_TASK_PARAMS = {:new_task => 1}
9
+
10
+ def self.url=(url)
11
+ @@url = url
12
+ end
13
+
14
+ def self.url
15
+ @@url
16
+ end
17
+
18
+ def self.complete_task_and_reassign(task_key)
19
+ response = complete_task task_key, true
20
+ if response.body and response.body.strip.any?
21
+ response.body
22
+ else
23
+ response
24
+ end
25
+ end
26
+
27
+ def self.complete_task(task_key, reassign = false)
28
+ params = {:task_key => task_key}
29
+ params.merge! NEW_TASK_PARAMS if reassign
30
+ Net::HTTP.post_form URI.join(url, COMPLETE_PATH), params
31
+ end
32
+
33
+ end
@@ -0,0 +1,12 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "tcorps"
3
+ s.version = "0.1.1"
4
+ s.date = "2009-08-05"
5
+ s.summary = "Library for communicating with the TransparencyCorps API."
6
+ s.description = "Library for communicating with the TransparencyCorps API."
7
+ s.email = "eric@sunlightfoundation.com"
8
+ s.homepage = "http://github.com/sunlightlabs/ruby-tcorps/"
9
+ s.authors = ["Eric Mill"]
10
+ s.files = ['ruby-tcorps.gemspec', 'lib/tcorps.rb', 'lib/transparency_corps.rb',
11
+ 'README.md', 'LICENSE']
12
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sunlightlabs-tcorps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Eric Mill
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-05 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Library for communicating with the TransparencyCorps API.
17
+ email: eric@sunlightfoundation.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - ruby-tcorps.gemspec
26
+ - lib/tcorps.rb
27
+ - lib/transparency_corps.rb
28
+ - README.md
29
+ - LICENSE
30
+ has_rdoc: false
31
+ homepage: http://github.com/sunlightlabs/ruby-tcorps/
32
+ licenses:
33
+ post_install_message:
34
+ rdoc_options: []
35
+
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: "0"
43
+ version:
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ requirements: []
51
+
52
+ rubyforge_project:
53
+ rubygems_version: 1.3.5
54
+ signing_key:
55
+ specification_version: 2
56
+ summary: Library for communicating with the TransparencyCorps API.
57
+ test_files: []
58
+