guidestar 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -2
- data/lib/guidestar.rb +4 -0
- data/lib/guidestar/request.rb +4 -2
- data/lib/guidestar/result.rb +40 -19
- data/lib/guidestar/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -33,7 +33,7 @@ Once you initialize it, you can use it in your code via:
|
|
33
33
|
results.total_count
|
34
34
|
# => 1292
|
35
35
|
|
36
|
-
results.
|
36
|
+
results.each do |org|
|
37
37
|
org.name
|
38
38
|
# => 'Monkey Paradise'
|
39
39
|
org.ein
|
@@ -46,9 +46,14 @@ Once you initialize it, you can use it in your code via:
|
|
46
46
|
|
47
47
|
For getting the next page of results, it behaves similarly to kaminari or will_paginate:
|
48
48
|
|
49
|
-
results.per(50).page(2).
|
49
|
+
results.per(50).page(2).each { |more_orgs| puts more_orgs.name }
|
50
50
|
|
51
|
+
If you need more direct access to the array of results, just hit:
|
51
52
|
|
53
|
+
results.organizations
|
54
|
+
|
55
|
+
The way you use it is all super-flexible. You can pass in your options beforehand or
|
56
|
+
chain them along the way.
|
52
57
|
|
53
58
|
## Contributing
|
54
59
|
|
data/lib/guidestar.rb
CHANGED
data/lib/guidestar/request.rb
CHANGED
@@ -2,7 +2,8 @@ module Guidestar
|
|
2
2
|
module Request
|
3
3
|
|
4
4
|
def get(path, data={})
|
5
|
-
|
5
|
+
set_params(data)
|
6
|
+
Guidestar::Result.new(path,self)
|
6
7
|
end
|
7
8
|
|
8
9
|
def get_raw(path, data={})
|
@@ -20,7 +21,8 @@ module Guidestar
|
|
20
21
|
@options[:page_size] = @options.delete(:per) if @options[:per]
|
21
22
|
@options[:zip_radius] = @options.delete(:zipradius) if @options[:zipradius]
|
22
23
|
@options[:org_name] = @options.delete(:name) if @options[:name]
|
23
|
-
@options[:offset] = (@options.delete(:page)-1)
|
24
|
+
@options[:offset] = (@options.delete(:page)-1) * @options[:page_size].to_i if @options[:page]
|
25
|
+
@options[:ein] = @options[:ein].to_s.insert(2,'-') if @options[:ein] && @options[:ein].to_s[2] != '-'
|
24
26
|
builder = Nokogiri::XML::Builder.new do |xml|
|
25
27
|
xml.query do
|
26
28
|
xml.version @options[:version]
|
data/lib/guidestar/result.rb
CHANGED
@@ -1,38 +1,59 @@
|
|
1
1
|
module Guidestar
|
2
2
|
class Result
|
3
|
-
#
|
4
|
-
# Public: Returns the String xml of the response from Guidestar
|
5
|
-
attr_reader :xml
|
6
3
|
|
7
|
-
|
8
|
-
|
4
|
+
include Enumerable
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
def_delegators :organizations, :size, :length, :last
|
8
|
+
def_delegators :data, :xml, :total_count, :search_time
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
def initialize(path, client)
|
11
|
+
@path = path
|
12
|
+
@client = client
|
13
|
+
@options = {}
|
14
|
+
@data = Hashie::Mash.new
|
15
|
+
end
|
12
16
|
|
13
|
-
# Public:
|
17
|
+
# Public: Contains the data we retrieve, or gets new data if there
|
18
|
+
# are new parameters on the request.
|
19
|
+
#
|
20
|
+
# Returns an Array of organizations from the search
|
14
21
|
def organizations
|
15
22
|
return @organizations if @organizations
|
16
|
-
|
23
|
+
load_response
|
17
24
|
@organizations
|
18
25
|
end
|
19
26
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
27
|
+
# Internal: Contains a few extra details that might be desired, like
|
28
|
+
# the total_count and search_time, which are also available via
|
29
|
+
# delegation
|
30
|
+
#
|
31
|
+
# Returns a Hash of extra data
|
32
|
+
def data
|
33
|
+
return @data if @organizations
|
34
|
+
load_response
|
35
|
+
@data
|
36
|
+
end
|
37
|
+
|
38
|
+
# Public: Iterates through the inner array to make data more accessible
|
39
|
+
def each(&block)
|
40
|
+
organizations.each(&block)
|
24
41
|
end
|
25
42
|
|
26
43
|
private
|
27
44
|
|
28
|
-
def
|
29
|
-
|
30
|
-
@
|
31
|
-
@
|
32
|
-
@
|
45
|
+
def load_response
|
46
|
+
raw_response = @client.get_raw(@path, @options)
|
47
|
+
@data[:xml] = ::MultiXml.parse(raw_response.body.string)['root']
|
48
|
+
@data[:total_count] = @data[:xml]['totalResults'].to_i
|
49
|
+
@data[:search_time] = @data[:xml]['searchTime'].to_f
|
33
50
|
|
51
|
+
@options = {}
|
34
52
|
@organizations = []
|
35
|
-
|
53
|
+
|
54
|
+
orgs = @data[:xml]['organizations']['organization'] if @data[:xml]['organizations']
|
55
|
+
return if orgs.nil?
|
56
|
+
|
36
57
|
orgs = [orgs] unless orgs.is_a?(Array)
|
37
58
|
orgs.each do |org|
|
38
59
|
org = Hashie::Mash.new clean_keys(org)
|
data/lib/guidestar/version.rb
CHANGED