class CPIU::API
Interacts with the BLS.gov public API
Constants
- SERIESID
The time series to query
- URL
URL
to send POST requests to
Public Class Methods
request_data(startyear, endyear, ann_avg = false, calcs = false)
click to toggle source
Requests CPI-U data from the BLS server given two years between 1913 and the present. The API
will only return a maximum range of 20 years from the start year.
@param startyear [Integer] the first year to get data for @param endyear [Integer] the last year to get data for @param ann_avg [Boolean] set to true to include the average of monthly CPI
values for a year
@param calcs [Boolean] set to true to include net and percent CPI change
calculations
@return [Hash{String => String, Integer, Array}] the response data
retrieved from the server
# File lib/cpiu/api.rb, line 43 def self.request_data(startyear, endyear, ann_avg = false, calcs = false) response = RestClient.post(URL, { 'seriesid' => [SERIESID], 'startyear' => startyear, 'endyear' => endyear, 'annualaverage' => ann_avg, 'calculations' => calcs, 'registrationkey' => ENV['BLS_API_KEY'] }.to_json, content_type: 'application/json') JSON(response) end