Class: AkamaiApi::CLI::CCU::StatusRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/akamai_api/cli/ccu/status_renderer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ StatusRenderer

Returns a new instance of StatusRenderer.



8
9
10
# File 'lib/akamai_api/cli/ccu/status_renderer.rb', line 8

def initialize(response)
  @response = response
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'lib/akamai_api/cli/ccu/status_renderer.rb', line 6

def response
  @response
end

Instance Method Details

#purge_descriptionObject



48
49
50
51
52
53
54
# File 'lib/akamai_api/cli/ccu/status_renderer.rb', line 48

def purge_description
  if response.completed_at
    "Purge request has been successfully completed:"
  else
    "Purge request is currently enqueued:"
  end
end

#purge_statusObject



38
39
40
41
42
43
44
45
46
# File 'lib/akamai_api/cli/ccu/status_renderer.rb', line 38

def purge_status
  output = [
    purge_description,
    "\t* Result: #{response.code} - #{response.status}",
    "\t* Purge ID: #{response.purge_id} | Support ID: #{response.support_id}",
    "\t* Submitted by: #{response.} on #{response.}"
  ]
  output.concat response.completed_at ? successful_completed_purge : successful_pending_purge
end

#queue_statusObject



29
30
31
32
33
34
35
36
# File 'lib/akamai_api/cli/ccu/status_renderer.rb', line 29

def queue_status
  [
    "Akamai CCU Queue Status",
    "\t* Result: #{response.code} - #{response.message}",
    "\t* Support ID: #{response.support_id}",
    "\t* Queue Length: #{response.queue_length}"
  ]
end

#renderObject



20
21
22
23
24
25
26
27
# File 'lib/akamai_api/cli/ccu/status_renderer.rb', line 20

def render
  res = response.is_a?(AkamaiApi::CCU::Status::Response) ? queue_status : purge_status
  [
    '----------',
    res,
    '----------'
  ].join "\n"
end

#render_errorObject



12
13
14
15
16
17
18
# File 'lib/akamai_api/cli/ccu/status_renderer.rb', line 12

def render_error
  if response.is_a? AkamaiApi::CCU::PurgeStatus::NotFound
    render_not_found
  else
    render_generic_error
  end
end

#render_generic_errorObject



67
68
69
70
71
72
73
74
75
# File 'lib/akamai_api/cli/ccu/status_renderer.rb', line 67

def render_generic_error
  [
    "----------",
    "Error #{response.code}: '#{response.message}' (#{response.detail})",
    "  Described by: #{response.described_by}",
    "  Support ID: #{response.support_id}",
    "----------"
  ].join "\n"
end

#render_not_foundObject



56
57
58
59
60
61
62
63
64
65
# File 'lib/akamai_api/cli/ccu/status_renderer.rb', line 56

def render_not_found
  [
    "----------",
    "No purge request found using #{response.progress_uri}:",
    "\t* Result: #{response.code} - #{response.message}",
    "\t* Support ID: #{response.support_id}",
    "\t* Time to wait before next check: #{response.time_to_wait} secs.",
    "----------"
  ].join "\n"
end

#successful_completed_purgeObject



77
78
79
# File 'lib/akamai_api/cli/ccu/status_renderer.rb', line 77

def successful_completed_purge
  ["\t* Completed on: #{response.completed_at}"]
end

#successful_pending_purgeObject



81
82
83
84
85
86
87
# File 'lib/akamai_api/cli/ccu/status_renderer.rb', line 81

def successful_pending_purge
  [
    "\t* Estimated time was: #{response.original_estimated_time} secs.",
    "\t* Queue length was: #{response.original_queue_length}",
    "\t* Time to wait before next check: #{response.time_to_wait} secs.",
  ]
end