class Finnegans::Resource

Constants

ACTIONS_MAP
TYPE_NAMES

Attributes

active[R]
active?[R]
code[R]

Public Class Methods

new(code:, active:, client:, with_details: false) click to toggle source
# 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

Public Instance Methods

actions() click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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

Private Instance Methods

client() click to toggle source
# File lib/finnegans/resource.rb, line 79
def client
  @_client
end
details() click to toggle source
# File lib/finnegans/resource.rb, line 83
def details
  @_details ||= get_details
end
ensure_type!(type_name) click to toggle source
# File lib/finnegans/resource.rb, line 95
def ensure_type!(type_name)
  unless type == type_name.to_sym
    raise ActionError.new, "This action is only available for resources that are type :#{type_name}"
  end
end
get_details(refresh: false) click to toggle source
# File lib/finnegans/resource.rb, line 87
def get_details(refresh: false)
  return @_details if defined?(@_details) && !refresh

  _details = client.catalog_detail(code)
  _details.delete('DefinitionXml')
  @_details = _details
end