Class: ReamazeAPI::Message

Inherits:
Resource show all
Defined in:
lib/reamaze_api/message.rb

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from ReamazeAPI::Resource

Instance Method Details

#all(params = {}) ⇒ Object

Retrieves messages.

Parameters:

  • params (defaults to: {})

    Hash of parameters (those not listed below are passed directly to the API):

  • API

    Routes GET /messages GET /conversations/slug/messages

  • See

Options Hash (params):

  • :conversation_slug (Object)

    Optional conversation slug

Returns:

  • a Hash.



17
18
19
20
21
22
# File 'lib/reamaze_api/message.rb', line 17

def all(params = {})
  params = Utils.symbolize_hash(params)
  url    = message_path(params.delete(:conversation_slug))

  paginate url, :messages, params
end

#create(params) ⇒ Object

Create a new message under the given conversation.

Parameters:

  • params

    Hash of parameters (those not listed below are passed directly to the API):

  • API

    Routes POST /conversations/slug/messages

  • See

Options Hash (params):

  • :conversation_slug (Object)

    Required conversation slug

Returns:

  • a Hash.



37
38
39
40
41
42
43
44
45
46
# File 'lib/reamaze_api/message.rb', line 37

def create(params)
  params = Utils.symbolize_hash(params)
  slug   = params.fetch(:conversation_slug)

  params.delete :conversation_slug

  post message_path(slug), params
rescue KeyError => e
  Utils.error_hash(e)
end

#message_path(conversation_slug = nil) ⇒ Object (private)

Private: Messages API path. If a conversation slug is supplied the returned path is prefixed with “/conversations/#slug”.

Parameters:

  • conversation_slug (defaults to: nil)

    The conversation slug

Returns:

  • a String.



56
57
58
59
60
61
62
# File 'lib/reamaze_api/message.rb', line 56

def message_path(conversation_slug = nil)
  if conversation_slug
    "/conversations/#{conversation_slug}/messages"
  else
    "/messages"
  end
end