Class: Cts::Mpx::Entry
- Inherits:
-
Object
- Object
- Cts::Mpx::Entry
- Includes:
- Creatable
- Defined in:
- lib/cts/mpx/entry.rb
Overview
ORM style class to contain any entry from the data services.
Instance Attribute Summary collapse
-
#id ⇒ Entry
Return the id of the entry.
Class Method Summary collapse
-
.load_by_id(user: nil, id: nil, fields: nil, account_id: nil) ⇒ Entry
Load a Entry based on a long form ID.
Instance Method Summary collapse
-
#initialize ⇒ Entry
constructor
Initialize an entry.
-
#load(user: nil, fields: nil, account_id: 'urn:theplatform:auth:root') ⇒ Driver::Response
Load data from the remote services based on the id.
-
#save(user: nil) ⇒ Driver::Response
Save the entry to the remote services.
-
#to_h ⇒ Hash
Return a [Hash] of the entry.
Constructor Details
Instance Attribute Details
#id ⇒ Entry
Return the id of the entry.
30 31 32 |
# File 'lib/cts/mpx/entry.rb', line 30 def id @id end |
Class Method Details
.load_by_id(user: nil, id: nil, fields: nil, account_id: nil) ⇒ Entry
Load a Entry based on a long form ID
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/cts/mpx/entry.rb', line 17 def self.load_by_id(user: nil, id: nil, fields: nil, account_id: nil) Driver::Helpers.required_arguments %i[user id], binding Driver::Exceptions.raise_unless_argument_error? user, User Driver::Exceptions.raise_unless_reference? id e = new e.id = id e.load user: user, fields: fields, account_id: account_id e end |
Instance Method Details
#load(user: nil, fields: nil, account_id: 'urn:theplatform:auth:root') ⇒ Driver::Response
Load data from the remote services based on the id.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/cts/mpx/entry.rb', line 68 def load(user: nil, fields: nil, account_id: 'urn:theplatform:auth:root') Driver::Exceptions.raise_unless_required_keyword? binding, :user Driver::Exceptions.raise_unless_argument_error? user, User Driver::Exceptions.raise_unless_argument_error? fields, String if fields Driver::Exceptions.raise_unless_reference? id Registry.fetch_and_store_domain user, account_id response = Services::Data.get account_id: account_id, user: user, service: service, endpoint: endpoint, fields: fields, ids: id.split("/").last entries = response.data['entries'] raise "could not load #{id}" unless entries.any? self.fields.parse data: entries.first, xmlns: response.data['xmlns'] self end |
#save(user: nil) ⇒ Driver::Response
Save the entry to the remote services.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/cts/mpx/entry.rb', line 88 def save(user: nil) Driver::Helpers.required_arguments %i[user], binding Driver::Exceptions.raise_unless_argument_error? user, User raise ArgumentError, "fields['ownerId'] is a required field" unless fields['ownerId'] raise ArgumentError, "endpoint is a required attribute" unless endpoint raise ArgumentError, "service is a required attribute" unless service p = Driver::Page.create entries: [fields.to_h], xmlns: fields.xmlns Registry.fetch_and_store_domain user, fields["ownerId"] response_params = { account_id: fields['ownerId'], user: user, service: service, endpoint: endpoint, page: p } result = Services::Data.send(id ? :put : :post, response_params) result.data if result.service_exception? self end |
#to_h ⇒ Hash
Return a [Hash] of the entry.
57 58 59 60 61 62 |
# File 'lib/cts/mpx/entry.rb', line 57 def to_h { xmlns: fields.xmlns, entry: fields.to_h } end |