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.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +13 -0
  3. data/.yardopts +4 -0
  4. data/Gemfile +16 -0
  5. data/README.md +53 -52
  6. data/Thorfile +7 -1
  7. data/akamai_api.gemspec +1 -7
  8. data/bin/akamai_api +2 -1
  9. data/cassettes/akamai_api_ccu_arl_invalidate/invalid_credentials.yml +1 -1
  10. data/cassettes/akamai_api_ccu_arl_invalidate/invalid_item.yml +1 -1
  11. data/cassettes/akamai_api_ccu_arl_invalidate/multiple_items.yml +1 -1
  12. data/cassettes/akamai_api_ccu_arl_invalidate/single_item.yml +1 -1
  13. data/cassettes/akamai_api_ccu_arl_remove/invalid_credentials.yml +1 -1
  14. data/cassettes/akamai_api_ccu_arl_remove/invalid_item.yml +2 -2
  15. data/cassettes/akamai_api_ccu_arl_remove/multiple_items.yml +1 -1
  16. data/cassettes/akamai_api_ccu_arl_remove/single_item.yml +1 -1
  17. data/cassettes/akamai_api_ccu_cpcode_invalidate/invalid_credentials.yml +1 -1
  18. data/cassettes/akamai_api_ccu_cpcode_invalidate/invalid_item.yml +1 -1
  19. data/cassettes/akamai_api_ccu_cpcode_invalidate/multiple_items.yml +1 -1
  20. data/cassettes/akamai_api_ccu_cpcode_invalidate/single_item.yml +1 -1
  21. data/cassettes/akamai_api_ccu_cpcode_remove/invalid_credentials.yml +1 -1
  22. data/cassettes/akamai_api_ccu_cpcode_remove/invalid_item.yml +1 -1
  23. data/cassettes/akamai_api_ccu_cpcode_remove/multiple_items.yml +1 -1
  24. data/cassettes/akamai_api_ccu_cpcode_remove/single_item.yml +1 -1
  25. data/cassettes/akamai_api_eccu_all_ids/invalid_credentials.yml +68 -0
  26. data/cassettes/akamai_api_eccu_all_ids/successful.yml +72 -0
  27. data/cassettes/akamai_api_eccu_destroy/invalid_credentials.yml +69 -0
  28. data/cassettes/akamai_api_eccu_destroy/not_found_request.yml +55 -0
  29. data/cassettes/akamai_api_eccu_destroy/successful.yml +57 -0
  30. data/cassettes/akamai_api_eccu_find/invalid_credentials.yml +69 -0
  31. data/cassettes/akamai_api_eccu_find/not_found_request.yml +55 -0
  32. data/cassettes/akamai_api_eccu_find/successful.yml +70 -0
  33. data/cassettes/akamai_api_eccu_find/successful_without_content.yml +70 -0
  34. data/cassettes/akamai_api_eccu_publish/invalid_credentials.yml +5 -5
  35. data/cassettes/akamai_api_eccu_publish/invalid_domain.yml +7 -7
  36. data/cassettes/akamai_api_eccu_publish/successful.yml +8 -8
  37. data/cassettes/akamai_api_eccu_update_email/invalid_credentials.yml +69 -0
  38. data/cassettes/akamai_api_eccu_update_email/not_found_request.yml +55 -0
  39. data/cassettes/akamai_api_eccu_update_email/successful.yml +57 -0
  40. data/cassettes/akamai_api_eccu_update_notes/invalid_credentials.yml +70 -0
  41. data/cassettes/akamai_api_eccu_update_notes/not_found_request.yml +56 -0
  42. data/cassettes/akamai_api_eccu_update_notes/successful.yml +58 -0
  43. data/features/ccu_arl_invalidate.feature +5 -9
  44. data/features/ccu_arl_remove.feature +5 -9
  45. data/features/ccu_cpcode_invalidate.feature +2 -6
  46. data/features/ccu_cpcode_remove.feature +2 -6
  47. data/features/ccu_purge_status.feature +2 -2
  48. data/features/eccu_publish.feature +6 -42
  49. data/features/step_definitions/file_named_with_content_steps.rb +3 -0
  50. data/features/support/env.rb +12 -3
  51. data/lib/akamai_api/ccu/base_response.rb +27 -0
  52. data/lib/akamai_api/ccu/error.rb +38 -0
  53. data/lib/akamai_api/ccu/purge/request.rb +58 -11
  54. data/lib/akamai_api/ccu/purge/response.rb +15 -9
  55. data/lib/akamai_api/ccu/purge.rb +14 -3
  56. data/lib/akamai_api/ccu/purge_status/not_found.rb +18 -0
  57. data/lib/akamai_api/ccu/purge_status/request.rb +41 -7
  58. data/lib/akamai_api/ccu/purge_status/response.rb +49 -3
  59. data/lib/akamai_api/ccu/purge_status.rb +17 -9
  60. data/lib/akamai_api/ccu/status/request.rb +20 -7
  61. data/lib/akamai_api/ccu/status/response.rb +8 -2
  62. data/lib/akamai_api/ccu/status.rb +13 -2
  63. data/lib/akamai_api/ccu/unrecognized_option.rb +6 -0
  64. data/lib/akamai_api/ccu.rb +132 -23
  65. data/lib/akamai_api/cli/app.rb +15 -13
  66. data/lib/akamai_api/cli/ccu/arl.rb +10 -4
  67. data/lib/akamai_api/cli/ccu/base.rb +11 -3
  68. data/lib/akamai_api/cli/ccu/cp_code.rb +10 -4
  69. data/lib/akamai_api/cli/ccu/purge_renderer.rb +1 -1
  70. data/lib/akamai_api/cli/ccu/status_renderer.rb +46 -26
  71. data/lib/akamai_api/cli/ccu.rb +2 -4
  72. data/lib/akamai_api/cli/command.rb +60 -25
  73. data/lib/akamai_api/cli/eccu/base.rb +59 -0
  74. data/lib/akamai_api/cli/eccu/entry_renderer.rb +5 -3
  75. data/lib/akamai_api/cli/eccu.rb +2 -56
  76. data/lib/akamai_api/cli.rb +2 -6
  77. data/lib/akamai_api/eccu/base_edit_request.rb +51 -0
  78. data/lib/akamai_api/eccu/base_request.rb +32 -0
  79. data/lib/akamai_api/eccu/destroy_request.rb +30 -0
  80. data/lib/akamai_api/eccu/find_request.rb +45 -0
  81. data/lib/akamai_api/eccu/find_response.rb +110 -0
  82. data/lib/akamai_api/eccu/invalid_domain.rb +7 -0
  83. data/lib/akamai_api/eccu/list_request.rb +21 -0
  84. data/lib/akamai_api/eccu/not_found.rb +6 -0
  85. data/lib/akamai_api/eccu/publish_request.rb +75 -0
  86. data/lib/akamai_api/eccu/soap_body.rb +99 -0
  87. data/lib/akamai_api/eccu/update_attribute_request.rb +62 -0
  88. data/lib/akamai_api/eccu.rb +19 -0
  89. data/lib/akamai_api/eccu_request.rb +39 -117
  90. data/lib/akamai_api/error.rb +5 -0
  91. data/lib/akamai_api/unauthorized.rb +6 -0
  92. data/lib/akamai_api/version.rb +1 -1
  93. data/lib/akamai_api.rb +18 -4
  94. data/spec/features/ccu/purge_request_spec.rb +10 -12
  95. data/spec/features/ccu/purge_status_request_spec.rb +5 -5
  96. data/spec/features/ccu/status_request_spec.rb +3 -3
  97. data/spec/features/eccu/destroy_spec.rb +28 -0
  98. data/spec/features/eccu/find_request_spec.rb +34 -0
  99. data/spec/features/eccu/list_request_spec.rb +22 -0
  100. data/spec/features/eccu/publish_request_spec.rb +29 -0
  101. data/spec/features/eccu/update_email_spec.rb +28 -0
  102. data/spec/features/eccu/update_notes_spec.rb +28 -0
  103. data/spec/lib/akamai_api/ccu/{response_spec.rb → base_response_spec.rb} +2 -2
  104. data/spec/lib/akamai_api/ccu/purge/request_spec.rb +26 -20
  105. data/spec/lib/akamai_api/ccu/purge/response_spec.rb +16 -26
  106. data/spec/lib/akamai_api/ccu/purge_status/not_found_response_spec.rb +34 -34
  107. data/spec/lib/akamai_api/ccu/purge_status/request_spec.rb +24 -12
  108. data/spec/lib/akamai_api/ccu/purge_status/{successful_response_spec.rb → response_spec.rb} +8 -8
  109. data/spec/lib/akamai_api/ccu/status/request_spec.rb +6 -6
  110. data/spec/lib/akamai_api/ccu/status/response_spec.rb +2 -2
  111. data/spec/lib/akamai_api/ccu_spec.rb +7 -7
  112. data/spec/lib/akamai_api/cli/ccu/status_renderer_spec.rb +5 -17
  113. data/spec/lib/akamai_api/eccu/destroy_request_spec.rb +75 -0
  114. data/spec/lib/akamai_api/eccu/find_request_spec.rb +74 -0
  115. data/spec/lib/akamai_api/eccu/find_response_spec.rb +159 -0
  116. data/spec/lib/akamai_api/eccu/list_request_spec.rb +43 -0
  117. data/spec/lib/akamai_api/eccu/publish_request_spec.rb +133 -0
  118. data/spec/lib/akamai_api/eccu/soap_body_spec.rb +46 -0
  119. data/spec/lib/akamai_api/eccu/update_attribute_request_spec.rb +86 -0
  120. data/spec/lib/akamai_api/eccu_request_spec.rb +149 -158
  121. data/spec/spec_helper.rb +11 -3
  122. metadata +90 -104
  123. data/lib/akamai_api/ccu/purge_status/not_found_response.rb +0 -9
  124. data/lib/akamai_api/ccu/purge_status/successful_response.rb +0 -25
  125. data/lib/akamai_api/ccu/response.rb +0 -18
  126. data/lib/akamai_api/soap_body.rb +0 -40
  127. data/spec/lib/akamai_api/soap_body_spec.rb +0 -48
  128. data/spec/support/savon_backports.rb +0 -10
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe AkamaiApi::Ccu::Purge::Request do
3
+ describe AkamaiApi::CCU::Purge::Request do
4
4
  it "includes httparty" do
5
5
  expect(subject.class.included_modules).to include HTTParty
6
6
  end
@@ -14,8 +14,8 @@ describe AkamaiApi::Ccu::Purge::Request do
14
14
  end
15
15
 
16
16
  describe "#action" do
17
- it "is 'remove' by default" do
18
- expect(subject.action).to eq 'remove'
17
+ it "is :remove by default" do
18
+ expect(subject.action).to eq :remove
19
19
  end
20
20
 
21
21
  it "can be changed" do
@@ -23,13 +23,13 @@ describe AkamaiApi::Ccu::Purge::Request do
23
23
  end
24
24
 
25
25
  it "raises an error if an invalid value is set" do
26
- expect { subject.action = 'foobar' }.to raise_error AkamaiApi::Ccu::UnrecognizedOption
26
+ expect { subject.action = 'foobar' }.to raise_error AkamaiApi::CCU::UnrecognizedOption
27
27
  end
28
28
  end
29
29
 
30
30
  describe "#type" do
31
- it "is 'arl' by default" do
32
- expect(subject.type).to eq 'arl'
31
+ it "is :arl by default" do
32
+ expect(subject.type).to eq :arl
33
33
  end
34
34
 
35
35
  it "can be changed" do
@@ -37,13 +37,13 @@ describe AkamaiApi::Ccu::Purge::Request do
37
37
  end
38
38
 
39
39
  it "raises an error if an invalid value is set" do
40
- expect { subject.type = 'foobar' }.to raise_error AkamaiApi::Ccu::UnrecognizedOption
40
+ expect { subject.type = 'foobar' }.to raise_error AkamaiApi::CCU::UnrecognizedOption
41
41
  end
42
42
  end
43
43
 
44
44
  describe "#domain" do
45
- it "is 'production' by default" do
46
- expect(subject.domain).to eq 'production'
45
+ it "is :production by default" do
46
+ expect(subject.domain).to eq :production
47
47
  end
48
48
 
49
49
  it "can be changed" do
@@ -51,12 +51,12 @@ describe AkamaiApi::Ccu::Purge::Request do
51
51
  end
52
52
 
53
53
  it "raises an error if an invalid value is set" do
54
- expect { subject.domain = 'foobar' }.to raise_error AkamaiApi::Ccu::UnrecognizedOption
54
+ expect { subject.domain = 'foobar' }.to raise_error AkamaiApi::CCU::UnrecognizedOption
55
55
  end
56
56
  end
57
57
 
58
58
  describe "#execute" do
59
- let(:fake_response) { double code: 201, parsed_response: {} }
59
+ let(:fake_response) { double code: 201, parsed_response: { 'httpStatus' => 201, 'submissionTime' => 1 } }
60
60
  let(:sample_arl) { 'http://www.foo.bar/t.txt' }
61
61
 
62
62
  it "executes a post on the base url" do
@@ -68,7 +68,7 @@ describe AkamaiApi::Ccu::Purge::Request do
68
68
  end
69
69
 
70
70
  it "sets the auth in the post" do
71
- subject.stub auth: 'foo'
71
+ allow(AkamaiApi).to receive(:auth) { 'foo' }
72
72
  expect(subject.class).to receive :post do |path, args|
73
73
  expect(args[:basic_auth]).to eq 'foo'
74
74
  fake_response
@@ -78,25 +78,25 @@ describe AkamaiApi::Ccu::Purge::Request do
78
78
 
79
79
  it "accepts a single element" do
80
80
  expect(subject).to receive(:request_body).with([sample_arl])
81
- subject.class.stub post: fake_response
81
+ allow(subject.class).to receive(:post) { fake_response }
82
82
  subject.execute sample_arl
83
83
  end
84
84
 
85
85
  it "accepts a collection with a single element" do
86
86
  expect(subject).to receive(:request_body).with([sample_arl])
87
- subject.class.stub post: fake_response
87
+ allow(subject.class).to receive(:post) { fake_response }
88
88
  subject.execute sample_arl
89
89
  end
90
90
 
91
91
  it "accepts a collection" do
92
92
  expect(subject).to receive(:request_body).with(['a', 'b'])
93
- subject.class.stub post: fake_response
93
+ allow(subject.class).to receive(:post) { fake_response }
94
94
  subject.execute ['a', 'b']
95
95
  end
96
96
 
97
97
  it "works with splatting" do
98
98
  expect(subject).to receive(:request_body).with(['a', 'b'])
99
- subject.class.stub post: fake_response
99
+ allow(subject.class).to receive(:post) { fake_response }
100
100
  subject.execute 'a', 'b'
101
101
  end
102
102
 
@@ -111,14 +111,20 @@ describe AkamaiApi::Ccu::Purge::Request do
111
111
 
112
112
  it "raises an exception when the response code is 401" do
113
113
  fake_response = double code: 401
114
- subject.class.stub post: fake_response
114
+ allow(subject.class).to receive(:post) { fake_response }
115
115
  expect { subject.execute sample_arl }.to raise_error AkamaiApi::Unauthorized
116
116
  end
117
117
 
118
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'
119
+ fake_response = double code: 201, parsed_response: { 'httpStatus' => 201 }
120
+ allow(subject.class).to receive(:post) { fake_response }
121
+ expect(subject.execute(sample_arl).raw).to eq 'httpStatus' => 201
122
+ end
123
+
124
+ it "raises an error when json code in response is not successful" do
125
+ fake_response = double code: 201, parsed_response: { 'httpStatus' => 403 }
126
+ allow(subject.class).to receive(:post) { fake_response }
127
+ expect { subject.execute sample_arl }.to raise_error AkamaiApi::CCU::Error
122
128
  end
123
129
  end
124
130
  end
@@ -1,43 +1,33 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe AkamaiApi::Ccu::Purge::Response do
3
+ describe AkamaiApi::CCU::Purge::Response do
4
4
  let(:raw) do
5
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'
6
+ "httpStatus" => 201,
7
+ "detail" => "Request accepted.",
8
+ "estimatedSeconds" => 420,
9
+ "purgeId" => "95b5a092-043f-4af0-843f-aaf0043faaf0",
10
+ "progressUri" => "/ccu/v2/purges/95b5a092-043f-4af0-843f-aaf0043faaf0",
11
+ "pingAfterSeconds" => 420,
12
+ "supportId" => "17PY1321286429616716-211907680"
15
13
  }
16
14
  end
17
- subject { AkamaiApi::Ccu::Purge::Response.new raw }
15
+ subject { AkamaiApi::CCU::Purge::Response.new raw }
18
16
 
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'
17
+ it '#detail returns the title attribute' do
18
+ expect(subject.detail).to eq 'Request accepted.'
25
19
  end
26
20
 
27
21
  it '#time_to_wait returns the pingAfterSeconds attribute' do
28
- expect(subject.time_to_wait).to eq 100
22
+ expect(subject.time_to_wait).to eq 420
29
23
  end
30
24
 
31
25
  it '#purge_id returns the purgeId attribute' do
32
- expect(subject.purge_id).to eq '120'
26
+ expect(subject.purge_id).to eq "95b5a092-043f-4af0-843f-aaf0043faaf0"
33
27
  end
34
28
 
35
29
  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'
30
+ expect(subject.support_id).to eq "17PY1321286429616716-211907680"
41
31
  end
42
32
 
43
33
  it '#code returns the httpStatus attribute' do
@@ -45,10 +35,10 @@ describe AkamaiApi::Ccu::Purge::Response do
45
35
  end
46
36
 
47
37
  it '#estimated_time returns the estimatedSeconds attribute' do
48
- expect(subject.estimated_time).to eq 90
38
+ expect(subject.estimated_time).to eq 420
49
39
  end
50
40
 
51
41
  it '#uri returns the progressUri attribute' do
52
- expect(subject.uri).to eq 'http://asd.com'
42
+ expect(subject.uri).to eq "/ccu/v2/purges/95b5a092-043f-4af0-843f-aaf0043faaf0"
53
43
  end
54
44
  end
@@ -1,41 +1,41 @@
1
- require 'spec_helper'
1
+ # require 'spec_helper'
2
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 }
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
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
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
20
 
21
- it '#purge_id returns purgeId attribute' do
22
- expect(subject.purge_id).to eq '12345678-1234-5678-1234-123456789012'
23
- end
21
+ # it '#purge_id returns purgeId attribute' do
22
+ # expect(subject.purge_id).to eq '12345678-1234-5678-1234-123456789012'
23
+ # end
24
24
 
25
- it '#support_id returns supportId attribute' do
26
- expect(subject.support_id).to eq '12345678901234567890-123456789'
27
- end
25
+ # it '#support_id returns supportId attribute' do
26
+ # expect(subject.support_id).to eq '12345678901234567890-123456789'
27
+ # end
28
28
 
29
- it '#code returns httpStatus attribute' do
30
- expect(subject.code).to eq 200
31
- end
29
+ # it '#code returns httpStatus attribute' do
30
+ # expect(subject.code).to eq 200
31
+ # end
32
32
 
33
- it '#status returns purgeStatus attribute' do
34
- expect(subject.status).to eq 'Unknown'
35
- end
33
+ # it '#status returns purgeStatus attribute' do
34
+ # expect(subject.status).to eq 'Unknown'
35
+ # end
36
36
 
37
- it '#message returns detail attribute' do
38
- raw['detail'] = 'asd'
39
- expect(subject.message).to eq 'asd'
40
- end
41
- end
37
+ # it '#message returns detail attribute' do
38
+ # raw['detail'] = 'asd'
39
+ # expect(subject.message).to eq 'asd'
40
+ # end
41
+ # end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe AkamaiApi::Ccu::PurgeStatus::Request do
3
+ describe AkamaiApi::CCU::PurgeStatus::Request do
4
4
  it "includes httparty" do
5
5
  expect(subject.class.included_modules).to include HTTParty
6
6
  end
@@ -10,10 +10,10 @@ describe AkamaiApi::Ccu::PurgeStatus::Request do
10
10
  end
11
11
 
12
12
  describe "#execute" do
13
- let(:fake_response) { double code: 200, parsed_response: {} }
13
+ let(:fake_response) { double code: 200, parsed_response: { 'httpStatus' => 200, 'submissionTime' => 1 } }
14
14
 
15
15
  it "executes a GET request on the given progress_uri" do
16
- expect(AkamaiApi::Ccu::PurgeStatus::Request).to receive :get do |uri, args|
16
+ expect(AkamaiApi::CCU::PurgeStatus::Request).to receive :get do |uri, args|
17
17
  expect(uri).to eq '/ccu/v2/purges/foo'
18
18
  fake_response
19
19
  end
@@ -21,8 +21,8 @@ describe AkamaiApi::Ccu::PurgeStatus::Request do
21
21
  end
22
22
 
23
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|
24
+ allow(AkamaiApi).to receive(:auth) { 'foo' }
25
+ expect(AkamaiApi::CCU::PurgeStatus::Request).to receive :get do |uri, args|
26
26
  expect(args).to eq basic_auth: 'foo'
27
27
  fake_response
28
28
  end
@@ -30,20 +30,32 @@ describe AkamaiApi::Ccu::PurgeStatus::Request do
30
30
  end
31
31
 
32
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
33
+ allow(fake_response).to receive(:code) { 401 }
34
+ expect(AkamaiApi::CCU::PurgeStatus::Request).to receive(:get).and_return fake_response
35
35
  expect { subject.execute '/ccu/v2/purges/foo' }.to raise_error AkamaiApi::Unauthorized
36
36
  end
37
37
 
38
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
39
+ allow(fake_response).to receive(:parsed_response) { { 'httpStatus' => 201, 'submissionTime' => 1 } }
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
+ it "raises an error if json code in response is not valid" do
45
+ allow(fake_response).to receive(:parsed_response) { { 'httpStatus' => 400, 'submissionTime' => 1 } }
46
+ expect(AkamaiApi::CCU::PurgeStatus::Request).to receive(:get).and_return fake_response
47
+ expect { subject.execute '/ccu/v2/purges/foo' }.to raise_error AkamaiApi::CCU::Error
48
+ end
49
+
50
+ it "raises an error when json code in response has no submissionTime" do
51
+ fake_response = double code: 201, parsed_response: { 'httpStatus' => 201 }
52
+ expect(AkamaiApi::CCU::PurgeStatus::Request).to receive(:get).and_return fake_response
53
+ expect { subject.execute '/ccu/v2/purges/foo' }.to raise_error AkamaiApi::CCU::PurgeStatus::NotFound
42
54
  end
43
55
 
44
56
  context "when the given progressUri is the purgeId" do
45
57
  it "the progressUri prefix is appended" do
46
- expect(AkamaiApi::Ccu::PurgeStatus::Request).to receive :get do |uri, args|
58
+ expect(AkamaiApi::CCU::PurgeStatus::Request).to receive :get do |uri, args|
47
59
  expect(uri).to eq '/ccu/v2/purges/foo'
48
60
  fake_response
49
61
  end
@@ -53,7 +65,7 @@ describe AkamaiApi::Ccu::PurgeStatus::Request do
53
65
 
54
66
  context "when the given progressUri isn't prefixed by a slash" do
55
67
  it "a slash is prefixed" do
56
- expect(AkamaiApi::Ccu::PurgeStatus::Request).to receive :get do |uri, args|
68
+ expect(AkamaiApi::CCU::PurgeStatus::Request).to receive :get do |uri, args|
57
69
  expect(uri).to eq '/ccu/v2/purges/foo'
58
70
  fake_response
59
71
  end
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe AkamaiApi::Ccu::PurgeStatus::SuccessfulResponse do
3
+ describe AkamaiApi::CCU::PurgeStatus::Response do
4
4
  let(:raw) do
5
5
  {
6
6
  'originalEstimatedSeconds' => 480,
7
- 'progressUri' => '/ccu/v2/purges/12345678-1234-5678-1234-123456789012',
7
+ 'progressUri' => '/CCU/v2/purges/12345678-1234-5678-1234-123456789012',
8
8
  'originalQueueLength' => 6,
9
9
  'purgeId' => '12345678-1234-5678-1234-123456789012',
10
10
  'supportId' => '12345678901234567890-123456789',
@@ -16,18 +16,18 @@ describe AkamaiApi::Ccu::PurgeStatus::SuccessfulResponse do
16
16
  'pingAfterSeconds' => 60
17
17
  }
18
18
  end
19
- subject { AkamaiApi::Ccu::PurgeStatus::SuccessfulResponse.new raw }
19
+ subject { AkamaiApi::CCU::PurgeStatus::Response.new raw }
20
20
 
21
- it '#estimated_time returns estimatedSeconds attribute' do
22
- expect(subject.estimated_time).to eq 480
21
+ it '#original_estimated_time returns originalEstimatedSeconds attribute' do
22
+ expect(subject.original_estimated_time).to eq 480
23
23
  end
24
24
 
25
25
  it '#progress_uri returns progressUri attribute' do
26
- expect(subject.progress_uri).to eq '/ccu/v2/purges/12345678-1234-5678-1234-123456789012'
26
+ expect(subject.progress_uri).to eq '/CCU/v2/purges/12345678-1234-5678-1234-123456789012'
27
27
  end
28
28
 
29
- it '#queue_length returns originalQueueLength attribute' do
30
- expect(subject.queue_length).to eq 6
29
+ it '#original_queue_length returns originalQueueLength attribute' do
30
+ expect(subject.original_queue_length).to eq 6
31
31
  end
32
32
 
33
33
  it '#purge_id returns purgeId attribute' do
@@ -1,22 +1,22 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe AkamaiApi::Ccu::Status::Request do
3
+ describe AkamaiApi::CCU::Status::Request do
4
4
  it 'executes a get upon base url passing the basic auth' do
5
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
6
+ allow(AkamaiApi).to receive(:auth) { 'foo' }
7
+ expect(AkamaiApi::CCU::Status::Request).to receive(:get).with('/', basic_auth: 'foo').and_return fake_response
8
8
  subject.execute
9
9
  end
10
10
 
11
11
  it 'raises an unauthorized error if code is 401' do
12
12
  fake_response = double code: 401, parsed_response: {}
13
- expect(AkamaiApi::Ccu::Status::Request).to receive(:get).and_return fake_response
13
+ expect(AkamaiApi::CCU::Status::Request).to receive(:get).and_return fake_response
14
14
  expect { subject.execute }.to raise_error AkamaiApi::Unauthorized
15
15
  end
16
16
 
17
17
  it 'returns a StatusResponse' do
18
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
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
21
  end
22
22
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe AkamaiApi::Ccu::Status::Response do
3
+ describe AkamaiApi::CCU::Status::Response do
4
4
  let(:raw) do
5
5
  {
6
6
  'httpStatus' => 201,
@@ -9,7 +9,7 @@ describe AkamaiApi::Ccu::Status::Response do
9
9
  'supportId' => '21'
10
10
  }
11
11
  end
12
- subject { AkamaiApi::Ccu::Status::Response.new raw }
12
+ subject { AkamaiApi::CCU::Status::Response.new raw }
13
13
 
14
14
  it '#code returns the httpStatus property' do
15
15
  expect(subject.code).to eq 201
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe AkamaiApi::Ccu do
4
- subject { AkamaiApi::Ccu }
3
+ describe AkamaiApi::CCU do
4
+ subject { AkamaiApi::CCU }
5
5
 
6
6
  %w(invalidate remove).each do |action|
7
7
  describe "##{action}" do
@@ -35,18 +35,18 @@ describe AkamaiApi::Ccu do
35
35
  it 'delegates to Purge::Request' do
36
36
  fake_request = double
37
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').
38
+ expect(AkamaiApi::CCU::Purge::Request).to receive(:new).with('foo', 'bar', domain: 'asd').
39
39
  and_return fake_request
40
40
  expect(subject.purge 'foo', 'bar', 'baz', domain: 'asd').to eq 'quiz'
41
41
  end
42
42
 
43
43
  describe 'raises an error when' do
44
44
  it 'action is not allowed' do
45
- expect { subject.purge :sss, :cpcode, '12345' }.to raise_error AkamaiApi::Ccu::UnrecognizedOption
45
+ expect { subject.purge :sss, :cpcode, '12345' }.to raise_error AkamaiApi::CCU::UnrecognizedOption
46
46
  end
47
47
 
48
48
  it 'type is not allowed' do
49
- expect { subject.purge :remove, :foo, '12345' }.to raise_error AkamaiApi::Ccu::UnrecognizedOption
49
+ expect { subject.purge :remove, :foo, '12345' }.to raise_error AkamaiApi::CCU::UnrecognizedOption
50
50
  end
51
51
 
52
52
  it 'domain is specified and not allowed' do
@@ -58,7 +58,7 @@ describe AkamaiApi::Ccu do
58
58
  describe '#status' do
59
59
  context "when no argument is given" do
60
60
  it "delegates to Status request instance" do
61
- expect(AkamaiApi::Ccu::Status::Request).to receive(:new).and_return double execute: 'foo'
61
+ expect(AkamaiApi::CCU::Status::Request).to receive(:new).and_return double execute: 'foo'
62
62
  expect(subject.status).to eq 'foo'
63
63
  end
64
64
  end
@@ -66,7 +66,7 @@ describe AkamaiApi::Ccu do
66
66
  context "when a progress uri is passed as argument" do
67
67
  it "delegates to PurgeStatus request instance" do
68
68
  fake_instance = double
69
- expect(AkamaiApi::Ccu::PurgeStatus::Request).to receive(:new).and_return fake_instance
69
+ expect(AkamaiApi::CCU::PurgeStatus::Request).to receive(:new).and_return fake_instance
70
70
  expect(fake_instance).to receive(:execute).with('foo').and_return 'asd'
71
71
  expect(subject.status 'foo').to eq 'asd'
72
72
  end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module AkamaiApi
4
- describe Cli::Ccu::StatusRenderer do
5
- subject { Cli::Ccu::StatusRenderer.new Ccu::Status::Response.new({}) }
4
+ describe CLI::CCU::StatusRenderer do
5
+ subject { CLI::CCU::StatusRenderer.new CCU::Status::Response.new({}) }
6
6
 
7
7
  describe '#render' do
8
8
  it 'returns a string' do
@@ -10,27 +10,15 @@ module AkamaiApi
10
10
  end
11
11
 
12
12
  it 'delegates to #render_status if response is a Status::Response' do
13
- expect(subject).to receive(:render_status)
13
+ expect(subject).to receive(:queue_status)
14
14
  subject.render
15
15
  end
16
16
 
17
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)
18
+ subject = CLI::CCU::StatusRenderer.new CCU::PurgeStatus::Response.new({})
19
+ expect(subject).to receive(:purge_status)
20
20
  subject.render
21
21
  end
22
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
23
  end
36
24
  end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ describe AkamaiApi::ECCU::DestroyRequest do
4
+ subject { AkamaiApi::ECCU::DestroyRequest.new '1234' }
5
+
6
+ describe "#execute" do
7
+ let(:fake_client) { double call: nil }
8
+
9
+ before do
10
+ allow(AkamaiApi::ECCU).to receive(:client) { fake_client }
11
+ end
12
+
13
+ it "calls 'delete' via savon with a message" do
14
+ fake_response = double body: { delete_response: { success: true } }
15
+ expect(subject).to receive(:request_body).and_return double(to_s: 'asd')
16
+ expect(fake_client).to receive(:call).with(:delete, message: 'asd').and_return fake_response
17
+ subject.execute
18
+ end
19
+
20
+ it "returns 'true' if response hash reports to be successful" do
21
+ allow(subject).to receive(:request_body) { 'example' }
22
+ allow(fake_client).to receive(:call) { double(body: { delete_response: { success: true } }) }
23
+ expect(subject.execute).to be_truthy
24
+ end
25
+
26
+ it "returns 'false' if response hash reports to be unsuccessful" do
27
+ allow(subject).to receive(:request_body) { 'example' }
28
+ allow(fake_client).to receive(:call) { double(body: { delete_response: { success: false } }) }
29
+ expect(subject.execute).to be_falsy
30
+ end
31
+
32
+ it "raises NotFound if request raises a Savon::SOAPFault with particular message" do
33
+ expect(fake_client).to receive :call do
34
+ exc = Savon::SOAPFault.new({}, {})
35
+ allow(exc).to receive(:to_hash) { { fault: { faultstring: 'asdasd fileId xsxx does not exist' } } }
36
+ allow(exc).to receive(:to_s) { '' }
37
+ raise exc
38
+ end
39
+ expect { subject.execute }.to raise_error AkamaiApi::ECCU::NotFound
40
+ end
41
+
42
+ it "raises unauthorized if request raises a Savon::HTTPError with code 401" do
43
+ expect(fake_client).to receive :call do
44
+ raise Savon::HTTPError, double(code: 401)
45
+ end
46
+ expect { subject.execute }.to raise_error AkamaiApi::Unauthorized
47
+ end
48
+
49
+ it "raises Savon:HTTPError if request raises this exception and its code differs from 401" do
50
+ expect(fake_client).to receive :call do
51
+ raise Savon::HTTPError, double(code: 402)
52
+ end
53
+ expect { subject.execute }.to raise_error Savon::HTTPError
54
+ end
55
+ end
56
+
57
+ describe "#request_body" do
58
+ def subject_request_body
59
+ subject.send :request_body
60
+ end
61
+
62
+ it "returns a SoapBody object" do
63
+ expect(subject_request_body).to be_a AkamaiApi::ECCU::SoapBody
64
+ end
65
+
66
+ it "sets an integer value named 'fileId' with the given code" do
67
+ expect_any_instance_of(AkamaiApi::ECCU::SoapBody).to receive(:integer).with :fileId, 1234
68
+ subject_request_body
69
+ end
70
+
71
+ it "sets only fileId" do
72
+ expect(subject_request_body.to_s).to eq "<fileId xsi:type=\"xsd:int\">1234</fileId>"
73
+ end
74
+ end
75
+ end