Class: Courier::Messages

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/messages.rb

Constant Summary collapse

KEY =
"/messages"

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ Messages

Returns a new instance of Messages.



5
6
7
# File 'lib/trycourier/messages.rb', line 5

def initialize(session)
  @session = session
end

Instance Method Details

#cancel(message_id:) ⇒ Object



41
42
43
44
45
# File 'lib/trycourier/messages.rb', line 41

def cancel(message_id:)
  path = "#{KEY}/#{message_id}/cancel"
  res = @session.send(path, "POST")
  ErrorHandler.check_err(res)
end

#get(message_id:) ⇒ Object



35
36
37
38
39
# File 'lib/trycourier/messages.rb', line 35

def get(message_id:)
  path = "#{KEY}/#{message_id}"
  res = @session.send(path, "GET")
  ErrorHandler.check_err(res)
end

#get_history(message_id:, type: nil) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/trycourier/messages.rb', line 47

def get_history(message_id:, type: nil)
  path = "#{KEY}/#{message_id}/history"
  params = {}
  if type
    params["type"] = type
  end
  res = @session.send(path, "GET", params: params)
  ErrorHandler.check_err(res)
end

#list(cursor: nil, event: nil, list_id: nil, message_id: nil, notification: nil, recipient: nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/trycourier/messages.rb', line 9

def list(cursor: nil, event: nil, list_id: nil, message_id: nil,
  notification: nil, recipient: nil)
  params = {}

  if cursor
    params["cursor"] = cursor
  end
  if event
    params["event"] = event
  end
  if list_id
    params["list"] = list_id
  end
  if message_id
    params["messageId"] = message_id
  end
  if notification
    params["notification"] = notification
  end
  if recipient
    params["recipient"] = recipient
  end
  res = @session.send(KEY, "GET", params: params)
  ErrorHandler.check_err(res)
end