akamai_api 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/Guardfile +5 -15
  3. data/README.md +106 -36
  4. data/Thorfile +5 -0
  5. data/akamai_api.gemspec +6 -3
  6. data/bin/akamai_api +1 -2
  7. data/cassettes/akamai_api_ccu_arl_invalidate/invalid_credentials.yml +37 -0
  8. data/cassettes/akamai_api_ccu_arl_invalidate/invalid_item.yml +36 -0
  9. data/cassettes/akamai_api_ccu_arl_invalidate/multiple_items.yml +38 -0
  10. data/cassettes/akamai_api_ccu_arl_invalidate/single_item.yml +38 -0
  11. data/cassettes/akamai_api_ccu_arl_remove/invalid_credentials.yml +37 -0
  12. data/cassettes/akamai_api_ccu_arl_remove/invalid_item.yml +36 -0
  13. data/cassettes/akamai_api_ccu_arl_remove/multiple_items.yml +38 -0
  14. data/cassettes/akamai_api_ccu_arl_remove/single_item.yml +38 -0
  15. data/cassettes/akamai_api_ccu_cpcode_invalidate/invalid_credentials.yml +37 -0
  16. data/cassettes/akamai_api_ccu_cpcode_invalidate/invalid_item.yml +36 -0
  17. data/cassettes/akamai_api_ccu_cpcode_invalidate/multiple_items.yml +38 -0
  18. data/cassettes/akamai_api_ccu_cpcode_invalidate/single_item.yml +38 -0
  19. data/cassettes/akamai_api_ccu_cpcode_remove/invalid_credentials.yml +37 -0
  20. data/cassettes/akamai_api_ccu_cpcode_remove/invalid_item.yml +36 -0
  21. data/cassettes/akamai_api_ccu_cpcode_remove/multiple_items.yml +38 -0
  22. data/cassettes/akamai_api_ccu_cpcode_remove/single_item.yml +38 -0
  23. data/cassettes/akamai_api_ccu_purge_status/completed_request.yml +35 -0
  24. data/cassettes/akamai_api_ccu_purge_status/enqueued_request.yml +35 -0
  25. data/cassettes/akamai_api_ccu_purge_status/invalid_credentials.yml +35 -0
  26. data/cassettes/akamai_api_ccu_purge_status/not_found_request.yml +37 -0
  27. data/cassettes/akamai_api_ccu_status/invalid_credentials.yml +35 -0
  28. data/cassettes/akamai_api_ccu_status/valid_credentials.yml +34 -0
  29. data/cassettes/akamai_api_eccu_last_request/invalid_credentials.yml +68 -0
  30. data/cassettes/akamai_api_eccu_last_request/valid_credentials.yml +140 -0
  31. data/cassettes/akamai_api_eccu_publish/invalid_credentials.yml +73 -0
  32. data/cassettes/akamai_api_eccu_publish/invalid_domain.yml +60 -0
  33. data/cassettes/akamai_api_eccu_publish/successful.yml +126 -0
  34. data/cassettes/akamai_api_eccu_requests/invalid_credentials.yml +68 -0
  35. data/cassettes/akamai_api_eccu_requests/valid_credentials.yml +325 -0
  36. data/features/ccu_arl_invalidate.feature +83 -0
  37. data/features/ccu_arl_remove.feature +83 -0
  38. data/features/ccu_cpcode_invalidate.feature +83 -0
  39. data/features/ccu_cpcode_remove.feature +83 -0
  40. data/features/ccu_purge_status.feature +83 -0
  41. data/features/ccu_status.feature +31 -0
  42. data/features/eccu_last_request.feature +47 -0
  43. data/features/eccu_publish.feature +98 -0
  44. data/features/eccu_requests.feature +43 -0
  45. data/features/step_definitions/contain_multiple_times_steps.rb +3 -0
  46. data/features/support/env.rb +58 -0
  47. data/lib/akamai_api/ccu/purge/request.rb +76 -0
  48. data/lib/akamai_api/ccu/purge/response.rb +31 -0
  49. data/lib/akamai_api/ccu/purge.rb +5 -0
  50. data/lib/akamai_api/ccu/purge_status/not_found_response.rb +9 -0
  51. data/lib/akamai_api/ccu/purge_status/request.rb +32 -0
  52. data/lib/akamai_api/ccu/purge_status/response.rb +19 -0
  53. data/lib/akamai_api/ccu/purge_status/successful_response.rb +25 -0
  54. data/lib/akamai_api/ccu/purge_status.rb +10 -0
  55. data/lib/akamai_api/ccu/response.rb +18 -0
  56. data/lib/akamai_api/ccu/status/request.rb +23 -0
  57. data/lib/akamai_api/ccu/status/response.rb +11 -0
  58. data/lib/akamai_api/ccu/status.rb +2 -0
  59. data/lib/akamai_api/ccu.rb +14 -50
  60. data/lib/akamai_api/cli/app.rb +2 -2
  61. data/lib/akamai_api/cli/ccu/arl.rb +36 -0
  62. data/lib/akamai_api/cli/ccu/base.rb +18 -0
  63. data/lib/akamai_api/cli/ccu/cp_code.rb +39 -0
  64. data/lib/akamai_api/cli/ccu/purge_renderer.rb +49 -0
  65. data/lib/akamai_api/cli/ccu/status_renderer.rb +69 -0
  66. data/lib/akamai_api/cli/ccu.rb +5 -10
  67. data/lib/akamai_api/cli/eccu/entry_renderer.rb +63 -0
  68. data/lib/akamai_api/cli/eccu.rb +16 -14
  69. data/lib/akamai_api/cli.rb +7 -2
  70. data/lib/akamai_api/eccu_request.rb +19 -1
  71. data/lib/akamai_api/version.rb +1 -1
  72. data/lib/akamai_api.rb +3 -1
  73. data/spec/features/ccu/purge_request_spec.rb +94 -0
  74. data/spec/features/ccu/purge_status_request_spec.rb +31 -0
  75. data/spec/features/ccu/status_request_spec.rb +17 -0
  76. data/spec/fixtures/ccu/successful_purge.json +1 -0
  77. data/spec/lib/akamai_api/ccu/purge/request_spec.rb +124 -0
  78. data/spec/lib/akamai_api/ccu/purge/response_spec.rb +54 -0
  79. data/spec/lib/akamai_api/ccu/purge_status/not_found_response_spec.rb +41 -0
  80. data/spec/lib/akamai_api/ccu/purge_status/request_spec.rb +64 -0
  81. data/spec/lib/akamai_api/ccu/purge_status/successful_response_spec.rb +86 -0
  82. data/spec/lib/akamai_api/ccu/response_spec.rb +15 -0
  83. data/spec/lib/akamai_api/ccu/status/request_spec.rb +22 -0
  84. data/spec/lib/akamai_api/ccu/status/response_spec.rb +29 -0
  85. data/spec/lib/akamai_api/ccu_spec.rb +49 -61
  86. data/spec/lib/akamai_api/cli/ccu/status_renderer_spec.rb +36 -0
  87. data/spec/lib/akamai_api/eccu_request_spec.rb +5 -5
  88. data/spec/spec_helper.rb +21 -1
  89. metadata +163 -26
  90. data/lib/akamai_api/ccu_response.rb +0 -51
  91. data/lib/akamai_api/cli/ccu_arl.rb +0 -40
  92. data/lib/akamai_api/cli/ccu_cp_code.rb +0 -48
  93. data/lib/akamai_api/cli/template.rb +0 -36
  94. data/lib/akamai_api/cp_code.rb +0 -33
  95. data/spec/fixtures/ccu/successful_purge.xml +0 -15
  96. data/spec/fixtures/cp_code/collection.xml +0 -21
  97. data/spec/fixtures/cp_code/single.xml +0 -16
  98. data/spec/lib/akamai_api/cp_code_spec.rb +0 -47
  99. data/wsdls/cpcode.wsdl +0 -2765
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Given I request the current status' do
4
+ context 'and given my login credentials are correct', vcr: { cassette_name: 'akamai_api_ccu_status/valid_credentials' } do
5
+ it 'I receive a successful response object' do
6
+ expect(AkamaiApi::Ccu.status).to be_a AkamaiApi::Ccu::Status::Response
7
+ end
8
+ end
9
+
10
+ context 'and given my login credentials are wrong', vcr: { cassette_name: 'akamai_api_ccu_status/invalid_credentials' } do
11
+ before { AkamaiApi::Ccu.stub auth: { username: 'foo', password: 'bar' } }
12
+
13
+ it 'an error is raised' do
14
+ expect { AkamaiApi::Ccu.status }.to raise_error AkamaiApi::Unauthorized
15
+ end
16
+ end
17
+ end
@@ -0,0 +1 @@
1
+ {"estimatedSeconds": 420, "progressUri": "/ccu/v2/purges/6a727459-cc60-11e3-bcb6-55367cb65536", "purgeId": "6a727459-cc60-11e3-bcb6-55367cb65536", "supportId": "17PY1398420021554891-311977056", "httpStatus": 201, "detail": "Request accepted.", "pingAfterSeconds": 420}
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+
3
+ describe AkamaiApi::Ccu::Purge::Request do
4
+ it "includes httparty" do
5
+ expect(subject.class.included_modules).to include HTTParty
6
+ end
7
+
8
+ it "sets a base_uri" do
9
+ expect(subject.class.base_uri).to eq 'https://api.ccu.akamai.com/ccu/v2/queues/default'
10
+ end
11
+
12
+ it "sets a content type header" do
13
+ expect(subject.class.headers).to eq 'Content-Type' => 'application/json'
14
+ end
15
+
16
+ describe "#action" do
17
+ it "is 'remove' by default" do
18
+ expect(subject.action).to eq 'remove'
19
+ end
20
+
21
+ it "can be changed" do
22
+ expect { subject.action = 'invalidate' }.to change(subject, :action).to 'invalidate'
23
+ end
24
+
25
+ it "raises an error if an invalid value is set" do
26
+ expect { subject.action = 'foobar' }.to raise_error AkamaiApi::Ccu::UnrecognizedOption
27
+ end
28
+ end
29
+
30
+ describe "#type" do
31
+ it "is 'arl' by default" do
32
+ expect(subject.type).to eq 'arl'
33
+ end
34
+
35
+ it "can be changed" do
36
+ expect { subject.type = 'cpcode' }.to change(subject, :type).to eq 'cpcode'
37
+ end
38
+
39
+ it "raises an error if an invalid value is set" do
40
+ expect { subject.type = 'foobar' }.to raise_error AkamaiApi::Ccu::UnrecognizedOption
41
+ end
42
+ end
43
+
44
+ describe "#domain" do
45
+ it "is 'production' by default" do
46
+ expect(subject.domain).to eq 'production'
47
+ end
48
+
49
+ it "can be changed" do
50
+ expect { subject.domain = 'staging' }.to change(subject, :domain).to eq 'staging'
51
+ end
52
+
53
+ it "raises an error if an invalid value is set" do
54
+ expect { subject.domain = 'foobar' }.to raise_error AkamaiApi::Ccu::UnrecognizedOption
55
+ end
56
+ end
57
+
58
+ describe "#execute" do
59
+ let(:fake_response) { double code: 201, parsed_response: {} }
60
+ let(:sample_arl) { 'http://www.foo.bar/t.txt' }
61
+
62
+ it "executes a post on the base url" do
63
+ expect(subject.class).to receive :post do |path, args|
64
+ expect(path).to eq '/'
65
+ fake_response
66
+ end
67
+ subject.execute sample_arl
68
+ end
69
+
70
+ it "sets the auth in the post" do
71
+ subject.stub auth: 'foo'
72
+ expect(subject.class).to receive :post do |path, args|
73
+ expect(args[:basic_auth]).to eq 'foo'
74
+ fake_response
75
+ end
76
+ subject.execute sample_arl
77
+ end
78
+
79
+ it "accepts a single element" do
80
+ expect(subject).to receive(:request_body).with([sample_arl])
81
+ subject.class.stub post: fake_response
82
+ subject.execute sample_arl
83
+ end
84
+
85
+ it "accepts a collection with a single element" do
86
+ expect(subject).to receive(:request_body).with([sample_arl])
87
+ subject.class.stub post: fake_response
88
+ subject.execute sample_arl
89
+ end
90
+
91
+ it "accepts a collection" do
92
+ expect(subject).to receive(:request_body).with(['a', 'b'])
93
+ subject.class.stub post: fake_response
94
+ subject.execute ['a', 'b']
95
+ end
96
+
97
+ it "works with splatting" do
98
+ expect(subject).to receive(:request_body).with(['a', 'b'])
99
+ subject.class.stub post: fake_response
100
+ subject.execute 'a', 'b'
101
+ end
102
+
103
+ it "sets the request body" do
104
+ expect(subject).to receive(:request_body).with([sample_arl]).and_return 'foo'
105
+ expect(subject.class).to receive :post do |path, args|
106
+ expect(args[:body]).to eq 'foo'
107
+ fake_response
108
+ end
109
+ subject.execute sample_arl
110
+ end
111
+
112
+ it "raises an exception when the response code is 401" do
113
+ fake_response = double code: 401
114
+ subject.class.stub post: fake_response
115
+ expect { subject.execute sample_arl }.to raise_error AkamaiApi::Unauthorized
116
+ end
117
+
118
+ it "returns a response built with the resulted json" do
119
+ fake_response = double code: 201, parsed_response: { a: 'b' }
120
+ subject.class.stub post: fake_response
121
+ expect(subject.execute(sample_arl).raw).to eq a: 'b'
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe AkamaiApi::Ccu::Purge::Response do
4
+ let(:raw) do
5
+ {
6
+ 'describedBy' => 'foo',
7
+ 'title' => 'bar',
8
+ 'pingAfterSeconds' => 100,
9
+ 'purgeId' => '120',
10
+ 'supportId' => '130',
11
+ 'detail' => 'baz',
12
+ 'httpStatus' => 201,
13
+ 'estimatedSeconds' => 90,
14
+ 'progressUri' => 'http://asd.com'
15
+ }
16
+ end
17
+ subject { AkamaiApi::Ccu::Purge::Response.new raw }
18
+
19
+ it '#described_by returns the describedBy attribute' do
20
+ expect(subject.described_by).to eq 'foo'
21
+ end
22
+
23
+ it '#title returns the title attribute' do
24
+ expect(subject.title).to eq 'bar'
25
+ end
26
+
27
+ it '#time_to_wait returns the pingAfterSeconds attribute' do
28
+ expect(subject.time_to_wait).to eq 100
29
+ end
30
+
31
+ it '#purge_id returns the purgeId attribute' do
32
+ expect(subject.purge_id).to eq '120'
33
+ end
34
+
35
+ it '#support_id returns the supportId attribute' do
36
+ expect(subject.support_id).to eq '130'
37
+ end
38
+
39
+ it '#message returns the detail attribute' do
40
+ expect(subject.message).to eq 'baz'
41
+ end
42
+
43
+ it '#code returns the httpStatus attribute' do
44
+ expect(subject.code).to eq 201
45
+ end
46
+
47
+ it '#estimated_time returns the estimatedSeconds attribute' do
48
+ expect(subject.estimated_time).to eq 90
49
+ end
50
+
51
+ it '#uri returns the progressUri attribute' do
52
+ expect(subject.uri).to eq 'http://asd.com'
53
+ end
54
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe AkamaiApi::Ccu::PurgeStatus::NotFoundResponse do
4
+ let(:raw) do
5
+ {
6
+ 'progressUri' => '/ccu/v2/purges/12345678-1234-5678-1234-123456789012',
7
+ 'purgeId' => '12345678-1234-5678-1234-123456789012',
8
+ 'supportId' => '12345678901234567890-123456789',
9
+ 'httpStatus' => 200,
10
+ 'purgeStatus' => 'Unknown',
11
+ 'pingAfterSeconds' => 60,
12
+ 'detail' => 'foobarbaz'
13
+ }
14
+ end
15
+ subject { AkamaiApi::Ccu::PurgeStatus::NotFoundResponse.new raw }
16
+
17
+ it '#progress_uri returns progressUri attribute' do
18
+ expect(subject.progress_uri).to eq '/ccu/v2/purges/12345678-1234-5678-1234-123456789012'
19
+ end
20
+
21
+ it '#purge_id returns purgeId attribute' do
22
+ expect(subject.purge_id).to eq '12345678-1234-5678-1234-123456789012'
23
+ end
24
+
25
+ it '#support_id returns supportId attribute' do
26
+ expect(subject.support_id).to eq '12345678901234567890-123456789'
27
+ end
28
+
29
+ it '#code returns httpStatus attribute' do
30
+ expect(subject.code).to eq 200
31
+ end
32
+
33
+ it '#status returns purgeStatus attribute' do
34
+ expect(subject.status).to eq 'Unknown'
35
+ end
36
+
37
+ it '#message returns detail attribute' do
38
+ raw['detail'] = 'asd'
39
+ expect(subject.message).to eq 'asd'
40
+ end
41
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe AkamaiApi::Ccu::PurgeStatus::Request do
4
+ it "includes httparty" do
5
+ expect(subject.class.included_modules).to include HTTParty
6
+ end
7
+
8
+ it "sets a base_uri" do
9
+ expect(subject.class.base_uri).to eq 'https://api.ccu.akamai.com'
10
+ end
11
+
12
+ describe "#execute" do
13
+ let(:fake_response) { double code: 200, parsed_response: {} }
14
+
15
+ it "executes a GET request on the given progress_uri" do
16
+ expect(AkamaiApi::Ccu::PurgeStatus::Request).to receive :get do |uri, args|
17
+ expect(uri).to eq '/ccu/v2/purges/foo'
18
+ fake_response
19
+ end
20
+ subject.execute '/ccu/v2/purges/foo'
21
+ end
22
+
23
+ it "sets the auth in the request" do
24
+ AkamaiApi::Ccu.stub auth: 'foo'
25
+ expect(AkamaiApi::Ccu::PurgeStatus::Request).to receive :get do |uri, args|
26
+ expect(args).to eq basic_auth: 'foo'
27
+ fake_response
28
+ end
29
+ subject.execute '/ccu/v2/purges/foo'
30
+ end
31
+
32
+ it "raises an exception when the response code is 401" do
33
+ fake_response.stub code: 401
34
+ expect(AkamaiApi::Ccu::PurgeStatus::Request).to receive(:get).and_return fake_response
35
+ expect { subject.execute '/ccu/v2/purges/foo' }.to raise_error AkamaiApi::Unauthorized
36
+ end
37
+
38
+ it "returns a response built with the received json" do
39
+ fake_response.stub parsed_response: {a: 'b'}
40
+ expect(AkamaiApi::Ccu::PurgeStatus::Request).to receive(:get).and_return fake_response
41
+ expect(subject.execute '/ccu/v2/purges/foo' ).to be_a AkamaiApi::Ccu::PurgeStatus::Response
42
+ end
43
+
44
+ context "when the given progressUri is the purgeId" do
45
+ it "the progressUri prefix is appended" do
46
+ expect(AkamaiApi::Ccu::PurgeStatus::Request).to receive :get do |uri, args|
47
+ expect(uri).to eq '/ccu/v2/purges/foo'
48
+ fake_response
49
+ end
50
+ subject.execute 'foo'
51
+ end
52
+ end
53
+
54
+ context "when the given progressUri isn't prefixed by a slash" do
55
+ it "a slash is prefixed" do
56
+ expect(AkamaiApi::Ccu::PurgeStatus::Request).to receive :get do |uri, args|
57
+ expect(uri).to eq '/ccu/v2/purges/foo'
58
+ fake_response
59
+ end
60
+ subject.execute 'ccu/v2/purges/foo'
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ describe AkamaiApi::Ccu::PurgeStatus::SuccessfulResponse do
4
+ let(:raw) do
5
+ {
6
+ 'originalEstimatedSeconds' => 480,
7
+ 'progressUri' => '/ccu/v2/purges/12345678-1234-5678-1234-123456789012',
8
+ 'originalQueueLength' => 6,
9
+ 'purgeId' => '12345678-1234-5678-1234-123456789012',
10
+ 'supportId' => '12345678901234567890-123456789',
11
+ 'httpStatus' => 200,
12
+ 'completionTime' => '2014-02-19T22:16:20Z',
13
+ 'submittedBy' => 'test1',
14
+ 'purgeStatus' => 'In-Progress',
15
+ 'submissionTime' => '2014-02-19T21:16:20Z',
16
+ 'pingAfterSeconds' => 60
17
+ }
18
+ end
19
+ subject { AkamaiApi::Ccu::PurgeStatus::SuccessfulResponse.new raw }
20
+
21
+ it '#estimated_time returns estimatedSeconds attribute' do
22
+ expect(subject.estimated_time).to eq 480
23
+ end
24
+
25
+ it '#progress_uri returns progressUri attribute' do
26
+ expect(subject.progress_uri).to eq '/ccu/v2/purges/12345678-1234-5678-1234-123456789012'
27
+ end
28
+
29
+ it '#queue_length returns originalQueueLength attribute' do
30
+ expect(subject.queue_length).to eq 6
31
+ end
32
+
33
+ it '#purge_id returns purgeId attribute' do
34
+ expect(subject.purge_id).to eq '12345678-1234-5678-1234-123456789012'
35
+ end
36
+
37
+ it '#support_id returns supportId attribute' do
38
+ expect(subject.support_id).to eq '12345678901234567890-123456789'
39
+ end
40
+
41
+ it '#code returns httpStatus attribute' do
42
+ expect(subject.code).to eq 200
43
+ end
44
+
45
+ describe '#completed_at' do
46
+ it 'returns a Time object' do
47
+ expect(subject.completed_at).to be_a Time
48
+ end
49
+
50
+ it 'returns completionTime attribute' do
51
+ expect(subject.completed_at.iso8601).to eq '2014-02-19T22:16:20Z'
52
+ end
53
+
54
+ it 'can return nil' do
55
+ raw['completionTime'] = nil
56
+ expect(subject.completed_at).to be_nil
57
+ end
58
+ end
59
+
60
+ it '#submitted_by returns submittedBy attribute' do
61
+ expect(subject.submitted_by).to eq 'test1'
62
+ end
63
+
64
+ it '#status returns purgeStatus attribute' do
65
+ expect(subject.status).to eq 'In-Progress'
66
+ end
67
+
68
+ describe '#submitted_at' do
69
+ it 'returns a Time object' do
70
+ expect(subject.submitted_at).to be_a Time
71
+ end
72
+
73
+ it 'can return nil' do
74
+ raw['submissionTime'] = nil
75
+ expect(subject.submitted_at).to be_nil
76
+ end
77
+
78
+ it 'returns submissionTime attribute' do
79
+ expect(subject.submitted_at.iso8601).to eq '2014-02-19T21:16:20Z'
80
+ end
81
+ end
82
+
83
+ it '#time_to_wait returns pingAfterSeconds attribute' do
84
+ expect(subject.time_to_wait).to eq 60
85
+ end
86
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe AkamaiApi::Ccu::Response do
4
+ subject { AkamaiApi::Ccu::Response.new 'supportId' => 'foo', 'httpStatus' => 201 }
5
+
6
+ it '#support_id returns the supportId attribute' do
7
+ expect(subject.support_id).to eq 'foo'
8
+ end
9
+
10
+ %w(code http_status).each do |reader|
11
+ it "##{reader} returns the httpStatus attribute" do
12
+ expect(subject.send reader).to eq 201
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe AkamaiApi::Ccu::Status::Request do
4
+ it 'executes a get upon base url passing the basic auth' do
5
+ fake_response = double code: 200, parsed_response: {}
6
+ AkamaiApi::Ccu.stub auth: 'foo'
7
+ expect(AkamaiApi::Ccu::Status::Request).to receive(:get).with('/', basic_auth: 'foo').and_return fake_response
8
+ subject.execute
9
+ end
10
+
11
+ it 'raises an unauthorized error if code is 401' do
12
+ fake_response = double code: 401, parsed_response: {}
13
+ expect(AkamaiApi::Ccu::Status::Request).to receive(:get).and_return fake_response
14
+ expect { subject.execute }.to raise_error AkamaiApi::Unauthorized
15
+ end
16
+
17
+ it 'returns a StatusResponse' do
18
+ fake_response = double code: 200, parsed_response: {}
19
+ expect(AkamaiApi::Ccu::Status::Request).to receive(:get).and_return fake_response
20
+ expect(subject.execute).to be_a AkamaiApi::Ccu::Status::Response
21
+ end
22
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe AkamaiApi::Ccu::Status::Response do
4
+ let(:raw) do
5
+ {
6
+ 'httpStatus' => 201,
7
+ 'queueLength' => 1,
8
+ 'detail' => 'asd',
9
+ 'supportId' => '21'
10
+ }
11
+ end
12
+ subject { AkamaiApi::Ccu::Status::Response.new raw }
13
+
14
+ it '#code returns the httpStatus property' do
15
+ expect(subject.code).to eq 201
16
+ end
17
+
18
+ it '#queue_length returns the queueLength property' do
19
+ expect(subject.queue_length).to eq 1
20
+ end
21
+
22
+ it '#message returns the detail property' do
23
+ expect(subject.message).to eq 'asd'
24
+ end
25
+
26
+ it '#support_id returns the supportId property' do
27
+ expect(subject.support_id).to eq '21'
28
+ end
29
+ end
@@ -1,87 +1,75 @@
1
1
  require 'spec_helper'
2
2
 
3
- module AkamaiApi
4
- describe Ccu do
5
- include Savon::SpecHelper
3
+ describe AkamaiApi::Ccu do
4
+ subject { AkamaiApi::Ccu }
6
5
 
7
- before(:all) { savon.mock! }
8
- after(:all) { savon.unmock! }
9
-
10
- let(:fixture) { File.read 'spec/fixtures/ccu/successful_purge.xml' }
11
-
12
- def soap_body method, *uris
13
- method_parts = method.split('_')
14
- options = ["action=#{method_parts.first}", "type=#{method_parts.last}"]
15
- SoapBody.new do
16
- string :name, AkamaiApi.config[:auth].first
17
- string :pwd, AkamaiApi.config[:auth].last
18
- string :network, ''
19
- array :opt, options
20
- array :uri, uris
21
- end
22
- end
23
-
24
- shared_examples 'purge helper' do
25
- before do
26
- body = soap_body(method, '12345').to_s
27
- savon.expects(:purge_request).with(:message => body).returns(fixture)
6
+ %w(invalidate remove).each do |action|
7
+ describe "##{action}" do
8
+ it 'raises error if less than 2 arguments are given' do
9
+ expect { subject.send action, 'foo' }.to raise_error ArgumentError
28
10
  end
29
11
 
30
- it 'responds with a CcuResponse object' do
31
- Ccu.send(method, '12345').should be_a CcuResponse
12
+ it 'delegates to #purge with the given type' do
13
+ expect(subject).to receive(:purge).with(action.to_sym, :cpcode, 'foo', domain: 'asd').and_return 'bar'
14
+ expect(subject.send action, :cpcode, 'foo', domain: 'asd').to eq 'bar'
32
15
  end
16
+ end
33
17
 
34
- context 'when data are correct' do
35
- it 'returns the expected response code' do
36
- Ccu.send(method, '12345').code.should == 100
37
- end
38
-
39
- it 'returns a successful message' do
40
- Ccu.send(method, '12345').message.should == 'Success.'
41
- end
18
+ %w(arl cpcode).each do |type|
19
+ describe "##{action}_#{type}" do
20
+ let(:method) { "#{action}_#{type}" }
42
21
 
43
- it 'returns a unique session id' do
44
- Ccu.send(method, '12345').session_id.should == '97870328-018c-11e2-aabc-489beabc489b'
22
+ it 'raises error if less than 1 argument is given' do
23
+ expect { subject.send method }.to raise_error ArgumentError
45
24
  end
46
25
 
47
- it 'returns the estimated time in seconds' do
48
- Ccu.send(method, '12345').estimated_time.should == 420
26
+ it 'delegates to #purge with the given items' do
27
+ expect(subject).to receive(:purge).with(action.to_sym, type.to_sym, 'foo', domain: 'asd').and_return 'bar'
28
+ expect(subject.send method, 'foo', domain: 'asd').to eq 'bar'
49
29
  end
50
30
  end
51
31
  end
32
+ end
52
33
 
53
- context '#invalidate_arl' do
54
- let(:method) { 'invalidate_arl' }
55
- it_should_behave_like 'purge helper'
56
- end
57
-
58
- context '#invalidate_cpcode' do
59
- let(:method) { 'invalidate_cpcode' }
60
- it_should_behave_like 'purge helper'
61
- end
62
-
63
- context '#remove_arl' do
64
- let(:method) { 'remove_arl' }
65
- it_should_behave_like 'purge helper'
66
- end
67
-
68
- context '#remove_cpcode' do
69
- let(:method) { 'remove_cpcode' }
70
- it_should_behave_like 'purge helper'
34
+ describe '#purge' do
35
+ it 'delegates to Purge::Request' do
36
+ fake_request = double
37
+ expect(fake_request).to receive(:execute).with('baz').and_return 'quiz'
38
+ expect(AkamaiApi::Ccu::Purge::Request).to receive(:new).with('foo', 'bar', domain: 'asd').
39
+ and_return fake_request
40
+ expect(subject.purge 'foo', 'bar', 'baz', domain: 'asd').to eq 'quiz'
71
41
  end
72
42
 
73
- describe '#purge raises an error when' do
43
+ describe 'raises an error when' do
74
44
  it 'action is not allowed' do
75
- expect { Ccu.purge :sss, :cpcode, '12345' }.to raise_error Ccu::UnrecognizedOption
45
+ expect { subject.purge :sss, :cpcode, '12345' }.to raise_error AkamaiApi::Ccu::UnrecognizedOption
76
46
  end
77
47
 
78
48
  it 'type is not allowed' do
79
- expect { Ccu.purge :remove, :foo, '12345' }.to raise_error Ccu::UnrecognizedOption
49
+ expect { subject.purge :remove, :foo, '12345' }.to raise_error AkamaiApi::Ccu::UnrecognizedOption
80
50
  end
81
51
 
82
52
  it 'domain is specified and not allowed' do
83
- expect { Ccu.purge :remove, :arl, 'foo', :domain => :foo }.to raise_error
53
+ expect { subject.purge :remove, :arl, 'foo', :domain => :foo }.to raise_error
54
+ end
55
+ end
56
+ end
57
+
58
+ describe '#status' do
59
+ context "when no argument is given" do
60
+ it "delegates to Status request instance" do
61
+ expect(AkamaiApi::Ccu::Status::Request).to receive(:new).and_return double execute: 'foo'
62
+ expect(subject.status).to eq 'foo'
63
+ end
64
+ end
65
+
66
+ context "when a progress uri is passed as argument" do
67
+ it "delegates to PurgeStatus request instance" do
68
+ fake_instance = double
69
+ expect(AkamaiApi::Ccu::PurgeStatus::Request).to receive(:new).and_return fake_instance
70
+ expect(fake_instance).to receive(:execute).with('foo').and_return 'asd'
71
+ expect(subject.status 'foo').to eq 'asd'
84
72
  end
85
73
  end
86
74
  end
87
- end
75
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ module AkamaiApi
4
+ describe Cli::Ccu::StatusRenderer do
5
+ subject { Cli::Ccu::StatusRenderer.new Ccu::Status::Response.new({}) }
6
+
7
+ describe '#render' do
8
+ it 'returns a string' do
9
+ expect(subject.render).to be_a String
10
+ end
11
+
12
+ it 'delegates to #render_status if response is a Status::Response' do
13
+ expect(subject).to receive(:render_status)
14
+ subject.render
15
+ end
16
+
17
+ it 'delegates to #render_purge_status if response is a PurgeStatus::Response' do
18
+ subject = Cli::Ccu::StatusRenderer.new Ccu::PurgeStatus::SuccessfulResponse.new({})
19
+ expect(subject).to receive(:render_purge_status)
20
+ subject.render
21
+ end
22
+ end
23
+
24
+ it '#render_purge_status delegates to #render_successful_purge_status for success response' do
25
+ subject = Cli::Ccu::StatusRenderer.new Ccu::PurgeStatus::SuccessfulResponse.new({})
26
+ expect(subject).to receive :render_successful_purge_status
27
+ subject.render_purge_status
28
+ end
29
+
30
+ it '#render_purge_status delegates to #render_not_found_purge_status for not foundresponse' do
31
+ subject = Cli::Ccu::StatusRenderer.new Ccu::PurgeStatus::NotFoundResponse.new({})
32
+ expect(subject).to receive :render_not_found_purge_status
33
+ subject.render_purge_status
34
+ end
35
+ end
36
+ end
@@ -52,7 +52,7 @@ module AkamaiApi
52
52
 
53
53
  describe '::last' do
54
54
  it 'find the most recent entry' do
55
- EccuRequest.stub! :all_ids => %w(a b)
55
+ EccuRequest.stub :all_ids => %w(a b)
56
56
  EccuRequest.should_receive(:find).with('b', anything()).and_return :a
57
57
  EccuRequest.last.should == :a
58
58
  end
@@ -60,7 +60,7 @@ module AkamaiApi
60
60
 
61
61
  describe '::first' do
62
62
  it 'find the oldest entry' do
63
- EccuRequest.stub! :all_ids => %w(a b)
63
+ EccuRequest.stub :all_ids => %w(a b)
64
64
  EccuRequest.should_receive(:find).with('a', anything()).and_return :a
65
65
  EccuRequest.first.should == :a
66
66
  end
@@ -68,13 +68,13 @@ module AkamaiApi
68
68
 
69
69
  describe '::all' do
70
70
  it 'returns the detail for each enlisted id' do
71
- EccuRequest.stub! :all_ids => %w(a b)
71
+ EccuRequest.stub :all_ids => %w(a b)
72
72
  EccuRequest.should_receive(:find).with('a', anything()).and_return(:a)
73
73
  EccuRequest.should_receive(:find).with('b', anything()).and_return(:b)
74
74
  EccuRequest.all.should =~ [:a, :b]
75
75
  end
76
76
  it 'returns the detail for each enlisted id even if only one id is returned' do
77
- EccuRequest.stub! :all_ids => "a"
77
+ EccuRequest.stub :all_ids => "a"
78
78
  EccuRequest.should_receive(:find).with('a', anything()).and_return(:a)
79
79
  EccuRequest.all.should =~ [:a]
80
80
  end
@@ -256,4 +256,4 @@ module AkamaiApi
256
256
  end
257
257
  end
258
258
  end
259
- end
259
+ end