foundation_center 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 84e79a417918c7041d15f7bb9080765299b06504
4
+ data.tar.gz: 00979da9c96ac05332773ec312126cfcf9596dc3
5
+ SHA512:
6
+ metadata.gz: 00478d03b3c4454eb4e3f8d5c4b8951d37fc3d745e7f8e51b40e604e23182073840b53bd9c5c3bcf45484e507ca4f91482cbe0a617e911f39396cb377f3a57f5
7
+ data.tar.gz: 35da0a00fcd4680074a228584904e0b26e7f133f2d70d93ae66881c41fdcdfa469c7908b79031ee18df72c0f73a790fc5520aa989060adf4f26412c6e52f569b
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+ ruby '2.0.0'
3
+
4
+ # Specify your gem's dependencies in foundation-center.gemspec
5
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Dan Porter
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ # FoundationCenter
2
+
3
+ A Ruby interface to the Foundation Center grant recipients API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'foundation_center'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install foundation_center
18
+
19
+ ## Usage
20
+
21
+ Fetch a list of grant recipients:
22
+
23
+ >> FoundationCenter.recipients
24
+ => [
25
+ {"recipient_ein"=>27121965, "recipient_name"=>"Emard-Parker",
26
+ "longitude"=>-86.08014482580468, "latitude"=>42.20946211250427},
27
+
28
+ {"recipient_ein"=>102016794, "recipient_name"=>"Cummerata, Heaney and Ullrich",
29
+ "longitude"=>-81.5489744409065, "latitude"=>32.790804352283004},
30
+
31
+ ...
32
+ ]
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'foundation_center'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "foundation_center"
8
+ spec.version = FoundationCenter::VERSION
9
+ spec.authors = ["Dan Porter"]
10
+ spec.email = ["wolfpakz@gmail.com"]
11
+ spec.description = %q{A Ruby interface to the Foundation Center grant recipients API}
12
+ spec.summary = %q{Provides a simple interface for fetching information about grant recipients and the grants they've received.}
13
+ spec.homepage = "http://github.com/wolfpakz/foundation-center"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rest-client", "~> 1.6.7"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake", "~> 10.0.4"
25
+ spec.add_development_dependency "rspec", "~> 2.13.0"
26
+ spec.add_development_dependency "shoulda-matchers", "~> 2.1.0"
27
+ spec.add_development_dependency "faker", "~> 1.1.2"
28
+ end
@@ -0,0 +1,24 @@
1
+ require 'foundation_center/version'
2
+
3
+ module FoundationCenter
4
+
5
+ URL = 'http://gisdev.foundationcenter.org/sustainArts/webServices'
6
+
7
+ class << self
8
+
9
+ def get_recipients
10
+ response = resource['getRecipients.php'].get
11
+ JSON.parse response
12
+ end
13
+
14
+ def get_recipient_details(ein)
15
+ response = resource['getRecipientDetails.php'].get :params => {:ein => ein}
16
+ JSON.parse response
17
+ end
18
+
19
+ def resource
20
+ RestClient::Resource.new(URL)
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module FoundationCenter
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Foundation Center' do
4
+
5
+ context 'Listing grant recipients' do
6
+ before(:each) do
7
+ # Fake the response json
8
+ @fake_json = fake_recipients_json
9
+
10
+ RestClient::Resource.any_instance.should_receive(:get) { @fake_json }
11
+ end
12
+
13
+ it 'returns an array' do
14
+ FoundationCenter.get_recipients.should be_kind_of(Array)
15
+ end
16
+
17
+ it 'returns a hash for every grant recipient' do
18
+ # Parse the fake JSON so we can count the recipients
19
+ fakes = JSON.parse @fake_json
20
+ fakes.should be_kind_of(Array)
21
+
22
+ # One for every recipient
23
+ recipients = FoundationCenter.get_recipients
24
+ recipients.length.should == fakes.length
25
+
26
+ # All of which are hashes
27
+ recipients.each do |r|
28
+ r.should be_kind_of(Hash)
29
+ end
30
+ end
31
+ end
32
+
33
+ context 'Recipient details' do
34
+ before(:each) do
35
+ # Fake the response json
36
+ @fake_json = fake_recipient_details_json
37
+
38
+ @parsed_json = JSON.parse @fake_json
39
+ @ein = @parsed_json['recipients'].first['recip_ein']
40
+
41
+ RestClient::Resource.any_instance.should_receive(:get) { @fake_json }
42
+ end
43
+
44
+ it 'returns a hash' do
45
+ FoundationCenter.get_recipient_details(@ein).should be_kind_of(Hash)
46
+ end
47
+
48
+ it 'returns details about a grant recipient' do
49
+ results = FoundationCenter.get_recipient_details(@ein)
50
+
51
+ results.should include('recipients')
52
+ results['recipients'].should be_an(Array)
53
+
54
+ recipient = results['recipients'].first
55
+ recipient.should be_a(Hash)
56
+ recipient.should include('recip_ein')
57
+
58
+ recipient['recip_ein'].should == @ein
59
+ end
60
+
61
+ it 'returns details about the grants a recipient has received' do
62
+ results = FoundationCenter.get_recipient_details(@ein)
63
+
64
+ results.should include('grants')
65
+ results['grants'].should be_an(Array)
66
+
67
+ grants = results['grants']
68
+ grants.all? { |grant| grant.is_a?(Hash) }.should be_true
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,109 @@
1
+ require 'json'
2
+ require 'faker'
3
+ require 'rest-client'
4
+
5
+ # This file was generated by the `rspec --init` command. Conventionally, all
6
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
7
+ # Require this file using `require "spec_helper"` to ensure that it is only
8
+ # loaded once.
9
+ #
10
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
11
+ RSpec.configure do |config|
12
+ config.treat_symbols_as_metadata_keys_with_true_values = true
13
+ config.run_all_when_everything_filtered = true
14
+ config.filter_run :focus
15
+
16
+ # Run specs in random order to surface order dependencies. If you find an
17
+ # order dependency and want to debug it, you can fix the order by providing
18
+ # the seed, which is printed after each run.
19
+ # --seed 1234
20
+ config.order = 'random'
21
+ end
22
+
23
+ def fake_ein
24
+ '%09d' % (rand(999999998) + 1)
25
+ end
26
+
27
+ def fake_recipients_json
28
+ #
29
+ # Yanked this directly from Foundation Center's API
30
+ #
31
+ "\r\n\r\n[{\"recipient_ein\":10559608,\"recipient_name\":\"Allied Media Projects\",\"longitude\":-83.0522468,\"latitude\":42.4140992},{\"recipient_ein\":10885325,\"recipient_name\":\"Harriet Tubman Center for Recruitment and Development of Organizers\",\"longitude\":-83.0433412,\"latitude\":42.3345747},{\"recipient_ein\":20648595,\"recipient_name\":\"Michigan Avenue Business Association\",\"longitude\":-83.1306395,\"latitude\":42.3311259},{\"recipient_ein\":20701008,\"recipient_name\":\"'Sistahs Providing Intelligence, Creativity and Empowerment'\",\"longitude\":-83.0522468,\"latitude\":42.4140992},{\"recipient_ein\":20754855,\"recipient_name\":\"Detroit International Jazz Festival Foundation\",\"longitude\":-83.130645,\"latitude\":42.4685724},{\"recipient_ein\":20755116,\"recipient_name\":\"Belle Isle Womens Committee\",\"longitude\":-83.209149,\"latitude\":42.5462149},{\"recipient_ein\":30390058,\"recipient_name\":\"Ballet Renaissance\",\"longitude\":-83.0522468,\"latitude\":42.4140992}]"
32
+ end
33
+
34
+ def fake_grant_key
35
+ rand(99999998) + 1
36
+ end
37
+
38
+ def fake_gm_key
39
+ '%s%03d' % [Faker::Lorem.words(1).first.upcase, rand(98) + 1]
40
+ end
41
+
42
+ def fake_grant_amount
43
+ ('%d000' % (rand(998) + 1)).to_i
44
+ end
45
+
46
+ def fake_grant_details
47
+ {
48
+ "grant_key" => fake_grant_key,
49
+ "gm_key" => fake_gm_key,
50
+ "gm_ein" => fake_ein,
51
+ "gm_name" => Faker::Company.name,
52
+ "gm_state" => Faker::Address.state_abbr,
53
+ "amount" => fake_grant_amount,
54
+ "duration" => 1,
55
+ "year_issued" => [2007, 2008, 2009, 2010, 2011, 2012, 2013].sample,
56
+ "description" => Faker::Lorem.paragraph(5),
57
+ "grant_activity_code" => "A3D; W52; R20",
58
+ "grant_activity_tran" => "'Media access and policy; Electronic communications/Internet; Civil/human rights, advocacy'",
59
+ "grant_pop_code" => "E0; P0",
60
+ "grant_pop_tran" => "Minorities; Economically disadvantaged",
61
+ "grant_area_served_tran" => " ",
62
+ "grant_support_tran" => "Management development/capacity building; Advocacy; Electronic media/online services; Research; Technical assistance",
63
+ "matching_support_flag" => " ",
64
+ "continuing_support_flag" => " ",
65
+ "source_of_data" => "04/11-06/11 EF",
66
+ "grant_country_tran" => " ",
67
+ "edition" => 812,
68
+ "currency" => " ",
69
+ "unconverted_amt" => " ",
70
+ "fund_name" => " ",
71
+ "fund_type" => " ",
72
+ "fund_sub_type" => " ",
73
+ "program_area" => " ",
74
+ "activity_override" => "A3D",
75
+ "activity_override_tran" => "Media access and policy",
76
+ "domestic_foreign_flag" => "D",
77
+ "county" => "Wayne ",
78
+ "area_name" => "'Detroit-Warren-Livonia, MI'"
79
+ }
80
+ end
81
+
82
+ def fake_recipient_details
83
+ {
84
+ 'recipient_key' => rand(9999998) + 1,
85
+ 'recip_ein' => fake_ein,
86
+ 'recip_name' => Faker::Company.name,
87
+ 'recip_street_addr' => Faker::Address.street_address,
88
+ 'recip_street_addr2' => Faker::Address.secondary_address,
89
+ 'recip_city' => Faker::Address.city,
90
+ 'recip_state' => Faker::Address.state_abbr,
91
+ 'recip_zipcode' => Faker::Address.zip_code,
92
+ 'recip_county' => "Wayne",
93
+ 'recip_type_code' => "A3E",
94
+ 'recip_type_tran' => "Media democracy",
95
+ 'recip_auspice' => "N",
96
+ 'recip_pop_code' => "E0; P0",
97
+ 'recip_pop_tran' => "Minorities; Economically disadvantaged",
98
+ 'recip_unit' => " ",
99
+ 'longitude' => -83.0522468,
100
+ 'latitude' => 42.4140992
101
+ }
102
+ end
103
+
104
+ def fake_recipient_details_json
105
+ {
106
+ :recipients => [fake_recipient_details],
107
+ :grants => (rand(4) + 1).times.map { fake_grant_details }
108
+ }.to_json
109
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: foundation_center
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dan Porter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 10.0.4
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 10.0.4
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.13.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 2.13.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: shoulda-matchers
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 2.1.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 2.1.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: faker
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 1.1.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 1.1.2
97
+ description: A Ruby interface to the Foundation Center grant recipients API
98
+ email:
99
+ - wolfpakz@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .rspec
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - foundation_center.gemspec
111
+ - lib/foundation_center.rb
112
+ - lib/foundation_center/version.rb
113
+ - spec/foundation_center_spec.rb
114
+ - spec/spec_helper.rb
115
+ homepage: http://github.com/wolfpakz/foundation-center
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.0.3
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Provides a simple interface for fetching information about grant recipients
139
+ and the grants they've received.
140
+ test_files:
141
+ - spec/foundation_center_spec.rb
142
+ - spec/spec_helper.rb