Class: BeaApi::Client
- Inherits:
-
Object
- Object
- BeaApi::Client
- Defined in:
- lib/bea_api/client.rb
Overview
> BeaApi::Client
client#initialize method takes an api_key
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#datasets ⇒ Object
readonly
Returns the value of attribute datasets.
Instance Method Summary collapse
- #get_data(dataset, fields) ⇒ Object
- #get_datasets ⇒ Object
- #get_parameter_values(dataset, parameter) ⇒ Object
- #get_parameters(dataset) ⇒ Object
-
#initialize(api_key) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(api_key) ⇒ Client
Returns a new instance of Client.
12 13 14 15 |
# File 'lib/bea_api/client.rb', line 12 def initialize(api_key) fail ArgumentError, 'You must set an api_key.' unless api_key _validate_api_key(api_key) end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
5 6 7 |
# File 'lib/bea_api/client.rb', line 5 def api_key @api_key end |
#datasets ⇒ Object (readonly)
Returns the value of attribute datasets.
6 7 8 |
# File 'lib/bea_api/client.rb', line 6 def datasets @datasets end |
Instance Method Details
#get_data(dataset, fields) ⇒ Object
32 33 34 35 36 |
# File 'lib/bea_api/client.rb', line 32 def get_data(dataset, fields) fail ArgumentError, 'Invalid dataset.' unless datasets.include?(dataset) fail ArgumentError, 'Invalid fields.' unless fields.class == Hash && !fields.empty? _method(dataset, 'GetData', fields) end |
#get_datasets ⇒ Object
17 18 19 |
# File 'lib/bea_api/client.rb', line 17 def get_datasets() _method(nil, 'GetDataSetList', {}) end |
#get_parameter_values(dataset, parameter) ⇒ Object
26 27 28 29 30 |
# File 'lib/bea_api/client.rb', line 26 def get_parameter_values(dataset, parameter) fail ArgumentError, 'Invalid dataset.' unless datasets.include?(dataset) fail ArgumentError, 'Invalid parameter name.' unless parameter _method(dataset, 'GetParameterValues', {parametername: parameter}) end |
#get_parameters(dataset) ⇒ Object
21 22 23 24 |
# File 'lib/bea_api/client.rb', line 21 def get_parameters(dataset) fail ArgumentError, 'Invalid dataset.' unless datasets.include?(dataset) _method(dataset, 'GetParameterList', {}) end |