Class: CemAcpt::Goss::Api::ActionResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/cem_acpt/goss/api/action_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, action, status, body) ⇒ ActionResponse

Returns a new instance of ActionResponse.



9
10
11
12
13
14
15
# File 'lib/cem_acpt/goss/api/action_response.rb', line 9

def initialize(host, action, status, body)
  @host = host
  @action = action
  @status = status
  @body = body
  @metadata = {}
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



7
8
9
# File 'lib/cem_acpt/goss/api/action_response.rb', line 7

def action
  @action
end

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/cem_acpt/goss/api/action_response.rb', line 7

def body
  @body
end

#hostObject (readonly)

Returns the value of attribute host.



7
8
9
# File 'lib/cem_acpt/goss/api/action_response.rb', line 7

def host
  @host
end

#metadataObject (readonly)

Returns the value of attribute metadata.



7
8
9
# File 'lib/cem_acpt/goss/api/action_response.rb', line 7

def 
  @metadata
end

Instance Method Details

#errorObject



44
45
46
# File 'lib/cem_acpt/goss/api/action_response.rb', line 44

def error
  results.find(&:error)
end

#error?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/cem_acpt/goss/api/action_response.rb', line 48

def error?
  !success? && !error.nil?
end

#inspectObject



21
22
23
# File 'lib/cem_acpt/goss/api/action_response.rb', line 21

def inspect
  to_s
end

#resultsObject



52
53
54
# File 'lib/cem_acpt/goss/api/action_response.rb', line 52

def results
  @results ||= @body['results'].map { |r| ActionResponseResult.new(r) }
end

#results?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/cem_acpt/goss/api/action_response.rb', line 56

def results?
  !results.nil? && !results.empty?
end

#statusObject Also known as: http_status



35
36
37
# File 'lib/cem_acpt/goss/api/action_response.rb', line 35

def status
  @status.to_i
end

#success?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/cem_acpt/goss/api/action_response.rb', line 40

def success?
  status == 200
end

#summaryObject



60
61
62
# File 'lib/cem_acpt/goss/api/action_response.rb', line 60

def summary
  @summary ||= ActionResponseSummary.new(@body['summary'])
end

#summary?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/cem_acpt/goss/api/action_response.rb', line 64

def summary?
  !summary.nil? && !summary.empty?
end

#to_hObject



25
26
27
28
29
30
31
32
33
# File 'lib/cem_acpt/goss/api/action_response.rb', line 25

def to_h
  {
    host: host,
    action: action,
    status: @status,
    body: @body,
    metadata: @metadata,
  }
end

#to_sObject



17
18
19
# File 'lib/cem_acpt/goss/api/action_response.rb', line 17

def to_s
  "#<#{self.class.name}:0x#{object_id.to_s(16)}>"
end