Module: Camper::Client::MessageTypesAPI

Included in:
Camper::Client
Defined in:
lib/camper/api/message_types.rb

Overview

Defines methods related to message types.

Instance Method Summary collapse

Instance Method Details

#create_message_type(project, name, icon) ⇒ Resource

Create a messages type in a given project

Examples:

client.create_message_type(my_project, 'Farewell', '👋')

Parameters:

  • project (Project)

    project where the message type belongs to

  • name (String)

    name of the new message type

  • icon (String)

    icon to associate with the new message type

Returns:

Raises:

See Also:



46
47
48
49
50
# File 'lib/camper/api/message_types.rb', line 46

def create_message_type(project, name, icon)
  raise Error::InvalidParameter, 'Name and icon parameters cannot be blank' if name.blank? || icon.blank?

  post("/buckets/#{project.id}/categories", body: { name: name, icon: icon })
end

#delete_message_type(project, type) ⇒ Object Also known as: trash_message_type

Delete a message type in a given project

Examples:

client.delete_message_type(my_project, type)

Parameters:

  • project (Project)

    project where the message type belongs to

  • type (Resource|Integer|String)

    resource or id representing a message type

See Also:



81
82
83
84
85
# File 'lib/camper/api/message_types.rb', line 81

def delete_message_type(project, type)
  type_id = type.respond_to?(:id) ? type.id : type

  delete("/buckets/#{project.id}/categories/#{type_id}")
end

#message_type(project, message_type_id) ⇒ Resource

Get a messages type in a given project

Examples:

client.message_type(my_project, '10')
client.message_type(my_project, 64926)

Parameters:

  • project (Project)

    project to get the messages type from

  • message_type_id (Integer|String)

    id of the message type to retrieve

Returns:

See Also:



31
32
33
# File 'lib/camper/api/message_types.rb', line 31

def message_type(project, message_type_id)
  get("/buckets/#{project.id}/categories/#{message_type_id}")
end

#message_types(project) ⇒ PaginatedResponse<Resource>

Get a paginated list of all messages types in a given project

Examples:

client.messages_types(my_project)

Parameters:

  • project (Project)

    project to get the messages types from

Returns:

See Also:



16
17
18
# File 'lib/camper/api/message_types.rb', line 16

def message_types(project)
  get("/buckets/#{project.id}/categories")
end

#update_message_type(project, type, options = {}) ⇒ Resource

Update a message type in a given project

Examples:

client.update_message_type(my_project, type, name: 'Quick Update')
client.update_message_type(my_project, type, icon: '🤙')

Parameters:

  • project (Project)

    project where the message type belongs to

  • type (Resource|Integer|String)

    resource or id representing a message type

  • options (Hash) (defaults to: {})

    hash containing the name and/or icon to modify

Returns:

Raises:

See Also:



65
66
67
68
69
70
71
# File 'lib/camper/api/message_types.rb', line 65

def update_message_type(project, type, options = {})
  raise Error::InvalidParameter, 'options cannot be empty' if options.empty?

  type_id = type.respond_to?(:id) ? type.id : type

  put("/buckets/#{project.id}/categories/#{type_id}", body: options)
end