first_giving_api 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +7 -0
- data/first_giving_api.gemspec +31 -0
- data/lib/first_giving_api.rb +20 -0
- data/lib/first_giving_api/charity.rb +86 -0
- data/lib/first_giving_api/configuration.rb +29 -0
- data/lib/first_giving_api/version.rb +3 -0
- data/spec/lib/first_giving_api_spec.rb +55 -0
- data/spec/spec_helper.rb +1 -0
- metadata +159 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 990edb07fa3e1a0c737b8c9c91b5b6c6c2f8603d
|
4
|
+
data.tar.gz: 4a4fb6675033cc7a09da14dd4fa44af4a61e60b1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 98073b3bf89a669f3bf5d65d6661ca20fe3f8c76d52a6426efa5a109c54b20157ea07f47b648e0217e4a20fc2860be9156ec0c4114747ea844e0a7e996e66142
|
7
|
+
data.tar.gz: 8bd0b93f413cbe5efb4957942497c4781e87d6971430374a59c46365cfcb2e6a9c05ec171f0d0c3fba678b9cf3aec4455c3bb1c76fdf5486cf596f66495311af
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
firstgiving
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0-p247
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Omar Shariff Delmo
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# FirstGivingApi
|
2
|
+
|
3
|
+
This is a Wrapper for the API of developers.firstgiving.com
|
4
|
+
|
5
|
+
I am a newbie so I would greatly appreciate any feedback or help regarding this project
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'first_giving_api'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install first_giving_api
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## TODO
|
26
|
+
|
27
|
+
Add class for donations
|
28
|
+
|
29
|
+
Refactor Charity search methods
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
1. Fork it
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'first_giving_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "first_giving_api"
|
8
|
+
spec.version = FirstGivingApi::VERSION
|
9
|
+
spec.authors = ["Omar Shariff Delmo"]
|
10
|
+
spec.email = ["omaruu@gmail.com"]
|
11
|
+
spec.description = %q{A Ruby Wrapper for the First Giving API}
|
12
|
+
spec.summary = %q{First Giving API Wrapper}
|
13
|
+
spec.homepage = ""
|
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_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
#include RSPEC
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
|
27
|
+
spec.add_runtime_dependency 'curb'
|
28
|
+
spec.add_runtime_dependency 'nokogiri'
|
29
|
+
spec.add_runtime_dependency 'pry'
|
30
|
+
spec.add_runtime_dependency 'crack'
|
31
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "first_giving_api/version"
|
2
|
+
require "first_giving_api/charity"
|
3
|
+
require "first_giving_api/configuration"
|
4
|
+
|
5
|
+
module FirstGivingApi
|
6
|
+
extend Configuration
|
7
|
+
|
8
|
+
#default lookup method
|
9
|
+
def self.lookup(charity_name)
|
10
|
+
Charity.new.query_contains(charity_name)
|
11
|
+
end
|
12
|
+
#lookup returns set that starts with search term
|
13
|
+
def self.lookup_starting_with(charity_name)
|
14
|
+
Charity.new.query_starts_with(charity_name)
|
15
|
+
end
|
16
|
+
#lookup using UUID
|
17
|
+
def self.lookup_id(charity_uuid)
|
18
|
+
Charity.new.query_uuid(charity_uuid)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'curb'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'crack'
|
4
|
+
|
5
|
+
module FirstGivingApi
|
6
|
+
class Charity
|
7
|
+
BASE_URL = 'http://graphapi.firstgiving.com/v1/list/organization?'
|
8
|
+
UUID_QUERY_URL = 'http://graphapi.firstgiving.com/v1/object/organization/'
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
end
|
12
|
+
|
13
|
+
def query_starts_with(charity_name)
|
14
|
+
http = Curl.get(BASE_URL+"q=organization_name:#{charity_name}*")
|
15
|
+
response = Crack::XML.parse(http.body_str)
|
16
|
+
result = response["payload"]["payload"].to_a
|
17
|
+
result.each do |subset|
|
18
|
+
subset.shift
|
19
|
+
end
|
20
|
+
result
|
21
|
+
end
|
22
|
+
def query_contains(charity_name)
|
23
|
+
http = Curl.get(BASE_URL+"q=organization_name:#{charity_name}")
|
24
|
+
response = Crack::XML.parse(http.body_str)
|
25
|
+
result = response["payload"]["payload"].to_a
|
26
|
+
result.each do |subset|
|
27
|
+
subset.shift
|
28
|
+
end
|
29
|
+
result
|
30
|
+
end
|
31
|
+
def query_uuid(charity_uuid)
|
32
|
+
http = Curl.get(UUID_QUERY_URL+charity_uuid)
|
33
|
+
response = Crack::XML.parse(http.body_str)
|
34
|
+
result = response["payload"]["payload"]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class ApiResponse
|
39
|
+
# attr_reader :organization_uuid,
|
40
|
+
# :organization_type_id,
|
41
|
+
# :government_id,
|
42
|
+
# :parent_organization_uuid,
|
43
|
+
# :address_line_1,
|
44
|
+
# :address_line_2,
|
45
|
+
# :address_line_3,
|
46
|
+
# :address_line_full,
|
47
|
+
# :city,
|
48
|
+
# :region,
|
49
|
+
# :postal_code,
|
50
|
+
# :county,
|
51
|
+
# :country,
|
52
|
+
# :address_full,
|
53
|
+
# :phone_number,
|
54
|
+
# :area_code,
|
55
|
+
# :url,
|
56
|
+
# :category_code,
|
57
|
+
# :latitude,
|
58
|
+
# :longitude,
|
59
|
+
# :revoked
|
60
|
+
|
61
|
+
def initialize(result)
|
62
|
+
# xml = Crack::XML.parse(result)
|
63
|
+
# @organization_uuid = xml.at('OrganizationUuid').text
|
64
|
+
# @organization_type_id = xml.at('OgranizationTypeId').text
|
65
|
+
# @government_id = xml.at('GovernmentId').text
|
66
|
+
# @parent_organization_uuid = xml.at('ParentOrganizationUuid').text
|
67
|
+
# @address_line_1 = xml.at('AddressLine1').text
|
68
|
+
# @address_line_2 = xml.at('AddressLine2').text
|
69
|
+
# @address_line_3 = xml.at('AddressLine3').text
|
70
|
+
# @address_line_full = xml.at('AddressLineFull').text
|
71
|
+
# @city = xml.at('City').text
|
72
|
+
# @region = xml.at('Region').text
|
73
|
+
# @postal_code = xml.at('PostalCode').text
|
74
|
+
# @county = xml.at('County').text
|
75
|
+
# @country = xml.at('Country').text
|
76
|
+
# @address_full = xml.at('AddressFull').text
|
77
|
+
# @phone_number = xml.at('PhoneNumber').text
|
78
|
+
# @area_code = xml.at('AreaCode').text
|
79
|
+
# @url = xml.at('Url').text
|
80
|
+
# @category_code = xml.at('CategoryCode').text
|
81
|
+
# @latitude = xml.at('Latitude').text
|
82
|
+
# @longitude = xml.at('Longitude').text
|
83
|
+
# @revoked = xml.at('Revoked')
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module FirstGivingApi
|
2
|
+
module Configuration
|
3
|
+
VALID_CONNECTION_KEYS = [:endpoint, :user_agent, :method].freeze
|
4
|
+
VALID_OPTIONS_KEYS = [:api_key, :format].freeze
|
5
|
+
VALID_CONFIG_KEYS = VALID_CONNECTION_KEYS + VALID_OPTIONS_KEYS
|
6
|
+
|
7
|
+
DEFAULT_ENDPOINT = nil
|
8
|
+
DEFAULT_METHOD = :get
|
9
|
+
DEFAULT_USER_AGENT = "First Giving API Ruby Gem #{FirstGivingApi::VERSION}".freeze
|
10
|
+
|
11
|
+
DEFAULT_API_KEY = nil
|
12
|
+
DEFAULT_FORMAT = :json
|
13
|
+
|
14
|
+
attr_accessor *VALID_CONFIG_KEYS
|
15
|
+
|
16
|
+
def self.extended(base)
|
17
|
+
base.reset
|
18
|
+
end
|
19
|
+
|
20
|
+
def reset
|
21
|
+
self.endpoint = DEFAULT_ENDPOINT
|
22
|
+
self.method = DEFAULT_METHOD
|
23
|
+
self.user_agent = DEFAULT_USER_AGENT
|
24
|
+
|
25
|
+
self.api_key = DEFAULT_API_KEY
|
26
|
+
self.format = DEFAULT_FORMAT
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pry'
|
3
|
+
|
4
|
+
describe FirstGivingApi do
|
5
|
+
context "configuration" do
|
6
|
+
describe ".app_key" do
|
7
|
+
it "should return default key" do
|
8
|
+
FirstGivingApi.api_key.should eql(FirstGivingApi::Configuration::DEFAULT_API_KEY)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
describe ".format" do
|
12
|
+
it "should return default format" do
|
13
|
+
FirstGivingApi.format.should eql(FirstGivingApi::Configuration::DEFAULT_FORMAT)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
describe ".user_agent" do
|
17
|
+
it "should return default user agent" do
|
18
|
+
FirstGivingApi.user_agent.should eql(FirstGivingApi::Configuration::DEFAULT_USER_AGENT)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
describe ".method" do
|
22
|
+
it "should return default http method" do
|
23
|
+
FirstGivingApi.method.should eql(FirstGivingApi::Configuration::DEFAULT_METHOD)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
context "charity" do
|
28
|
+
describe "query_contains" do
|
29
|
+
it "should return data for charities containing marijuana" do
|
30
|
+
org_data = FirstGivingApi.lookup("MARIJUANA")
|
31
|
+
org_data.should_not be_nil
|
32
|
+
org_data.each do |org|
|
33
|
+
org[0]["organization_name"].should include("MARIJUANA")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
describe "query_starts_with" do
|
38
|
+
it "should return data for charities starting with marijuana" do
|
39
|
+
org_data = FirstGivingApi.lookup_starting_with("MARIJUANA")
|
40
|
+
org_data.should_not be_nil
|
41
|
+
org_data.each do |org|
|
42
|
+
org[0]["organization_name"].should start_with("MARIJUANA")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
describe "query_with_id" do
|
47
|
+
it "should return data for the charity with UUID 0f0e0f80-2024-11e0-a279-4061860da51d" do
|
48
|
+
org_data = FirstGivingApi.lookup_id("0f0e0f80-2024-11e0-a279-4061860da51d")
|
49
|
+
org_data.should_not be_nil
|
50
|
+
org_data["organization_uuid"].should eql("0f0e0f80-2024-11e0-a279-4061860da51d")
|
51
|
+
org_data.keys.should eql(["organization_uuid", "organization_type_id", "organization_name", "government_id", "parent_organization_uuid", "address_line_1", "address_line_2", "address_line_3", "address_line_full", "city", "region", "postal_code", "county", "country", "address_full", "phone_number", "area_code", "url", "category_code", "latitude", "longitude", "revoked"])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'first_giving_api'
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: first_giving_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Omar Shariff Delmo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: curb
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: nokogiri
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: crack
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: A Ruby Wrapper for the First Giving API
|
112
|
+
email:
|
113
|
+
- omaruu@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- .rspec
|
120
|
+
- .ruby-gemset
|
121
|
+
- .ruby-version
|
122
|
+
- Gemfile
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- first_giving_api.gemspec
|
127
|
+
- lib/first_giving_api.rb
|
128
|
+
- lib/first_giving_api/charity.rb
|
129
|
+
- lib/first_giving_api/configuration.rb
|
130
|
+
- lib/first_giving_api/version.rb
|
131
|
+
- spec/lib/first_giving_api_spec.rb
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
homepage: ''
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
metadata: {}
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - '>='
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 2.0.6
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: First Giving API Wrapper
|
157
|
+
test_files:
|
158
|
+
- spec/lib/first_giving_api_spec.rb
|
159
|
+
- spec/spec_helper.rb
|