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,74 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AkamaiApi::ECCU::FindRequest do
|
4
|
+
subject { AkamaiApi::ECCU::FindRequest.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 'get_info' via savon with a message" do
|
14
|
+
fake_response = double body: { get_info_response: { success: true } }
|
15
|
+
expect(subject).to receive(:request_body).with(true).and_return double(to_s: 'asd')
|
16
|
+
expect(fake_client).to receive(:call).with(:get_info, message: 'asd').and_return fake_response
|
17
|
+
subject.execute true
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns a FindResponse" do
|
21
|
+
allow(subject).to receive(:request_body) { 'example' }
|
22
|
+
allow(fake_client).to receive(:call) { double(body: { get_info_response: { ECCU_info: {} } }) }
|
23
|
+
expect(subject.execute 'foo').to be_a AkamaiApi::ECCU::FindResponse
|
24
|
+
end
|
25
|
+
|
26
|
+
it "raises NotFound if request raises a Savon::SOAPFault with particular message" do
|
27
|
+
expect(fake_client).to receive :call do
|
28
|
+
exc = Savon::SOAPFault.new({}, {})
|
29
|
+
allow(exc).to receive(:to_hash) { { fault: { faultstring: 'asdasd fileId xsxx does not exist' } } }
|
30
|
+
allow(exc).to receive(:to_s) { '' }
|
31
|
+
raise exc
|
32
|
+
end
|
33
|
+
expect { subject.execute true }.to raise_error AkamaiApi::ECCU::NotFound
|
34
|
+
end
|
35
|
+
|
36
|
+
it "raises unauthorized if request raises a Savon::HTTPError with code 401" do
|
37
|
+
expect(fake_client).to receive :call do
|
38
|
+
raise Savon::HTTPError, double(code: 401)
|
39
|
+
end
|
40
|
+
expect { subject.execute true }.to raise_error AkamaiApi::Unauthorized
|
41
|
+
end
|
42
|
+
|
43
|
+
it "raises Savon:HTTPError if request raises this exception and its code differs from 401" do
|
44
|
+
expect(fake_client).to receive :call do
|
45
|
+
raise Savon::HTTPError, double(code: 402)
|
46
|
+
end
|
47
|
+
expect { subject.execute true }.to raise_error Savon::HTTPError
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#request_body" do
|
52
|
+
def subject_request_body value
|
53
|
+
subject.send :request_body, value
|
54
|
+
end
|
55
|
+
|
56
|
+
it "returns a SoapBody object" do
|
57
|
+
expect(subject_request_body false).to be_a AkamaiApi::ECCU::SoapBody
|
58
|
+
end
|
59
|
+
|
60
|
+
it "sets an integer value named 'fileId' with the given code" do
|
61
|
+
expect_any_instance_of(AkamaiApi::ECCU::SoapBody).to receive(:integer).with :fileId, 1234
|
62
|
+
subject_request_body false
|
63
|
+
end
|
64
|
+
|
65
|
+
it "sets a boolean value named 'retrieveContents' with the given value" do
|
66
|
+
expect_any_instance_of(AkamaiApi::ECCU::SoapBody).to receive(:boolean).with :retrieveContents, false
|
67
|
+
subject_request_body '1'
|
68
|
+
end
|
69
|
+
|
70
|
+
it "sets only fileId" do
|
71
|
+
expect(subject_request_body(false).to_s).to eq "<fileId xsi:type=\"xsd:int\">1234</fileId><retrieveContents xsi:type=\"xsd:boolean\">false</retrieveContents>"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AkamaiApi::ECCU::FindResponse do
|
4
|
+
let(:raw_data) do
|
5
|
+
{
|
6
|
+
file_id: '1234',
|
7
|
+
notes: 'Notes',
|
8
|
+
status_change_email: "guest@mikamai.com",
|
9
|
+
upload_date: 'date',
|
10
|
+
uploaded_by: 'guest',
|
11
|
+
version: '1',
|
12
|
+
contents: Base64.encode64('hello world'),
|
13
|
+
file_size: '1',
|
14
|
+
filename: 'file.txt',
|
15
|
+
md5_digest: '123',
|
16
|
+
extended_status_message: 'status',
|
17
|
+
status_code: '200',
|
18
|
+
status_message: 'message',
|
19
|
+
status_update_date: 'asdasd',
|
20
|
+
property_name: 'foo.bar',
|
21
|
+
property_name_exact_match: true,
|
22
|
+
property_type: 'hostheader'
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
subject { AkamaiApi::ECCU::FindResponse.new raw_data }
|
27
|
+
|
28
|
+
describe "#code" do
|
29
|
+
it "returns the 'file_id' property" do
|
30
|
+
expect(subject.code).to eq "1234"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
{
|
35
|
+
:notes => :notes,
|
36
|
+
:email => :status_change_email,
|
37
|
+
:uploaded_at => :upload_date,
|
38
|
+
:uploaded_by => :uploaded_by,
|
39
|
+
:version => :version_string
|
40
|
+
}.each do |local_name, soap_name|
|
41
|
+
describe "##{local_name}" do
|
42
|
+
it "returns the '#{soap_name}' property when its a string" do
|
43
|
+
expect(subject.send local_name).to eq raw_data[soap_name]
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns nil when the '#{soap_name}' property isnt a string" do
|
47
|
+
raw_data[soap_name] = {}
|
48
|
+
expect(subject.send local_name).to be_nil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#file" do
|
54
|
+
it "returns an hash" do
|
55
|
+
expect(subject.file).to be_a Hash
|
56
|
+
end
|
57
|
+
|
58
|
+
it "returns a de-encoded content when there is a 'contents' property'" do
|
59
|
+
expect(subject.file[:content]).to eq 'hello world'
|
60
|
+
end
|
61
|
+
|
62
|
+
it "doesnt return any content when the 'contents' property isnt a String" do
|
63
|
+
raw_data[:contents] = {}
|
64
|
+
expect(subject.file).to_not have_key :content
|
65
|
+
end
|
66
|
+
|
67
|
+
it "returns a size property" do
|
68
|
+
expect(subject.file[:size]).to eq 1
|
69
|
+
end
|
70
|
+
|
71
|
+
it "returns the file name when there is a 'file_name' property" do
|
72
|
+
expect(subject.file[:name]).to eq 'file.txt'
|
73
|
+
end
|
74
|
+
|
75
|
+
it "doesnt return any file name when the 'filename' property isnt a String" do
|
76
|
+
raw_data[:filename] = {}
|
77
|
+
expect(subject.file).to_not have_key :name
|
78
|
+
end
|
79
|
+
|
80
|
+
it "returns the md5 when there is an 'md5' property" do
|
81
|
+
expect(subject.file[:md5]).to eq '123'
|
82
|
+
end
|
83
|
+
|
84
|
+
it "doesnt return any md5 when the 'md5' property isnt a String" do
|
85
|
+
raw_data[:md5_digest] = {}
|
86
|
+
expect(subject.file).to_not have_key :md5
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "#status" do
|
91
|
+
it "returns an hash" do
|
92
|
+
expect(subject.status).to be_a Hash
|
93
|
+
end
|
94
|
+
|
95
|
+
it "returns an 'extended' property when there is an 'extended_status_property'" do
|
96
|
+
expect(subject.status[:extended]).to eq 'status'
|
97
|
+
end
|
98
|
+
|
99
|
+
it "does not return any 'extended' when the 'extended_status_property' isnt a String" do
|
100
|
+
raw_data[:extended_status_message] = {}
|
101
|
+
expect(subject.status).to_not have_key :extended
|
102
|
+
end
|
103
|
+
|
104
|
+
it "returns a 'code' property when there is a 'status_code'" do
|
105
|
+
expect(subject.status[:code]).to eq 200
|
106
|
+
end
|
107
|
+
|
108
|
+
it "returns a 'message' property when there is a 'status_message'" do
|
109
|
+
expect(subject.status[:message]).to eq 'message'
|
110
|
+
end
|
111
|
+
|
112
|
+
it "does not return any 'message' property when 'status_message' isnt a String" do
|
113
|
+
raw_data[:status_message] = {}
|
114
|
+
expect(subject.status).to_not have_key :message
|
115
|
+
end
|
116
|
+
|
117
|
+
it "returns an 'updated_at' property when there is a 'status_update_date'" do
|
118
|
+
expect(subject.status[:updated_at]).to eq 'asdasd'
|
119
|
+
end
|
120
|
+
|
121
|
+
it "does not return any 'updated_at' property when 'status_update_date' isnt a String" do
|
122
|
+
raw_data[:status_update_date] = {}
|
123
|
+
expect(subject.status).to_not have_key :updated_at
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "#property" do
|
128
|
+
it "returns an Hash" do
|
129
|
+
expect(subject.property).to be_a Hash
|
130
|
+
end
|
131
|
+
|
132
|
+
it "returns a 'name' property when there is a 'property_name'" do
|
133
|
+
expect(subject.property[:name]).to eq 'foo.bar'
|
134
|
+
end
|
135
|
+
|
136
|
+
it "does not return any 'name' property when 'propert_name' isnt a String" do
|
137
|
+
raw_data[:property_name] = nil
|
138
|
+
expect(subject.property).to_not have_key :name
|
139
|
+
end
|
140
|
+
|
141
|
+
it "returns a 'exact_match' property set to true when 'property_name_exact_match' is true" do
|
142
|
+
expect(subject.property[:exact_match]).to be_truthy
|
143
|
+
end
|
144
|
+
|
145
|
+
it "returns a 'exact_match' property set to false when 'property_name_exact_match' isnt true" do
|
146
|
+
raw_data[:property_name_exact_match] = {}
|
147
|
+
expect(subject.property[:exact_match]).to be_falsy
|
148
|
+
end
|
149
|
+
|
150
|
+
it "returns a 'type' property when there is a 'property_type'" do
|
151
|
+
expect(subject.property[:type]).to eq 'hostheader'
|
152
|
+
end
|
153
|
+
|
154
|
+
it "does not return any 'type' property when 'property_type' isnt a String" do
|
155
|
+
raw_data[:property_type] = {}
|
156
|
+
expect(subject.property).to_not have_key :type
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AkamaiApi::ECCU::ListRequest do
|
4
|
+
subject { AkamaiApi::ECCU::ListRequest.new }
|
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 'get_ids' via savon" do
|
14
|
+
fake_response = double body: { get_ids_response: { file_ids: { file_ids: [1,2] } } }
|
15
|
+
expect(fake_client).to receive(:call).with(:get_ids).and_return fake_response
|
16
|
+
subject.execute
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns an array of ids" do
|
20
|
+
allow(fake_client).to receive(:call) { double(body: { get_ids_response: { file_ids: { file_ids: [1,2] } } }) }
|
21
|
+
expect(subject.execute).to eq [1,2]
|
22
|
+
end
|
23
|
+
|
24
|
+
it "wraps in array if only one result is returned" do
|
25
|
+
allow(fake_client).to receive(:call) { double(body: { get_ids_response: { file_ids: { file_ids: 1 } } }) }
|
26
|
+
expect(subject.execute).to eq [1]
|
27
|
+
end
|
28
|
+
|
29
|
+
it "raises unauthorized if request raises a Savon::HTTPError with code 401" do
|
30
|
+
expect(fake_client).to receive :call do
|
31
|
+
raise Savon::HTTPError, double(code: 401)
|
32
|
+
end
|
33
|
+
expect { subject.execute }.to raise_error AkamaiApi::Unauthorized
|
34
|
+
end
|
35
|
+
|
36
|
+
it "raises Savon:HTTPError if request raises this exception and its code differs from 401" do
|
37
|
+
expect(fake_client).to receive :call do
|
38
|
+
raise Savon::HTTPError, double(code: 402)
|
39
|
+
end
|
40
|
+
expect { subject.execute }.to raise_error Savon::HTTPError
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AkamaiApi::ECCU::PublishRequest do
|
4
|
+
subject { AkamaiApi::ECCU::PublishRequest.new 'foo.com', type: 'hostasd', exact_match: 'foo' }
|
5
|
+
|
6
|
+
describe 'constructor' do
|
7
|
+
it 'sets property_name to the given value' do
|
8
|
+
expect(subject.property_name).to eq 'foo.com'
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'sets property_type to the given value' do
|
12
|
+
expect(subject.property_type).to eq 'hostasd'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'sets property_type to hostheader if no value is given' do
|
16
|
+
subject = AkamaiApi::ECCU::PublishRequest.new 'foo.com'
|
17
|
+
expect(subject.property_type).to eq 'hostheader'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'sets property_exact_match to the given boolean value' do
|
21
|
+
expect(subject.property_exact_match).to be_falsy
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'sets property_exact_match to true if no value is given' do
|
25
|
+
subject = AkamaiApi::ECCU::PublishRequest.new 'foo.com'
|
26
|
+
expect(subject.property_exact_match).to be_truthy
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#execute' do
|
31
|
+
let(:fake_client) { double call: nil }
|
32
|
+
|
33
|
+
before do
|
34
|
+
allow(AkamaiApi::ECCU).to receive(:client) { fake_client }
|
35
|
+
end
|
36
|
+
|
37
|
+
it "calls 'upload' via savon with a message and the message_tag 'upload'" do
|
38
|
+
fake_response = double body: { upload_response: { file_id: 1 } }
|
39
|
+
expect(subject).to receive(:request_body).with('foo', {}).and_return double(to_s: 'asd')
|
40
|
+
expect(fake_client).to receive(:call).with(:upload, message_tag: 'upload', message: 'asd').and_return fake_response
|
41
|
+
subject.execute 'foo'
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns the request Id" do
|
45
|
+
allow(subject).to receive(:request_body) { 'example' }
|
46
|
+
allow(fake_client).to receive(:call) { double(body: { upload_response: { file_id: 1 } }) }
|
47
|
+
expect(subject.execute 'foo').to be_a Fixnum
|
48
|
+
end
|
49
|
+
|
50
|
+
it "raises unauthorized if request raises a Savon::HTTPError with code 401" do
|
51
|
+
expect(fake_client).to receive :call do
|
52
|
+
raise Savon::HTTPError, double(code: 401)
|
53
|
+
end
|
54
|
+
expect { subject.execute 'foo' }.to raise_error AkamaiApi::Unauthorized
|
55
|
+
end
|
56
|
+
|
57
|
+
it "raises Savon:HTTPError if request raises this exception and its code differs from 401" do
|
58
|
+
expect(fake_client).to receive :call do
|
59
|
+
raise Savon::HTTPError, double(code: 402)
|
60
|
+
end
|
61
|
+
expect { subject.execute 'foo' }.to raise_error Savon::HTTPError
|
62
|
+
end
|
63
|
+
|
64
|
+
it "raises InvalidDomain if request raises a Savon::SOAPFault with particular message" do
|
65
|
+
expect(fake_client).to receive :call do
|
66
|
+
exc = Savon::SOAPFault.new({}, {})
|
67
|
+
allow(exc).to receive(:to_hash) { { fault: { faultstring: 'asdasd You are not authorized to specify this digital property.' } } }
|
68
|
+
allow(exc).to receive(:to_s) { '' }
|
69
|
+
raise exc
|
70
|
+
end
|
71
|
+
expect { subject.execute 'foo' }.to raise_error AkamaiApi::ECCU::InvalidDomain
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '#subject_request_body' do
|
76
|
+
def subject_request_body *args
|
77
|
+
subject.send :request_body, *args
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'sets a string with the given file name' do
|
81
|
+
expect(subject_request_body('foo', file_name: 'asd').to_s).to include "<filename xsi:type=\"xsd:string\">asd</filename>"
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'sets an empty string if no file name is found' do
|
85
|
+
expect(subject_request_body('foo', {}).to_s).to include "<filename xsi:type=\"xsd:string\"></filename>"
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'sets a text with the given content' do
|
89
|
+
expect_any_instance_of(AkamaiApi::ECCU::SoapBody).to receive(:text).with :contents, 'asd'
|
90
|
+
subject_request_body 'asd', {}
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'sets a string with the given version' do
|
94
|
+
expect(subject_request_body('asd', version: '1').to_s).to include "<versionString xsi:type=\"xsd:string\">1</versionString>"
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'sets an empty string with there is no given version' do
|
98
|
+
expect(subject_request_body('asd', {}).to_s).to include "<versionString xsi:type=\"xsd:string\"></versionString>"
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'sets a string with the given notes' do
|
102
|
+
expect(subject_request_body('asd', notes: 'asdasd').to_s).to include "<notes xsi:type=\"xsd:string\">asdasd</notes>"
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'sets a string with a default message if no notes are given' do
|
106
|
+
expect(subject_request_body('asd', {}).to_s).to include "<notes xsi:type=\"xsd:string\">ECCU Request using AkamaiApi #{AkamaiApi::VERSION}</notes>"
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'sets a string with the given email' do
|
110
|
+
expect(subject_request_body('asd', emails: 'foo@bar.com').to_s).to include "<statusChangeEmail xsi:type=\"xsd:string\">foo@bar.com</statusChangeEmail>"
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'sets a string with the given emails' do
|
114
|
+
expect(subject_request_body('asd', emails: ['foo@bar.com', 'asd@bar.com']).to_s).to include "<statusChangeEmail xsi:type=\"xsd:string\">foo@bar.com,asd@bar.com</statusChangeEmail>"
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'sets no string with emails if no email is given' do
|
118
|
+
expect(subject_request_body('asd', {}).to_s).to_not include "emails"
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'sets the property name' do
|
122
|
+
expect(subject_request_body('asd', {}).to_s).to include "<propertyName xsi:type=\"xsd:string\">foo.com</propertyName>"
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'sets the property type' do
|
126
|
+
expect(subject_request_body('asd', {}).to_s).to include "<propertyType xsi:type=\"xsd:string\">hostasd</propertyType>"
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'sets the exact match' do
|
130
|
+
expect(subject_request_body('asd', {}).to_s).to include "<propertyNameExactMatch xsi:type=\"xsd:boolean\">false</propertyNameExactMatch>"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AkamaiApi::ECCU::SoapBody do
|
4
|
+
let(:config) { double :env_namespace => '', :soap_version => '2' }
|
5
|
+
|
6
|
+
describe '#string' do
|
7
|
+
before { subject.string 'foo', 'sample' }
|
8
|
+
|
9
|
+
it 'adds a string field' do
|
10
|
+
expect(subject.to_s).to match /<foo.*>sample<\/foo>/
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'sets the correct type attribute' do
|
14
|
+
expect(subject.to_s).to match /<foo xsi:type=\"xsd:string\">/
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#array' do
|
19
|
+
before { subject.array 'foo', ['a', 'b'] }
|
20
|
+
|
21
|
+
it 'adds an array field' do
|
22
|
+
expect(subject.to_s).to match /<foo.*><item>a<\/item><item>b<\/item><\/foo>/
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'sets the correct type attribute' do
|
26
|
+
expect(subject.to_s).to match /<foo.*xsi:type="wsdl:ArrayOfString"/
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'sets the correct arrayType attribute' do
|
30
|
+
expect(subject.to_s).to match /<foo.*soapenc:arrayType="xsd:string\[2\]"/
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#text' do
|
35
|
+
before { subject.text 'foo', 'foo' }
|
36
|
+
|
37
|
+
it 'adds a base64 encoded string field' do
|
38
|
+
match = subject.to_s.match /<foo.*>(.+)<\/foo>/m
|
39
|
+
expect(Base64.decode64 match[1]).to eq 'foo'
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'sets the correct type attribute' do
|
43
|
+
expect(subject.to_s).to match /<foo.*xsi:type="xsd:base64Binary/
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AkamaiApi::ECCU::UpdateAttributeRequest do
|
4
|
+
subject { AkamaiApi::ECCU::UpdateAttributeRequest.new '1234', :status_change_email }
|
5
|
+
|
6
|
+
describe '#attribute_for_soap' do
|
7
|
+
it 'returns a camelized symbol with first letter in downcase' do
|
8
|
+
expect(subject.send :attribute_for_soap).to eq :statusChangeEmail
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#execute" do
|
13
|
+
let(:fake_client) { double call: nil }
|
14
|
+
|
15
|
+
before do
|
16
|
+
allow(AkamaiApi::ECCU).to receive(:client) { fake_client }
|
17
|
+
end
|
18
|
+
|
19
|
+
it "calls the appropriate soap method via savon with a message" do
|
20
|
+
fake_response = double body: { set_status_change_email_response: { success: true } }
|
21
|
+
expect(subject).to receive(:request_body).with('foo').and_return double(to_s: 'asd')
|
22
|
+
expect(fake_client).to receive(:call).with(:set_status_change_email, message: 'asd').and_return fake_response
|
23
|
+
subject.execute 'foo'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns 'true' if response hash reports to be successful" do
|
27
|
+
allow(subject).to receive(:request_body) { 'example' }
|
28
|
+
allow(fake_client).to receive(:call) { double(body: { set_status_change_email_response: { success: true } }) }
|
29
|
+
expect(subject.execute 'foo').to be_truthy
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns 'false' if response hash reports to be unsuccessful" do
|
33
|
+
allow(subject).to receive(:request_body) { 'example' }
|
34
|
+
allow(fake_client).to receive(:call) { double(body: { set_status_change_email_response: { success: false } }) }
|
35
|
+
expect(subject.execute 'foo').to be_falsy
|
36
|
+
end
|
37
|
+
|
38
|
+
it "raises NotFound if request raises a Savon::SOAPFault with particular message" do
|
39
|
+
expect(fake_client).to receive :call do
|
40
|
+
exc = Savon::SOAPFault.new({}, {})
|
41
|
+
allow(exc).to receive(:to_hash) { { fault: { faultstring: 'asdasd fileId xsxx does not exist' } } }
|
42
|
+
allow(exc).to receive(:to_s) { '' }
|
43
|
+
raise exc
|
44
|
+
end
|
45
|
+
expect { subject.execute 'foo' }.to raise_error AkamaiApi::ECCU::NotFound
|
46
|
+
end
|
47
|
+
|
48
|
+
it "raises unauthorized if request raises a Savon::HTTPError with code 401" do
|
49
|
+
expect(fake_client).to receive :call do
|
50
|
+
raise Savon::HTTPError, double(code: 401)
|
51
|
+
end
|
52
|
+
expect { subject.execute 'foo' }.to raise_error AkamaiApi::Unauthorized
|
53
|
+
end
|
54
|
+
|
55
|
+
it "raises Savon:HTTPError if request raises this exception and its code differs from 401" do
|
56
|
+
expect(fake_client).to receive :call do
|
57
|
+
raise Savon::HTTPError, double(code: 402)
|
58
|
+
end
|
59
|
+
expect { subject.execute 'foo' }.to raise_error Savon::HTTPError
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "#request_body" do
|
64
|
+
def subject_request_body *args
|
65
|
+
subject.send :request_body, *args
|
66
|
+
end
|
67
|
+
|
68
|
+
it "returns a SoapBody object" do
|
69
|
+
expect(subject_request_body 'foo').to be_a AkamaiApi::ECCU::SoapBody
|
70
|
+
end
|
71
|
+
|
72
|
+
it "sets an integer value named 'fileId' with the given code" do
|
73
|
+
expect_any_instance_of(AkamaiApi::ECCU::SoapBody).to receive(:integer).with :fileId, 1234
|
74
|
+
subject_request_body 'foo'
|
75
|
+
end
|
76
|
+
|
77
|
+
it "sets a string value named 'statusChangeEmails' with the given email" do
|
78
|
+
expect_any_instance_of(AkamaiApi::ECCU::SoapBody).to receive(:string).with :statusChangeEmail, 'foo'
|
79
|
+
subject_request_body 'foo'
|
80
|
+
end
|
81
|
+
|
82
|
+
it "sets only fileId and email" do
|
83
|
+
expect(subject_request_body('foo').to_s).to eq "<fileId xsi:type=\"xsd:int\">1234</fileId><statusChangeEmail xsi:type=\"xsd:string\">foo</statusChangeEmail>"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|