Class: ReactorSDK::Resources::Revision

Inherits:
BaseResource show all
Defined in:
lib/reactor_sdk/resources/revision.rb

Instance Attribute Summary collapse

Attributes inherited from BaseResource

#attributes, #id, #meta, #relationships, #type

Instance Method Summary collapse

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.

Parameters:

  • id (String)

    Adobe revision ID

  • type (String)

    JSON:API type (“revisions”)

  • attributes (Hash) (defaults to: {})

    Revision attributes

  • meta (Hash) (defaults to: {})

    Optional metadata

  • included_entity (Hash, nil) (defaults to: nil)

    Raw included resource from API response

  • relationships (Hash, nil) (defaults to: {})

    Relationships hash from the revision



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: meta,
    relationships: relationships
  )
  @included_entity = included_entity
  extract_entity_identity(revision_relationships || relationships)
end

Instance Attribute Details

#entity_idString? (readonly)

Returns the Adobe ID of the resource this revision belongs to. Extracted from the JSON:API relationships on the revision.

Returns:

  • (String, nil)

    Resource ID (e.g. “RL123”) or nil if not present



76
77
78
# File 'lib/reactor_sdk/resources/revision.rb', line 76

def entity_id
  @entity_id
end

#entity_typeString? (readonly)

Returns the JSON:API type of the resource this revision belongs to. Extracted from the JSON:API relationships on the revision.

Returns:

  • (String, nil)

    Resource type (e.g. “rules”) or nil if not present



84
85
86
# File 'lib/reactor_sdk/resources/revision.rb', line 84

def entity_type
  @entity_type
end

Instance Method Details

#activity_typeString?

Returns The action that triggered this revision Common values: “created”, “updated”, “published”, “rejected”.

Returns:

  • (String, nil)

    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_atString

Returns ISO8601 timestamp when this revision was created.

Returns:

  • (String)

    ISO8601 timestamp when this revision was created



33
# File 'lib/reactor_sdk/resources/revision.rb', line 33

attribute :created_at

#entity_relationshipsHash

Returns the full relationships snapshot of the resource at this revision.

Returns:

  • (Hash)


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_snapshotHash

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.

Returns:

  • (Hash)

    Full attributes of the revisioned resource, or {} if absent



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

#inspectString

Returns Human-readable representation.

Returns:

  • (String)

    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