Class: Finnegans::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/finnegans/resource.rb

Defined Under Namespace

Classes: ActionError

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#activeObject (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

#codeObject (readonly)

Returns the value of attribute code.



18
19
20
# File 'lib/finnegans/resource.rb', line 18

def code
  @code
end

Instance Method Details

#actionsObject



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

#listObject



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

#typeObject



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