Class: ReactorSDK::Resources::Revision
- Inherits:
-
BaseResource
- Object
- BaseResource
- ReactorSDK::Resources::Revision
- Defined in:
- lib/reactor_sdk/resources/revision.rb
Instance Attribute Summary collapse
-
#entity_id ⇒ String?
readonly
Returns the Adobe ID of the resource this revision belongs to.
-
#entity_type ⇒ String?
readonly
Returns the JSON:API type of the resource this revision belongs to.
Attributes inherited from BaseResource
#attributes, #id, #meta, #relationships, #type
Instance Method Summary collapse
-
#activity_type ⇒ String?
The action that triggered this revision Common values: “created”, “updated”, “published”, “rejected”.
-
#created_at ⇒ String
ISO8601 timestamp when this revision was created.
-
#entity_relationships ⇒ Hash
Returns the full relationships snapshot of the resource at this revision.
-
#entity_snapshot ⇒ Hash
Returns the full attributes snapshot of the resource at this revision.
-
#initialize(id:, type:, attributes: {}, meta: {}, relationships: {}, included_entity: nil, revision_relationships: nil) ⇒ Revision
constructor
Overrides BaseResource initializer to extract the included entity and relationship data from the raw JSON:API response.
-
#inspect ⇒ String
Human-readable representation.
Methods inherited from BaseResource
#==, #[], attribute, #relationship_data, #relationship_id, #relationship_ids, #to_h
Constructor Details
#initialize(id:, type:, attributes: {}, meta: {}, relationships: {}, included_entity: nil, revision_relationships: nil) ⇒ Revision
Overrides BaseResource initializer to extract the included entity and relationship data from the raw JSON:API response.
In addition to standard id/type/attributes/meta, the Revision resource accepts two extra keyword arguments:
- included_entity: the raw included resource hash from the API response
- relationships: the relationships hash from the revision data object
These are passed by the ResponseParser when building a Revision from a full GET /revisions/:id response.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/reactor_sdk/resources/revision.rb', line 105 def initialize( id:, type:, attributes: {}, meta: {}, relationships: {}, included_entity: nil, revision_relationships: nil ) super( id: id, type: type, attributes: attributes, meta: , relationships: relationships ) @included_entity = included_entity extract_entity_identity(revision_relationships || relationships) end |
Instance Attribute Details
#entity_id ⇒ String? (readonly)
Returns the Adobe ID of the resource this revision belongs to. Extracted from the JSON:API relationships on the revision.
76 77 78 |
# File 'lib/reactor_sdk/resources/revision.rb', line 76 def entity_id @entity_id end |
#entity_type ⇒ String? (readonly)
Returns the JSON:API type of the resource this revision belongs to. Extracted from the JSON:API relationships on the revision.
84 85 86 |
# File 'lib/reactor_sdk/resources/revision.rb', line 84 def entity_type @entity_type end |
Instance Method Details
#activity_type ⇒ String?
Returns The action that triggered this revision Common values: “created”, “updated”, “published”, “rejected”.
37 |
# File 'lib/reactor_sdk/resources/revision.rb', line 37 attribute :activity_type |
#created_at ⇒ String
Returns ISO8601 timestamp when this revision was created.
33 |
# File 'lib/reactor_sdk/resources/revision.rb', line 33 attribute :created_at |
#entity_relationships ⇒ Hash
Returns the full relationships snapshot of the resource at this revision.
64 65 66 67 68 |
# File 'lib/reactor_sdk/resources/revision.rb', line 64 def entity_relationships return {} if @included_entity.nil? @included_entity.fetch('relationships', {}) end |
#entity_snapshot ⇒ Hash
Returns the full attributes snapshot of the resource at this revision.
Adobe returns the revisioned resource in the JSON:API ‘included` array when fetching a revision. This method extracts those attributes so the app can compare two snapshots field by field.
Returns an empty Hash if the included snapshot is not present —this happens when fetching a revision list (GET /rules/:id/revisions) rather than a single revision (GET /revisions/:id). Always use revisions.find(id) when you need the full snapshot.
53 54 55 56 57 |
# File 'lib/reactor_sdk/resources/revision.rb', line 53 def entity_snapshot return {} if @included_entity.nil? @included_entity.fetch('attributes', {}) end |
#inspect ⇒ String
Returns Human-readable representation.
128 129 130 131 132 133 134 |
# File 'lib/reactor_sdk/resources/revision.rb', line 128 def inspect '#<ReactorSDK::Resources::Revision ' \ "id=#{id.inspect} " \ "activity_type=#{activity_type.inspect} " \ "entity_id=#{entity_id.inspect} " \ "entity_type=#{entity_type.inspect}>" end |