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, from: nil, to: nil, limit: nil, cursor: nil, &block) ⇒ Object
- #get(id) ⇒ Object
- #page(channel: nil, status: nil, from: nil, to: nil, limit: nil, cursor: nil) ⇒ Object
Methods inherited from Sendara::Resource
Constructor Details
This class inherits a constructor from Sendara::Resource
Instance Method Details
#each(channel: nil, status: nil, from: nil, to: nil, limit: nil, cursor: nil, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sendara/resources/messages.rb', line 21 def each(channel: nil, status: nil, from: nil, to: nil, limit: nil, cursor: nil, &block) unless block_given? return enum_for(:each, channel: channel, status: status, from: from, to: to, limit: limit, cursor: cursor) end loop do current = page(channel: channel, status: status, 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) ⇒ Object
37 38 39 |
# File 'lib/sendara/resources/messages.rb', line 37 def get(id) request(:get, "/v1/messages/#{encode(id)}") || {} end |
#page(channel: nil, status: nil, from: nil, to: nil, limit: nil, cursor: nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/sendara/resources/messages.rb', line 8 def page(channel: nil, status: nil, from: nil, to: nil, limit: nil, cursor: nil) query = compact_params( "channel" => channel, "status" => status, "from" => from, "to" => to, "limit" => limit, "cursor" => cursor ) response = request(:get, "/v1/messages", query: query) || {} MessagePage.from_response(response) end |