Class: Usps::Imis::BusinessObject
- Inherits:
-
Object
- Object
- Usps::Imis::BusinessObject
- Includes:
- Requests
- Defined in:
- lib/usps/imis/business_object.rb
Overview
DEV
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.
-
#ordinal ⇒ Object
readonly
Ordinal to build override ID param of the URL (e.g. used for Panels).
Instance Method Summary collapse
-
#delete ⇒ String
Remove a business object for the current member.
-
#get ⇒ Hash
Get a business object for the current member.
-
#get_field(name) ⇒ Hash
Get a single named field from a business object for the current member.
-
#initialize(api, business_object_name, ordinal: nil) ⇒ BusinessObject
constructor
A new instance of
BusinessObject. -
#post(body) ⇒ Hash
Create a business object for the current member.
-
#put(body) ⇒ Hash
Update a business object for the current member.
-
#put_fields(fields) ⇒ Hash
Update only specific fields on a business object for the current member.
Constructor Details
#initialize(api, business_object_name, ordinal: nil) ⇒ BusinessObject
A new instance of BusinessObject
27 28 29 30 31 |
# File 'lib/usps/imis/business_object.rb', line 27 def initialize(api, business_object_name, ordinal: nil) @api = api @business_object_name = business_object_name @ordinal = ordinal end |
Instance Attribute Details
#api ⇒ Object (readonly)
The parent Api object
15 16 17 |
# File 'lib/usps/imis/business_object.rb', line 15 def api @api end |
#business_object_name ⇒ Object (readonly)
Name of the iMIS Business Object
19 20 21 |
# File 'lib/usps/imis/business_object.rb', line 19 def business_object_name @business_object_name end |
#ordinal ⇒ Object (readonly)
Ordinal to build override ID param of the URL (e.g. used for Panels)
23 24 25 |
# File 'lib/usps/imis/business_object.rb', line 23 def ordinal @ordinal end |
Instance Method Details
#delete ⇒ String
Remove a business object for the current member
97 98 99 100 101 |
# File 'lib/usps/imis/business_object.rb', line 97 def delete request = Net::HTTP::Delete.new(uri) result = submit(uri, (request)) result.body end |
#get ⇒ Hash
Get a business object for the current member
37 38 39 40 41 |
# File 'lib/usps/imis/business_object.rb', line 37 def get request = Net::HTTP::Get.new(uri) result = submit(uri, (request)) JSON.parse(result.body) end |
#get_field(name) ⇒ Hash
Get a single named field from a business object for the current member
49 50 51 52 53 54 |
# File 'lib/usps/imis/business_object.rb', line 49 def get_field(name) values = get['Properties']['$values'] value = values.find { |hash| hash['Name'] == name }['Value'] value.is_a?(String) ? value : value['$value'] end |
#post(body) ⇒ Hash
Create a business object for the current member
86 87 88 89 90 91 |
# File 'lib/usps/imis/business_object.rb', line 86 def post(body) request = Net::HTTP::Post.new(uri(id: '')) request.body = JSON.dump(body) result = submit(uri, (request)) JSON.parse(result.body) end |
#put(body) ⇒ Hash
Update a business object for the current member
73 74 75 76 77 78 |
# File 'lib/usps/imis/business_object.rb', line 73 def put(body) request = Net::HTTP::Put.new(uri) request.body = JSON.dump(body) result = submit(uri, (request)) JSON.parse(result.body) end |
#put_fields(fields) ⇒ Hash
Update only specific fields on a business object for the current member
62 63 64 65 |
# File 'lib/usps/imis/business_object.rb', line 62 def put_fields(fields) updated = filter_fields(fields) put(updated) end |