Class: CloudParty::Responses::Accounts
- Inherits:
-
Object
- Object
- CloudParty::Responses::Accounts
- Includes:
- CloudParty::Response
- Defined in:
- lib/cloud_party/responses/accounts.rb
Instance Attribute Summary collapse
-
#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) ⇒ Accounts
constructor
A new instance of Accounts.
- #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) ⇒ Accounts
Returns a new instance of Accounts.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cloud_party/responses/accounts.rb', line 8 def initialize(method_name, endpoint, response) @code = response.code @body = JSON.parse(response.body, symbolize_names: true) @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::APIError.new(, response) end @results = [] @body[:result].each do |res| @results << CloudParty::Responses::Result.new(res) 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
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
39 40 41 |
# File 'lib/cloud_party/responses/accounts.rb', line 39 def @messages end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
45 46 47 |
# File 'lib/cloud_party/responses/accounts.rb', line 45 def results @results end |
Instance Method Details
#inspect ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cloud_party/responses/accounts.rb', line 47 def inspect wanted_methods = %i[errors messages success results result] our_methods = methods.select do |m| wanted_methods.include? m end outputs = [] our_methods.each do |m| outputs << "#{m}=#{send(m)}" end "#<Response: #{outputs.join(', ')}>" end |
#result ⇒ Object
41 42 43 |
# File 'lib/cloud_party/responses/accounts.rb', line 41 def result @results.first end |
#successful? ⇒ Boolean Also known as: success
35 36 37 |
# File 'lib/cloud_party/responses/accounts.rb', line 35 def successful? @success end |
#to_s ⇒ Object
59 60 61 |
# File 'lib/cloud_party/responses/accounts.rb', line 59 def to_s inspect end |