cpiu 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,114 +1,114 @@
1
- # CPIU
2
-
3
- [![Build Status](https://travis-ci.org/clpo13/cpiu-ruby.svg?branch=master)](https://travis-ci.org/clpo13/cpiu-ruby)
4
- [![Coverage Status](https://coveralls.io/repos/github/clpo13/cpiu-ruby/badge.svg?branch=master)](https://coveralls.io/github/clpo13/cpiu-ruby?branch=master)
5
- [![Gem Version](https://badge.fury.io/rb/cpiu.svg)](https://badge.fury.io/rb/cpiu)
6
-
7
- CPIU is a Ruby interface for [CPI-U](https://www.bls.gov/cpi/) data provided by the U.S. Bureau of Labor Statistics. CPI-U data are commonly used for calculating inflation. More info on the BLS Public Data API is available [here](https://www.bls.gov/developers/home.htm).
8
-
9
- Neither I nor BLS.gov can vouch for the data or analyses derived from these data after the data have been retrieved from BLS.gov.
10
-
11
- ## Installation
12
-
13
- Add this line to your application's Gemfile:
14
-
15
- ```ruby
16
- gem 'cpiu', '~> 0.1'
17
- ```
18
-
19
- And then execute:
20
-
21
- ```bash
22
- bundle
23
- ```
24
-
25
- Or install it yourself as:
26
-
27
- ```bash
28
- gem install cpiu
29
- ```
30
-
31
- ## Usage
32
-
33
- Add the following to your program:
34
-
35
- ```ruby
36
- require 'cpiu'
37
- ```
38
-
39
- The following methods will retrieve JSON objects containing CPI-U data:
40
-
41
- * `CPIU::Data.single_year(year)` - data for a single year
42
- * `CPIU::Data.year_range(startyear, endyear)` - data for a year range no greater than 20 years
43
-
44
- The data is returned in an array of hashes:
45
-
46
- ```ruby
47
- [
48
- {
49
- "year" => "1913",
50
- "period" => "M12",
51
- "periodName" => "December",
52
- "value" => "10.0",
53
- "footnotes" => [{}]
54
- },
55
- ...
56
- ]
57
- ```
58
-
59
- A raw API call method is available too:
60
-
61
- * `CPIU::API.request_data(startyear, endyear, ann_avg, calcs)`
62
-
63
- If set to `true`, `ann_avg` will return the average CPI value for each year, and `calcs` will return net and percent changes in CPI. This method returns all response data in the form of a hash:
64
-
65
- ```ruby
66
- {
67
- "status" => "REQUEST_SUCCEEDED",
68
- "responseTime" => 34,
69
- "message" => [],
70
- "Results" => {
71
- "series" => [
72
- {
73
- "seriesID" => "CUUR0000SA0",
74
- "data" => [
75
- {
76
- "year" => "1913",
77
- "period" => "M13",
78
- "periodName" => "Annual",
79
- "value" => "9.9",
80
- "footnotes" => [{}],
81
- "calculations" => {
82
- "net_changes" => {},
83
- "pct_changes" => {
84
- "1" => "-1.0",
85
- "3" => "-1.0",
86
- "6" => "0.0"
87
- }
88
- }
89
- },
90
- ...
91
- ]
92
- }
93
- ]
94
- }
95
- }
96
- ```
97
-
98
- ## Development
99
-
100
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
101
-
102
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
103
-
104
- ### TODO
105
-
106
- * [ ] Handle API errors
107
-
108
- ## Contributing
109
-
110
- Bug reports and pull requests are welcome on GitHub at <https://github.com/clpo13/ruby_cpiu>.
111
-
112
- ## License
113
-
114
- This code is licensed under [GPLv3](LICENSE.txt).
1
+ # CPIU
2
+
3
+ [![Build Status](https://travis-ci.org/clpo13/cpiu-ruby.svg?branch=master)](https://travis-ci.org/clpo13/cpiu-ruby)
4
+ [![Coverage Status](https://coveralls.io/repos/github/clpo13/cpiu-ruby/badge.svg?branch=master)](https://coveralls.io/github/clpo13/cpiu-ruby?branch=master)
5
+ [![Gem Version](https://badge.fury.io/rb/cpiu.svg)](https://badge.fury.io/rb/cpiu)
6
+
7
+ CPIU is a Ruby interface for [CPI-U](https://www.bls.gov/cpi/) data provided by the U.S. Bureau of Labor Statistics. CPI-U data are commonly used for calculating inflation. More info on the BLS Public Data API is available [here](https://www.bls.gov/developers/home.htm).
8
+
9
+ Neither I nor BLS.gov can vouch for the data or analyses derived from these data after the data have been retrieved from BLS.gov.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'cpiu', '~> 0.1'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ ```bash
22
+ bundle
23
+ ```
24
+
25
+ Or install it yourself as:
26
+
27
+ ```bash
28
+ gem install cpiu
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ Add the following to your program:
34
+
35
+ ```ruby
36
+ require 'cpiu'
37
+ ```
38
+
39
+ The following methods will retrieve JSON objects containing CPI-U data:
40
+
41
+ * `CPIU::Data.single_year(year)` - data for a single year
42
+ * `CPIU::Data.year_range(startyear, endyear)` - data for a year range no greater than 20 years
43
+
44
+ The data is returned in an array of hashes:
45
+
46
+ ```ruby
47
+ [
48
+ {
49
+ "year" => "1913",
50
+ "period" => "M12",
51
+ "periodName" => "December",
52
+ "value" => "10.0",
53
+ "footnotes" => [{}]
54
+ },
55
+ ...
56
+ ]
57
+ ```
58
+
59
+ A raw API call method is available too:
60
+
61
+ * `CPIU::API.request_data(startyear, endyear, ann_avg, calcs)`
62
+
63
+ If set to `true`, `ann_avg` will return the average CPI value for each year, and `calcs` will return net and percent changes in CPI. This method returns all response data in the form of a hash:
64
+
65
+ ```ruby
66
+ {
67
+ "status" => "REQUEST_SUCCEEDED",
68
+ "responseTime" => 34,
69
+ "message" => [],
70
+ "Results" => {
71
+ "series" => [
72
+ {
73
+ "seriesID" => "CUUR0000SA0",
74
+ "data" => [
75
+ {
76
+ "year" => "1913",
77
+ "period" => "M13",
78
+ "periodName" => "Annual",
79
+ "value" => "9.9",
80
+ "footnotes" => [{}],
81
+ "calculations" => {
82
+ "net_changes" => {},
83
+ "pct_changes" => {
84
+ "1" => "-1.0",
85
+ "3" => "-1.0",
86
+ "6" => "0.0"
87
+ }
88
+ }
89
+ },
90
+ ...
91
+ ]
92
+ }
93
+ ]
94
+ }
95
+ }
96
+ ```
97
+
98
+ ## Development
99
+
100
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
101
+
102
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
103
+
104
+ ### TODO
105
+
106
+ * [ ] Handle API errors
107
+
108
+ ## Contributing
109
+
110
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/clpo13/ruby_cpiu>.
111
+
112
+ ## License
113
+
114
+ This code is licensed under [GPLv3](LICENSE.txt).
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task default: :spec
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -1,14 +1,14 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'cpiu'
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require 'irb'
14
- IRB.start(__FILE__)
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'cpiu'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup CHANGED
@@ -1,8 +1,8 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -1,51 +1,51 @@
1
- # coding: utf-8
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
- lib = File.expand_path('../lib', __FILE__)
20
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
21
- require 'cpiu/version'
22
-
23
- Gem::Specification.new do |spec|
24
- spec.name = 'cpiu'
25
- spec.version = CPIU::VERSION
26
- spec.authors = ['Cody Logan']
27
- spec.email = ['cody@madrants.net']
28
-
29
- spec.summary = 'A Ruby interface for getting CPI-U data from BLS.gov'
30
- spec.homepage = 'https://github.com/clpo13/cpiu-ruby'
31
-
32
- spec.license = 'GPL-3.0'
33
-
34
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
35
- f.match(%r{^(test|spec|features)/})
36
- end
37
- spec.bindir = 'exe'
38
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
39
- spec.require_paths = ['lib']
40
-
41
- spec.add_development_dependency 'bundler', '~> 1.15'
42
- spec.add_development_dependency 'rake', '~> 10.0'
43
- spec.add_development_dependency 'rspec', '~> 3.2'
44
- spec.add_development_dependency 'webmock', '~> 3.0'
45
- spec.add_development_dependency 'vcr', '~> 3.0'
46
- spec.add_development_dependency 'coveralls', '~> 0.8'
47
-
48
- spec.add_dependency 'rest-client', '~> 2.0'
49
- spec.add_dependency 'json', '~> 2.1'
50
- spec.add_dependency 'dotenv', '~> 2.2'
51
- end
1
+ # coding: utf-8
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
+ lib = File.expand_path('../lib', __FILE__)
20
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
21
+ require 'cpiu/version'
22
+
23
+ Gem::Specification.new do |spec|
24
+ spec.name = 'cpiu'
25
+ spec.version = CPIU::VERSION
26
+ spec.authors = ['Cody Logan']
27
+ spec.email = ['cody@madrants.net']
28
+
29
+ spec.summary = 'A Ruby interface for getting CPI-U data from BLS.gov'
30
+ spec.homepage = 'https://github.com/clpo13/cpiu-ruby'
31
+
32
+ spec.license = 'GPL-3.0'
33
+
34
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
35
+ f.match(%r{^(test|spec|features)/})
36
+ end
37
+ spec.bindir = 'exe'
38
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
39
+ spec.require_paths = ['lib']
40
+
41
+ spec.add_development_dependency 'bundler', '~> 1.15'
42
+ spec.add_development_dependency 'rake', '~> 10.0'
43
+ spec.add_development_dependency 'rspec', '~> 3.2'
44
+ spec.add_development_dependency 'webmock', '~> 3.0'
45
+ spec.add_development_dependency 'vcr', '~> 3.0'
46
+ spec.add_development_dependency 'coveralls', '~> 0.8'
47
+
48
+ spec.add_dependency 'rest-client', '~> 2.0'
49
+ spec.add_dependency 'json', '~> 2.1'
50
+ spec.add_dependency 'dotenv', '~> 2.2'
51
+ end
@@ -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":1913,"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:15 GMT
29
- Strict-Transport-Security:
30
- - max-age=31536000; includeSubdomains;
31
- Set-Cookie:
32
- - JSESSIONID=09DB0ABAB033B05BC1CECBB682675792; Version=1; Path="/publicAPI/";
33
- Secure; HttpOnly
34
- Content-Type:
35
- - application/json
36
- Content-Length:
37
- - '1137'
38
- body:
39
- encoding: UTF-8
40
- string: |-
41
- {"status":"REQUEST_SUCCEEDED","responseTime":38,"message":[],"Results":{
42
- "series":
43
- [{"seriesID":"CUUR0000SA0","data":[{"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:14 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":1913,"annualaverage":true,"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
+ - '155'
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:18 GMT
29
+ Strict-Transport-Security:
30
+ - max-age=31536000; includeSubdomains;
31
+ Set-Cookie:
32
+ - JSESSIONID=A9CE914E44FC0BA028240B0F3D107829; Version=1; Path="/publicAPI/";
33
+ Secure; HttpOnly
34
+ Content-Type:
35
+ - application/json
36
+ Content-Length:
37
+ - '1221'
38
+ body:
39
+ encoding: UTF-8
40
+ string: |-
41
+ {"status":"REQUEST_SUCCEEDED","responseTime":32,"message":[],"Results":{
42
+ "series":
43
+ [{"seriesID":"CUUR0000SA0","data":[{"year":"1913","period":"M13","periodName":"Annual","value":"9.9","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:25 GMT
47
+ recorded_with: VCR 3.0.3