Class: Orghunter::Search
- Inherits:
-
Object
- Object
- Orghunter::Search
- Defined in:
- lib/orghunter/search.rb
Instance Attribute Summary collapse
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
- #count ⇒ Object
- #create_charities(charity_hashes) ⇒ Object
- #create_string ⇒ Object
- #final_position ⇒ Object
-
#initialize(args) ⇒ Search
constructor
A new instance of Search.
- #query_api ⇒ Object
- #rows_returned ⇒ Object
- #start_position ⇒ Object
Constructor Details
permalink #initialize(args) ⇒ Search
Returns a new instance of Search.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/orghunter/search.rb', line 5 def initialize(args) @ein = args[:ein] ? "&ein=#{args[:ein]}" : @search_term = args[:search_term] ? "&searchTerm=#{args[:search_term]}" : '' @city = args[:city] ? "&city=#{args[:city]}" : '' @state = args[:state] ? "&state=#{args[:state]}" : '' @zip_code = args[:zip_code] ? "&zipCode=#{args[:zip_code]}" : '' @category = args[:category] ? "&category=#{args[:category]}" : '' @eligible = args[:eligible] ? "&eligible=1" : '' @rows = args[:rows] ? "&rows=#{args[:rows]}" : '' @start = args[:start] ? "&start=#{args[:start]}" : '' query_api end |
Instance Attribute Details
permalink #results ⇒ Object (readonly)
Returns the value of attribute results.
3 4 5 |
# File 'lib/orghunter/search.rb', line 3 def results @results end |
Instance Method Details
permalink #count ⇒ Object
[View source]
34 35 36 37 |
# File 'lib/orghunter/search.rb', line 34 def count return 0 if @response_json['data'].empty? @response_json['data'][0]['recordCount'] end |
permalink #create_charities(charity_hashes) ⇒ Object
[View source]
30 31 32 |
# File 'lib/orghunter/search.rb', line 30 def create_charities(charity_hashes) charity_hashes.map{|charity_hash| Charity.new(charity_hash)} end |
permalink #create_string ⇒ Object
[View source]
18 19 20 21 |
# File 'lib/orghunter/search.rb', line 18 def create_string unencoded_url = "http://data.orghunter.com/v1/charitysearch?user_key=#{Orghunter.configuration.api_key}#{@ein}#{@search_term}#{@city}#{@state}#{@zip_code}#{@category}#{@eligible}#{@rows}#{@start}" @query_url = URI::encode(unencoded_url) end |
permalink #final_position ⇒ Object
[View source]
43 44 45 |
# File 'lib/orghunter/search.rb', line 43 def final_position start_position + rows_returned end |
permalink #query_api ⇒ Object
[View source]
23 24 25 26 27 28 |
# File 'lib/orghunter/search.rb', line 23 def query_api create_string response = Net::HTTP.get_response(URI(@query_url)) @response_json = JSON.parse(response.body) @results = create_charities(@response_json['data']) end |
permalink #rows_returned ⇒ Object
[View source]
47 48 49 |
# File 'lib/orghunter/search.rb', line 47 def rows_returned @response_json['data'][0]['rows'] end |
permalink #start_position ⇒ Object
[View source]
39 40 41 |
# File 'lib/orghunter/search.rb', line 39 def start_position @response_json['data'][0]['start'] end |