class CloudParty::Responses::DNSRecords
'/zones' endpoint response object
Attributes
errors[R]
messages[R]
results[R]
Public Class Methods
new(method_name, endpoint, response, options)
click to toggle source
@raise [CloudParty::APIError] if the library encountered
an error and {#successful?} is false
@raise [CloudParty::UnRecognizedEndpointError] if the library encountered
an unknown endpoint for this class
# File lib/cloud_party/responses/dns_records.rb, line 13 def initialize(method_name, endpoint, response, options) @code = response.code @body = JSON.parse(response.body, symbolize_names: true) @parsed_response = response.parsed_response @success = @body[:success] unless successful? message = <<~MESSAGE Unable to #{method_name.to_s.upcase} to endpoint: #{endpoint}. Inspect CloudParty::APIError#response for further details MESSAGE raise CloudParty::Errors::APIError.new(message, response) end @results = [] if endpoint =~ /^\/zones\/:id\/dns_records\/?$/ @body[:result].each do |res| @results << CloudParty::Responses::Result.new(res) end elsif endpoint =~ /^\/zones\/:id\/dns_records\/:identifier\/?$/ if method_name == :get @results = CloudParty::Responses::Result.new(@body[:result]) end else raise Errors::UnRecognizedEndpointError.new(endpoint, self.class) end if endpoint =~ /^\/zones\/:id\/dns_records\/import\/?$/ if @body.fetch(:timing, nil) @timing = CloudParty::Responses::Timing.new(@body[:timing]) end @errors = [] @body[:errors].each do |err| @errors << CloudParty::Responses::Error.new(err) end @messages = [] @body[:messages].each do |msg| @messages << CloudParty::Responses::Message.new(msg) end end end
Public Instance Methods
inspect()
click to toggle source
# File lib/cloud_party/responses/dns_records.rb, line 73 def inspect wanted_methods = %i[success messages errors results] our_methods = methods.select do |m| wanted_methods.include? m end outputs = [] our_methods.sort.each do |m| outputs << "#{m}=#{send(m)}" end "#<Response: #{outputs.join(', ')}>" end
result()
click to toggle source
# File lib/cloud_party/responses/dns_records.rb, line 63 def result if check_result_type(@body[:result]) == 'Array' CloudParty::Responses::Result.new(@body[:result].first) elsif check_result_type(@body[:result]) == 'Hash' CloudParty::Responses::Result.new(@body[:result]) else raise CloudParty::Errors::UnRecognizedResultTypeError.new(@body[:result].class) end end
successful?()
click to toggle source
# File lib/cloud_party/responses/dns_records.rb, line 57 def successful? @success end
Also aliased as: success
to_s()
click to toggle source
# File lib/cloud_party/responses/dns_records.rb, line 85 def to_s inspect end