donors_choose 0.0.4 → 0.9.0

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/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ script: "rspec"
3
+ rvm:
4
+ - 1.8.7
5
+ - 1.9.2
6
+ - 1.9.3
7
+ - rbx-18mode
8
+ - rbx-19mode
9
+ - ruby-head
10
+ - jruby-18mode
11
+ - jruby-19mode
12
+ - jruby-head
13
+ - ree
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # DonorsChoose
2
2
 
3
- TODO: Write a gem description
3
+ DonorsChoose.org is an online charity that makes it easy for anyone to help students in need.
4
+
5
+ This is a gem that wraps [their API](http://developer.donorschoose.org/home).
4
6
 
5
7
  ## Installation
6
8
 
@@ -18,7 +20,27 @@ Or install it yourself as:
18
20
 
19
21
  ## Usage
20
22
 
21
- TODO: Write usage instructions here
23
+ The first thing you should do is [request an API
24
+ key](http://developer.donorschoose.org/help-contact). They provide a test key,
25
+ "DONORSCHOOSE", that will occasionally be turned off. So be nice and get your
26
+ own. :)
27
+
28
+ We're currently developing support for the full API, but right now, there are
29
+ just two methods.
30
+
31
+ DonorsChoose.api_key = "DONORSCHOOSE"
32
+
33
+ projects = DonorsChoose.projects_near_me("40.4405556", "-79.9961111")
34
+ projects = DonorsChoose.projects_by_zip("15232")
35
+
36
+ Projects will be an array of objects that contain all of the data returned by
37
+ the request. You can learn about these objects through introspection:
38
+
39
+ > (projects.first.methods - Object.new.methods)
40
+ => [:id, ...
41
+
42
+ For example. These objects are dynamically created based on the response, so
43
+ minor API updates may change the attributes.
22
44
 
23
45
  ## Contributing
24
46
 
@@ -0,0 +1,36 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://api.donorschoose.org:80/common/json_feed.html?APIKey=DONORSCHOOSE&community=1007:3&state=NC
6
+ body:
7
+ headers:
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ server:
14
+ - nginx
15
+ content-type:
16
+ - text/plain;charset=UTF-8
17
+ content-language:
18
+ - en-US
19
+ cache-control:
20
+ - private, max-age=600
21
+ expires:
22
+ - Tue, 14 Feb 2012 20:01:14 GMT
23
+ date:
24
+ - Tue, 14 Feb 2012 19:51:14 GMT
25
+ content-length:
26
+ - '796'
27
+ connection:
28
+ - keep-alive
29
+ x-n:
30
+ - S
31
+ body: ! "\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\t\r\n\r\n\t
32
+ \ \t\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n{\"searchTerms\":\"+cityid:1007 AND +statecode:NC
33
+ AND +historical:fall +_val_:"add(product(10.0,staticNewbie),add(product(100.0,recal(add(ms(NOW,explorationth),3.16911),3.16e-11,1,1)),add(product(10000.0,add(product(1.25,sun(5.0,
34
+ static)),product(0.75,stationor))),add(product(100000.0,stationeri),add(product(1000000.0,sun(10.0,staticNeedBinary)),0)))))"
35
+ > Many Farms, Arizona\",\"searchURL\":\"http://www.donorschoose.org/donors/search.html?community=1007%3a3&state=NC&utm_source=api&utm_medium=feed&utm_content=searchlink&utm_campaign=DONORSCHOOSE\",\"totalProposals\":\"0\",\"index\":\"0\",\"max\":\"10\",\"proposals\":[]}\r\n"
36
+ http_version: '1.1'
@@ -18,4 +18,6 @@ Gem::Specification.new do |gem|
18
18
  gem.add_runtime_dependency "json"
19
19
 
20
20
  gem.add_development_dependency "rspec"
21
+ gem.add_development_dependency "vcr"
22
+ gem.add_development_dependency "webmock"
21
23
  end
data/lib/donors_choose.rb CHANGED
@@ -1,16 +1,19 @@
1
1
  require 'donors_choose/version'
2
2
  require 'donors_choose/request'
3
- require 'json'
4
- require 'ostruct'
5
3
 
6
4
  module DonorsChoose
7
5
  extend self
8
- attr_accessor :api_key
6
+
7
+ attr_writer :api_key
8
+ def api_key
9
+ @api_key || "DONORSCHOOSE"
10
+ end
9
11
 
10
12
  def projects_near_me(latitude, longitude)
11
- request = Request.new(:centerLat => latitude, :centerLong => longitude)
12
- data = JSON.parse(request.fetch)["proposals"]
13
+ Request.get(:centerLat => latitude, :centerLong => longitude)
14
+ end
13
15
 
14
- data.collect {|datum| OpenStruct.new(datum)}
16
+ def projects_by_zip(zipcode)
17
+ Request.get(:keyword => zipcode)
15
18
  end
16
19
  end
@@ -1,12 +1,23 @@
1
1
  require 'cgi'
2
2
  require 'uri'
3
3
  require 'net/http'
4
+ require 'json'
5
+ require 'ostruct'
4
6
 
5
7
  class DonorsChoose::Request
8
+ def self.get(params)
9
+ new(params).get
10
+ end
11
+
6
12
  def initialize(params)
7
13
  @params = params
8
14
  end
9
15
 
16
+ def get
17
+ data = JSON.parse(fetch)["proposals"]
18
+ data.collect {|datum| OpenStruct.new(datum)}
19
+ end
20
+
10
21
  def fetch
11
22
  base_uri = 'http://api.donorschoose.org/common/json_feed.html'
12
23
  uri_params = @params.collect do |key, value|
@@ -1,3 +1,3 @@
1
1
  module DonorsChoose
2
- VERSION = "0.0.4"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -8,13 +8,27 @@ describe DonorsChoose do
8
8
  DonorsChoose.api_key.should eql(key)
9
9
  end
10
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"}]}')
11
+ context "requesting data" do
12
+ let(:test_title) { "A test project" }
14
13
 
15
- DonorsChoose::Request.should_receive(:new).and_return(request)
14
+ it "is able to find projects near me" do
15
+ projects = [double]
16
+ DonorsChoose::Request.should_receive(:get).
17
+ with(:centerLat => "40.4405556", :centerLong => "-79.9961111").
18
+ and_return(projects)
16
19
 
17
- projects = DonorsChoose.projects_near_me("40.4405556", "-79.9961111")
18
- projects.first.title.should eql("A test project")
20
+ results = DonorsChoose.projects_near_me("40.4405556", "-79.9961111")
21
+ results.should eq(projects)
22
+ end
23
+
24
+ it "is able to find projects by zip code" do
25
+ projects = [double]
26
+ DonorsChoose::Request.should_receive(:get).
27
+ with(:keyword => "15232").
28
+ and_return(projects)
29
+
30
+ results = DonorsChoose.projects_by_zip("15232")
31
+ results.should eq(projects)
32
+ end
19
33
  end
20
34
  end
data/spec/request_spec.rb CHANGED
@@ -1,7 +1,20 @@
1
1
  $:.unshift("lib")
2
2
  require 'donors_choose/request'
3
3
 
4
+ require 'vcr'
5
+ require 'webmock'
6
+ VCR.config do |c|
7
+ c.stub_with :webmock
8
+ c.cassette_library_dir = 'cassettes'
9
+ end
10
+
11
+ RSpec.configure do |config|
12
+ config.extend VCR::RSpec::Macros
13
+ end
14
+
4
15
  describe DonorsChoose::Request do
16
+ use_vcr_cassette
17
+
5
18
  it "is able to request data from the API" do
6
19
  DonorsChoose.api_key = "DONORSCHOOSE"
7
20
 
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
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-02-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &70347294684420 !ruby/object:Gem::Requirement
16
+ requirement: &70326897943640 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70347294684420
24
+ version_requirements: *70326897943640
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70347294683700 !ruby/object:Gem::Requirement
27
+ requirement: &70326897943120 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,29 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70347294683700
35
+ version_requirements: *70326897943120
36
+ - !ruby/object:Gem::Dependency
37
+ name: vcr
38
+ requirement: &70326897942580 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70326897942580
47
+ - !ruby/object:Gem::Dependency
48
+ name: webmock
49
+ requirement: &70326897941960 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70326897941960
36
58
  description: A gem to wrap the DonorsChoose.org API.
37
59
  email:
38
60
  - steve@steveklabnik.com
@@ -42,10 +64,12 @@ extra_rdoc_files: []
42
64
  files:
43
65
  - .gitignore
44
66
  - .rvmrc
67
+ - .travis.yml
45
68
  - Gemfile
46
69
  - LICENSE
47
70
  - README.md
48
71
  - Rakefile
72
+ - cassettes/DonorsChoose_Request.yml
49
73
  - donors_choose.gemspec
50
74
  - lib/donors_choose.rb
51
75
  - lib/donors_choose/request.rb