Class: Sendly::LabelsResource

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ LabelsResource

Returns a new instance of LabelsResource.



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

def initialize(client)
  @client = client
end

Instance Method Details

#create(name:, color: nil, description: nil) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/sendly/labels_resource.rb', line 9

def create(name:, color: nil, description: nil)
  body = { name: name }
  body[:color] = color if color
  body[:description] = description if description

  response = @client.post("/labels", body)
  Label.new(response)
end

#delete(id) ⇒ Object

Raises:



23
24
25
26
27
# File 'lib/sendly/labels_resource.rb', line 23

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

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

#listObject



18
19
20
21
# File 'lib/sendly/labels_resource.rb', line 18

def list
  response = @client.get("/labels")
  (response["data"] || []).map { |l| Label.new(l) }
end