Module: Camper::Client::MessagesAPI

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

Overview

Defines methods related to messages.

Instance Method Summary collapse

Instance Method Details

#create_message(parent, subject, options = {}) ⇒ Resource

Create a message

Examples:

client.create_message(my_project, 'New Infrastructure')
client.create_message(message_board, 'New Launch',
  content: 'This launch will be awesome',
  category_id: '23'
)

Parameters:

  • parent (Project|Resource)

    either a project or message board resource

  • subject (String)

    subject of the new message

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

    hash containing the content and/or category id for the new message

Returns:

See Also:



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/camper/api/messages.rb', line 60

def create_message(parent, subject, options = {})
  if parent.is_a?(Project)
    bucket_id, board_id = parent.id, parent.message_board.id
  else
    bucket_id, board_id = parent.bucket.id, parent.id
  end

  post(
    "/buckets/#{bucket_id}/message_boards/#{board_id}/messages",
    body: options.merge({ subject: subject, status: 'active' })
  )
end

#message(parent, message_id) ⇒ Resource

Get a paginated list of active messages under the given message board or project

Examples:

client.message(my_project, '2343')
client.message(message_board, 234)

Parameters:

  • parent (Project|Resource)

    either a project or message board resource

  • message_id (Integer|String)

    id of the message to retrieve

Returns:

See Also:



39
40
41
42
43
# File 'lib/camper/api/messages.rb', line 39

def message(parent, message_id)
  bucket_id = parent.is_a?(Project) ? parent.id : parent.bucket.id

  get("/buckets/#{bucket_id}/messages/#{message_id}")
end

#messages(parent) ⇒ PaginatedResponse<Resource>

Get a paginated list of active messages under the given message board or project

Examples:

client.messages(message_board)
client.messages(my_project)

Parameters:

Returns:

See Also:



18
19
20
21
22
23
24
25
26
# File 'lib/camper/api/messages.rb', line 18

def messages(parent)
  if parent.is_a?(Project)
    bucket_id, board_id = parent.id, parent.message_board.id
  else
    bucket_id, board_id = parent.bucket.id, parent.id
  end

  get("/buckets/#{bucket_id}/message_boards/#{board_id}/messages")
end

#trash_message(message) ⇒ Object

Trash message

it calls the trash_recording endpoint under the hood

Examples:

client.trash_message(message)

Parameters:

  • todo (Resource)

    the message to be trashed

Raises:

See Also:



103
104
105
# File 'lib/camper/api/messages.rb', line 103

def trash_message(message)
  trash_recording(message)
end

#update_message(message, options = {}) ⇒ Resource

Update a message

Examples:

client.update_message(message, subject: 'New Infrastructure')
client.update_message(message, content: 'This launch will be awesome')
client.update_message(message, category_id: '6918641') # message type id

Parameters:

  • message (Resource)

    message to update

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

    subject of the new message

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

    hash containing subject, content and/or category_id to update

Returns:

Raises:

See Also:



87
88
89
90
91
# File 'lib/camper/api/messages.rb', line 87

def update_message(message, options = {})
  raise Error::InvalidParameter, 'options cannot be empty' if options.empty?

  update("/buckets/#{message.bucket.id}/messages/#{message.id}", body: options)
end