Class: Sendly::MessageList
- Inherits:
-
Object
- Object
- Sendly::MessageList
- Includes:
- Enumerable
- Defined in:
- lib/sendly/types.rb
Overview
Represents a paginated list of messages
Instance Attribute Summary collapse
-
#data ⇒ Array<Message>
readonly
Messages in this page.
-
#has_more ⇒ Boolean
readonly
Whether there are more pages.
-
#limit ⇒ Integer
readonly
Current limit.
-
#offset ⇒ Integer
readonly
Current offset.
-
#total ⇒ Integer
readonly
Total number of messages.
Instance Method Summary collapse
-
#count ⇒ Integer
(also: #size, #length)
Get message count.
-
#each(&block) ⇒ Object
Iterate over messages.
-
#empty? ⇒ Boolean
Check if empty.
-
#first ⇒ Message?
Get first message.
-
#initialize(response) ⇒ MessageList
constructor
A new instance of MessageList.
-
#last ⇒ Message?
Get last message.
Constructor Details
#initialize(response) ⇒ MessageList
Returns a new instance of MessageList.
170 171 172 173 174 175 176 |
# File 'lib/sendly/types.rb', line 170 def initialize(response) @data = (response["data"] || []).map { |m| Message.new(m) } @total = response["count"] || @data.length @limit = response["limit"] || 20 @offset = response["offset"] || 0 @has_more = (@offset + @data.length) < @total end |
Instance Attribute Details
#data ⇒ Array<Message> (readonly)
Returns Messages in this page.
156 157 158 |
# File 'lib/sendly/types.rb', line 156 def data @data end |
#has_more ⇒ Boolean (readonly)
Returns Whether there are more pages.
168 169 170 |
# File 'lib/sendly/types.rb', line 168 def has_more @has_more end |
#limit ⇒ Integer (readonly)
Returns Current limit.
162 163 164 |
# File 'lib/sendly/types.rb', line 162 def limit @limit end |
#offset ⇒ Integer (readonly)
Returns Current offset.
165 166 167 |
# File 'lib/sendly/types.rb', line 165 def offset @offset end |
#total ⇒ Integer (readonly)
Returns Total number of messages.
159 160 161 |
# File 'lib/sendly/types.rb', line 159 def total @total end |
Instance Method Details
#count ⇒ Integer Also known as: size, length
Get message count
185 186 187 |
# File 'lib/sendly/types.rb', line 185 def count data.length end |
#each(&block) ⇒ Object
Iterate over messages
179 180 181 |
# File 'lib/sendly/types.rb', line 179 def each(&block) data.each(&block) end |
#empty? ⇒ Boolean
Check if empty
194 195 196 |
# File 'lib/sendly/types.rb', line 194 def empty? data.empty? end |
#first ⇒ Message?
Get first message
200 201 202 |
# File 'lib/sendly/types.rb', line 200 def first data.first end |
#last ⇒ Message?
Get last message
206 207 208 |
# File 'lib/sendly/types.rb', line 206 def last data.last end |