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
(also: #destroy)
Remove a business object for the current member.
-
#get ⇒ Hash
(also: #read)
Get a business object for the current member.
-
#get_field(name) ⇒ Hash
(also: #fetch)
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
(also: #create)
Create a business object for the current member.
-
#put(body) ⇒ Hash
(also: #update)
Update a business object for the current member.
-
#put_fields(fields) ⇒ Hash
(also: #patch)
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
29 30 31 32 33 |
# File 'lib/usps/imis/business_object.rb', line 29 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
17 18 19 |
# File 'lib/usps/imis/business_object.rb', line 17 def api @api end |
#business_object_name ⇒ Object (readonly)
Name of the iMIS Business Object
21 22 23 |
# File 'lib/usps/imis/business_object.rb', line 21 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)
25 26 27 |
# File 'lib/usps/imis/business_object.rb', line 25 def ordinal @ordinal end |
Instance Method Details
#delete ⇒ String Also known as: destroy
Remove a business object for the current member
106 107 108 109 110 |
# File 'lib/usps/imis/business_object.rb', line 106 def delete request = Net::HTTP::Delete.new(uri) result = submit(uri, (request)) result.body end |
#get ⇒ Hash Also known as: read
Get a business object for the current member
39 40 41 42 43 |
# File 'lib/usps/imis/business_object.rb', line 39 def get request = Net::HTTP::Get.new(uri) result = submit(uri, (request)) JSON.parse(result.body) end |
#get_field(name) ⇒ Hash Also known as: fetch
Get a single named field from a business object for the current member
52 53 54 55 56 57 |
# File 'lib/usps/imis/business_object.rb', line 52 def get_field(name) values = get['Properties']['$values'] value = values.find { it['Name'] == name }['Value'] value.is_a?(String) ? value : value['$value'] end |
#post(body) ⇒ Hash Also known as: create
Create a business object for the current member
94 95 96 97 98 99 |
# File 'lib/usps/imis/business_object.rb', line 94 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 Also known as: update
Update a business object for the current member
Any properties not included will be left unmodified
80 81 82 83 84 85 |
# File 'lib/usps/imis/business_object.rb', line 80 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 Also known as: patch
Update only specific fields on a business object for the current member
66 67 68 69 |
# File 'lib/usps/imis/business_object.rb', line 66 def put_fields(fields) updated = filter_fields(fields) put(updated) end |