akamai_api 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +13 -0
- data/.yardopts +4 -0
- data/Gemfile +16 -0
- data/README.md +53 -52
- data/Thorfile +7 -1
- data/akamai_api.gemspec +1 -7
- data/bin/akamai_api +2 -1
- data/cassettes/akamai_api_ccu_arl_invalidate/invalid_credentials.yml +1 -1
- data/cassettes/akamai_api_ccu_arl_invalidate/invalid_item.yml +1 -1
- data/cassettes/akamai_api_ccu_arl_invalidate/multiple_items.yml +1 -1
- data/cassettes/akamai_api_ccu_arl_invalidate/single_item.yml +1 -1
- data/cassettes/akamai_api_ccu_arl_remove/invalid_credentials.yml +1 -1
- data/cassettes/akamai_api_ccu_arl_remove/invalid_item.yml +2 -2
- data/cassettes/akamai_api_ccu_arl_remove/multiple_items.yml +1 -1
- data/cassettes/akamai_api_ccu_arl_remove/single_item.yml +1 -1
- data/cassettes/akamai_api_ccu_cpcode_invalidate/invalid_credentials.yml +1 -1
- data/cassettes/akamai_api_ccu_cpcode_invalidate/invalid_item.yml +1 -1
- data/cassettes/akamai_api_ccu_cpcode_invalidate/multiple_items.yml +1 -1
- data/cassettes/akamai_api_ccu_cpcode_invalidate/single_item.yml +1 -1
- data/cassettes/akamai_api_ccu_cpcode_remove/invalid_credentials.yml +1 -1
- data/cassettes/akamai_api_ccu_cpcode_remove/invalid_item.yml +1 -1
- data/cassettes/akamai_api_ccu_cpcode_remove/multiple_items.yml +1 -1
- data/cassettes/akamai_api_ccu_cpcode_remove/single_item.yml +1 -1
- data/cassettes/akamai_api_eccu_all_ids/invalid_credentials.yml +68 -0
- data/cassettes/akamai_api_eccu_all_ids/successful.yml +72 -0
- data/cassettes/akamai_api_eccu_destroy/invalid_credentials.yml +69 -0
- data/cassettes/akamai_api_eccu_destroy/not_found_request.yml +55 -0
- data/cassettes/akamai_api_eccu_destroy/successful.yml +57 -0
- data/cassettes/akamai_api_eccu_find/invalid_credentials.yml +69 -0
- data/cassettes/akamai_api_eccu_find/not_found_request.yml +55 -0
- data/cassettes/akamai_api_eccu_find/successful.yml +70 -0
- data/cassettes/akamai_api_eccu_find/successful_without_content.yml +70 -0
- data/cassettes/akamai_api_eccu_publish/invalid_credentials.yml +5 -5
- data/cassettes/akamai_api_eccu_publish/invalid_domain.yml +7 -7
- data/cassettes/akamai_api_eccu_publish/successful.yml +8 -8
- data/cassettes/akamai_api_eccu_update_email/invalid_credentials.yml +69 -0
- data/cassettes/akamai_api_eccu_update_email/not_found_request.yml +55 -0
- data/cassettes/akamai_api_eccu_update_email/successful.yml +57 -0
- data/cassettes/akamai_api_eccu_update_notes/invalid_credentials.yml +70 -0
- data/cassettes/akamai_api_eccu_update_notes/not_found_request.yml +56 -0
- data/cassettes/akamai_api_eccu_update_notes/successful.yml +58 -0
- data/features/ccu_arl_invalidate.feature +5 -9
- data/features/ccu_arl_remove.feature +5 -9
- data/features/ccu_cpcode_invalidate.feature +2 -6
- data/features/ccu_cpcode_remove.feature +2 -6
- data/features/ccu_purge_status.feature +2 -2
- data/features/eccu_publish.feature +6 -42
- data/features/step_definitions/file_named_with_content_steps.rb +3 -0
- data/features/support/env.rb +12 -3
- data/lib/akamai_api/ccu/base_response.rb +27 -0
- data/lib/akamai_api/ccu/error.rb +38 -0
- data/lib/akamai_api/ccu/purge/request.rb +58 -11
- data/lib/akamai_api/ccu/purge/response.rb +15 -9
- data/lib/akamai_api/ccu/purge.rb +14 -3
- data/lib/akamai_api/ccu/purge_status/not_found.rb +18 -0
- data/lib/akamai_api/ccu/purge_status/request.rb +41 -7
- data/lib/akamai_api/ccu/purge_status/response.rb +49 -3
- data/lib/akamai_api/ccu/purge_status.rb +17 -9
- data/lib/akamai_api/ccu/status/request.rb +20 -7
- data/lib/akamai_api/ccu/status/response.rb +8 -2
- data/lib/akamai_api/ccu/status.rb +13 -2
- data/lib/akamai_api/ccu/unrecognized_option.rb +6 -0
- data/lib/akamai_api/ccu.rb +132 -23
- data/lib/akamai_api/cli/app.rb +15 -13
- data/lib/akamai_api/cli/ccu/arl.rb +10 -4
- data/lib/akamai_api/cli/ccu/base.rb +11 -3
- data/lib/akamai_api/cli/ccu/cp_code.rb +10 -4
- data/lib/akamai_api/cli/ccu/purge_renderer.rb +1 -1
- data/lib/akamai_api/cli/ccu/status_renderer.rb +46 -26
- data/lib/akamai_api/cli/ccu.rb +2 -4
- data/lib/akamai_api/cli/command.rb +60 -25
- data/lib/akamai_api/cli/eccu/base.rb +59 -0
- data/lib/akamai_api/cli/eccu/entry_renderer.rb +5 -3
- data/lib/akamai_api/cli/eccu.rb +2 -56
- data/lib/akamai_api/cli.rb +2 -6
- data/lib/akamai_api/eccu/base_edit_request.rb +51 -0
- data/lib/akamai_api/eccu/base_request.rb +32 -0
- data/lib/akamai_api/eccu/destroy_request.rb +30 -0
- data/lib/akamai_api/eccu/find_request.rb +45 -0
- data/lib/akamai_api/eccu/find_response.rb +110 -0
- data/lib/akamai_api/eccu/invalid_domain.rb +7 -0
- data/lib/akamai_api/eccu/list_request.rb +21 -0
- data/lib/akamai_api/eccu/not_found.rb +6 -0
- data/lib/akamai_api/eccu/publish_request.rb +75 -0
- data/lib/akamai_api/eccu/soap_body.rb +99 -0
- data/lib/akamai_api/eccu/update_attribute_request.rb +62 -0
- data/lib/akamai_api/eccu.rb +19 -0
- data/lib/akamai_api/eccu_request.rb +39 -117
- data/lib/akamai_api/error.rb +5 -0
- data/lib/akamai_api/unauthorized.rb +6 -0
- data/lib/akamai_api/version.rb +1 -1
- data/lib/akamai_api.rb +18 -4
- data/spec/features/ccu/purge_request_spec.rb +10 -12
- data/spec/features/ccu/purge_status_request_spec.rb +5 -5
- data/spec/features/ccu/status_request_spec.rb +3 -3
- data/spec/features/eccu/destroy_spec.rb +28 -0
- data/spec/features/eccu/find_request_spec.rb +34 -0
- data/spec/features/eccu/list_request_spec.rb +22 -0
- data/spec/features/eccu/publish_request_spec.rb +29 -0
- data/spec/features/eccu/update_email_spec.rb +28 -0
- data/spec/features/eccu/update_notes_spec.rb +28 -0
- data/spec/lib/akamai_api/ccu/{response_spec.rb → base_response_spec.rb} +2 -2
- data/spec/lib/akamai_api/ccu/purge/request_spec.rb +26 -20
- data/spec/lib/akamai_api/ccu/purge/response_spec.rb +16 -26
- data/spec/lib/akamai_api/ccu/purge_status/not_found_response_spec.rb +34 -34
- data/spec/lib/akamai_api/ccu/purge_status/request_spec.rb +24 -12
- data/spec/lib/akamai_api/ccu/purge_status/{successful_response_spec.rb → response_spec.rb} +8 -8
- data/spec/lib/akamai_api/ccu/status/request_spec.rb +6 -6
- data/spec/lib/akamai_api/ccu/status/response_spec.rb +2 -2
- data/spec/lib/akamai_api/ccu_spec.rb +7 -7
- data/spec/lib/akamai_api/cli/ccu/status_renderer_spec.rb +5 -17
- data/spec/lib/akamai_api/eccu/destroy_request_spec.rb +75 -0
- data/spec/lib/akamai_api/eccu/find_request_spec.rb +74 -0
- data/spec/lib/akamai_api/eccu/find_response_spec.rb +159 -0
- data/spec/lib/akamai_api/eccu/list_request_spec.rb +43 -0
- data/spec/lib/akamai_api/eccu/publish_request_spec.rb +133 -0
- data/spec/lib/akamai_api/eccu/soap_body_spec.rb +46 -0
- data/spec/lib/akamai_api/eccu/update_attribute_request_spec.rb +86 -0
- data/spec/lib/akamai_api/eccu_request_spec.rb +149 -158
- data/spec/spec_helper.rb +11 -3
- metadata +90 -104
- data/lib/akamai_api/ccu/purge_status/not_found_response.rb +0 -9
- data/lib/akamai_api/ccu/purge_status/successful_response.rb +0 -25
- data/lib/akamai_api/ccu/response.rb +0 -18
- data/lib/akamai_api/soap_body.rb +0 -40
- data/spec/lib/akamai_api/soap_body_spec.rb +0 -48
- data/spec/support/savon_backports.rb +0 -10
@@ -0,0 +1,38 @@
|
|
1
|
+
require "akamai_api/error"
|
2
|
+
|
3
|
+
module AkamaiApi::CCU
|
4
|
+
# Error received after a request done through the Akamai CCU interface.
|
5
|
+
class Error < AkamaiApi::Error
|
6
|
+
# @return [Hash<String, Object>] raw Raw object describing the error.
|
7
|
+
attr_reader :raw
|
8
|
+
|
9
|
+
# @param [Hash<String, Object>] raw Raw object describing the error.
|
10
|
+
def initialize raw
|
11
|
+
@raw = raw
|
12
|
+
super raw['title'] || raw['detail']
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [String] Reference provided to Customer Care when needed.
|
16
|
+
def support_id
|
17
|
+
raw['supportId']
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [String] Specific detail about the error
|
21
|
+
def detail
|
22
|
+
raw['detail']
|
23
|
+
end
|
24
|
+
|
25
|
+
alias_method :title, :message
|
26
|
+
|
27
|
+
# @return [Fixnum] Response HTTP Status Code describing the error
|
28
|
+
def code
|
29
|
+
raw['httpStatus']
|
30
|
+
end
|
31
|
+
alias_method :http_status, :code
|
32
|
+
|
33
|
+
# @return [String] URI pointing to a verbose error description
|
34
|
+
def described_by
|
35
|
+
raw['describedBy']
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -1,4 +1,19 @@
|
|
1
|
-
|
1
|
+
require "httparty"
|
2
|
+
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/core_ext/array'
|
5
|
+
|
6
|
+
require "akamai_api/unauthorized"
|
7
|
+
require "akamai_api/ccu/unrecognized_option"
|
8
|
+
require "akamai_api/ccu/purge/response"
|
9
|
+
|
10
|
+
module AkamaiApi::CCU::Purge
|
11
|
+
# {AkamaiApi::CCU::Purge} encapsulates the behavior needed to purge a resource from Akamai via CCU.
|
12
|
+
#
|
13
|
+
# @example Remove a single ARL
|
14
|
+
# AkamaiApi::CCU::Purge::Request.new.execute('http://foo.bar/t.txt')
|
15
|
+
# @example Invalidate multiple CPCodes
|
16
|
+
# AkamaiApi::CCU::Purge::Request.new(:invalidate, :cpcode).execute(12345, 12346)
|
2
17
|
class Request
|
3
18
|
include HTTParty
|
4
19
|
format :json
|
@@ -7,37 +22,64 @@ module AkamaiApi::Ccu::Purge
|
|
7
22
|
|
8
23
|
attr_reader :type, :action, :domain
|
9
24
|
|
10
|
-
|
25
|
+
# @param [String] action type of clean action. See {#action} for allowed values
|
26
|
+
# @param [String] type resource type. See {#type} for allowed values
|
27
|
+
# @param [Hash<Symbol, String>] args optional arguments
|
28
|
+
# @option args [String] :domain (:production) Domain type. See {#domain} for allowed values
|
29
|
+
def initialize action = :remove, type=:arl, args = {}
|
11
30
|
self.action = action
|
12
31
|
self.type = type
|
13
|
-
self.domain = args[:domain] ||
|
32
|
+
self.domain = args[:domain] || :production
|
14
33
|
end
|
15
34
|
|
35
|
+
# @!attribute [rw] action
|
36
|
+
# Clean action type.
|
37
|
+
# @return [:invalidate] when you want to simply mark resources as invalid
|
38
|
+
# @return [:remove] when you want to force resources removal
|
39
|
+
# @raise [AkamaiApi::CCU::UnrecognizedOption] if an invalid value is provided
|
16
40
|
def action= value
|
17
41
|
raise_unrecognized_action(value) unless valid_action?(value)
|
18
42
|
@action = value
|
19
43
|
end
|
20
44
|
|
45
|
+
# @!attribute [rw] type
|
46
|
+
# Resource type.
|
47
|
+
# @return [:cpcode] when request targets entire CPCode(s)
|
48
|
+
# @return [:arl] when request targets single ARL(s)
|
49
|
+
# @raise [AkamaiApi::CCU::UnrecognizedOption] if an invalid value is provided
|
21
50
|
def type= value
|
22
51
|
raise_unrecognized_type(value) unless valid_type?(value)
|
23
52
|
@type = value
|
24
53
|
end
|
25
54
|
|
55
|
+
# @!attribute [rw] domain
|
56
|
+
# Domain type to target.
|
57
|
+
# @return [:production] production environment
|
58
|
+
# @return [:staging] staging environment
|
59
|
+
# @raise [AkamaiApi::CCU::UnrecognizedOption] if an invalid value is provided
|
26
60
|
def domain= value
|
27
61
|
raise_unrecognized_domain(value) unless valid_domain?(value)
|
28
62
|
@domain = value
|
29
63
|
end
|
30
64
|
|
65
|
+
# Clean the requested resources.
|
66
|
+
# @param [Array<String>] items One or more resources to clean
|
67
|
+
# @return [Response] an object representing the received response
|
68
|
+
# @raise [AkamaiApi::CCU::Error] when there is an error in the request
|
69
|
+
# @raise [AkamaiApi::Unauthorized] when login credentials are invalid
|
70
|
+
# @example Clean a single resource
|
71
|
+
# request.execute 'http://foo.bar/t.txt'
|
72
|
+
# @example Clean multiple resources
|
73
|
+
# request.execute '12345', '12346'
|
31
74
|
def execute *items
|
32
75
|
items = Array.wrap(items.first) if items.length == 1
|
33
|
-
response = self.class.post('/', basic_auth: auth, body: request_body(items))
|
76
|
+
response = self.class.post('/', basic_auth: AkamaiApi.auth, body: request_body(items))
|
34
77
|
parse_response response
|
35
78
|
end
|
36
79
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
80
|
+
# Request body to send to the API.
|
81
|
+
# @param [Array<String>] items resources to clean
|
82
|
+
# @return [String] request body in JSON format
|
41
83
|
def request_body items
|
42
84
|
{ type: type, action: action, domain: domain, objects: items }.to_json
|
43
85
|
end
|
@@ -46,19 +88,20 @@ module AkamaiApi::Ccu::Purge
|
|
46
88
|
|
47
89
|
def parse_response response
|
48
90
|
raise ::AkamaiApi::Unauthorized if response.code == 401
|
91
|
+
raise AkamaiApi::CCU::Error.new response.parsed_response unless successful_response? response
|
49
92
|
Response.new response.parsed_response
|
50
93
|
end
|
51
94
|
|
52
95
|
def raise_unrecognized_action bad_action
|
53
|
-
raise ::AkamaiApi::
|
96
|
+
raise ::AkamaiApi::CCU::UnrecognizedOption, "Unknown action '#{bad_action}' (allowed values: invalidate, remove)"
|
54
97
|
end
|
55
98
|
|
56
99
|
def raise_unrecognized_type bad_type
|
57
|
-
raise ::AkamaiApi::
|
100
|
+
raise ::AkamaiApi::CCU::UnrecognizedOption, "Unknown type '#{bad_type}' (allowed values: arl, cpcode)"
|
58
101
|
end
|
59
102
|
|
60
103
|
def raise_unrecognized_domain bad_domain
|
61
|
-
raise ::AkamaiApi::
|
104
|
+
raise ::AkamaiApi::CCU::UnrecognizedOption, "Unknown domain '#{bad_domain}' (allowed_values: production, staging)"
|
62
105
|
end
|
63
106
|
|
64
107
|
def valid_action? action
|
@@ -72,5 +115,9 @@ module AkamaiApi::Ccu::Purge
|
|
72
115
|
def valid_domain? domain
|
73
116
|
%w(production staging).include? domain.to_s
|
74
117
|
end
|
118
|
+
|
119
|
+
def successful_response? response
|
120
|
+
(200...300).include? response.parsed_response['httpStatus']
|
121
|
+
end
|
75
122
|
end
|
76
123
|
end
|
@@ -1,31 +1,37 @@
|
|
1
|
-
|
2
|
-
class Response < ::AkamaiApi::Ccu::Response
|
3
|
-
def described_by
|
4
|
-
raw['describedBy']
|
5
|
-
end
|
6
|
-
|
7
|
-
def title
|
8
|
-
raw['title']
|
9
|
-
end
|
1
|
+
require "akamai_api/ccu/base_response"
|
10
2
|
|
3
|
+
module AkamaiApi::CCU::Purge
|
4
|
+
# This class represents the response received after a successful purge request
|
5
|
+
class Response < AkamaiApi::CCU::BaseResponse
|
6
|
+
# @return [Fixnum] Suggested time to wait (in seconds) before asking the status again
|
11
7
|
def time_to_wait
|
12
8
|
raw['pingAfterSeconds']
|
13
9
|
end
|
10
|
+
alias_method :ping_after_seconds, :time_to_wait
|
14
11
|
|
12
|
+
# Purge Request identifier
|
13
|
+
# @return [String] Purge Request identifier
|
15
14
|
def purge_id
|
16
15
|
raw['purgeId']
|
17
16
|
end
|
18
17
|
|
18
|
+
# Message detailing the response
|
19
|
+
# @return [String] message detailing the response.
|
19
20
|
def message
|
20
21
|
raw['detail']
|
21
22
|
end
|
23
|
+
alias_method :detail, :message
|
22
24
|
|
25
|
+
# @return [Fixnum] Estimated time (in seconds) for the operation to be completed
|
23
26
|
def estimated_time
|
24
27
|
raw['estimatedSeconds']
|
25
28
|
end
|
29
|
+
alias_method :estimated_seconds, :estimated_time
|
26
30
|
|
31
|
+
# @return [String] URI to use to check the status of the request
|
27
32
|
def uri
|
28
33
|
raw['progressUri']
|
29
34
|
end
|
35
|
+
alias_method :progress_uri, :uri
|
30
36
|
end
|
31
37
|
end
|
data/lib/akamai_api/ccu/purge.rb
CHANGED
@@ -1,5 +1,16 @@
|
|
1
|
-
require
|
2
|
-
require File.expand_path '../purge/response', __FILE__
|
1
|
+
require "akamai_api/ccu/purge/request"
|
3
2
|
|
4
|
-
module
|
3
|
+
# This module encapsulates classes aiming to purge resources using the Akamai CCU interface.
|
4
|
+
#
|
5
|
+
# @example Handling a purge response
|
6
|
+
# begin
|
7
|
+
# req = AkamaiApi::CCU::Purge::Request.new
|
8
|
+
# res = req.execute 'http://foo.bar/a.txt', 'http://www.foo.bar/a.txt'
|
9
|
+
# puts "Request #{res.purge_id} was successful (#{res.message})"
|
10
|
+
# rescue AkamaiApi::CCU::Error
|
11
|
+
# puts "Error #{$!.code} - #{$!.message}"
|
12
|
+
# rescue AkamaiApi::Unauthorized
|
13
|
+
# puts "Invalid login"
|
14
|
+
# end
|
15
|
+
module AkamaiApi::CCU::Purge
|
5
16
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "akamai_api/ccu/error"
|
2
|
+
|
3
|
+
module AkamaiApi::CCU::PurgeStatus
|
4
|
+
# {NotFound} is raised when the requested resource cannot be found
|
5
|
+
class NotFound < AkamaiApi::CCU::Error
|
6
|
+
# @return [String] URI to use to check the status of the request
|
7
|
+
def progress_uri
|
8
|
+
raw['progressUri']
|
9
|
+
end
|
10
|
+
alias_method :uri, :progress_uri
|
11
|
+
|
12
|
+
# @return [Fixnum] Suggested time to wait (in seconds) before asking the status again
|
13
|
+
def time_to_wait
|
14
|
+
raw['pingAfterSeconds']
|
15
|
+
end
|
16
|
+
alias_method :ping_after_seconds, :time_to_wait
|
17
|
+
end
|
18
|
+
end
|
@@ -1,23 +1,53 @@
|
|
1
|
-
|
1
|
+
require "httparty"
|
2
|
+
|
3
|
+
require "akamai_api/unauthorized"
|
4
|
+
require "akamai_api/ccu/error"
|
5
|
+
require "akamai_api/ccu/purge_status/response"
|
6
|
+
require "akamai_api/ccu/purge_status/not_found"
|
7
|
+
|
8
|
+
module AkamaiApi::CCU::PurgeStatus
|
9
|
+
# {Request} is used to check the status of a purge request using Akamai CCU.
|
10
|
+
#
|
11
|
+
# @example Check using {AkamaiApi::CCU::Purge::Response#purge_id}
|
12
|
+
# purge_id # => "12345678-1234-5678-1234-123456789012"
|
13
|
+
# AkamaiApi::CCU::PurgeStatus::Request.execute(purge_id)
|
14
|
+
# @example Check using {AkamaiApi::CCU::Purge::Response#progress_uri}
|
15
|
+
# progress_uri # => "/CCU/v2/purges/12345678-1234-5678-1234-123456789012"
|
16
|
+
# AkamaiApi::CCU::PurgeStatus::Request.execute(progress_uri)
|
2
17
|
class Request
|
3
18
|
include HTTParty
|
4
19
|
format :json
|
5
20
|
base_uri 'https://api.ccu.akamai.com'
|
6
21
|
|
7
|
-
|
8
|
-
|
9
|
-
|
22
|
+
# Checks the status of the requested associated with the given argument
|
23
|
+
# @param [String] purge_id_or_progress_uri a purge request ID or URI
|
24
|
+
# @return [Response] an object detailing the response
|
25
|
+
# @raise [AkamaiApi::CCU::PurgeStatus::NotFound] when the request cannot be found
|
26
|
+
# @raise [AkamaiApi::CCU::Error] when there is an error in the request
|
27
|
+
# @raise [AkamaiApi::Unauthorized] when login credentials are invalid
|
28
|
+
def self.execute purge_id_or_progress_uri
|
29
|
+
new.execute purge_id_or_progress_uri
|
10
30
|
end
|
11
31
|
|
12
|
-
|
13
|
-
|
32
|
+
# Checks the status of the requested associated with the given argument
|
33
|
+
# @return [Response] an object detailing the response
|
34
|
+
# @raise [AkamaiApi::CCU::PurgeStatus::NotFound] when the request cannot be found
|
35
|
+
# @raise [AkamaiApi::CCU::Error] when there is an error in the request
|
36
|
+
# @raise [AkamaiApi::Unauthorized] when login credentials are invalid
|
37
|
+
def execute purge_id_or_progress_uri
|
38
|
+
purge_id_or_progress_uri = normalize_progress_uri purge_id_or_progress_uri
|
39
|
+
response = self.class.get purge_id_or_progress_uri, basic_auth: AkamaiApi.auth
|
40
|
+
parse_response response
|
14
41
|
end
|
15
42
|
|
16
43
|
private
|
17
44
|
|
18
45
|
def parse_response response
|
19
46
|
raise AkamaiApi::Unauthorized if response.code == 401
|
20
|
-
|
47
|
+
parsed = response.parsed_response
|
48
|
+
raise AkamaiApi::CCU::Error.new parsed unless successful_response? parsed
|
49
|
+
raise AkamaiApi::CCU::PurgeStatus::NotFound.new parsed unless parsed['submissionTime']
|
50
|
+
AkamaiApi::CCU::PurgeStatus::Response.new(parsed)
|
21
51
|
end
|
22
52
|
|
23
53
|
def normalize_progress_uri progress_uri
|
@@ -28,5 +58,9 @@ module AkamaiApi::Ccu::PurgeStatus
|
|
28
58
|
"/ccu/v2/purges#{progress_uri}"
|
29
59
|
end
|
30
60
|
end
|
61
|
+
|
62
|
+
def successful_response? parsed_response
|
63
|
+
(200...300).include? parsed_response['httpStatus']
|
64
|
+
end
|
31
65
|
end
|
32
66
|
end
|
@@ -1,19 +1,65 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require "akamai_api/ccu/base_response"
|
2
|
+
|
3
|
+
module AkamaiApi::CCU::PurgeStatus
|
4
|
+
# This class represents a successful response and details a purge request status
|
5
|
+
class Response < AkamaiApi::CCU::BaseResponse
|
6
|
+
# @return [String] URI to use to check the status of the request
|
3
7
|
def progress_uri
|
4
8
|
raw['progressUri']
|
5
9
|
end
|
10
|
+
alias_method :uri, :progress_uri
|
6
11
|
|
12
|
+
# Purge Request identifier
|
13
|
+
# @return [String] Purge Request identifier
|
7
14
|
def purge_id
|
8
15
|
raw['purgeId']
|
9
16
|
end
|
10
17
|
|
11
|
-
|
18
|
+
# Status of the purge request
|
19
|
+
# @return ['In-Progress'] when the request is in progress
|
20
|
+
# @return ['Done'] when the request has been completed
|
21
|
+
# @return ['Unknown']
|
22
|
+
def purge_status
|
12
23
|
raw['purgeStatus']
|
13
24
|
end
|
25
|
+
alias_method :status, :purge_status
|
14
26
|
|
27
|
+
# @return [Fixnum] Suggested time to wait (in seconds) before asking the status again
|
15
28
|
def time_to_wait
|
16
29
|
raw['pingAfterSeconds']
|
17
30
|
end
|
31
|
+
alias_method :ping_after_seconds, :time_to_wait
|
32
|
+
|
33
|
+
# @return [Fixnum] Estimated time (in seconds) for the operation to be completed, calculated when the request was submitted
|
34
|
+
def original_estimated_time
|
35
|
+
raw['originalEstimatedSeconds']
|
36
|
+
end
|
37
|
+
alias_method :original_estimated_seconds, :original_estimated_time
|
38
|
+
|
39
|
+
# @return [Fixnum] Number of jobs in queue, calculated when the request was submitted
|
40
|
+
def original_queue_length
|
41
|
+
raw['originalQueueLength']
|
42
|
+
end
|
43
|
+
|
44
|
+
# The time the request was completed
|
45
|
+
# @return [Time] the time the request was completed
|
46
|
+
# @return [nil] when the request has not been completed (= its status isn't 'Done')
|
47
|
+
def completed_at
|
48
|
+
raw['completionTime'] && Time.iso8601(raw['completionTime'])
|
49
|
+
end
|
50
|
+
alias_method :completion_time, :completed_at
|
51
|
+
|
52
|
+
# @return [String] The request author name
|
53
|
+
def submitted_by
|
54
|
+
raw['submittedBy']
|
55
|
+
end
|
56
|
+
|
57
|
+
# The time the request was accepted
|
58
|
+
# @return [Time] the time the request was accepted
|
59
|
+
# @return [nil] when the request is still not accepted (= its status is neither 'Done' nor 'In-Progress')
|
60
|
+
def submitted_at
|
61
|
+
raw['submissionTime'] && Time.iso8601(raw['submissionTime'])
|
62
|
+
end
|
63
|
+
alias_method :submission_time, :submitted_at
|
18
64
|
end
|
19
65
|
end
|
@@ -1,10 +1,18 @@
|
|
1
|
-
|
2
|
-
def self.build_response parsed_response
|
3
|
-
response_class = parsed_response['submittedBy'] ? SuccessfulResponse : NotFoundResponse
|
4
|
-
response_class.new parsed_response
|
5
|
-
end
|
6
|
-
end
|
1
|
+
require "akamai_api/ccu/purge_status/request"
|
7
2
|
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
# This module encapsulates the classes you need to check the status of purge request
|
4
|
+
# submitted using the Akamai CCU interface.
|
5
|
+
#
|
6
|
+
# @example Checking the status of a purge request
|
7
|
+
# purge_id_or_progress_uri # => "/CCU/v2/purges/12345678-1234-5678-1234-123456789012"
|
8
|
+
# begin
|
9
|
+
# res = AkamaiApi::CCU::PurgeStatus::Request.execute purge_id_or_progress_uri
|
10
|
+
# puts "Request status is '#{res.status}'"
|
11
|
+
# puts "Request has been completed on '#{res.completed_at}'" if res.completed_at
|
12
|
+
# rescue AkamaiApi::CCU::Error
|
13
|
+
# puts "Error #{$!.code} - #{$!.message}"
|
14
|
+
# rescue AkamaiApi::Unauthorized
|
15
|
+
# puts "Invalid login"
|
16
|
+
# end
|
17
|
+
module AkamaiApi::CCU::PurgeStatus
|
18
|
+
end
|
@@ -1,23 +1,36 @@
|
|
1
|
-
|
1
|
+
require "httparty"
|
2
|
+
require "akamai_api/unauthorized"
|
3
|
+
require "akamai_api/ccu/status/response"
|
4
|
+
|
5
|
+
module AkamaiApi::CCU::Status
|
6
|
+
# {Request} can be used to check the status of the Akamai CCU queue
|
2
7
|
class Request
|
3
8
|
include HTTParty
|
4
9
|
format :json
|
5
10
|
base_uri 'https://api.ccu.akamai.com/ccu/v2/queues/default'
|
6
11
|
|
12
|
+
# Checks the status of the Akamai CCU queue
|
13
|
+
# @return [Response] a response object describing the status of the Akamai CCU queue
|
14
|
+
# @raise [AkamaiApi::CCU::Error] when there is an error in the request
|
15
|
+
# @raise [AkamaiApi::Unauthorized] when login credentials are invalid
|
16
|
+
def self.execute
|
17
|
+
new.execute
|
18
|
+
end
|
19
|
+
|
20
|
+
# Checks the status of the Akamai CCU queue
|
21
|
+
# @return [Response] a response object describing the status of the Akamai CCU queue
|
22
|
+
# @raise [AkamaiApi::CCU::Error] when there is an error in the request
|
23
|
+
# @raise [AkamaiApi::Unauthorized] when login credentials are invalid
|
7
24
|
def execute
|
8
|
-
response = self.class.get('/', basic_auth: auth)
|
25
|
+
response = self.class.get('/', basic_auth: AkamaiApi.auth)
|
9
26
|
parse_response response
|
10
27
|
end
|
11
28
|
|
12
29
|
private
|
13
30
|
|
14
|
-
def auth
|
15
|
-
AkamaiApi::Ccu.auth
|
16
|
-
end
|
17
|
-
|
18
31
|
def parse_response response
|
19
32
|
raise AkamaiApi::Unauthorized if response.code == 401
|
20
|
-
AkamaiApi::
|
33
|
+
AkamaiApi::CCU::Status::Response.new response.parsed_response
|
21
34
|
end
|
22
35
|
end
|
23
36
|
end
|
@@ -1,11 +1,17 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require "akamai_api/ccu/base_response"
|
2
|
+
|
3
|
+
module AkamaiApi::CCU::Status
|
4
|
+
# This response class describes the status of the Akamai CCU Queue
|
5
|
+
class Response < AkamaiApi::CCU::BaseResponse
|
6
|
+
# @return [Fixnum] Number of jobs in queue
|
3
7
|
def queue_length
|
4
8
|
raw['queueLength']
|
5
9
|
end
|
6
10
|
|
11
|
+
# @return [String] Message detailing the response
|
7
12
|
def message
|
8
13
|
raw['detail']
|
9
14
|
end
|
15
|
+
alias_method :detail, :message
|
10
16
|
end
|
11
17
|
end
|
@@ -1,2 +1,13 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
require "akamai_api/ccu/status/request"
|
2
|
+
|
3
|
+
# This module encapsulates the classes you need to check the status of the Akamai CCU queue,
|
4
|
+
#
|
5
|
+
# @example Checking the status of the Akamai CCU queue
|
6
|
+
# begin
|
7
|
+
# res = AkamaiApi::CCU::Status::Request.execute
|
8
|
+
# puts "There are #{res.queue_length} jobs in queue"
|
9
|
+
# rescue AkamaiApi::Unauthorized
|
10
|
+
# puts "Invalid login"
|
11
|
+
# end
|
12
|
+
module AkamaiApi::CCU::Status
|
13
|
+
end
|