Class: Whatsapp::MessageTemplates::Response::Collection
- Inherits:
-
Object
- Object
- Whatsapp::MessageTemplates::Response::Collection
- Includes:
- Enumerable
- Defined in:
- lib/ruby/whatsapp/message_templates/response/collection.rb
Overview
A page of templates: {data, paging, summary}.
Enumerable over its templates, so list.select(&:approved?) reads naturally
without reaching for .data first.
Paging is exposed rather than followed automatically: the caller decides whether
to walk the whole account, and passing #next_cursor back as after: is one
line. Auto-pagination would hide an unbounded number of requests behind a single
innocuous-looking call.
Source: https://developers.facebook.com/docs/graph-api/reference/whats-app-business-account/message_templates/
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #each {|template| ... } ⇒ Enumerator
-
#initialize(data: [], paging: nil, summary: nil) ⇒ Collection
constructor
A new instance of Collection.
-
#next_cursor ⇒ String?
The cursor to pass as
after:to fetch the next page. -
#remaining ⇒ Integer?
How many more templates the account can hold.
Constructor Details
#initialize(data: [], paging: nil, summary: nil) ⇒ Collection
Returns a new instance of Collection.
34 35 36 37 38 |
# File 'lib/ruby/whatsapp/message_templates/response/collection.rb', line 34 def initialize(data: [], paging: nil, summary: nil) @data = data @paging = paging @summary = summary end |
Instance Attribute Details
#data ⇒ Array<Node>
21 22 23 |
# File 'lib/ruby/whatsapp/message_templates/response/collection.rb', line 21 def data @data end |
#paging ⇒ Paging?
25 26 27 |
# File 'lib/ruby/whatsapp/message_templates/response/collection.rb', line 25 def paging @paging end |
#summary ⇒ Summary?
29 30 31 |
# File 'lib/ruby/whatsapp/message_templates/response/collection.rb', line 29 def summary @summary end |
Class Method Details
.deserialize(response) ⇒ Collection
43 44 45 46 47 48 49 50 51 |
# File 'lib/ruby/whatsapp/message_templates/response/collection.rb', line 43 def deserialize(response) response ||= {} new( data: Array(response["data"]).map { |node| Node.deserialize(node) }, paging: response["paging"] && Paging.deserialize(response["paging"]), summary: response["summary"] && Summary.deserialize(response["summary"]) ) end |
Instance Method Details
#each {|template| ... } ⇒ Enumerator
56 57 58 |
# File 'lib/ruby/whatsapp/message_templates/response/collection.rb', line 56 def each(&) data.each(&) end |
#next_cursor ⇒ String?
The cursor to pass as after: to fetch the next page.
62 63 64 |
# File 'lib/ruby/whatsapp/message_templates/response/collection.rb', line 62 def next_cursor paging&.after end |
#remaining ⇒ Integer?
How many more templates the account can hold.
68 69 70 |
# File 'lib/ruby/whatsapp/message_templates/response/collection.rb', line 68 def remaining summary&.remaining end |