Class: Rerout::Resources::Tags

Inherits:
Object
  • Object
show all
Defined in:
lib/rerout/tags_resource.rb

Overview

Tag management namespace — list, create, update, and delete the tags that can be attached to links for the project that owns the API key. Reach it via ‘client.tags`.

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Tags

Returns a new instance of Tags.

Parameters:



12
13
14
# File 'lib/rerout/tags_resource.rb', line 12

def initialize(client)
  @client = client
end

Instance Method Details

#create(input) ⇒ Rerout::Models::Tag

Create a tag. ‘color` is optional; the server validates and defaults it.

Parameters:

Returns:



28
29
30
31
32
# File 'lib/rerout/tags_resource.rb', line 28

def create(input)
  body = coerce_create_input(input)
  response = @client.request(method: :post, path: '/v1/projects/me/tags', body: body)
  Models::Tag.from_hash(response)
end

#delete(tag_id) ⇒ Hash

Delete a tag and drop its assignments from all links. Idempotent.

Parameters:

  • tag_id (String)

    the tag id (‘tag_…`).

Returns:

  • (Hash)

    ‘{ “deleted” => true }`



51
52
53
# File 'lib/rerout/tags_resource.rb', line 51

def delete(tag_id)
  @client.request(method: :delete, path: tag_path(tag_id))
end

#listRerout::Models::ListTagsResult

List the project’s tags with their live link counts.



19
20
21
22
# File 'lib/rerout/tags_resource.rb', line 19

def list
  response = @client.request(method: :get, path: '/v1/projects/me/tags')
  Models::ListTagsResult.from_hash(response)
end

#update(tag_id, input) ⇒ Rerout::Models::Tag

Update a tag’s name and/or color. Mirrors ‘links.update`: omitted fields are left unchanged. There is no client-side empty-payload check — the server rejects a fully empty patch with `400`.

Parameters:

Returns:



41
42
43
44
45
# File 'lib/rerout/tags_resource.rb', line 41

def update(tag_id, input)
  body = coerce_update_input(input)
  response = @client.request(method: :patch, path: tag_path(tag_id), body: body)
  Models::Tag.from_hash(response)
end