Module: CloudConnect::Messages

Included in:
Client
Defined in:
lib/cloud_connect/client/messages.rb

Instance Method Summary (collapse)

Instance Method Details

- (Array<Hashie::Mash>) messages(opts = {})

Returns all messages that match parameters provided in +opts+ list (if +opts+ is provided)

Parameters:

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

    the options to filter the messages.

Options Hash (opts):

  • :ret (String) — default: 'id, time'

    Select attributes to fetch

  • :channelids (String)

    List of channel ids

  • :messageids (String)

    List of message ids

  • :unitids (String)

    List of unit ids

  • :userids (String)

    List of user ids

  • :status (String)

    Message status (0 (new), 1 (sent), 2 (received), 3 (failed))

  • :timedout (String) — default: false

    Include timed-out messages

  • :from (String)

    Minimum date

  • :to (String)

    Maximum date

  • :direction (String)

    Message direction (unittouser or usertounit)

  • :replyto (String)

    List of reference message ids

  • :id_min (Integer)

    Minimum ID

  • :id_max (Integer)

    Maximum ID

  • :limit (Integer) — default: 25

    Number of elements to fetch

Returns:

  • (Array<Hashie::Mash>)

    Messages

See Also:



26
27
28
29
# File 'lib/cloud_connect/client/messages.rb', line 26

def messages(opts = {})
  messages = connection.get(connection.build_url("messages", opts)).body
  messages.map!{|hash| hash.values.first}
end

- (Hashie::Mash) send_message(unit, channel, content, opts = {})

Send a message to a specific device

Parameters:

  • unit (Integer)
  • channel (Integer)
  • content (String)
  • opts (Hash) (defaults to: {})

Returns:

  • (Hashie::Mash)

    The message

See Also:



39
40
41
42
43
44
45
46
47
# File 'lib/cloud_connect/client/messages.rb', line 39

def send_message(unit, channel, content, opts = {})
  # TODO: rename #message_create ?
  opts.merge! :channelid => channel, :unitid => unit, :content => content
  response = connection.post do |req|
    req.url 'messages'
    req.body = {:message => opts}
  end
  response.body.values.first
end