Skip to page content
Secretary of Labor Hilda L. Solis

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.

gem install json
gem install ruby-hmac


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.

Add Service Reference

For the DOL Service Operation sample please use http://api.dol.gov/V1/SummerJobs

Locate Dataset Location path from Dataset, for Summer Job Plus 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.

Require DOLDataSDK

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.

Instantiate DataContext and DataRequest

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

Standard DOL API datasets Call #call_api Method with valid arguments

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

Standard DOL Service Operation Call #call_api Method with valid arguments

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

Standard DOL API datasets display results

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

Standard DOL APIService Operation ,Parse json result and display.

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.

Wait For Requests

The finished code should look like this:

For Standard DOL API datasets :

Full Code for Standard DOL API datasets

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

Full Code for DOL Service Operation


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.

Configure Security, set API key and security token


Run the Application

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

Enter 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 :

Run the appliation to see a list of Agencies printed to the terminal

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

Run the appliation to see a list of jobs printed to the terminal