Class: ReactorSDK::Endpoints::DataElements

Inherits:
BaseEndpoint show all
Defined in:
lib/reactor_sdk/endpoints/data_elements.rb

Instance Method Summary collapse

Methods inherited from BaseEndpoint

#initialize

Constructor Details

This class inherits a constructor from ReactorSDK::Endpoints::BaseEndpoint

Instance Method Details

#comprehensive_upstream_chain(data_element_or_id, library_id:, property_id:) ⇒ ReactorSDK::Resources::ComprehensiveUpstreamChain

Resolves the data element across the ordered upstream chain using snapshot-aware comprehensive review objects.

Parameters:

Returns:



180
181
182
183
184
185
186
187
# File 'lib/reactor_sdk/endpoints/data_elements.rb', line 180

def comprehensive_upstream_chain(data_element_or_id, library_id:, property_id:)
  libraries_endpoint.comprehensive_upstream_chain_for_resource(
    data_element_or_id,
    library_id: library_id,
    property_id: property_id,
    resource_type: 'data_elements'
  )
end

#create(property_id:, name:, delegate_descriptor_id:, settings:, extension_id:, enabled: true) ⇒ ReactorSDK::Resources::DataElement

Creates a new data element within a property.

Requires an extension_id — fetch the property’s extensions first:

extensions  = client.extensions.list_for_property(property_id)
extension_id = extensions.find { |e| e.delegate_descriptor_id.start_with?("core::") }.id

The settings field must be a JSON-encoded string matching the delegate schema. For Core custom code the settings schema only allows “source” —do NOT include “language”:

settings: JSON.generate({ source: "return document.title;" })

Parameters:

  • property_id (String)

    Adobe property ID

  • name (String)

    Display name

  • delegate_descriptor_id (String)

    Extension delegate identifier

  • settings (String)

    JSON-encoded settings string

  • extension_id (String)

    Adobe extension ID

  • enabled (Boolean) (defaults to: true)

    Whether enabled (default: true)

Returns:

Raises:



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/reactor_sdk/endpoints/data_elements.rb', line 69

def create(
  property_id:,
  name:,
  delegate_descriptor_id:,
  settings:,
  extension_id:,
  enabled: true
)
  payload  = build_data_element_payload(
    name, delegate_descriptor_id, settings, extension_id, enabled
  )
  response = @connection.post("/properties/#{property_id}/data_elements", payload)
  @parser.parse(response['data'], Resources::DataElement)
end

#create_note(data_element_id, text) ⇒ ReactorSDK::Resources::Note

Creates a note on a data element.

Parameters:

  • data_element_id (String)
  • text (String)

Returns:



206
207
208
# File 'lib/reactor_sdk/endpoints/data_elements.rb', line 206

def create_note(data_element_id, text)
  create_note_for_path("/data_elements/#{data_element_id}/notes", text)
end

#delete(data_element_id) ⇒ nil

Deletes a data element permanently.

Parameters:

  • data_element_id (String)

    Adobe data element ID

Returns:

  • (nil)

Raises:



129
130
131
132
# File 'lib/reactor_sdk/endpoints/data_elements.rb', line 129

def delete(data_element_id)
  @connection.delete("/data_elements/#{data_element_id}")
  nil
end

#find(data_element_id) ⇒ ReactorSDK::Resources::DataElement

Retrieves a single data element by its Adobe ID.

Parameters:

  • data_element_id (String)

    Adobe data element ID (format: “DE” + hex)

Returns:

Raises:



43
44
45
46
# File 'lib/reactor_sdk/endpoints/data_elements.rb', line 43

def find(data_element_id)
  response = @connection.get("/data_elements/#{data_element_id}")
  @parser.parse(response['data'], Resources::DataElement)
end

#find_comprehensive(data_element_id, library_id:, property_id:) ⇒ ReactorSDK::Resources::ComprehensiveDataElement

Fetches the data element from a library-context review snapshot together with impact analysis and normalized review payload.

Parameters:

  • data_element_id (String)
  • library_id (String)
  • property_id (String)

Returns:



160
161
162
163
164
165
166
167
168
169
# File 'lib/reactor_sdk/endpoints/data_elements.rb', line 160

def find_comprehensive(data_element_id, library_id:, property_id:)
  snapshot = libraries_endpoint.find_snapshot(library_id, property_id: property_id)
  comprehensive = snapshot.comprehensive_resource(data_element_id, resource_type: 'data_elements')
  unless comprehensive
    raise ReactorSDK::ResourceNotFoundError,
          "Data element #{data_element_id} was not found in library #{library_id}"
  end

  comprehensive
end

#list_for_property(property_id) ⇒ Array<ReactorSDK::Resources::DataElement>

Lists all data elements for a given property. Follows pagination automatically — returns all data elements.

Parameters:

  • property_id (String)

    Adobe property ID

Returns:

Raises:



31
32
33
34
# File 'lib/reactor_sdk/endpoints/data_elements.rb', line 31

def list_for_property(property_id)
  records = @paginator.all("/properties/#{property_id}/data_elements")
  records.map { |r| @parser.parse(r, Resources::DataElement) }
end

#list_notes(data_element_id) ⇒ Array<ReactorSDK::Resources::Note>

Lists notes attached to a data element.

Parameters:

  • data_element_id (String)

Returns:



195
196
197
# File 'lib/reactor_sdk/endpoints/data_elements.rb', line 195

def list_notes(data_element_id)
  list_notes_for_path("/data_elements/#{data_element_id}/notes")
end

#revise(data_element_id) ⇒ ReactorSDK::Resources::DataElement

Revises a data element so it can be added to a library.

Adobe Launch requires every resource to be explicitly revised before it can be added to a library.

Always call revise after create or update, before libraries.add_data_elements.

Parameters:

  • data_element_id (String)

    Adobe data element ID

Returns:

Raises:



110
111
112
113
114
115
116
117
118
119
120
# File 'lib/reactor_sdk/endpoints/data_elements.rb', line 110

def revise(data_element_id)
  payload = {
    data: {
      id: data_element_id,
      type: 'data_elements',
      meta: { action: 'revise' }
    }
  }
  response = @connection.patch("/data_elements/#{data_element_id}", payload)
  @parser.parse(response['data'], Resources::DataElement)
end

#update(data_element_id, attributes) ⇒ ReactorSDK::Resources::DataElement

Updates an existing data element.

Parameters:

  • data_element_id (String)

    Adobe data element ID

  • attributes (Hash)

    Fields to update

Returns:

Raises:



92
93
94
95
96
# File 'lib/reactor_sdk/endpoints/data_elements.rb', line 92

def update(data_element_id, attributes)
  payload  = build_payload('data_elements', attributes, id: data_element_id)
  response = @connection.patch("/data_elements/#{data_element_id}", payload)
  @parser.parse(response['data'], Resources::DataElement)
end

#upstream_chain(data_element_or_id, library_id:, property_id:) ⇒ ReactorSDK::Resources::UpstreamChain

Resolves the data element across the ordered upstream library chain.

Parameters:

  • data_element_or_id (String, ReactorSDK::Resources::DataElement)
  • library_id (String)

    Adobe library ID used as the comparison root

  • property_id (String)

    Adobe property ID containing the library chain

Returns:



142
143
144
145
146
147
148
149
# File 'lib/reactor_sdk/endpoints/data_elements.rb', line 142

def upstream_chain(data_element_or_id, library_id:, property_id:)
  libraries_endpoint.upstream_chain_for_resource(
    data_element_or_id,
    library_id: library_id,
    property_id: property_id,
    resource_type: 'data_elements'
  )
end