Ruby DOL Data SDK Sample
Overview
This sample will provide the steps to create a simple Ruby application that can consume DOL Data.
Following these steps in order will allow your application to operate correctly.
Download this project |
Download project for Service Operation.
This solution was built using:
Create a New Project
Create a project folder for this sample.
Create a new text document using any text editor and save it as Sample.rb in the project folder.
Add SDK to Project
Copy the DOLDataSDK.rb file into the project folder.
Ensure that you have installed the
json
and ruby-hmac gems.


Locate the Dataset Path
Each Dataset has a Dataset Location path that gives the URL that will be needed to reach the Dataset on the API. For this sample please see the one circled in red.

For the DOL Service Operation sample please use http://api.dol.gov/V1/SummerJobs
Implementing the DOL Data Request
The DOLDataSDK.rb file handles everything required for submitting data requests to the DOL API. We will need the SDK classes in that file so we add them to Sample.rb with a require statement.

In order to submit data requests, we will need to create two objects; an instance of DOL::DataContext, to hold various information about our data request, and an instance of DOL::DataRequest, to handle the submission of the request.

Next, we need to call DOL::DataRequest#call_api on the newly created DOL::DataRequest instance. This method submits the request to the DOL API. The method argument represents the Dataset and table portion of the Data location path. The arguments argument represents additional information sent to the API to narrow down the data you wish to recieve.
For Standard DOL API datasets

For DOL Service Operation (e.g. Summer Job Plus)

Additionally, we need to provide #call_api with a block to execute after the DOL API returns the data we requested.
For Standard DOL API datasets

For DOL Service Operation (e.g. Summer Job Plus)

Finally, we need to tell Ruby to wait until the request finishes before closing. We do this by calling DOL::DataRequest#wait_until_finished on the DOL::DataRequest instance.

The finished code should look like this:
For Standard DOL API datasets :

For DOL Service Operation (e.g. Summer Job Plus) :

Configure Security
Secure logins are provided using the following code; we will need to insure that the DOL::DataContext instance is initialied with both an ApiKey and a SharedSecret. Replace "your-token" and "your-shared-secret" in DOL::DataContext.new with your Token and SharedSecret.
- The ApiKey corresponds to the Token identifier in your token list.
- The SharedSecret that is associated with that token.

Run the Application
In order to run this application you will need to open a terminal window and navigate into your project folder.

Run the program with ruby Sample.rb and you should see a list of Agencies printed to the terminal.
For Standard DOL API datasets :

For DOL Service Operation (e.g. Summer Job Plus) :
