forked from USDepartmentofLabor/Ruby-Sample-App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSample.rb
executable file
·56 lines (43 loc) · 1.47 KB
/
Sample.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#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 = ''
API_SECRET = ''
API_DATA = ''
API_URI = 'V1'
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 'DOLAgency/Agencies', :select => 'Agency,AgencyFullName', :orderby => 'AgencyFullName' 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['Agency']} - #{n['AgencyFullName']}"
end
#end if the JSON is parsed
#if the JSON is not parsed
print results
#end if the JSON is not parsed
end
end
######### CALL 2# This calls the Derpartment of Labor data set callL: Make API call for Summer Jobs####################
#Make API call
#request.call_api 'SummerJobs/getJobsListing', :format => '\'json\'', :query => '\'farm\'',
# :region => '', :locality => '',
# :skipcount => '1' do |results, error|
# if error
# puts error
# else
# Jobs = results['getJobsListing']
# JobsListing = Jobs['items']
# results
# JobsListing.each do |n|
# puts "#{n['title']} - #{n['snippet']}"
# end
# end
#end
request.wait_until_finished