cdnetworks-client 0.0.7 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# Cdnetworks Client
|
2
2
|
|
3
|
-
The Cdnetworks Client is a simple wrapper for
|
3
|
+
The Cdnetworks Client is a simple wrapper for three [Cdnetworks](http://www.cdnetworks.com/) APIs
|
4
4
|
* Config Open API v1.0
|
5
|
-
* Cache Purge Open API v2.0
|
5
|
+
* Cache Purge Open API v2.0 (older cache flushing API)
|
6
|
+
* Cache Flush Open API v2.3.2 (most current cache flushing API)
|
6
7
|
|
7
8
|
This gem allows a user to call methods from either of these APIs using the same syntax.
|
8
9
|
|
@@ -74,6 +75,18 @@ You can also add in parameters
|
|
74
75
|
</pre>
|
75
76
|
|
76
77
|
## Purging a cache
|
78
|
+
|
79
|
+
### If you are using Cache Flush Open API v2.3.2
|
80
|
+
|
81
|
+
<pre>
|
82
|
+
cdn.do_purge(:pad => "cdn.example.com", :type => "all")
|
83
|
+
</pre>
|
84
|
+
|
85
|
+
<pre>
|
86
|
+
cdn.do_purge(:pad => "cdn.example.com", :path => ["images/one.jpg", "images/two.jpg"])
|
87
|
+
</pre>
|
88
|
+
|
89
|
+
### If you are using Cache Purge Open API v2.0
|
77
90
|
<pre>
|
78
91
|
cdn.execute_cache_purge(:purgeUriList => "cdn.example.com")
|
79
92
|
</pre>
|
@@ -82,7 +95,19 @@ You can also add in parameters
|
|
82
95
|
cdn.execute_cache_purge(:purgeUriList => ["cdn.example.com", "cdn.foo.com"])
|
83
96
|
</pre>
|
84
97
|
|
98
|
+
## Getting the status of a cache purge
|
99
|
+
<pre>
|
100
|
+
cdn.status(:pid => 1234)
|
101
|
+
</pre>
|
102
|
+
|
85
103
|
## Listing all PAD domain names
|
104
|
+
|
105
|
+
### If you are using Cache Flush Open API v2.3.2
|
106
|
+
<pre>
|
107
|
+
cdn.pad_list
|
108
|
+
</pre>
|
109
|
+
|
110
|
+
### If you are using Cache Purge Open API v2.0
|
86
111
|
<pre>
|
87
112
|
cdn.get_cache_domain_list
|
88
113
|
</pre>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module CacheFlushOpenApi
|
2
|
+
|
3
|
+
def do_purge(options={})
|
4
|
+
call(cache_flush_path("doPurge"),add_flush_credentials(options))
|
5
|
+
end
|
6
|
+
|
7
|
+
def pad_list(options={})
|
8
|
+
call(cache_flush_path("padList"),add_flush_credentials(options))
|
9
|
+
end
|
10
|
+
|
11
|
+
def status(options={})
|
12
|
+
call(cache_flush_path("status"),add_flush_credentials(options))
|
13
|
+
end
|
14
|
+
|
15
|
+
def cache_flush_path(command)
|
16
|
+
"/purge/rest/#{command}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_flush_credentials(options)
|
20
|
+
options[:user] = @user
|
21
|
+
options[:pass] = @password
|
22
|
+
|
23
|
+
options
|
24
|
+
end
|
25
|
+
end
|
data/lib/cdnetworks-client.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require "cdnetworks-client/version"
|
2
2
|
require "cdnetworks-client/cache_purge_api"
|
3
3
|
require "cdnetworks-client/config_open_api"
|
4
|
+
require "cdnetworks-client/cache_flush_open_api"
|
4
5
|
|
5
6
|
class CdnetworksClient
|
6
7
|
include ConfigOpenApi
|
7
8
|
include CachePurgeApi
|
9
|
+
include CacheFlushOpenApi
|
8
10
|
|
9
11
|
|
10
12
|
def initialize(credentials={})
|
@@ -24,7 +26,7 @@ class CdnetworksClient
|
|
24
26
|
response = http.request(compose_request(path,options))
|
25
27
|
response_hash = { code: response.code, body: response.body }
|
26
28
|
rescue StandardError=>e
|
27
|
-
|
29
|
+
"An error has occurred connecting to the CDNetworks API (#{e})"
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
@@ -137,65 +137,151 @@ describe CdnetworksClient do
|
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
|
-
context "
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
140
|
+
context "with Cache Purge Open API v2.0" do
|
141
|
+
context "purging a cache" do
|
142
|
+
before(:each) do
|
143
|
+
stub_request(:post, "#{@url}/OpenAPI/services/CachePurgeAPI/executeCachePurge").
|
144
|
+
to_return(:status => 200, :body => "", :headers => {})
|
145
|
+
end
|
145
146
|
|
146
|
-
|
147
|
-
|
147
|
+
it "calls the purge method of the cdnetworks api" do
|
148
|
+
@cdn_api.execute_cache_purge
|
148
149
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
150
|
+
a_request(:post, "#{@url}/OpenAPI/services/CachePurgeAPI/executeCachePurge").
|
151
|
+
with(:body => 'userId=user%40user.com&password=secret',
|
152
|
+
:headers => {
|
153
|
+
'Accept' =>'*/*',
|
154
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
155
|
+
'User-Agent' =>'Ruby'}).
|
156
|
+
should have_been_made
|
157
|
+
end
|
157
158
|
|
158
|
-
|
159
|
-
|
159
|
+
it "includes the options passed as a hash" do
|
160
|
+
@cdn_api.execute_cache_purge(:purgeUriList => "cdn.example.com")
|
160
161
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
162
|
+
a_request(:post, "#{@url}/OpenAPI/services/CachePurgeAPI/executeCachePurge").
|
163
|
+
with(:body => 'purgeUriList=cdn.example.com&userId=user%40user.com&password=secret',
|
164
|
+
:headers => {
|
165
|
+
'Accept' =>'*/*',
|
166
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
167
|
+
'User-Agent' =>'Ruby'}).
|
168
|
+
should have_been_made
|
169
|
+
end
|
170
|
+
|
171
|
+
it "handles options passed as an array" do
|
172
|
+
@cdn_api.execute_cache_purge(:purgeUriList => ["cdn.example.com", "pad.foo.com"])
|
173
|
+
|
174
|
+
a_request(:post, "#{@url}/OpenAPI/services/CachePurgeAPI/executeCachePurge").
|
175
|
+
with(:body => 'purgeUriList=cdn.example.com&purgeUriList=pad.foo.com&userId=user%40user.com&password=secret',
|
176
|
+
:headers => {
|
177
|
+
'Accept' =>'*/*',
|
178
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
179
|
+
'User-Agent' =>'Ruby'}).
|
180
|
+
should have_been_made
|
181
|
+
end
|
168
182
|
end
|
169
183
|
|
170
|
-
|
171
|
-
|
184
|
+
context "getting a cache domain list" do
|
185
|
+
before(:each) do
|
186
|
+
stub_request(:post, "https://openapi.us.cdnetworks.com/OpenAPI/services/CachePurgeAPI/getCacheDomainList").
|
187
|
+
to_return(:status => 200, :body => "", :headers => {})
|
188
|
+
end
|
172
189
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
190
|
+
it "calls the cache domain list method of the cdnetworks api" do
|
191
|
+
@cdn_api.get_cache_domain_list
|
192
|
+
|
193
|
+
a_request(:post, "#{@url}/OpenAPI/services/CachePurgeAPI/getCacheDomainList").
|
194
|
+
with(:body => 'userId=user%40user.com&password=secret',
|
195
|
+
:headers => {
|
196
|
+
'Accept' =>'*/*',
|
197
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
198
|
+
'User-Agent' =>'Ruby'}).
|
199
|
+
should have_been_made
|
200
|
+
end
|
180
201
|
end
|
181
202
|
end
|
182
203
|
|
183
|
-
context "
|
184
|
-
|
185
|
-
|
186
|
-
|
204
|
+
context "with Cache Flush Open API v2.3.2" do
|
205
|
+
context "purging a cache" do
|
206
|
+
before(:each) do
|
207
|
+
stub_request(:post, "#{@url}/purge/rest/doPurge").
|
208
|
+
to_return(:status => 200, :body => "", :headers => {})
|
209
|
+
end
|
210
|
+
|
211
|
+
it "calls the purge method" do
|
212
|
+
@cdn_api.do_purge
|
213
|
+
|
214
|
+
a_request(:post, "#{@url}/purge/rest/doPurge").
|
215
|
+
with(:body => 'user=user%40user.com&pass=secret',
|
216
|
+
:headers => {
|
217
|
+
'Accept' =>'*/*',
|
218
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
219
|
+
'User-Agent' =>'Ruby'}).
|
220
|
+
should have_been_made
|
221
|
+
end
|
222
|
+
|
223
|
+
it "handles options passed as a hash" do
|
224
|
+
@cdn_api.do_purge(:pad => "cdn.example.com", :type => "all")
|
225
|
+
|
226
|
+
a_request(:post, "#{@url}/purge/rest/doPurge").
|
227
|
+
with(:body => 'pad=cdn.example.com&type=all&user=user%40user.com&pass=secret',
|
228
|
+
:headers => {
|
229
|
+
'Accept' =>'*/*',
|
230
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
231
|
+
'User-Agent' =>'Ruby'}).
|
232
|
+
should have_been_made
|
233
|
+
end
|
234
|
+
|
235
|
+
it "handles options passed as an array" do
|
236
|
+
@cdn_api.do_purge(:path => ["/images/one.jpg", "/images/two.jpg"])
|
237
|
+
a_request(:post, "#{@url}/purge/rest/doPurge").
|
238
|
+
with(:body => 'path=%2Fimages%2Fone.jpg&path=%2Fimages%2Ftwo.jpg&user=user%40user.com&pass=secret',
|
239
|
+
:headers => {
|
240
|
+
'Accept' =>'*/*',
|
241
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
242
|
+
'User-Agent' =>'Ruby'}).
|
243
|
+
should have_been_made
|
244
|
+
end
|
187
245
|
end
|
188
246
|
|
189
|
-
|
190
|
-
|
247
|
+
context "getting a list of PADs" do
|
248
|
+
it "calls the list method" do
|
249
|
+
@cdn_api.pad_list
|
191
250
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
251
|
+
a_request(:post, "#{@url}/purge/rest/padList").
|
252
|
+
with(:body => 'user=user%40user.com&pass=secret',
|
253
|
+
:headers => {
|
254
|
+
'Accept' =>'*/*',
|
255
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
256
|
+
'User-Agent' =>'Ruby'}).
|
257
|
+
should have_been_made
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
context "get the status of a purge" do
|
262
|
+
it "calls the status method" do
|
263
|
+
@cdn_api.status
|
264
|
+
|
265
|
+
a_request(:post, "#{@url}/purge/rest/status").
|
266
|
+
with(:body => 'user=user%40user.com&pass=secret',
|
267
|
+
:headers => {
|
268
|
+
'Accept' =>'*/*',
|
269
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
270
|
+
'User-Agent' =>'Ruby'}).
|
271
|
+
should have_been_made
|
272
|
+
end
|
273
|
+
|
274
|
+
it "handles options passsed as a hash" do
|
275
|
+
@cdn_api.status(pid: 1234)
|
276
|
+
|
277
|
+
a_request(:post, "#{@url}/purge/rest/status").
|
278
|
+
with(:body => 'pid=1234&user=user%40user.com&pass=secret',
|
279
|
+
:headers => {
|
280
|
+
'Accept' =>'*/*',
|
281
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
282
|
+
'User-Agent' =>'Ruby'}).
|
283
|
+
should have_been_made
|
284
|
+
end
|
199
285
|
end
|
200
286
|
end
|
201
287
|
|
@@ -252,7 +338,9 @@ describe CdnetworksClient do
|
|
252
338
|
end
|
253
339
|
|
254
340
|
it "returns an error" do
|
255
|
-
@cdn_api.list
|
341
|
+
error_result = @cdn_api.list
|
342
|
+
error_result.should include("An error has occurred")
|
343
|
+
error_result.should include("execution expired")
|
256
344
|
end
|
257
345
|
end
|
258
346
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cdnetworks-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-09-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- Rakefile
|
60
60
|
- cdnetworks-client.gemspec
|
61
61
|
- lib/cdnetworks-client.rb
|
62
|
+
- lib/cdnetworks-client/cache_flush_open_api.rb
|
62
63
|
- lib/cdnetworks-client/cache_purge_api.rb
|
63
64
|
- lib/cdnetworks-client/config_open_api.rb
|
64
65
|
- lib/cdnetworks-client/version.rb
|