cpiu 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,47 +1,47 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: post
5
- uri: https://api.bls.gov/publicAPI/v2/timeseries/data/
6
- body:
7
- encoding: UTF-8
8
- string: '{"seriesid":["CUUR0000SA0"],"startyear":1913,"endyear":1914,"annualaverage":false,"calculations":false,"registrationkey":"<SECURE>"}'
9
- headers:
10
- Accept:
11
- - "*/*"
12
- Accept-Encoding:
13
- - gzip, deflate
14
- User-Agent:
15
- - rest-client/2.0.2 (mingw32 x86_64) ruby/2.4.1p111
16
- Content-Type:
17
- - application/json
18
- Content-Length:
19
- - '156'
20
- Host:
21
- - api.bls.gov
22
- response:
23
- status:
24
- code: 200
25
- message: OK
26
- headers:
27
- Date:
28
- - Tue, 01 Aug 2017 23:28:36 GMT
29
- Strict-Transport-Security:
30
- - max-age=31536000; includeSubdomains;
31
- Set-Cookie:
32
- - JSESSIONID=F7FDB348E776CCB74BBDC3102716FACA; Version=1; Path="/publicAPI/";
33
- Secure; HttpOnly
34
- Content-Type:
35
- - application/json
36
- Content-Length:
37
- - '2154'
38
- body:
39
- encoding: UTF-8
40
- string: |-
41
- {"status":"REQUEST_SUCCEEDED","responseTime":45,"message":[],"Results":{
42
- "series":
43
- [{"seriesID":"CUUR0000SA0","data":[{"year":"1914","period":"M12","periodName":"December","value":"10.1","footnotes":[{}]},{"year":"1914","period":"M11","periodName":"November","value":"10.2","footnotes":[{}]},{"year":"1914","period":"M10","periodName":"October","value":"10.1","footnotes":[{}]},{"year":"1914","period":"M09","periodName":"September","value":"10.2","footnotes":[{}]},{"year":"1914","period":"M08","periodName":"August","value":"10.2","footnotes":[{}]},{"year":"1914","period":"M07","periodName":"July","value":"10.0","footnotes":[{}]},{"year":"1914","period":"M06","periodName":"June","value":"9.9","footnotes":[{}]},{"year":"1914","period":"M05","periodName":"May","value":"9.9","footnotes":[{}]},{"year":"1914","period":"M04","periodName":"April","value":"9.8","footnotes":[{}]},{"year":"1914","period":"M03","periodName":"March","value":"9.9","footnotes":[{}]},{"year":"1914","period":"M02","periodName":"February","value":"9.9","footnotes":[{}]},{"year":"1914","period":"M01","periodName":"January","value":"10.0","footnotes":[{}]},{"year":"1913","period":"M12","periodName":"December","value":"10.0","footnotes":[{}]},{"year":"1913","period":"M11","periodName":"November","value":"10.1","footnotes":[{}]},{"year":"1913","period":"M10","periodName":"October","value":"10.0","footnotes":[{}]},{"year":"1913","period":"M09","periodName":"September","value":"10.0","footnotes":[{}]},{"year":"1913","period":"M08","periodName":"August","value":"9.9","footnotes":[{}]},{"year":"1913","period":"M07","periodName":"July","value":"9.9","footnotes":[{}]},{"year":"1913","period":"M06","periodName":"June","value":"9.8","footnotes":[{}]},{"year":"1913","period":"M05","periodName":"May","value":"9.7","footnotes":[{}]},{"year":"1913","period":"M04","periodName":"April","value":"9.8","footnotes":[{}]},{"year":"1913","period":"M03","periodName":"March","value":"9.8","footnotes":[{}]},{"year":"1913","period":"M02","periodName":"February","value":"9.8","footnotes":[{}]},{"year":"1913","period":"M01","periodName":"January","value":"9.8","footnotes":[{}]}]}]
44
- }}
45
- http_version:
46
- recorded_at: Tue, 01 Aug 2017 23:28:36 GMT
47
- recorded_with: VCR 3.0.3
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.bls.gov/publicAPI/v2/timeseries/data/
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"seriesid":["CUUR0000SA0"],"startyear":1913,"endyear":1914,"annualaverage":false,"calculations":false,"registrationkey":"<SECURE>"}'
9
+ headers:
10
+ Accept:
11
+ - "*/*"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - rest-client/2.0.2 (darwin16.6.0 x86_64) ruby/2.4.1p111
16
+ Content-Type:
17
+ - application/json
18
+ Content-Length:
19
+ - '156'
20
+ Host:
21
+ - api.bls.gov
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ headers:
27
+ Date:
28
+ - Wed, 02 Aug 2017 04:42:19 GMT
29
+ Strict-Transport-Security:
30
+ - max-age=31536000; includeSubdomains;
31
+ Set-Cookie:
32
+ - JSESSIONID=6BE4A1C96F1FD629B9A6C995B3F46E6C; Version=1; Path="/publicAPI/";
33
+ Secure; HttpOnly
34
+ Content-Type:
35
+ - application/json
36
+ Content-Length:
37
+ - '2154'
38
+ body:
39
+ encoding: UTF-8
40
+ string: |-
41
+ {"status":"REQUEST_SUCCEEDED","responseTime":37,"message":[],"Results":{
42
+ "series":
43
+ [{"seriesID":"CUUR0000SA0","data":[{"year":"1914","period":"M12","periodName":"December","value":"10.1","footnotes":[{}]},{"year":"1914","period":"M11","periodName":"November","value":"10.2","footnotes":[{}]},{"year":"1914","period":"M10","periodName":"October","value":"10.1","footnotes":[{}]},{"year":"1914","period":"M09","periodName":"September","value":"10.2","footnotes":[{}]},{"year":"1914","period":"M08","periodName":"August","value":"10.2","footnotes":[{}]},{"year":"1914","period":"M07","periodName":"July","value":"10.0","footnotes":[{}]},{"year":"1914","period":"M06","periodName":"June","value":"9.9","footnotes":[{}]},{"year":"1914","period":"M05","periodName":"May","value":"9.9","footnotes":[{}]},{"year":"1914","period":"M04","periodName":"April","value":"9.8","footnotes":[{}]},{"year":"1914","period":"M03","periodName":"March","value":"9.9","footnotes":[{}]},{"year":"1914","period":"M02","periodName":"February","value":"9.9","footnotes":[{}]},{"year":"1914","period":"M01","periodName":"January","value":"10.0","footnotes":[{}]},{"year":"1913","period":"M12","periodName":"December","value":"10.0","footnotes":[{}]},{"year":"1913","period":"M11","periodName":"November","value":"10.1","footnotes":[{}]},{"year":"1913","period":"M10","periodName":"October","value":"10.0","footnotes":[{}]},{"year":"1913","period":"M09","periodName":"September","value":"10.0","footnotes":[{}]},{"year":"1913","period":"M08","periodName":"August","value":"9.9","footnotes":[{}]},{"year":"1913","period":"M07","periodName":"July","value":"9.9","footnotes":[{}]},{"year":"1913","period":"M06","periodName":"June","value":"9.8","footnotes":[{}]},{"year":"1913","period":"M05","periodName":"May","value":"9.7","footnotes":[{}]},{"year":"1913","period":"M04","periodName":"April","value":"9.8","footnotes":[{}]},{"year":"1913","period":"M03","periodName":"March","value":"9.8","footnotes":[{}]},{"year":"1913","period":"M02","periodName":"February","value":"9.8","footnotes":[{}]},{"year":"1913","period":"M01","periodName":"January","value":"9.8","footnotes":[{}]}]}]
44
+ }}
45
+ http_version:
46
+ recorded_at: Wed, 02 Aug 2017 04:42:26 GMT
47
+ recorded_with: VCR 3.0.3
@@ -1,24 +1,24 @@
1
- # CPIU - a Ruby interface for fetching CPI-U data from BLS.gov
2
- # Copyright (C) 2017 Cody Logan
3
- #
4
- # This program is free software: you can redistribute it and/or modify
5
- # it under the terms of the GNU General Public License as published by
6
- # the Free Software Foundation, either version 3 of the License, or
7
- # (at your option) any later version.
8
- #
9
- # This program is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- # GNU General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU General Public License
15
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
-
17
- require 'cpiu/api'
18
- require 'cpiu/data'
19
- require 'cpiu/version'
20
-
21
- # main cpiu module
22
- module CPIU
23
- # Your code goes here...
24
- end
1
+ # CPIU - a Ruby interface for fetching CPI-U data from BLS.gov
2
+ # Copyright (C) 2017 Cody Logan
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'cpiu/api'
18
+ require 'cpiu/data'
19
+ require 'cpiu/version'
20
+
21
+ # main cpiu module
22
+ module CPIU
23
+ # Your code goes here...
24
+ end
@@ -1,57 +1,57 @@
1
- # frozen_string_literal: true
2
-
3
- # CPIU - a Ruby interface for fetching CPI-U data from BLS.gov
4
- # Copyright (C) 2017 Cody Logan
5
- #
6
- # This program is free software: you can redistribute it and/or modify
7
- # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation, either version 3 of the License, or
9
- # (at your option) any later version.
10
- #
11
- # This program is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- # GNU General Public License for more details.
15
- #
16
- # You should have received a copy of the GNU General Public License
17
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
-
19
- require 'rest-client'
20
- require 'json'
21
- require 'dotenv/load'
22
-
23
- module CPIU
24
- # Interacts with the BLS.gov public API
25
- class API
26
- # URL to send POST requests to
27
- URL = 'https://api.bls.gov/publicAPI/v2/timeseries/data/'.freeze
28
- # The time series to query
29
- SERIESID = 'CUUR0000SA0'.freeze
30
-
31
- # Requests CPI-U data from the BLS server given two years between 1913 and
32
- # the present. The API will only return a maximum range of 20 years from
33
- # the start year.
34
- #
35
- # @param startyear [Integer] the first year to get data for
36
- # @param endyear [Integer] the last year to get data for
37
- # @param ann_avg [Boolean] set to true to include the average of monthly CPI
38
- # values for a year
39
- # @param calcs [Boolean] set to true to include net and percent CPI change
40
- # calculations
41
- # @return [Hash{String => String, Integer, Array}] the response data
42
- # retrieved from the server
43
- def self.request_data(startyear, endyear, ann_avg = false, calcs = false)
44
- response = RestClient.post(URL,
45
- {
46
- 'seriesid' => [SERIESID],
47
- 'startyear' => startyear,
48
- 'endyear' => endyear,
49
- 'annualaverage' => ann_avg,
50
- 'calculations' => calcs,
51
- 'registrationkey' => ENV['BLS_API_KEY']
52
- }.to_json,
53
- content_type: 'application/json')
54
- JSON(response)
55
- end
56
- end
57
- end
1
+ # frozen_string_literal: true
2
+
3
+ # CPIU - a Ruby interface for fetching CPI-U data from BLS.gov
4
+ # Copyright (C) 2017 Cody Logan
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ require 'rest-client'
20
+ require 'json'
21
+ require 'dotenv/load'
22
+
23
+ module CPIU
24
+ # Interacts with the BLS.gov public API
25
+ class API
26
+ # URL to send POST requests to
27
+ URL = 'https://api.bls.gov/publicAPI/v2/timeseries/data/'.freeze
28
+ # The time series to query
29
+ SERIESID = 'CUUR0000SA0'.freeze
30
+
31
+ # Requests CPI-U data from the BLS server given two years between 1913 and
32
+ # the present. The API will only return a maximum range of 20 years from
33
+ # the start year.
34
+ #
35
+ # @param startyear [Integer] the first year to get data for
36
+ # @param endyear [Integer] the last year to get data for
37
+ # @param ann_avg [Boolean] set to true to include the average of monthly CPI
38
+ # values for a year
39
+ # @param calcs [Boolean] set to true to include net and percent CPI change
40
+ # calculations
41
+ # @return [Hash{String => String, Integer, Array}] the response data
42
+ # retrieved from the server
43
+ def self.request_data(startyear, endyear, ann_avg = false, calcs = false)
44
+ response = RestClient.post(URL,
45
+ {
46
+ 'seriesid' => [SERIESID],
47
+ 'startyear' => startyear,
48
+ 'endyear' => endyear,
49
+ 'annualaverage' => ann_avg,
50
+ 'calculations' => calcs,
51
+ 'registrationkey' => ENV['BLS_API_KEY']
52
+ }.to_json,
53
+ content_type: 'application/json')
54
+ JSON(response)
55
+ end
56
+ end
57
+ end
@@ -1,40 +1,57 @@
1
- # CPIU - a Ruby interface for fetching CPI-U data from BLS.gov
2
- # Copyright (C) 2017 Cody Logan
3
- #
4
- # This program is free software: you can redistribute it and/or modify
5
- # it under the terms of the GNU General Public License as published by
6
- # the Free Software Foundation, either version 3 of the License, or
7
- # (at your option) any later version.
8
- #
9
- # This program is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- # GNU General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU General Public License
15
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
-
17
- require 'cpiu/api'
18
-
19
- module CPIU
20
- # Return CPI data to the user while stripping the rest
21
- # of the response data returned by the server
22
- class Data
23
- # Get CPI data for a single year
24
- # @param year [Integer]
25
- # @return [Array<Hash>] an array of hashes containing monthly CPI values
26
- def self.single_year(year)
27
- response = CPIU::API.request_data(year, year)
28
- response['Results']['series'][0]['data']
29
- end
30
-
31
- # Get CPI data for a year range (up to 20 years)
32
- # @param startyear [Integer] the first year to get data for
33
- # @param endyear [Integer] the last year to get data for
34
- # @return [Array<Hash>] an array of hashes containing monthly CPI values
35
- def self.year_range(startyear, endyear)
36
- response = CPIU::API.request_data(startyear, endyear)
37
- response['Results']['series'][0]['data']
38
- end
39
- end
40
- end
1
+ # CPIU - a Ruby interface for fetching CPI-U data from BLS.gov
2
+ # Copyright (C) 2017 Cody Logan
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'cpiu/api'
18
+
19
+ module CPIU
20
+ # Return CPI data to the user while stripping the rest
21
+ # of the response data returned by the server
22
+ class Data
23
+ # Get CPI data for a single year
24
+ # @param year [Integer]
25
+ # @return [Array<Hash>] an array of hashes containing monthly CPI values
26
+ def self.single_year(year)
27
+ response = CPIU::API.request_data(year, year, true)
28
+ response['Results']['series'][0]['data']
29
+ end
30
+
31
+ # Get CPI data for a year range (up to 20 years)
32
+ # @param startyear [Integer] the first year to get data for
33
+ # @param endyear [Integer] the last year to get data for
34
+ # @return [Array<Hash>] an array of hashes containing monthly CPI values
35
+ def self.year_range(startyear, endyear)
36
+ response = CPIU::API.request_data(startyear, endyear)
37
+ response['Results']['series'][0]['data']
38
+ end
39
+
40
+ # Get annual average CPI for a given year
41
+ # @param year [Integer] the year
42
+ # @return [Float]
43
+ def self.cpiu_year(year)
44
+ data = CPIU::Data.single_year(year)
45
+ data[0]['value'].to_f
46
+ end
47
+
48
+ # Get CPI value for a given month and year
49
+ # @param year [Integer] the year
50
+ # @param month [Integer] the month (1-12)
51
+ # @return [Float]
52
+ def self.cpiu_month(year, month)
53
+ data = CPIU::Data.single_year(year).reverse
54
+ data[month - 1]['value'].to_f
55
+ end
56
+ end
57
+ end
@@ -1,22 +1,22 @@
1
- # frozen_string_literal: true
2
-
3
- # CPIU - a Ruby interface for fetching CPI-U data from BLS.gov
4
- # Copyright (C) 2017 Cody Logan
5
- #
6
- # This program is free software: you can redistribute it and/or modify
7
- # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation, either version 3 of the License, or
9
- # (at your option) any later version.
10
- #
11
- # This program is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- # GNU General Public License for more details.
15
- #
16
- # You should have received a copy of the GNU General Public License
17
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
-
19
- module CPIU
20
- # Current CPIU gem version
21
- VERSION = '0.1.1'.freeze
22
- end
1
+ # frozen_string_literal: true
2
+
3
+ # CPIU - a Ruby interface for fetching CPI-U data from BLS.gov
4
+ # Copyright (C) 2017 Cody Logan
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ module CPIU
20
+ # Current CPIU gem version
21
+ VERSION = '0.2.0'.freeze
22
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cpiu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Logan
@@ -153,13 +153,13 @@ files:
153
153
  - Rakefile
154
154
  - bin/console
155
155
  - bin/setup
156
+ - cpiu.gemspec
156
157
  - fixtures/vcr_cassettes/single_year.yml
157
158
  - fixtures/vcr_cassettes/year_range.yml
158
159
  - lib/cpiu.rb
159
160
  - lib/cpiu/api.rb
160
161
  - lib/cpiu/data.rb
161
162
  - lib/cpiu/version.rb
162
- - ruby_cpiu.gemspec
163
163
  homepage: https://github.com/clpo13/cpiu-ruby
164
164
  licenses:
165
165
  - GPL-3.0