Class: CloudParty::Responses::Zones
- Inherits:
-
Object
- Object
- CloudParty::Responses::Zones
- Defined in:
- lib/cloud_party/responses/zones.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) ⇒ Zones
constructor
A new instance of Zones.
- #inspect ⇒ Object
- #result ⇒ Object
- #successful? ⇒ Boolean (also: #success)
- #to_s ⇒ Object
Constructor Details
#initialize(method_name, endpoint, response, options) ⇒ Zones
Returns a new instance of Zones.
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/zones.rb', line 15 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/Rescue CloudParty::Errors::APIError#response for further details MESSAGE raise CloudParty::Errors::APIError.new(, response) end @results = [] if endpoint =~ /^\/zones\/?$/ @body[:result].each do |res| @results << CloudParty::Responses::Result.new(res) end elsif endpoint =~ /^\/zones\/:id\/dns_records\/?$/ raise CloudParty::Errors::RequestError.new("Use CloudParty::Nodes::DNSRecords for this endpoint.", method_name, endpoint, @code, nil) elsif endpoint =~ /^\/zones\/:id\/?$/ @result = CloudParty::Responses::Result.new(@body[:result]) @results << @result else raise Errors::UnRecognizedEndpointError.new(endpoint, self.class) 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 |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
52 53 54 |
# File 'lib/cloud_party/responses/zones.rb', line 52 def errors @errors end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
53 54 55 |
# File 'lib/cloud_party/responses/zones.rb', line 53 def @messages end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
54 55 56 |
# File 'lib/cloud_party/responses/zones.rb', line 54 def results @results end |
Instance Method Details
#inspect ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/cloud_party/responses/zones.rb', line 67 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
61 62 63 |
# File 'lib/cloud_party/responses/zones.rb', line 61 def result @body[:result] end |
#successful? ⇒ Boolean Also known as: success
55 56 57 |
# File 'lib/cloud_party/responses/zones.rb', line 55 def successful? @success end |
#to_s ⇒ Object
79 80 81 |
# File 'lib/cloud_party/responses/zones.rb', line 79 def to_s inspect end |