Class: Cloudflared::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/cloudflared/collection.rb

Constant Summary collapse

MAX_PER_PAGE =
100

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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 = messages
  @page = page
  @per_page = per_page
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'lib/cloudflared/collection.rb', line 7

def data
  @data
end

#errorsObject (readonly)

Returns the value of attribute errors.



7
8
9
# File 'lib/cloudflared/collection.rb', line 7

def errors
  @errors
end

#pageObject (readonly)

Returns the value of attribute page.



7
8
9
# File 'lib/cloudflared/collection.rb', line 7

def page
  @page
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



7
8
9
# File 'lib/cloudflared/collection.rb', line 7

def per_page
  @per_page
end

#successObject (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