Class: BankExchangeApi::Request::Base
- Inherits:
-
Object
- Object
- BankExchangeApi::Request::Base
show all
- Extended by:
- Param
- Defined in:
- lib/bank_exchange_api/request/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Param
param
Constructor Details
#initialize(cli, params = {}) ⇒ Base
Returns a new instance of Base.
11
12
13
14
|
# File 'lib/bank_exchange_api/request/base.rb', line 11
def initialize(cli, params={})
@cli = cli
params.each{ |k,v| public_send("#{k}=", v) }
end
|
Instance Attribute Details
#cli ⇒ Object
Returns the value of attribute cli.
9
10
11
|
# File 'lib/bank_exchange_api/request/base.rb', line 9
def cli
@cli
end
|
Instance Method Details
#endpoint ⇒ Object
38
39
40
|
# File 'lib/bank_exchange_api/request/base.rb', line 38
def endpoint
raise NotImplementedError, __method__
end
|
#get(*args) ⇒ Object
20
21
22
|
# File 'lib/bank_exchange_api/request/base.rb', line 20
def get(*args)
cli.connection.get(*args)
end
|
#json(root: nil, &block) ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'lib/bank_exchange_api/request/base.rb', line 24
def json(root: nil, &block)
paginator = -> (uri=query) { BankExchangeApi::Response::Json.new(get(uri), root: root) }
if block_given?
paginate(paginator) { |response| yield(response) }
else
paginate(paginator)
end
end
|
#params ⇒ Object
34
35
36
|
# File 'lib/bank_exchange_api/request/base.rb', line 34
def params
{}
end
|
#query ⇒ Object
16
17
18
|
# File 'lib/bank_exchange_api/request/base.rb', line 16
def query
[endpoint, URI.encode_www_form(params)].join('?')
end
|