Class: Courier::Lists
- Inherits:
-
Object
- Object
- Courier::Lists
- Defined in:
- lib/trycourier/lists.rb
Constant Summary collapse
- KEY =
"/lists"
Instance Method Summary collapse
- #delete(list_id:) ⇒ Object
- #get(list_id:) ⇒ Object
- #get_subscriptions(list_id:, cursor: nil) ⇒ Object
-
#initialize(session) ⇒ Lists
constructor
A new instance of Lists.
- #list(cursor: nil, pattern: nil) ⇒ Object
- #put(list_id:, name:) ⇒ Object
- #put_subscriptions(list_id:, recipients:) ⇒ Object
- #restore(list_id:) ⇒ Object
- #send(event:, list: nil, pattern: nil, data: {}, brand: nil, override: nil, idempotency_key: nil) ⇒ Object
- #subscribe(list_id:, recipient_id:) ⇒ Object
- #unsubscribe(list_id:, recipient_id:) ⇒ Object
Constructor Details
#initialize(session) ⇒ Lists
Returns a new instance of Lists.
5 6 7 |
# File 'lib/trycourier/lists.rb', line 5 def initialize(session) @session = session end |
Instance Method Details
#delete(list_id:) ⇒ Object
66 67 68 69 70 |
# File 'lib/trycourier/lists.rb', line 66 def delete(list_id:) path = "#{KEY}/#{list_id}" res = @session.send(path, "DELETE") ErrorHandler.check_err_non_json(res) end |
#get(list_id:) ⇒ Object
49 50 51 52 53 |
# File 'lib/trycourier/lists.rb', line 49 def get(list_id:) path = "#{KEY}/#{list_id}" res = @session.send(path, "GET") ErrorHandler.check_err(res) end |
#get_subscriptions(list_id:, cursor: nil) ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/trycourier/lists.rb', line 78 def get_subscriptions(list_id:, cursor: nil) path = "#{KEY}/#{list_id}/subscriptions" params = {} if cursor params["cursor"] = cursor end res = @session.send(path, "GET", params: params) ErrorHandler.check_err(res) end |
#list(cursor: nil, pattern: nil) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/trycourier/lists.rb', line 37 def list(cursor: nil, pattern: nil) params = {} if cursor params["cursor"] = cursor end if pattern params["pattern"] = pattern end res = @session.send(KEY, "GET", params: params) ErrorHandler.check_err(res) end |
#put(list_id:, name:) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/trycourier/lists.rb', line 55 def put(list_id:, name:) path = "#{KEY}/#{list_id}" payload = { "name": name.to_s } res = @session.send(path, "PUT", body: payload) ErrorHandler.check_err_non_json(res) end |
#put_subscriptions(list_id:, recipients:) ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/trycourier/lists.rb', line 88 def put_subscriptions(list_id:, recipients:) path = "#{KEY}/#{list_id}/subscriptions" payload = { "recipients": recipients } res = @session.send(path, "PUT", body: payload) ErrorHandler.check_err_non_json(res) end |
#restore(list_id:) ⇒ Object
72 73 74 75 76 |
# File 'lib/trycourier/lists.rb', line 72 def restore(list_id:) path = "#{KEY}/#{list_id}/restore" res = @session.send(path, "PUT") ErrorHandler.check_err_non_json(res) end |
#send(event:, list: nil, pattern: nil, data: {}, brand: nil, override: nil, idempotency_key: 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 34 35 |
# File 'lib/trycourier/lists.rb', line 9 def send(event:, list: nil, pattern: nil, data: {}, brand: nil, override: nil, idempotency_key: nil) path = "/send/list" payload = { "event": event, "data": data } if list payload["list"] = list end if pattern payload["pattern"] = pattern end if brand payload["brand"] = brand end if override payload["override"] = override end headers = {} if idempotency_key headers["idempotency_key"] = idempotency_key end res = @session.send(path, "POST", body: payload, headers: headers) ErrorHandler.check_err(res) end |
#subscribe(list_id:, recipient_id:) ⇒ Object
97 98 99 100 101 |
# File 'lib/trycourier/lists.rb', line 97 def subscribe(list_id:, recipient_id:) path = "#{KEY}/#{list_id}/subscriptions/#{recipient_id}" res = @session.send(path, "PUT") ErrorHandler.check_err_non_json(res) end |
#unsubscribe(list_id:, recipient_id:) ⇒ Object
103 104 105 106 107 |
# File 'lib/trycourier/lists.rb', line 103 def unsubscribe(list_id:, recipient_id:) path = "#{KEY}/#{list_id}/subscriptions/#{recipient_id}" res = @session.send(path, "DELETE") ErrorHandler.check_err_non_json(res) end |