Class: ReactorSDK::Endpoints::Rules

Inherits:
BaseEndpoint show all
Defined in:
lib/reactor_sdk/endpoints/rules.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(rule_or_id, library_id:, property_id:) ⇒ ReactorSDK::Resources::ComprehensiveUpstreamChain

Resolves the rule across the ordered upstream chain and returns comprehensive review objects for the target and upstream entries.

Parameters:

Returns:



114
115
116
117
118
119
120
121
# File 'lib/reactor_sdk/endpoints/rules.rb', line 114

def comprehensive_upstream_chain(rule_or_id, library_id:, property_id:)
  libraries_endpoint.comprehensive_upstream_chain_for_resource(
    rule_or_id,
    library_id: library_id,
    property_id: property_id,
    resource_type: 'rules'
  )
end

#create(property_id:, name:, enabled: true) ⇒ ReactorSDK::Resources::Rule

Creates a new rule within a property.

Parameters:

  • property_id (String)

    Adobe property ID

  • name (String)

    Display name for the rule

  • enabled (Boolean) (defaults to: true)

    Whether the rule is enabled (default: true)

Returns:

Raises:



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

def create(property_id:, name:, enabled: true)
  create_resource(
    "/properties/#{property_id}/rules",
    'rules',
    Resources::Rule,
    attributes: { name: name, enabled: enabled }
  )
end

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

Creates a note on a rule.

Parameters:

  • rule_id (String)

    Adobe rule ID

  • text (String)

    Note body text

Returns:



205
206
207
# File 'lib/reactor_sdk/endpoints/rules.rb', line 205

def create_note(rule_id, text)
  create_note_for_path("/rules/#{rule_id}/notes", text)
end

#delete(rule_id) ⇒ nil

Deletes a rule permanently.

Parameters:

  • rule_id (String)

    Adobe rule ID

Returns:

  • (nil)

Raises:



194
195
196
# File 'lib/reactor_sdk/endpoints/rules.rb', line 194

def delete(rule_id)
  delete_resource("/rules/#{rule_id}")
end

#find(rule_id) ⇒ ReactorSDK::Resources::Rule

Retrieves a single rule by its Adobe ID.

Parameters:

  • rule_id (String)

    Adobe rule ID (format: “RL” + hex string)

Returns:

Raises:



41
42
43
# File 'lib/reactor_sdk/endpoints/rules.rb', line 41

def find(rule_id)
  fetch_resource("/rules/#{rule_id}", Resources::Rule)
end

#find_comprehensive(rule_id, library_id:, property_id:) ⇒ ReactorSDK::Resources::ComprehensiveRule

Fetches the rule from a library-context review snapshot together with its associated rule components and normalized review payload.

Parameters:

  • rule_id (String)
  • library_id (String)
  • property_id (String)

Returns:



94
95
96
97
98
99
100
101
102
103
# File 'lib/reactor_sdk/endpoints/rules.rb', line 94

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

  comprehensive
end

#libraries(rule_id) ⇒ Array<ReactorSDK::Resources::Library>

Lists the libraries containing a rule.

Parameters:

  • rule_id (String)

    Adobe rule ID

Returns:



61
62
63
# File 'lib/reactor_sdk/endpoints/rules.rb', line 61

def libraries(rule_id)
  list_resources("/rules/#{rule_id}/libraries", Resources::Library)
end

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

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

Parameters:

  • property_id (String)

    Adobe property ID

Returns:

Raises:



30
31
32
# File 'lib/reactor_sdk/endpoints/rules.rb', line 30

def list_for_property(property_id)
  list_resources("/properties/#{property_id}/rules", Resources::Rule)
end

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

Lists notes attached directly to a rule.

Parameters:

  • rule_id (String)

Returns:



215
216
217
# File 'lib/reactor_sdk/endpoints/rules.rb', line 215

def list_notes(rule_id)
  list_notes_for_path("/rules/#{rule_id}/notes")
end

#origin(rule_id) ⇒ ReactorSDK::Resources::Rule

Retrieves the origin revision head for a rule.

Parameters:

  • rule_id (String)

    Adobe rule ID

Returns:



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

def origin(rule_id)
  fetch_resource("/rules/#{rule_id}/origin", Resources::Rule)
end

#property(rule_id) ⇒ ReactorSDK::Resources::Property

Retrieves the property that owns a rule.

Parameters:

  • rule_id (String)

    Adobe rule ID

Returns:



51
52
53
# File 'lib/reactor_sdk/endpoints/rules.rb', line 51

def property(rule_id)
  fetch_resource("/rules/#{rule_id}/property", Resources::Property)
end

#revise(rule_id) ⇒ ReactorSDK::Resources::Rule

Revises a rule 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. A newly created or updated rule cannot be added to a library until revised.

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

Parameters:

  • rule_id (String)

    Adobe rule ID

Returns:

Raises:



176
177
178
179
180
181
182
183
184
185
# File 'lib/reactor_sdk/endpoints/rules.rb', line 176

def revise(rule_id)
  update_resource(
    "/rules/#{rule_id}",
    rule_id,
    'rules',
    Resources::Rule,
    attributes: {},
    meta: { action: 'revise' }
  )
end

#rule_component_notes(rule_id) ⇒ Array<ReactorSDK::Resources::RuleComponent>

Lists rule components associated with the rule’s component notes route.

Parameters:

  • rule_id (String)

Returns:



225
226
227
# File 'lib/reactor_sdk/endpoints/rules.rb', line 225

def rule_component_notes(rule_id)
  list_resources("/rules/#{rule_id}/rule_component_notes", Resources::RuleComponent)
end

#update(rule_id, attributes) ⇒ ReactorSDK::Resources::Rule

Updates an existing rule.

Parameters:

  • rule_id (String)

    Adobe rule ID

  • attributes (Hash)

    Fields to update (e.g. { name: “New Name” })

Returns:

Raises:



159
160
161
# File 'lib/reactor_sdk/endpoints/rules.rb', line 159

def update(rule_id, attributes)
  update_resource("/rules/#{rule_id}", rule_id, 'rules', Resources::Rule, attributes: attributes)
end

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

Resolves the rule across the ordered upstream library chain.

This is a convenience wrapper around Libraries#upstream_chain_for_resource so rule workflows can stay resource-centric at the call site.

Parameters:

  • rule_or_id (String, ReactorSDK::Resources::Rule)
  • library_id (String)

    Adobe library ID used as the comparison root

  • property_id (String)

    Adobe property ID containing the library chain

Returns:



76
77
78
79
80
81
82
83
# File 'lib/reactor_sdk/endpoints/rules.rb', line 76

def upstream_chain(rule_or_id, library_id:, property_id:)
  libraries_endpoint.upstream_chain_for_resource(
    rule_or_id,
    library_id: library_id,
    property_id: property_id,
    resource_type: 'rules'
  )
end