Class: Sendly::RulesResource

Inherits:
Object
  • Object
show all
Defined in:
lib/sendly/rules_resource.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ RulesResource

Returns a new instance of RulesResource.



5
6
7
# File 'lib/sendly/rules_resource.rb', line 5

def initialize(client)
  @client = client
end

Instance Method Details

#create(name:, conditions:, actions:, priority: nil) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/sendly/rules_resource.rb', line 14

def create(name:, conditions:, actions:, priority: nil)
  body = { name: name, conditions: conditions, actions: actions }
  body[:priority] = priority if priority

  response = @client.post("/rules", body)
  Rule.new(response)
end

#delete(id) ⇒ Object

Raises:



35
36
37
38
39
# File 'lib/sendly/rules_resource.rb', line 35

def delete(id)
  raise ValidationError, "Rule ID is required" if id.nil? || id.empty?

  @client.delete("/rules/#{URI.encode_www_form_component(id)}")
end

#listObject



9
10
11
12
# File 'lib/sendly/rules_resource.rb', line 9

def list
  response = @client.get("/rules")
  (response["data"] || []).map { |r| Rule.new(r) }
end

#update(id, name: nil, conditions: nil, actions: nil, priority: nil) ⇒ Object

Raises:



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sendly/rules_resource.rb', line 22

def update(id, name: nil, conditions: nil, actions: nil, priority: nil)
  raise ValidationError, "Rule ID is required" if id.nil? || id.empty?

  body = {}
  body[:name] = name if name
  body[:conditions] = conditions if conditions
  body[:actions] = actions if actions
  body[:priority] = priority if priority

  response = @client.patch("/rules/#{URI.encode_www_form_component(id)}", body)
  Rule.new(response)
end