Class: BeaApi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/bea_api/client.rb

Overview

> BeaApi::Client

client#initialize method takes an api_key

Instance Attribute Summary collapse

Instance Method Summary collapse

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_keyObject (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

#datasetsObject (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_datasetsObject



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