donors_choose 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rvmrc +1 -0
- data/donors_choose.gemspec +7 -3
- data/lib/donors_choose/request.rb +18 -0
- data/lib/donors_choose/version.rb +1 -1
- data/lib/donors_choose.rb +13 -4
- data/spec/donors_choose_spec.rb +20 -0
- data/spec/request_spec.rb +12 -0
- metadata +34 -6
data/.gitignore
CHANGED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm --create use 1.9.3@donors_choose
|
data/donors_choose.gemspec
CHANGED
@@ -4,9 +4,9 @@ require File.expand_path('../lib/donors_choose/version', __FILE__)
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Steve Klabnik"]
|
6
6
|
gem.email = ["steve@steveklabnik.com"]
|
7
|
-
gem.description = %q{A gem
|
8
|
-
gem.summary = %q{A gem
|
9
|
-
gem.homepage = ""
|
7
|
+
gem.description = %q{A gem to wrap the DonorsChoose.org API.}
|
8
|
+
gem.summary = %q{A gem to wrap the DonorsChoose.org API.}
|
9
|
+
gem.homepage = "http://github.com/jumpstartlab/donors_choose"
|
10
10
|
|
11
11
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
12
|
gem.files = `git ls-files`.split("\n")
|
@@ -14,4 +14,8 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.name = "donors_choose"
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = DonorsChoose::VERSION
|
17
|
+
|
18
|
+
gem.add_runtime_dependency "json"
|
19
|
+
|
20
|
+
gem.add_development_dependency "rspec"
|
17
21
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'uri'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
class DonorsChoose::Request
|
6
|
+
def initialize(params)
|
7
|
+
@params = params
|
8
|
+
end
|
9
|
+
|
10
|
+
def fetch
|
11
|
+
base_uri = 'http://api.donorschoose.org/common/json_feed.html'
|
12
|
+
uri_params = @params.collect do |key, value|
|
13
|
+
"#{key}=#{CGI.escape(value.to_s)}"
|
14
|
+
end
|
15
|
+
uri_params = [uri_params, "APIKey=#{DonorsChoose.api_key}"].join("&")
|
16
|
+
Net::HTTP.get(URI(base_uri + "?" + uri_params))
|
17
|
+
end
|
18
|
+
end
|
data/lib/donors_choose.rb
CHANGED
@@ -1,7 +1,16 @@
|
|
1
|
-
require
|
1
|
+
require 'donors_choose/version'
|
2
|
+
require 'donors_choose/request'
|
3
|
+
require 'json'
|
4
|
+
require 'ostruct'
|
2
5
|
|
3
6
|
module DonorsChoose
|
4
|
-
|
5
|
-
|
7
|
+
extend self
|
8
|
+
attr_accessor :api_key
|
9
|
+
|
10
|
+
def projects_near_me(latitude, longitude)
|
11
|
+
request = Request.new(:centerLat => latitude, :centerLong => longitude)
|
12
|
+
data = JSON.parse(request.fetch)["proposals"]
|
6
13
|
|
7
|
-
|
14
|
+
data.collect {|datum| OpenStruct.new(datum)}
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.unshift("lib")
|
2
|
+
require 'donors_choose'
|
3
|
+
|
4
|
+
describe DonorsChoose do
|
5
|
+
it "is able to have an API key set" do
|
6
|
+
key = "this isn't an API key"
|
7
|
+
DonorsChoose.api_key = key
|
8
|
+
DonorsChoose.api_key.should eql(key)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "is able to find projects near me" do
|
12
|
+
request = double
|
13
|
+
request.should_receive(:fetch).and_return('{"proposals": [{"title": "A test project"}]}')
|
14
|
+
|
15
|
+
DonorsChoose::Request.should_receive(:new).and_return(request)
|
16
|
+
|
17
|
+
projects = DonorsChoose.projects_near_me("40.4405556", "-79.9961111")
|
18
|
+
projects.first.title.should eql("A test project")
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
$:.unshift("lib")
|
2
|
+
require 'donors_choose/request'
|
3
|
+
|
4
|
+
describe DonorsChoose::Request do
|
5
|
+
it "is able to request data from the API" do
|
6
|
+
DonorsChoose.api_key = "DONORSCHOOSE"
|
7
|
+
|
8
|
+
request = DonorsChoose::Request.new({:state => "NC",
|
9
|
+
:community => "1007:3"})
|
10
|
+
request.fetch.should_not be_nil
|
11
|
+
end
|
12
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: donors_choose
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,8 +10,30 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
date: 2012-02-14 00:00:00.000000000 Z
|
13
|
-
dependencies:
|
14
|
-
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: &70347294684420 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70347294684420
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70347294683700 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70347294683700
|
36
|
+
description: A gem to wrap the DonorsChoose.org API.
|
15
37
|
email:
|
16
38
|
- steve@steveklabnik.com
|
17
39
|
executables: []
|
@@ -19,14 +41,18 @@ extensions: []
|
|
19
41
|
extra_rdoc_files: []
|
20
42
|
files:
|
21
43
|
- .gitignore
|
44
|
+
- .rvmrc
|
22
45
|
- Gemfile
|
23
46
|
- LICENSE
|
24
47
|
- README.md
|
25
48
|
- Rakefile
|
26
49
|
- donors_choose.gemspec
|
27
50
|
- lib/donors_choose.rb
|
51
|
+
- lib/donors_choose/request.rb
|
28
52
|
- lib/donors_choose/version.rb
|
29
|
-
|
53
|
+
- spec/donors_choose_spec.rb
|
54
|
+
- spec/request_spec.rb
|
55
|
+
homepage: http://github.com/jumpstartlab/donors_choose
|
30
56
|
licenses: []
|
31
57
|
post_install_message:
|
32
58
|
rdoc_options: []
|
@@ -49,5 +75,7 @@ rubyforge_project:
|
|
49
75
|
rubygems_version: 1.8.16
|
50
76
|
signing_key:
|
51
77
|
specification_version: 3
|
52
|
-
summary: A gem
|
53
|
-
test_files:
|
78
|
+
summary: A gem to wrap the DonorsChoose.org API.
|
79
|
+
test_files:
|
80
|
+
- spec/donors_choose_spec.rb
|
81
|
+
- spec/request_spec.rb
|