Class: Finnegans::Resource
- Inherits:
-
Object
- Object
- Finnegans::Resource
- Defined in:
- lib/finnegans/resource.rb
Defined Under Namespace
Classes: ActionError
Instance Attribute Summary collapse
-
#active ⇒ Object
(also: #active?)
readonly
Returns the value of attribute active.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
Instance Method Summary collapse
- #actions ⇒ Object
- #get(resource_id) ⇒ Object
-
#initialize(code:, active:, client:, with_details: false) ⇒ Resource
constructor
A new instance of Resource.
- #list ⇒ Object
- #reports(**report_params) ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(code:, active:, client:, with_details: false) ⇒ Resource
Returns a new instance of Resource.
20 21 22 23 24 25 |
# File 'lib/finnegans/resource.rb', line 20 def initialize(code:, active:, client:, with_details: false) @code = code @active = active @_client = client get_details if with_details end |
Instance Attribute Details
#active ⇒ Object (readonly) Also known as: active?
Returns the value of attribute active.
18 19 20 |
# File 'lib/finnegans/resource.rb', line 18 def active @active end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
18 19 20 |
# File 'lib/finnegans/resource.rb', line 18 def code @code end |
Instance Method Details
#actions ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/finnegans/resource.rb', line 37 def actions return @_actions if defined?(@_actions) @_actions = details.map do |(_key, _value)| next unless _action = ACTIONS_MAP[_key] _action if _value end.compact end |
#get(resource_id) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/finnegans/resource.rb', line 47 def get(resource_id) ensure_type!(:entity) unless actions.include?(:get) raise ActionError.new, "The :get action is not available for this resource. Only #{actions} are available" end client.request("/#{code}/#{resource_id}") end |
#list ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/finnegans/resource.rb', line 57 def list ensure_type!(:entity) unless actions.include?(:list) raise ActionError.new, "The :get action is not available for this resource. Only #{actions} are available" end client.request("/#{code}/list") end |
#reports(**report_params) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/finnegans/resource.rb', line 67 def reports(**report_params) ensure_type!(:viewer) request_params = { params: { "PARAMWEBREPORT_MonedaID" => "PES" }.merge(report_params) } client.request("/reports/#{code}", request_params) end |
#type ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/finnegans/resource.rb', line 29 def type return @_type if defined?(@_type) _type_index = (details['Tipo']).to_i @type = TYPE_NAMES[_type_index] end |