donors_choose 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in donors_choose.gemspec
4
4
  gemspec
5
+
6
+ gem 'rake'
data/README.md CHANGED
@@ -30,13 +30,13 @@ just two methods.
30
30
 
31
31
  DonorsChoose.api_key = "DONORSCHOOSE"
32
32
 
33
- projects = DonorsChoose.projects_near_me("40.4405556", "-79.9961111")
34
- projects = DonorsChoose.projects_by_zip("15232")
33
+ projects = DonorsChoose::Project.near_me("40.4405556", "-79.9961111")
34
+ projects = DonorsChoose::Project.by_zip("15232")
35
35
 
36
36
  Projects will be an array of objects that contain all of the data returned by
37
37
  the request. You can learn about these objects through introspection:
38
38
 
39
- > (projects.first.methods - Object.new.methods)
39
+ > projects.first.methods(false)
40
40
  => [:id, ...
41
41
 
42
42
  For example. These objects are dynamically created based on the response, so
data/Rakefile CHANGED
@@ -1,2 +1,9 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ desc 'Run all specs in spec directory'
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task :default => :spec
@@ -19,6 +19,6 @@ Gem::Specification.new do |gem|
19
19
 
20
20
  gem.add_development_dependency "rspec"
21
21
  gem.add_development_dependency "vcr"
22
- gem.add_development_dependency "webmock"
22
+ gem.add_development_dependency "webmock", "~> 1.7.0"
23
23
  gem.add_development_dependency "yard"
24
24
  end
@@ -0,0 +1,7 @@
1
+ unless Object.new.respond_to?(:singleton_class)
2
+ class Object
3
+ def singleton_class
4
+ class << self; self; end
5
+ end
6
+ end
7
+ end
@@ -4,6 +4,8 @@ require 'net/http'
4
4
  require 'json'
5
5
  require 'ostruct'
6
6
 
7
+ require 'donors_choose/utils/static_struct'
8
+
7
9
  # This class provides a wrapper around all of the external interaction
8
10
  # we'll be doing. It's kinda important, given we're wrapping an API. ;)
9
11
  class DonorsChoose::Request
@@ -26,7 +28,7 @@ class DonorsChoose::Request
26
28
  # list of objects with the data.
27
29
  def process
28
30
  data = JSON.parse(get)["proposals"]
29
- data.collect {|datum| OpenStruct.new(datum)}
31
+ data.collect {|datum| DonorsChoose::Utils::StaticStruct.new(datum)}
30
32
  end
31
33
 
32
34
  # This method wraps Net::HTTP, basically. We build up our own parameter
@@ -0,0 +1,18 @@
1
+ require 'donors_choose/core_ext/object'
2
+
3
+ # simple implementation of the readonly OpenStruct class
4
+ module DonorsChoose
5
+ module Utils
6
+ class StaticStruct
7
+ def initialize(params={})
8
+ singleton_class.module_eval do
9
+ params.each do |key, value|
10
+ define_method key do
11
+ value
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,4 +1,4 @@
1
1
  module DonorsChoose
2
2
  # The current version of the gem.
3
- VERSION = "1.0.0"
3
+ VERSION = "1.1.0"
4
4
  end
@@ -1,10 +1,9 @@
1
- $:.unshift("lib")
2
1
  require 'donors_choose'
3
2
 
4
3
  describe DonorsChoose do
5
4
  it "is able to have an API key set" do
6
5
  key = "this isn't an API key"
7
- DonorsChoose.api_key = key
8
- DonorsChoose.api_key.should eq(key)
6
+ described_class.api_key = key
7
+ described_class.api_key.should eq(key)
9
8
  end
10
9
  end
@@ -1,4 +1,3 @@
1
- $:.unshift("lib")
2
1
  require 'donors_choose'
3
2
 
4
3
  describe DonorsChoose::Project do
@@ -10,7 +9,7 @@ describe DonorsChoose::Project do
10
9
  with(:centerLat => "40.4405556", :centerLong => "-79.9961111").
11
10
  and_return(projects)
12
11
 
13
- results = DonorsChoose::Project.near_me("40.4405556", "-79.9961111")
12
+ results = described_class.near_me("40.4405556", "-79.9961111")
14
13
  results.should eq(projects)
15
14
  end
16
15
 
@@ -20,7 +19,7 @@ describe DonorsChoose::Project do
20
19
  with(:zip => "15232").
21
20
  and_return(projects)
22
21
 
23
- results = DonorsChoose::Project.by_zip("15232")
22
+ results = described_class.by_zip("15232")
24
23
  results.should eq(projects)
25
24
  end
26
25
  end
@@ -1,8 +1,8 @@
1
- $:.unshift("lib")
2
1
  require 'donors_choose/request'
3
2
 
4
3
  require 'vcr'
5
4
  require 'webmock'
5
+
6
6
  YAML_SERIALIZATION_VERSION = RUBY_VERSION =~ /1\.8/ ? '1.8' : 'not_1.8'
7
7
  VCR.config do |c|
8
8
  c.cassette_library_dir = File.join(File.dirname(__FILE__), '..', 'cassettes', YAML_SERIALIZATION_VERSION)
@@ -19,8 +19,8 @@ describe DonorsChoose::Request do
19
19
  it "is able to request data from the API" do
20
20
  DonorsChoose.api_key = "DONORSCHOOSE"
21
21
 
22
- request = DonorsChoose::Request.new({:state => "NC",
23
- :community => "1007:3"})
22
+ request = described_class.new({:state => "NC",
23
+ :community => "1007:3"})
24
24
  request.process.should_not be_nil
25
25
  end
26
26
  end
@@ -0,0 +1,20 @@
1
+ require 'donors_choose/utils/static_struct'
2
+
3
+ describe DonorsChoose::Utils::StaticStruct do
4
+ let(:params) { {:foo => 'foo', :bar => 'bar'} }
5
+
6
+ it "is able to initialize with params" do
7
+ described_class.new(params).should be_instance_of(described_class)
8
+ end
9
+
10
+ it 'creates only getters' do
11
+ getters = described_class.new(params).methods(false).map(&:to_sym)
12
+
13
+ getters.include?(:foo).should be_true
14
+ getters.include?(:bar).should be_true
15
+ end
16
+
17
+ it 'returns set-ed param' do
18
+ described_class.new(params).foo.should eq('foo')
19
+ end
20
+ 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: 1.0.0
4
+ version: 1.1.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-16 00:00:00.000000000 Z
12
+ date: 2012-02-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &70192143544040 !ruby/object:Gem::Requirement
16
+ requirement: &70124032338040 !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: *70192143544040
24
+ version_requirements: *70124032338040
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70192143543600 !ruby/object:Gem::Requirement
27
+ requirement: &70124032337600 !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: *70192143543600
35
+ version_requirements: *70124032337600
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: vcr
38
- requirement: &70192143543140 !ruby/object:Gem::Requirement
38
+ requirement: &70124032337140 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,21 +43,21 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70192143543140
46
+ version_requirements: *70124032337140
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: webmock
49
- requirement: &70192143542700 !ruby/object:Gem::Requirement
49
+ requirement: &70124032336600 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
- - - ! '>='
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 1.7.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70192143542700
57
+ version_requirements: *70124032336600
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: yard
60
- requirement: &70192143542260 !ruby/object:Gem::Requirement
60
+ requirement: &70124032336100 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70192143542260
68
+ version_requirements: *70124032336100
69
69
  description: A gem to wrap the DonorsChoose.org API.
70
70
  email:
71
71
  - steve@steveklabnik.com
@@ -85,12 +85,15 @@ files:
85
85
  - cassettes/not_1.8/DonorsChoose_Request.yml
86
86
  - donors_choose.gemspec
87
87
  - lib/donors_choose.rb
88
+ - lib/donors_choose/core_ext/object.rb
88
89
  - lib/donors_choose/project.rb
89
90
  - lib/donors_choose/request.rb
91
+ - lib/donors_choose/utils/static_struct.rb
90
92
  - lib/donors_choose/version.rb
91
93
  - spec/donors_choose_spec.rb
92
94
  - spec/project_spec.rb
93
95
  - spec/request_spec.rb
96
+ - spec/static_struct_spec.rb
94
97
  homepage: http://github.com/jumpstartlab/donors_choose
95
98
  licenses: []
96
99
  post_install_message:
@@ -119,4 +122,5 @@ test_files:
119
122
  - spec/donors_choose_spec.rb
120
123
  - spec/project_spec.rb
121
124
  - spec/request_spec.rb
125
+ - spec/static_struct_spec.rb
122
126
  has_rdoc: