Class: Cloudflared::Collection
- Inherits:
-
Object
- Object
- Cloudflared::Collection
- Includes:
- Enumerable
- Defined in:
- lib/cloudflared/collection.rb
Constant Summary collapse
- MAX_PER_PAGE =
100
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#success ⇒ Object
readonly
Returns the value of attribute success.
Class Method Summary collapse
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(data:, success:, errors:, messages:, page: 1, per_page: 50) ⇒ Collection
constructor
A new instance of Collection.
Constructor Details
#initialize(data:, success:, errors:, messages:, page: 1, per_page: 50) ⇒ Collection
Returns a new instance of Collection.
19 20 21 22 23 24 25 26 |
# File 'lib/cloudflared/collection.rb', line 19 def initialize(data:, success:, errors:, messages:, page: 1, per_page: 50) @data = data @success = success @errors = errors @messages = @page = page @per_page = per_page end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/cloudflared/collection.rb', line 7 def data @data end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
7 8 9 |
# File 'lib/cloudflared/collection.rb', line 7 def errors @errors end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
7 8 9 |
# File 'lib/cloudflared/collection.rb', line 7 def page @page end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
7 8 9 |
# File 'lib/cloudflared/collection.rb', line 7 def per_page @per_page end |
#success ⇒ Object (readonly)
Returns the value of attribute success.
7 8 9 |
# File 'lib/cloudflared/collection.rb', line 7 def success @success end |
Class Method Details
.from_response(response, key:, type:) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/cloudflared/collection.rb', line 9 def self.from_response(response, key:, type:) body = response.body["result"] new( data: body[key].map { |attrs| type.new(attrs) }, success: body["success"], errors: body["errors"], messages: body["messages"] ) end |
Instance Method Details
#each(&block) ⇒ Object
28 29 30 |
# File 'lib/cloudflared/collection.rb', line 28 def each(&block) @data.each(&block) end |