Method: Fog::DNS::AWS::Mock#list_hosted_zones

Defined in:
lib/fog/aws/requests/dns/list_hosted_zones.rb

#list_hosted_zones(options = {}) ⇒ Object

[View source]

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/fog/aws/requests/dns/list_hosted_zones.rb', line 55

def list_hosted_zones(options = {})

  if options[:max_items].nil?
    maxitems = 100
  else
    maxitems = options[:max_items]
  end

  if options[:marker].nil?
    start = 0
  else
    start = self.data[:zones].find_index {|z| z[:id] == options[:marker]}
  end

  zones     = self.data[:zones].values[start, maxitems]
  next_zone = self.data[:zones].values[start + maxitems]
  truncated = !next_zone.nil?

  response = Excon::Response.new
  response.status = 200
  response.body = {
    'HostedZones' => zones.map do |z|
      {
        'Id' => z[:id],
        'Name' => z[:name],
        'CallerReference' => z[:reference],
        'Comment' => z[:comment],
      }
    end,
    'Marker' => options[:marker].to_s,
    'MaxItems' => options[:max_items].to_s,
    'IsTruncated' => truncated.to_s
  }

  if truncated
    response.body['NextMarker'] = next_zone[:id]
  end

  response
end