Class: Sendly::MessageList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/sendly/types.rb

Overview

Represents a paginated list of messages

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataArray<Message> (readonly)

Returns Messages in this page.

Returns:

  • (Array<Message>)

    Messages in this page



156
157
158
# File 'lib/sendly/types.rb', line 156

def data
  @data
end

#has_moreBoolean (readonly)

Returns Whether there are more pages.

Returns:

  • (Boolean)

    Whether there are more pages



168
169
170
# File 'lib/sendly/types.rb', line 168

def has_more
  @has_more
end

#limitInteger (readonly)

Returns Current limit.

Returns:

  • (Integer)

    Current limit



162
163
164
# File 'lib/sendly/types.rb', line 162

def limit
  @limit
end

#offsetInteger (readonly)

Returns Current offset.

Returns:

  • (Integer)

    Current offset



165
166
167
# File 'lib/sendly/types.rb', line 165

def offset
  @offset
end

#totalInteger (readonly)

Returns Total number of messages.

Returns:

  • (Integer)

    Total number of messages



159
160
161
# File 'lib/sendly/types.rb', line 159

def total
  @total
end

Instance Method Details

#countInteger Also known as: size, length

Get message count

Returns:

  • (Integer)


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

Returns:

  • (Boolean)


194
195
196
# File 'lib/sendly/types.rb', line 194

def empty?
  data.empty?
end

#firstMessage?

Get first message

Returns:



200
201
202
# File 'lib/sendly/types.rb', line 200

def first
  data.first
end

#lastMessage?

Get last message

Returns:



206
207
208
# File 'lib/sendly/types.rb', line 206

def last
  data.last
end