Class: Sendara::Resources::Messages
- Inherits:
-
Sendara::Resource
- Object
- Sendara::Resource
- Sendara::Resources::Messages
- Includes:
- Enumerable
- Defined in:
- lib/sendara/resources/messages.rb
Instance Method Summary collapse
- #each(channel: nil, status: nil, search: nil, from: nil, to: nil, limit: nil, cursor: nil, &block) ⇒ Object
- #get(id = nil, idempotency_key: nil) ⇒ Object
- #page(channel: nil, status: nil, search: nil, from: nil, to: nil, limit: nil, cursor: nil) ⇒ Object (also: #list)
Methods inherited from Sendara::Resource
Constructor Details
This class inherits a constructor from Sendara::Resource
Instance Method Details
#each(channel: nil, status: nil, search: nil, from: nil, to: nil, limit: nil, cursor: nil, &block) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sendara/resources/messages.rb', line 24 def each(channel: nil, status: nil, search: nil, from: nil, to: nil, limit: nil, cursor: nil, &block) unless block_given? return enum_for(:each, channel: channel, status: status, search: search, from: from, to: to, limit: limit, cursor: cursor) end loop do current = page(channel: channel, status: status, search: search, from: from, to: to, limit: limit, cursor: cursor) current..each(&block) break if current.next_cursor.nil? cursor = current.next_cursor end end |
#get(id = nil, idempotency_key: nil) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/sendara/resources/messages.rb', line 40 def get(id = nil, idempotency_key: nil) if idempotency_key return request(:get, "/v1/messages", query: { "idempotency_key" => idempotency_key }) || {} end raise ArgumentError, "get requires an id or idempotency_key" if id.nil? request(:get, "/v1/messages/#{encode(id)}") || {} end |
#page(channel: nil, status: nil, search: nil, from: nil, to: nil, limit: nil, cursor: nil) ⇒ Object Also known as: list
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/sendara/resources/messages.rb', line 8 def page(channel: nil, status: nil, search: nil, from: nil, to: nil, limit: nil, cursor: nil) query = compact_params( "channel" => channel, "status" => status, "search" => search, "from" => from, "to" => to, "limit" => limit, "cursor" => cursor ) response = request(:get, "/v1/messages", query: query) || {} MessagePage.from_response(response) end |