bea_api 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/README.md +109 -3
- data/lib/bea_api.rb +1 -0
- data/lib/bea_api/client.rb +0 -5
- data/lib/bea_api/exceptions.rb +4 -0
- data/lib/bea_api/request.rb +10 -28
- data/lib/bea_api/version.rb +1 -1
- data/spec/bea_api/client_spec.rb +12 -31
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDM4NWI2OWE3OTQ4OWRiMmZiYTI2NTMzMzQ4YmNkNjk5MGU1MGI2OQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGJhMGUzNjdkNmE1OWI4MjhmMGNjYzUzMWU3MWI3NzM1YzFhZmYwMg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTdlYjAyODI5Zjk2Mzc5NzhlNmJkOWFkMTdkZmQ5NWMwZjJiZGQ2ZGEyNjY2
|
10
|
+
ZWNhMjdiOGZjODVhZDZhNDIwOGQ5ODExZTJhNmNhMTE2ODdkNmNmOGQ3YTE2
|
11
|
+
OGI3OWJmMjhhYWEwMzdkMjY0MDcwZGFlZjY4YzVhYTExNjFiNTk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGRiNzg5OTZiMDUwYmVjYTU0OGM3ZDZmNTUzN2RhYjRjZDNhMmE4NjRjYTk2
|
14
|
+
MjE3NWZlOGEwNmFhM2RhNDQzYWFmNDg3MDNmYjEzMzc5YzA5ODdiZTFiMjcz
|
15
|
+
ZDg4YjIzOTJmNDI2OGViYTAxNDhhYjcyNTdlYzczZWY4NDEyOWI=
|
data/README.md
CHANGED
@@ -1,4 +1,110 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
#BEA API
|
2
|
+
[](https://circleci.com/gh/hoersten/bea_api/tree/master) [](https://codeclimate.com/github/hoersten/bea_api) [](https://codeclimate.com/github/hoersten/bea_api)
|
3
3
|
|
4
|
-
Ruby wrapper for the US Bureau of Economic Analysis (BEA) API
|
4
|
+
Ruby wrapper for the US Bureau of Economic Analysis (BEA) API. BEA is an agency of the United States Department of Commerce that produces economic accounts statistics. The API provides access to regional, national, industrial and international economic statistics. http://www.bea.gov/about/mission.htm
|
5
|
+
|
6
|
+
##Obtaining an API key
|
7
|
+
To be able to use this gem, you'll need a US Bureau of Economic Analysis API key. To request an API key, visit http://www.bea.gov/api/ and follow the instructions.
|
8
|
+
|
9
|
+
##Installing the gem
|
10
|
+
To use this gem, install it with ```gem install bea_api```
|
11
|
+
Or add it to your Gemfile: ```gem 'bea_api'``` and install it with ```bundle install```
|
12
|
+
|
13
|
+
##Usage / Retrieving BEA Data
|
14
|
+
|
15
|
+
###(Recommended) Set the API key as an environment variable
|
16
|
+
Once you have the API key, you may want to store it as an environment variable.
|
17
|
+
|
18
|
+
```sh
|
19
|
+
$ export $BEA_API_KEY='your-api-key'
|
20
|
+
```
|
21
|
+
###Register a New Client
|
22
|
+
```ruby
|
23
|
+
@client = BeaApi::Client.new(ENV['BEA_API_KEY']) # from the environment variable
|
24
|
+
@client = BeaApi::Client.new(API_KEY)
|
25
|
+
```
|
26
|
+
###Query a Dataset
|
27
|
+
|
28
|
+
####Parameters
|
29
|
+
Each of the datasets have different required fields and optional parameters. See http://www.bea.gov/API/docs/ for the full list of available parameters.
|
30
|
+
|
31
|
+
####Example
|
32
|
+
To get the 2013 GDP data for Alabama, Illinois and California:
|
33
|
+
```ruby
|
34
|
+
@client = BeaApi::Client.new(ENV['BEA_API_KEY']) # Create the client
|
35
|
+
results = @client.get_data(:RegionalData, { "Year" => 2013, "KeyCode" => "GDP_SP", "GEOFIPS" => "STATE:01000,17000,060000" } ) # Use the RegionalData dataset and use the parameters based upon their requirements
|
36
|
+
results.response # An array of hashes of the results from the call
|
37
|
+
```
|
38
|
+
```ruby
|
39
|
+
results.response
|
40
|
+
=> [
|
41
|
+
{"GeoFips"=>"01000", "GeoName"=>"Alabama", "Code"=>"GDP_SP", "TimePeriod"=>"2013", "CL_UNIT"=>"USD", "UNIT_MULT"=>"6", "DataValue"=>"193566"},
|
42
|
+
{"GeoFips"=>"06000", "GeoName"=>"California", "Code"=>"GDP_SP", "TimePeriod"=>"2013", "CL_UNIT"=>"USD", "UNIT_MULT"=>"6", "DataValue"=>"2202678"},
|
43
|
+
{"GeoFips"=>"17000", "GeoName"=>"Illinois", "Code"=>"GDP_SP", "TimePeriod"=>"2013", "CL_UNIT"=>"USD", "UNIT_MULT"=>"6", "DataValue"=>"720692"}
|
44
|
+
]
|
45
|
+
```
|
46
|
+
|
47
|
+
###Retrieving Metadata
|
48
|
+
The BEA API provides three methods for pulling metadata information.
|
49
|
+
1) **BeaApi::Client::get_datasets()** - pulls all the datasets available from the BEA
|
50
|
+
**Example**
|
51
|
+
```ruby
|
52
|
+
results = @client.get_datasets()
|
53
|
+
```
|
54
|
+
```ruby
|
55
|
+
results.response
|
56
|
+
=> [
|
57
|
+
{"DatasetName"=>"RegionalData", "DatasetDescription"=>"Retrieves various Regional datasets"},
|
58
|
+
{"DatasetName"=>"NIPA", "DatasetDescription"=>"Standard NIPA tables"},
|
59
|
+
{"DatasetName"=>"NIUnderlyingDetail", "DatasetDescription"=>"Standard NI underlying detail tables"},
|
60
|
+
{"DatasetName"=>"MNE", "DatasetDescription"=>"Multinational Enterprises"},
|
61
|
+
{"DatasetName"=>"FixedAssets", "DatasetDescription"=>"Standard Fixed Assets tables"},
|
62
|
+
{"DatasetName"=>"ITA", "DatasetDescription"=>"International Transactions Accounts"},
|
63
|
+
{"DatasetName"=>"IIP", "DatasetDescription"=>"International Investment Position"},
|
64
|
+
{"DatasetName"=>"GDPbyIndustry", "DatasetDescription"=>"GDP by Industry"}
|
65
|
+
]
|
66
|
+
```
|
67
|
+
2) **BeaApi::Client::get_parameters(dataset)** - pulls the parameters available for get_data for the given dataset
|
68
|
+
```ruby
|
69
|
+
results = @client.get_parameters(:RegionalData)
|
70
|
+
```
|
71
|
+
```ruby
|
72
|
+
results.response
|
73
|
+
=> [
|
74
|
+
{"ParameterName"=>"KeyCode", "ParameterDataType"=>"string", "ParameterDescription"=>"The code of the key statistic requested", "ParameterIsRequiredFlag"=>"1", "MultipleAcceptedFlag"=>"0"},
|
75
|
+
{"ParameterName"=>"GeoFips", "ParameterDataType"=>"string", "ParameterDescription"=>"GeoFips Code", "ParameterIsRequiredFlag"=>"0", "MultipleAcceptedFlag"=>"1"},
|
76
|
+
{"ParameterName"=>"Year", "ParameterDataType"=>"integer", "ParameterDescription"=>"Year", "ParameterIsRequiredFlag"=>"0", "ParameterDefaultValue"=>"ALL", "MultipleAcceptedFlag"=>"1", "AllValue"=>"ALL"}
|
77
|
+
]
|
78
|
+
```
|
79
|
+
3) **BeaApi::Client::get_parameter_values(dataset, parameter)** - pulls the possible values for a specific parameter for the given dataset's get_data
|
80
|
+
```ruby
|
81
|
+
results = @client.get_parameter_values(:RegionalData, "KeyCode")
|
82
|
+
```
|
83
|
+
```ruby
|
84
|
+
results.response
|
85
|
+
=> [
|
86
|
+
{"KeyCode"=>"GDP_SP", "Description"=>"GDP in current dollars (state annual product)"},
|
87
|
+
{"KeyCode"=>"RGDP_SP", "Description"=>"Real GDP in chained dollars (state annual product)"},
|
88
|
+
{"KeyCode"=>"PCRGDP_SP", "Description"=>"Per capita real GDP (state annual product)"},
|
89
|
+
{"KeyCode"=>"COMP_SP", "Description"=>"Compensation of employees (state annual product)"},
|
90
|
+
{"KeyCode"=>"TOPILS_SP", "Description"=>"Taxes on production and imports less subsidies (state annual product)"},
|
91
|
+
{"KeyCode"=>"GOS_SP", "Description"=>"Gross operating surplus (state annual product)"},
|
92
|
+
{"KeyCode"=>"SUBS_SP", "Description"=>"Subsidies (state annual product)"},
|
93
|
+
{"KeyCode"=>"TOPI_SP", "Description"=>"Taxes on production and imports (state annual product)"},
|
94
|
+
{"KeyCode"=>"GDP_MP", "Description"=>"GDP in current dollars (MSA annual product)"},
|
95
|
+
{"KeyCode"=>"RGDP_MP", "Description"=>"Real GDP in chained dollars (MSA annual product)"},
|
96
|
+
{"KeyCode"=>"PCRGDP_MP", "Description"=>"Per capita real GDP (MSA annual product)"},
|
97
|
+
{"KeyCode"=>"TPI_SI", "Description"=>"Total personal income (state annual income)"},
|
98
|
+
{"KeyCode"=>"POP_SI", "Description"=>"Population (state annual income)"},
|
99
|
+
{"KeyCode"=>"PCPI_SI", "Description"=>"Per capita personal income (state annual income)"},
|
100
|
+
{"KeyCode"=>"NFPI_SI", "Description"=>"Nonfarm personal income (state annual income)"},
|
101
|
+
{"KeyCode"=>"FPI_SI", "Description"=>"Farm income (state annual income)"},
|
102
|
+
{"KeyCode"=>"EARN_SI", "Description"=>"Earnings by place of work (state annual income)"},
|
103
|
+
{"KeyCode"=>"CGSI_SI", "Description"=>"Contributions for government social insurance (state annual income)"},
|
104
|
+
{"KeyCode"=>"AR_SI", "Description"=>"Adjustment for residence (state annual income)"},
|
105
|
+
{"KeyCode"=>"NE_SI", "Description"=>"Net earnings by place of residence (state annual income)"},
|
106
|
+
{"KeyCode"=>"DIR_SI", "Description"=>"Dividends, interest, and rent (state annual income)"},
|
107
|
+
{"KeyCode"=>"PCTR_SI", "Description"=>"Personal current transfer receipts (state annual income)"},
|
108
|
+
...
|
109
|
+
]
|
110
|
+
```
|
data/lib/bea_api.rb
CHANGED
data/lib/bea_api/client.rb
CHANGED
@@ -39,11 +39,6 @@ module BeaApi
|
|
39
39
|
def _validate_api_key(api_key)
|
40
40
|
@api_key = api_key
|
41
41
|
response = get_datasets()
|
42
|
-
if response.error_code == Request::InvalidKey
|
43
|
-
@api_key = nil
|
44
|
-
fail "'#{api_key}' is not a valid API key. Check your key for errors,
|
45
|
-
or request a new one at http://www.bea.gov/api/"
|
46
|
-
end
|
47
42
|
end
|
48
43
|
|
49
44
|
def _method(dataset, method, options)
|
data/lib/bea_api/request.rb
CHANGED
@@ -4,12 +4,8 @@ module BeaApi
|
|
4
4
|
require 'restclient'
|
5
5
|
require 'json'
|
6
6
|
|
7
|
-
attr_accessor :response, :
|
8
|
-
Success = 0 # Sucess, no errors
|
7
|
+
attr_accessor :response, :notes
|
9
8
|
InvalidKey = 3 # APIErrorCode 3: The BEA API UserID provided in the request does not exist.
|
10
|
-
MissingParams = 40 # APIErrorCode 40: The dataset requested requires parameters that were missing from the request
|
11
|
-
RetrivalError = 201 # APIErrorCode 201: Error retrieving NIPA/Fixed Assets data
|
12
|
-
GDPRetrivalError = 204 # APIErrorCode 204: Error retrieving GDP by Industry data
|
13
9
|
|
14
10
|
BEA_URL = 'http://www.bea.gov/api/data'
|
15
11
|
|
@@ -19,8 +15,6 @@ module BeaApi
|
|
19
15
|
end
|
20
16
|
|
21
17
|
def initialize(uri)
|
22
|
-
@error_code = Request::Success
|
23
|
-
@error_msg = ""
|
24
18
|
@response = RestClient.get(uri.to_s)
|
25
19
|
_parse_response
|
26
20
|
end
|
@@ -43,7 +37,7 @@ module BeaApi
|
|
43
37
|
def _response_html_success(response)
|
44
38
|
r = JSON.parse(response)
|
45
39
|
if (!r["BEAAPI"]["Error"].nil? || r["BEAAPI"]["Results"].first.first.to_s.downcase == 'error')
|
46
|
-
@response = _response_error(
|
40
|
+
@response = _response_error(r)
|
47
41
|
else
|
48
42
|
@response = _response_success(r)
|
49
43
|
end
|
@@ -79,32 +73,20 @@ module BeaApi
|
|
79
73
|
notes
|
80
74
|
end
|
81
75
|
|
82
|
-
def _response_error(
|
83
|
-
_parse_error(r)
|
84
|
-
{
|
85
|
-
code: response.code,
|
86
|
-
location: response.headers[:location],
|
87
|
-
error_code: @error_code,
|
88
|
-
error_msg: @error_msg
|
89
|
-
}
|
90
|
-
end
|
91
|
-
|
92
|
-
def _parse_error(r)
|
76
|
+
def _response_error(r)
|
93
77
|
if (!r["BEAAPI"]["Error"].nil?)
|
94
|
-
|
95
|
-
@error_msg = r["BEAAPI"]["Error"]["APIErrorDescription"]
|
78
|
+
err = r["BEAAPI"]["Error"]
|
96
79
|
else
|
97
|
-
|
98
|
-
|
80
|
+
err = r["BEAAPI"]["Results"].first.last
|
81
|
+
end
|
82
|
+
if (err["APIErrorCode"].to_i == InvalidKey)
|
83
|
+
fail InvalidKeyError, "'#{api_key}' is not a valid API key. Check your key for errors, or request a new one at http://www.bea.gov/api/"
|
99
84
|
end
|
85
|
+
fail ParameterError, err["APIErrorDescription"]
|
100
86
|
end
|
101
87
|
|
102
88
|
def _response_html_error(response)
|
103
|
-
|
104
|
-
code: response.code,
|
105
|
-
location: response.headers[:location],
|
106
|
-
body: response.body
|
107
|
-
}
|
89
|
+
fail StandardError, response.code + "\n" + response.body
|
108
90
|
end
|
109
91
|
|
110
92
|
end
|
data/lib/bea_api/version.rb
CHANGED
data/spec/bea_api/client_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe BeaApi::Client do
|
|
10
10
|
|
11
11
|
it 'should not initialize with an invalid api_key' do
|
12
12
|
VCR.use_cassette('initialize_client_failure') do
|
13
|
-
expect { BeaApi::Client.new('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX') }.to raise_error(/is not a valid API key/)
|
13
|
+
expect { BeaApi::Client.new('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX') }.to raise_error(BeaApi::InvalidKeyError, /is not a valid API key/)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -28,7 +28,6 @@ describe BeaApi::Client do
|
|
28
28
|
VCR.use_cassette('get_datasets') do
|
29
29
|
@client = BeaApi::Client.new(api_key)
|
30
30
|
@datasets = @client.get_datasets()
|
31
|
-
expect(@datasets.error_code).to eq(BeaApi::Request::Success)
|
32
31
|
expect(@datasets.response.count).to eq(@client.datasets.count)
|
33
32
|
@datasets.response.each do |r|
|
34
33
|
expect(@client.datasets).to include(r["DatasetName"].to_sym)
|
@@ -51,7 +50,7 @@ describe BeaApi::Client do
|
|
51
50
|
@client = BeaApi::Client.new(api_key)
|
52
51
|
@client.datasets.each do |d|
|
53
52
|
p = @client.get_parameters(d)
|
54
|
-
expect(p.
|
53
|
+
expect(p.response.count).not_to eq(0)
|
55
54
|
end
|
56
55
|
end
|
57
56
|
end
|
@@ -78,10 +77,10 @@ describe BeaApi::Client do
|
|
78
77
|
@client = BeaApi::Client.new(api_key)
|
79
78
|
@client.datasets.each do |d|
|
80
79
|
p = @client.get_parameters(d)
|
81
|
-
expect(p.
|
80
|
+
expect(p.response.count).not_to eq(0)
|
82
81
|
r = p.response.first
|
83
82
|
n = @client.get_parameter_values(d, r['ParameterName'])
|
84
|
-
expect(n.
|
83
|
+
expect(n.response.count).not_to eq(0)
|
85
84
|
end
|
86
85
|
end
|
87
86
|
end
|
@@ -109,15 +108,13 @@ describe BeaApi::Client do
|
|
109
108
|
it 'should not get data values for invalid parameters' do
|
110
109
|
VCR.use_cassette('get data for RegionalData with invalid parameters') do
|
111
110
|
@client = BeaApi::Client.new(api_key)
|
112
|
-
|
113
|
-
expect(r.error_code).not_to eq(BeaApi::Request::Success)
|
111
|
+
expect { @client.get_data(dataset, { "KeyCode" => "PCPI_CI", "GeoFIPS" => "STATE:00000,01000,02000,04000", "Year" => 3009 } ) }.to raise_error(BeaApi::ParameterError)
|
114
112
|
end
|
115
113
|
end
|
116
114
|
it 'should get data values for valid parameters' do
|
117
115
|
VCR.use_cassette('get data for RegionalData with valid parameters') do
|
118
116
|
@client = BeaApi::Client.new(api_key)
|
119
117
|
r = @client.get_data(dataset, { "KeyCode" => "PCPI_CI", "GeoFIPS" => "STATE:00000,01000,02000,04000", "Year" => 2009 } )
|
120
|
-
expect(r.error_code).to eq(BeaApi::Request::Success)
|
121
118
|
expect(r.response.count).to eq(4)
|
122
119
|
end
|
123
120
|
end
|
@@ -128,15 +125,13 @@ describe BeaApi::Client do
|
|
128
125
|
it 'should not get data values for invalid parameters' do
|
129
126
|
VCR.use_cassette('get data for NIPA with invalid parameters') do
|
130
127
|
@client = BeaApi::Client.new(api_key)
|
131
|
-
|
132
|
-
expect(r.error_code).to eq(BeaApi::Request::RetrivalError)
|
128
|
+
expect { @client.get_data(dataset, { "TableID" => 0, "Frequency" => "A", "Year" => 2009 } ) }.to raise_error(BeaApi::ParameterError)
|
133
129
|
end
|
134
130
|
end
|
135
131
|
it 'should get data values for valid parameters' do
|
136
132
|
VCR.use_cassette('get data for NIPA with valid parameters') do
|
137
133
|
@client = BeaApi::Client.new(api_key)
|
138
134
|
r = @client.get_data(dataset, { "TableID" => 1, "Frequency" => "A", "Year" => 2009 } )
|
139
|
-
expect(r.error_code).to eq(BeaApi::Request::Success)
|
140
135
|
expect(r.response.count).to eq(25)
|
141
136
|
end
|
142
137
|
end
|
@@ -147,15 +142,13 @@ describe BeaApi::Client do
|
|
147
142
|
it 'should not get data values for invalid parameters' do
|
148
143
|
VCR.use_cassette('get data for NI Underlying Detail with invalid parameters') do
|
149
144
|
@client = BeaApi::Client.new(api_key)
|
150
|
-
|
151
|
-
expect(r.error_code).to eq(BeaApi::Request::RetrivalError)
|
145
|
+
expect { @client.get_data(dataset, { "TableID" => 1, "Frequency" => "A", "Year" => 2009 } ) }.to raise_error(BeaApi::ParameterError)
|
152
146
|
end
|
153
147
|
end
|
154
148
|
it 'should get data values for valid parameters' do
|
155
149
|
VCR.use_cassette('get data for NI Underlying Detail with valid parameters') do
|
156
150
|
@client = BeaApi::Client.new(api_key)
|
157
151
|
r = @client.get_data(dataset, { "TableID" => 79, "Frequency" => "A", "Year" => 2004 } )
|
158
|
-
expect(r.error_code).to eq(BeaApi::Request::Success)
|
159
152
|
expect(r.response.count).to eq(30)
|
160
153
|
end
|
161
154
|
end
|
@@ -166,15 +159,13 @@ describe BeaApi::Client do
|
|
166
159
|
it 'should not get data values for invalid parameters' do
|
167
160
|
VCR.use_cassette('get data for MNE with invalid parameters') do
|
168
161
|
@client = BeaApi::Client.new(api_key)
|
169
|
-
|
170
|
-
#expect(r.error_code).not_to eq(BeaApi::Request::Success)
|
162
|
+
expect { @client.get_data(dataset, { "DirectionOfInvestment" => 'inval', "Classification" => "", "Year" => 2009, "State" => "01" } ) }.to raise_error(BeaApi::ParameterError)
|
171
163
|
end
|
172
164
|
end
|
173
165
|
it 'should get data values for valid parameters' do
|
174
166
|
VCR.use_cassette('get data for MNE with valid parameters') do
|
175
167
|
@client = BeaApi::Client.new(api_key)
|
176
168
|
r = @client.get_data(dataset, { "DirectionOfInvestment" => 'inward', "Classification" => "Country", "Year" => 2009, "State" => "01" } )
|
177
|
-
expect(r.error_code).to eq(BeaApi::Request::Success)
|
178
169
|
expect(r.response.count).to eq(1544)
|
179
170
|
end
|
180
171
|
end
|
@@ -185,15 +176,13 @@ describe BeaApi::Client do
|
|
185
176
|
it 'should not get data values for invalid parameters' do
|
186
177
|
VCR.use_cassette('get data for FixedAssets with invalid parameters') do
|
187
178
|
@client = BeaApi::Client.new(api_key)
|
188
|
-
|
189
|
-
expect(r.error_code).not_to eq(BeaApi::Request::Success)
|
179
|
+
expect { @client.get_data(dataset, { "TableID" => 0, "Year" => 2009 } ) }.to raise_error(BeaApi::ParameterError)
|
190
180
|
end
|
191
181
|
end
|
192
182
|
it 'should get data values for valid parameters' do
|
193
183
|
VCR.use_cassette('get data for FixedAssets with valid parameters') do
|
194
184
|
@client = BeaApi::Client.new(api_key)
|
195
185
|
r = @client.get_data(dataset, { "TableID" => 1, "Year" => 2009 } )
|
196
|
-
expect(r.error_code).to eq(BeaApi::Request::Success)
|
197
186
|
expect(r.response.count).to eq(24)
|
198
187
|
end
|
199
188
|
end
|
@@ -204,15 +193,13 @@ describe BeaApi::Client do
|
|
204
193
|
it 'should not get data values for invalid parameters' do
|
205
194
|
VCR.use_cassette('get data for ITA with invalid parameters') do
|
206
195
|
@client = BeaApi::Client.new(api_key)
|
207
|
-
|
208
|
-
expect(r.error_code).not_to eq(BeaApi::Request::Success)
|
196
|
+
expect { @client.get_data(dataset, { "Frequency" => "A", "Year" => 2009 } ) }.to raise_error(BeaApi::ParameterError)
|
209
197
|
end
|
210
198
|
end
|
211
199
|
it 'should get data values for valid parameters' do
|
212
200
|
VCR.use_cassette('get data for ITA with valid parameters') do
|
213
201
|
@client = BeaApi::Client.new(api_key)
|
214
202
|
r = @client.get_data(dataset, { "Indicator" => "CurrAndDepLiabsFoa", "Frequency" => "A", "Year" => 2009 } )
|
215
|
-
expect(r.error_code).to eq(BeaApi::Request::Success)
|
216
203
|
expect(r.response.count).to eq(1)
|
217
204
|
end
|
218
205
|
end
|
@@ -220,7 +207,6 @@ describe BeaApi::Client do
|
|
220
207
|
VCR.use_cassette('get data for ITA with 2 valid parameters') do
|
221
208
|
@client = BeaApi::Client.new(api_key)
|
222
209
|
r = @client.get_data(dataset, { "Indicator" => "CurrAndDepLiabsFoa", "Frequency" => "A", "Year" => "2009,2010" } )
|
223
|
-
expect(r.error_code).to eq(BeaApi::Request::Success)
|
224
210
|
expect(r.response.count).to eq(2)
|
225
211
|
end
|
226
212
|
end
|
@@ -231,15 +217,13 @@ describe BeaApi::Client do
|
|
231
217
|
it 'should not get data values for invalid parameters' do
|
232
218
|
VCR.use_cassette('get data for IIP with invalid parameters') do
|
233
219
|
@client = BeaApi::Client.new(api_key)
|
234
|
-
|
235
|
-
expect(r.error_code).not_to eq(BeaApi::Request::Success)
|
220
|
+
expect { @client.get_data(dataset, { "Frequency" => "A" } ) }.to raise_error(BeaApi::ParameterError)
|
236
221
|
end
|
237
222
|
end
|
238
223
|
it 'should get data values for valid parameters' do
|
239
224
|
VCR.use_cassette('get data for IIP with valid parameters') do
|
240
225
|
@client = BeaApi::Client.new(api_key)
|
241
226
|
r = @client.get_data(dataset, { "Frequency" => "A", "Year" => 2009 } )
|
242
|
-
expect(r.error_code).to eq(BeaApi::Request::Success)
|
243
227
|
expect(r.response.count).to eq(450)
|
244
228
|
end
|
245
229
|
end
|
@@ -250,15 +234,13 @@ describe BeaApi::Client do
|
|
250
234
|
it 'should not get data values for invalid parameters' do
|
251
235
|
VCR.use_cassette('get data for GDP by Industy with invalid parameters') do
|
252
236
|
@client = BeaApi::Client.new(api_key)
|
253
|
-
|
254
|
-
expect(r.error_code).not_to eq(BeaApi::Request::Success)
|
237
|
+
expect { @client.get_data(dataset, { "Industry" => "12" } ) }.to raise_error(BeaApi::ParameterError)
|
255
238
|
end
|
256
239
|
end
|
257
240
|
it 'should get data values for valid parameters' do
|
258
241
|
VCR.use_cassette('get data for GDP by Frequency with valid parameters') do
|
259
242
|
@client = BeaApi::Client.new(api_key)
|
260
243
|
r = @client.get_data(dataset, { "Industry" => "GDP", "TableID" => 1, "Frequency" => "A", "Year" => 2009 } )
|
261
|
-
expect(r.error_code).to eq(BeaApi::Request::Success)
|
262
244
|
expect(r.response.count).to eq(1)
|
263
245
|
end
|
264
246
|
end
|
@@ -266,7 +248,6 @@ describe BeaApi::Client do
|
|
266
248
|
VCR.use_cassette('get data for GDP by Frequency with valid parameters') do
|
267
249
|
@client = BeaApi::Client.new(api_key)
|
268
250
|
r = @client.get_data(dataset, { "Industry" => "GDP", "TableID" => 1, "Frequency" => "A", "Year" => "2009,2010" } )
|
269
|
-
expect(r.error_code).to eq(BeaApi::Request::Success)
|
270
251
|
expect(r.response.count).to eq(2)
|
271
252
|
end
|
272
253
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bea_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chad Hoersten
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- circle.yml
|
139
139
|
- lib/bea_api.rb
|
140
140
|
- lib/bea_api/client.rb
|
141
|
+
- lib/bea_api/exceptions.rb
|
141
142
|
- lib/bea_api/request.rb
|
142
143
|
- lib/bea_api/version.rb
|
143
144
|
- spec/api_key.rb
|