Class: Usps::Imis::Panel::BasePanel

Inherits:
Object
  • Object
show all
Defined in:
lib/usps/imis/panel/base_panel.rb

Overview

Base class for configuring Panels

Direct Known Subclasses

Education, Vsc

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api = nil, imis_id: nil) ⇒ BasePanel

Returns a new instance of BasePanel.



13
14
15
16
# File 'lib/usps/imis/panel/base_panel.rb', line 13

def initialize(api = nil, imis_id: nil)
  @api = api || Api.new
  @api.imis_id = imis_id if imis_id
end

Instance Attribute Details

#apiObject (readonly)

The parent Api object



11
12
13
# File 'lib/usps/imis/panel/base_panel.rb', line 11

def api
  @api
end

Instance Method Details

#delete(ordinal) ⇒ Object Also known as: destroy

Remove a specific object from the Panel

Parameters:

  • ordinal (Integer)

    The ordinal identifier for the desired object



74
75
76
# File 'lib/usps/imis/panel/base_panel.rb', line 74

def delete(ordinal)
  api.on(business_object, ordinal:).delete
end

#get(ordinal) ⇒ Object Also known as: read

Get a specific object from the Panel

Parameters:

  • ordinal (Integer)

    The ordinal identifier for the desired object



22
23
24
# File 'lib/usps/imis/panel/base_panel.rb', line 22

def get(ordinal)
  api.on(business_object, ordinal:).get
end

#get_field(ordinal, name) ⇒ Hash Also known as: fetch

Get a single named field from a Panel for the current member

Parameters:

  • ordinal (Integer)

    The ordinal identifier for the desired object

  • name (String)

    Field name to return

Returns:

  • (Hash)

    Response data from the API



34
35
36
# File 'lib/usps/imis/panel/base_panel.rb', line 34

def get_field(ordinal, name)
  api.on(business_object, ordinal:).get_field(name)
end

#post(data) ⇒ Object Also known as: create

Create a new object in the Panel

Parameters:

  • data (Hash)

    The record data for the desired object



65
66
67
# File 'lib/usps/imis/panel/base_panel.rb', line 65

def post(data)
  api.on(business_object).post(payload(data))
end

#put(data) ⇒ Object Also known as: update

Update an existing object in the Panel

Parameters:

  • data (Hash)

    The record data for the desired object – including the required ordinal identifier



56
57
58
# File 'lib/usps/imis/panel/base_panel.rb', line 56

def put(data)
  api.on(business_object, ordinal: data[:ordinal]).put(payload(data))
end

#put_fields(ordinal, fields) ⇒ Hash Also known as: patch

Update only specific fields on a Panel for the current member

Parameters:

  • ordinal (Integer)

    The ordinal identifier for the desired object

  • fields (Hash)

    Conforms to pattern { field_key => value }

Returns:

  • (Hash)

    Response data from the API



46
47
48
# File 'lib/usps/imis/panel/base_panel.rb', line 46

def put_fields(ordinal, fields)
  api.on(business_object, ordinal:).put_fields(fields)
end