Skip to content

Instantly share code, notes, and snippets.

@keccers
Created December 13, 2013 21:39
Show Gist options
  • Save keccers/7951807 to your computer and use it in GitHub Desktop.
Save keccers/7951807 to your computer and use it in GitHub Desktop.
DOL Ruby SDK example
#import the GOVDataSDK file into your sample project.
require './GOVDataSDK'
#Create a new object and call the extend data set.
API_HOST = 'http://api.dol.gov'
API_KEY = 'c789a707-76b6-470e-8e94-a9bfb9d9a7d6'
API_SECRET = 'bosses_office'
API_URI = 'V1'
API_DATA = 'article/xml'
context = GOV::DataContext.new API_HOST, API_KEY, API_SECRET, API_DATA, API_URI
request = GOV::DataRequest.new context
############ CALL 1 This is the an example using DOL's API. For other agencies, substitute the method and arguments as necessary.
request.call_api 'Compliance/WHD/foodService', :filter => "(city_nm eq 'New York')", :top => 20 do |results, error|
if error
puts error
else
print "\nattempting to print the results\n"
#if the JSON is parsed
results.each do |n|
puts "#{n['trade_nm']} - #{n['city_nm']}"
end
#end if the JSON is parsed
#if the JSON is not parsed
print results
#end if the JSON is not parsed
end
end
request.wait_until_finished
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment