Class: CloudParty::Responses::DNSRecords
- Inherits:
-
Object
- Object
- CloudParty::Responses::DNSRecords
- Includes:
- CloudParty::Response
- Defined in:
- lib/cloud_party/responses/dns_records.rb
Overview
‘/zones’ endpoint response object
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
-
#initialize(method_name, endpoint, response, options) ⇒ DNSRecords
constructor
A new instance of DNSRecords.
- #inspect ⇒ Object
- #result ⇒ Object
- #successful? ⇒ Boolean (also: #success)
- #to_s ⇒ Object
Methods included from CloudParty::Response
#check_result_type, #filter_by_account, included
Constructor Details
#initialize(method_name, endpoint, response, options) ⇒ DNSRecords
Returns a new instance of DNSRecords.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/cloud_party/responses/dns_records.rb', line 13 def initialize(method_name, endpoint, response, ) @code = response.code @body = JSON.parse(response.body, symbolize_names: true) @parsed_response = response.parsed_response @success = @body[:success] unless successful? = <<~MESSAGE Unable to #{method_name.to_s.upcase} to endpoint: #{endpoint}. Inspect CloudParty::APIError#response for further details MESSAGE raise CloudParty::Errors::APIError.new(, 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 |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
53 54 55 |
# File 'lib/cloud_party/responses/dns_records.rb', line 53 def errors @errors end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
54 55 56 |
# File 'lib/cloud_party/responses/dns_records.rb', line 54 def @messages end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
55 56 57 |
# File 'lib/cloud_party/responses/dns_records.rb', line 55 def results @results end |
Instance Method Details
#inspect ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# 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 ⇒ Object
63 64 65 66 67 68 69 70 71 |
# 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? ⇒ Boolean Also known as: success
57 58 59 |
# File 'lib/cloud_party/responses/dns_records.rb', line 57 def successful? @success end |
#to_s ⇒ Object
85 86 87 |
# File 'lib/cloud_party/responses/dns_records.rb', line 85 def to_s inspect end |