Created
February 14, 2012 20:37
-
-
Save leshill/1830164 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module DonorsChoose | |
extend self | |
attr_accessor :api_key | |
def projects_near_me(latitude, longitude) | |
Request.get(:centerLat => latitude, :centerLong => longitude) | |
end | |
def projects_by_zip(zipcode) | |
Request.get(:keyword => zipcode) | |
en | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DonorsChoose::Request | |
def self.get(params) | |
new(params).get | |
end | |
def initialize(params) | |
@params = params | |
end | |
def get | |
data = JSON.parse(fetch)["proposals"] | |
data.collect {|datum| OpenStruct.new(datum)} | |
end | |
private | |
def fetch | |
base_uri = 'http://api.donorschoose.org/common/json_feed.html' | |
uri_params = @params.collect do |key, value| | |
"#{key}=#{CGI.escape(value.to_s)}" | |
end | |
uri_params = [uri_params, "APIKey=#{DonorsChoose.api_key}"].join("&") | |
Net::HTTP.get(URI(base_uri + "?" + uri_params)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment