Class: CloudParty::Responses::Accounts

Inherits:
Object
  • Object
show all
Includes:
CloudParty::Response
Defined in:
lib/cloud_party/responses/accounts.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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 = <<~MESSAGE
      Unable to #{method_name.to_s.upcase} to endpoint:
      #{endpoint}. Inspect CloudParty::APIError#response
      for further details
    MESSAGE
    raise CloudParty::APIError.new(message, 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

#messagesObject (readonly)

Returns the value of attribute messages.



39
40
41
# File 'lib/cloud_party/responses/accounts.rb', line 39

def messages
  @messages
end

#resultsObject (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

#inspectObject



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

#resultObject



41
42
43
# File 'lib/cloud_party/responses/accounts.rb', line 41

def result
  @results.first
end

#successful?Boolean Also known as: success

Returns:

  • (Boolean)


35
36
37
# File 'lib/cloud_party/responses/accounts.rb', line 35

def successful?
  @success
end

#to_sObject



59
60
61
# File 'lib/cloud_party/responses/accounts.rb', line 59

def to_s
  inspect
end