Class: Usps::Imis::BusinessObject
- Inherits:
-
Object
- Object
- Usps::Imis::BusinessObject
- Includes:
- Requests
- Defined in:
- lib/usps/imis/business_object.rb
Overview
Configured accessor for a specific Business Object
Constant Summary collapse
- API_PATH =
Endpoint for general API requests
'api'
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
The parent
Apiobject. -
#business_object_name ⇒ Object
readonly
Name of the iMIS Business Object.
-
#logger ⇒ Object
readonly
Tagged logger.
-
#ordinal ⇒ Object
readonly
Ordinal to build override ID param of the URL (e.g. used for Panels).
Instance Method Summary collapse
-
#blank_object ⇒ Object
Build a blank object for the current iMIS ID.
-
#delete ⇒ true
(also: #destroy)
Remove a business object for the current member.
-
#get(*fields) ⇒ Usps::Imis::Data+
(also: #read)
Get a business object for the current member.
-
#get_field(field) ⇒ Object
(also: #fetch, #[])
Get a single named field from a business object for the current member.
-
#get_fields(*fields) ⇒ Array
(also: #fetch_all)
Get named fields from a business object for the current member.
-
#initialize(api, business_object_name, ordinal: nil) ⇒ BusinessObject
constructor
A new instance of
BusinessObject. -
#instance_variables_to_inspect ⇒ Object
Ruby 3.5 instance variable filter.
-
#post(body) ⇒ Usps::Imis::Data
(also: #create)
Create a business object for the current member.
-
#post_from_blank ⇒ Object
(also: #create_from_blank)
Create a business object for the current member, starting with a blank object and building properties.
-
#put(body) ⇒ Usps::Imis::Data
(also: #update)
Update a business object for the current member.
-
#put_field(field, value) ⇒ Usps::Imis::Data
(also: #[]=)
Update a single named field on a business object for the current member.
-
#put_fields(fields) ⇒ Usps::Imis::Data
(also: #patch)
Update only specific fields on a business object for the current member.
-
#query ⇒ Usps::Imis::Query
Run a query on the entire business object.
-
#with(imis_id) ⇒ Object
Support passthrough for Api#with.
Constructor Details
#initialize(api, business_object_name, ordinal: nil) ⇒ BusinessObject
A new instance of BusinessObject
36 37 38 39 40 41 |
# File 'lib/usps/imis/business_object.rb', line 36 def initialize(api, business_object_name, ordinal: nil) @api = api @business_object_name = business_object_name @ordinal = ordinal @logger ||= Imis.logger('BusinessObject') end |
Instance Attribute Details
#api ⇒ Object (readonly)
The parent Api object
20 21 22 |
# File 'lib/usps/imis/business_object.rb', line 20 def api @api end |
#business_object_name ⇒ Object (readonly)
Name of the iMIS Business Object
24 25 26 |
# File 'lib/usps/imis/business_object.rb', line 24 def business_object_name @business_object_name end |
#logger ⇒ Object (readonly)
Tagged logger
32 33 34 |
# File 'lib/usps/imis/business_object.rb', line 32 def logger @logger end |
#ordinal ⇒ Object (readonly)
Ordinal to build override ID param of the URL (e.g. used for Panels)
28 29 30 |
# File 'lib/usps/imis/business_object.rb', line 28 def ordinal @ordinal end |
Instance Method Details
#blank_object ⇒ Object
Build a blank object for the current iMIS ID
142 |
# File 'lib/usps/imis/business_object.rb', line 142 def blank_object(&) = BlankObject.new(self).build(&) |
#delete ⇒ true Also known as: destroy
Remove a business object for the current member
137 |
# File 'lib/usps/imis/business_object.rb', line 137 def delete = submit(uri, (http_delete)).body == '' # rubocop:disable Naming/PredicateMethod |
#get(*fields) ⇒ Usps::Imis::Data+ Also known as: read
Get a business object for the current member
If fields is provided, will return only those field values
69 |
# File 'lib/usps/imis/business_object.rb', line 69 def get(*fields) = fields.any? ? get_fields(*fields) : raw_object |
#get_field(field) ⇒ Object Also known as: fetch, []
Get a single named field from a business object for the current member
78 |
# File 'lib/usps/imis/business_object.rb', line 78 def get_field(field) = raw_object[field] |
#get_fields(*fields) ⇒ Array Also known as: fetch_all
Get named fields from a business object for the current member
88 89 90 91 |
# File 'lib/usps/imis/business_object.rb', line 88 def get_fields(*fields) values = raw_object fields.map { values[it] } end |
#instance_variables_to_inspect ⇒ Object
Ruby 3.5 instance variable filter
151 |
# File 'lib/usps/imis/business_object.rb', line 151 def instance_variables_to_inspect = instance_variables - %i[@api @logger] |
#post(body) ⇒ Usps::Imis::Data Also known as: create
Create a business object for the current member
130 |
# File 'lib/usps/imis/business_object.rb', line 130 def post(body) = put_object(http_post, body) |
#post_from_blank ⇒ Object Also known as: create_from_blank
Create a business object for the current member, starting with a blank object and building properties
146 |
# File 'lib/usps/imis/business_object.rb', line 146 def post_from_blank(&) = post(blank_object(&)) |
#put(body) ⇒ Usps::Imis::Data Also known as: update
Update a business object for the current member
Any properties not included will be left unmodified
121 |
# File 'lib/usps/imis/business_object.rb', line 121 def put(body) = put_object(http_put, body) |
#put_field(field, value) ⇒ Usps::Imis::Data Also known as: []=
Update a single named field on a business object for the current member
101 |
# File 'lib/usps/imis/business_object.rb', line 101 def put_field(field, value) = put(filter_fields(field => value)) |
#put_fields(fields) ⇒ Usps::Imis::Data Also known as: patch
Update only specific fields on a business object for the current member
110 |
# File 'lib/usps/imis/business_object.rb', line 110 def put_fields(fields) = put(filter_fields(fields)) |
#query ⇒ Usps::Imis::Query
Run a query on the entire business object
47 |
# File 'lib/usps/imis/business_object.rb', line 47 def query = api.query(business_object_name) |
#with(imis_id) ⇒ Object
Support passthrough for Api#with
51 52 53 54 55 56 57 58 59 |
# File 'lib/usps/imis/business_object.rb', line 51 def with(imis_id, &) # Bring into local scope wrapper_business_object_name = business_object_name wrapper_ordinal = ordinal api.with(imis_id) do on(wrapper_business_object_name, ordinal: wrapper_ordinal, &) end end |