donors_choose 0.9.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown
@@ -0,0 +1,109 @@
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=582
21
+ expires:
22
+ - Wed, 15 Feb 2012 21:43:28 GMT
23
+ date:
24
+ - Wed, 15 Feb 2012 21:33:46 GMT
25
+ content-length:
26
+ - "796"
27
+ connection:
28
+ - keep-alive
29
+ x-n:
30
+ - S
31
+ body: |
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+ {"searchTerms":"+cityid:1007 AND +statecode:NC 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, static)),product(0.75,stationor))),add(product(100000.0,stationeri),add(product(1000000.0,sun(10.0,staticNeedBinary)),0)))))" > 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":[]}
108
+
109
+ http_version: "1.1"
@@ -19,9 +19,9 @@
19
19
  cache-control:
20
20
  - private, max-age=600
21
21
  expires:
22
- - Tue, 14 Feb 2012 20:01:14 GMT
22
+ - Wed, 15 Feb 2012 21:43:36 GMT
23
23
  date:
24
- - Tue, 14 Feb 2012 19:51:14 GMT
24
+ - Wed, 15 Feb 2012 21:33:36 GMT
25
25
  content-length:
26
26
  - '796'
27
27
  connection:
@@ -20,4 +20,5 @@ Gem::Specification.new do |gem|
20
20
  gem.add_development_dependency "rspec"
21
21
  gem.add_development_dependency "vcr"
22
22
  gem.add_development_dependency "webmock"
23
+ gem.add_development_dependency "yard"
23
24
  end
data/lib/donors_choose.rb CHANGED
@@ -1,19 +1,19 @@
1
1
  require 'donors_choose/version'
2
2
  require 'donors_choose/request'
3
+ require 'donors_choose/project'
3
4
 
5
+ # This module provides the entry point for the library. Everything here
6
+ # is considered public, the rest of the objects are essentially internal.
4
7
  module DonorsChoose
5
- extend self
6
-
7
- attr_writer :api_key
8
- def api_key
9
- @api_key || "DONORSCHOOSE"
8
+ # An API key is needed to make requests. Get one
9
+ # [here](http://developer.donorschoose.org/help-contact).
10
+ def self.api_key=(key)
11
+ @api_key = key
10
12
  end
11
13
 
12
- def projects_near_me(latitude, longitude)
13
- Request.get(:centerLat => latitude, :centerLong => longitude)
14
- end
15
-
16
- def projects_by_zip(zipcode)
17
- Request.get(:keyword => zipcode)
14
+ # We default to the development key that works for everyone. Set it to
15
+ # something else in production environments.
16
+ def self.api_key
17
+ @api_key || "DONORSCHOOSE"
18
18
  end
19
19
  end
@@ -0,0 +1,14 @@
1
+ # This API allows us to find information about DonorsChoose projects,
2
+ # so a Project is the main class of the gem.
3
+ class DonorsChoose::Project
4
+
5
+ # This method finds all projects near a given latitude and longitude.
6
+ def self.near_me(latitude, longitude)
7
+ DonorsChoose::Request.get(:centerLat => latitude, :centerLong => longitude)
8
+ end
9
+
10
+ # This method allows you to look up all projects by a zip code.
11
+ def self.by_zip(zipcode)
12
+ DonorsChoose::Request.get(:zip => zipcode)
13
+ end
14
+ end
@@ -4,26 +4,43 @@ require 'net/http'
4
4
  require 'json'
5
5
  require 'ostruct'
6
6
 
7
+ # This class provides a wrapper around all of the external interaction
8
+ # we'll be doing. It's kinda important, given we're wrapping an API. ;)
7
9
  class DonorsChoose::Request
8
- def self.get(params)
9
- new(params).get
10
+
11
+ # This method is a convenient factory method, and is the easiest way
12
+ # to make a single request and get the data back.
13
+ def self.get(params)
14
+ new(params).process
10
15
  end
11
16
 
17
+ # This API operates through making GET requests to an endpoint. It takes
18
+ # a few different parameters to control how the data is acquired. We'll
19
+ # just take those so we can properly construct the request.
12
20
  def initialize(params)
13
21
  @params = params
14
22
  end
15
23
 
16
- def get
17
- data = JSON.parse(fetch)["proposals"]
24
+ # This method is the main business process of this class: get the data,
25
+ # parse the JSON it returns, grab the proposal list, and then build a
26
+ # list of objects with the data.
27
+ def process
28
+ data = JSON.parse(get)["proposals"]
18
29
  data.collect {|datum| OpenStruct.new(datum)}
19
30
  end
20
31
 
21
- def fetch
32
+ # This method wraps Net::HTTP, basically. We build up our own parameter
33
+ # list, construct our URI, and fetch it.
34
+ def get
22
35
  base_uri = 'http://api.donorschoose.org/common/json_feed.html'
23
- uri_params = @params.collect do |key, value|
36
+ Net::HTTP.get(URI(base_uri + "?" + uri_params))
37
+ end
38
+
39
+ def uri_params
40
+ params = @params.dup.collect do |key, value|
24
41
  "#{key}=#{CGI.escape(value.to_s)}"
25
42
  end
26
- uri_params = [uri_params, "APIKey=#{DonorsChoose.api_key}"].join("&")
27
- Net::HTTP.get(URI(base_uri + "?" + uri_params))
43
+ params << "APIKey=#{DonorsChoose.api_key}"
44
+ params.join("&")
28
45
  end
29
46
  end
@@ -1,3 +1,4 @@
1
1
  module DonorsChoose
2
- VERSION = "0.9.0"
2
+ # The current version of the gem.
3
+ VERSION = "1.0.0"
3
4
  end
@@ -5,30 +5,6 @@ describe DonorsChoose do
5
5
  it "is able to have an API key set" do
6
6
  key = "this isn't an API key"
7
7
  DonorsChoose.api_key = key
8
- DonorsChoose.api_key.should eql(key)
9
- end
10
-
11
- context "requesting data" do
12
- let(:test_title) { "A test project" }
13
-
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)
19
-
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
8
+ DonorsChoose.api_key.should eq(key)
33
9
  end
34
10
  end
@@ -0,0 +1,26 @@
1
+ $:.unshift("lib")
2
+ require 'donors_choose'
3
+
4
+ describe DonorsChoose::Project do
5
+ let(:test_title) { "A test project" }
6
+
7
+ it "is able to find projects near me" do
8
+ projects = [double]
9
+ DonorsChoose::Request.should_receive(:get).
10
+ with(:centerLat => "40.4405556", :centerLong => "-79.9961111").
11
+ and_return(projects)
12
+
13
+ results = DonorsChoose::Project.near_me("40.4405556", "-79.9961111")
14
+ results.should eq(projects)
15
+ end
16
+
17
+ it "is able to find projects by zip code" do
18
+ projects = [double]
19
+ DonorsChoose::Request.should_receive(:get).
20
+ with(:zip => "15232").
21
+ and_return(projects)
22
+
23
+ results = DonorsChoose::Project.by_zip("15232")
24
+ results.should eq(projects)
25
+ end
26
+ end
data/spec/request_spec.rb CHANGED
@@ -3,9 +3,10 @@ require 'donors_choose/request'
3
3
 
4
4
  require 'vcr'
5
5
  require 'webmock'
6
+ YAML_SERIALIZATION_VERSION = RUBY_VERSION =~ /1\.8/ ? '1.8' : 'not_1.8'
6
7
  VCR.config do |c|
8
+ c.cassette_library_dir = File.join(File.dirname(__FILE__), '..', 'cassettes', YAML_SERIALIZATION_VERSION)
7
9
  c.stub_with :webmock
8
- c.cassette_library_dir = 'cassettes'
9
10
  end
10
11
 
11
12
  RSpec.configure do |config|
@@ -20,6 +21,6 @@ describe DonorsChoose::Request do
20
21
 
21
22
  request = DonorsChoose::Request.new({:state => "NC",
22
23
  :community => "1007:3"})
23
- request.fetch.should_not be_nil
24
+ request.process.should_not be_nil
24
25
  end
25
26
  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.9.0
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-14 00:00:00.000000000 Z
12
+ date: 2012-02-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &70326897943640 !ruby/object:Gem::Requirement
16
+ requirement: &70192143544040 !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: *70326897943640
24
+ version_requirements: *70192143544040
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70326897943120 !ruby/object:Gem::Requirement
27
+ requirement: &70192143543600 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70326897943120
35
+ version_requirements: *70192143543600
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: vcr
38
- requirement: &70326897942580 !ruby/object:Gem::Requirement
38
+ requirement: &70192143543140 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70326897942580
46
+ version_requirements: *70192143543140
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: webmock
49
- requirement: &70326897941960 !ruby/object:Gem::Requirement
49
+ requirement: &70192143542700 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,18 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70326897941960
57
+ version_requirements: *70192143542700
58
+ - !ruby/object:Gem::Dependency
59
+ name: yard
60
+ requirement: &70192143542260 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70192143542260
58
69
  description: A gem to wrap the DonorsChoose.org API.
59
70
  email:
60
71
  - steve@steveklabnik.com
@@ -65,16 +76,20 @@ files:
65
76
  - .gitignore
66
77
  - .rvmrc
67
78
  - .travis.yml
79
+ - .yardopts
68
80
  - Gemfile
69
81
  - LICENSE
70
82
  - README.md
71
83
  - Rakefile
72
- - cassettes/DonorsChoose_Request.yml
84
+ - cassettes/1.8/DonorsChoose_Request.yml
85
+ - cassettes/not_1.8/DonorsChoose_Request.yml
73
86
  - donors_choose.gemspec
74
87
  - lib/donors_choose.rb
88
+ - lib/donors_choose/project.rb
75
89
  - lib/donors_choose/request.rb
76
90
  - lib/donors_choose/version.rb
77
91
  - spec/donors_choose_spec.rb
92
+ - spec/project_spec.rb
78
93
  - spec/request_spec.rb
79
94
  homepage: http://github.com/jumpstartlab/donors_choose
80
95
  licenses: []
@@ -102,4 +117,6 @@ specification_version: 3
102
117
  summary: A gem to wrap the DonorsChoose.org API.
103
118
  test_files:
104
119
  - spec/donors_choose_spec.rb
120
+ - spec/project_spec.rb
105
121
  - spec/request_spec.rb
122
+ has_rdoc: