cloudflare 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ace4e55d9c0023b9814c7cee5ec0d8d2a4c7390
4
- data.tar.gz: 7146dc89d31368a898ed15a329e8b22f17fc6ec7
3
+ metadata.gz: b32a40ccbdae3de9973839f3cf8c3294633cb7b2
4
+ data.tar.gz: ee7bd4dfcdbb1394c5ebcb531fbe01df27cdfa65
5
5
  SHA512:
6
- metadata.gz: 3b4ab2167a54eb0bcf176d3955fc5ffb9ca5730ac2621c5506b601508fdef593fde89cde06a6704b3e34c034de942fa566f63eeb62a352c942ecabc19a84bf60
7
- data.tar.gz: 332f791e53b7f0cf6549d07ede6a698db1818e309f236fc6b7a09bc2abf84099dfa402ea385c2646150c244f934394faa2ea023b38af8bfd08d417fd2c49fbca
6
+ metadata.gz: 4e955547a518f061827cbbd395158b824b0535118f40167010ca7bd951dc242167b779ff82b33d04b009ca7ce5965a5ea8606143106e6c64ce3ae787e6bfd222
7
+ data.tar.gz: 66a66ba091a22e43862898503d5dad947105ea3ab03d47230e24de2e87c5a461e232356c76a941c0c2117366227d7cdff23587d8c37c0d4b1e3a33e9cf84cbbc
@@ -1,15 +1,15 @@
1
1
  # Copyright, 2012, by Marcin Prokop.
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
5
5
  # in the Software without restriction, including without limitation the rights
6
6
  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
7
  # copies of the Software, and to permit persons to whom the Software is
8
8
  # furnished to do so, subject to the following conditions:
9
- #
9
+ #
10
10
  # The above copyright notice and this permission notice shall be included in
11
11
  # all copies or substantial portions of the Software.
12
- #
12
+ #
13
13
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
14
  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
15
  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -26,529 +26,530 @@ require 'json'
26
26
  # - http://www.cloudflare.com/docs/host-api.html
27
27
  #
28
28
  module CloudFlare
29
- class RequestError < StandardError
30
- def initialize(what, response)
31
- super(what)
32
-
33
- @response = response
34
- end
35
-
36
- attr :response
37
- end
38
-
39
- class Connection
40
- # URL for Client and Host API
41
- URL_API = {
42
- client: 'https://www.cloudflare.com/api_json.html',
43
- host: 'https://api.cloudflare.com/host-gw.html'
44
- }
45
-
46
- TIMEOUT = 5 # Default is 5 seconds
47
-
48
- # @param api_key [String] user or Host API key.
49
- # @param email [String] it is for a Client API.
50
- def initialize(api_key, email = nil)
51
- @params = Hash.new
52
-
53
- if email.nil?
54
- @params[:api_key] = api_key
55
- else
56
- @params[:api_key] = api_key
57
- @params[:email] = email
58
- end
59
-
60
- end
61
-
62
- # CLIENT
63
-
64
- # This function can be used to get currently settings of values such as the security level.
65
- #
66
- # @see http://www.cloudflare.com/docs/client-api.html#s3.1
67
- #
68
- # @param zone [String]
69
- # @param interval [Integer]
70
-
71
- def stats(zone, interval = 20)
72
- send_req({a: :stats, z: zone, interval: interval})
73
- end
74
-
75
- # This function lists all domains in a CloudFlare account along with other data.
76
- #
77
- # @see http://www.cloudflare.com/docs/client-api.html#s3.2
78
-
79
- def zone_load_multi
80
- send_req(a: :zone_load_multi)
81
- end
82
-
83
- # This function lists all of the DNS records from a particular domain in a CloudFlare account.
84
- #
85
- # @see http://www.cloudflare.com/docs/client-api.html#s3.3
86
- #
87
- # @param zone [String]
88
-
89
- def rec_load_all(zone)
90
- send_req({a: :rec_load_all, z: zone})
91
- end
92
-
93
- # This function checks whether one or more websites/domains are active under an account and return the zone ids (zids) for these.
94
- #
95
- # @see http://www.cloudflare.com/docs/client-api.html#s3.4
96
- #
97
- # @param zones [String or Array]
98
-
99
- def zone_check(*zones)
100
- send_req({a: :zone_check, zones: zones.kind_of?(Array) ? zones.join(',') : zones})
101
- end
102
-
103
- # This function pulls recent IPs hitting your site.
104
- #
105
- # @see http://www.cloudflare.com/docs/client-api.html#s3.5
106
- #
107
- # @param zone [String]
108
- # @param hours [Integer] max 48
109
- # @param classification [String] (optional) values: r|c|t
110
- # @param geo [Fixnum] (optional)
111
-
112
- def zone_ips(zone, classification = nil, hours = 24, geo = 1)
113
- send_req({a: :zone_ips, z: zone, hours: hours, "class" => classification, geo: geo})
114
- end
115
-
116
- # This function checks the threat score for a given IP.
117
- #
118
- # @see http://www.cloudflare.com/docs/client-api.html#s3.6
119
- #
120
- # @param ip [String]
121
-
122
- def ip_lkup(ip)
123
- send_req({a: :ip_lkup, ip: ip})
124
- end
125
-
126
- # This function retrieves all current settings for a given domain.
127
- #
128
- # @see http://www.cloudflare.com/docs/client-api.html#s3.7
129
- #
130
- # @param zone [String]
131
-
132
- def zone_settings(zone)
133
- send_req({a: :zone_settings, z: zone})
134
- end
135
-
136
- # This function sets the Basic Security Level to HELP I'M UNDER ATTACK / HIGH / MEDIUM / LOW / ESSENTIALLY OFF.
137
- #
138
- # @see http://www.cloudflare.com/docs/client-api.html#s4.1
139
- #
140
- # @param zone [String]
141
- # @param value [String] values: low|med|high|help|eoff
142
-
143
- def sec_lvl(zone, value)
144
- send_req({a: :sec_lvl, z: zone, v: value})
145
- end
146
-
147
- # This function sets the Caching Level to Aggressive or Basic.
148
- #
149
- # @see http://www.cloudflare.com/docs/client-api.html#s4.2
150
- #
151
- # @param zone [String]
152
- # @param value [String] values: agg|basic
153
-
154
- def cache_lvl(zone, value)
155
- send_req({a: :cache_lvl, z: zone, v: value})
156
- end
157
-
158
- # This function allows you to toggle Development Mode on or off for a particular domain.
159
- #
160
- # @see http://www.cloudflare.com/docs/client-api.html#s4.3
161
- #
162
- # @param zone [String]
163
- # @param value [Boolean]
164
-
165
- def devmode(zone, value)
166
- send_req({a: :devmode, z: zone, v: value ? 1 : 0})
167
- end
168
-
169
- # This function will purge CloudFlare of any cached files.
170
- #
171
- # @see http://www.cloudflare.com/docs/client-api.html#s4.4
172
- #
173
- # @param zone [String]
174
-
175
- def fpurge_ts(zone)
176
- send_req({a: :fpurge_ts, z: zone, v: 1})
177
- end
178
-
179
- # This function will purge a single file from CloudFlare's cache.
180
- #
181
- # @see http://www.cloudflare.com/docs/client-api.html#s4.5
182
- #
183
- # @param zone [String]
184
- # @param url [String]
185
-
186
- def zone_file_purge(zone, url)
187
- send_req({a: :zone_file_purge, z: zone, url: url})
188
- end
189
-
190
- # This function updates the snapshot of your site for CloudFlare's challenge page.
191
- #
192
- # @see http://www.cloudflare.com/docs/client-api.html#s4.6
193
- #
194
- # @param zoneid [Integer]
195
-
196
- def zone_grab(zoneid)
197
- send_req({a: :zone_grab, zid: zoneid})
198
- end
199
-
200
- # This function adds an IP address to your white lists.
201
- #
202
- # @see http://www.cloudflare.com/docs/client-api.html#s4.7
203
- #
204
- # @param ip [String]
205
-
206
- def whitelist(ip)
207
- send_req({a: :wl, key: ip})
208
- end
209
-
210
-
211
- # This function adds an IP address to your black lists.
212
- #
213
- # @see http://www.cloudflare.com/docs/client-api.html#s4.7
214
- #
215
- # @param ip [String]
216
-
217
- def blacklist(ip)
218
- send_req({a: :ban, key: ip})
219
- end
220
-
221
- # This function removes the IP from whitelist or blacklist.
222
- #
223
- # @see http://www.cloudflare.com/docs/client-api.html#s4.7
224
- #
225
- # @param ip [String]
226
-
227
- def remove_ip(ip)
228
- send_req({a: :nul, key: ip})
229
- end
230
-
231
- # This function toggles IPv6 support.
232
- #
233
- # @see http://www.cloudflare.com/docs/client-api.html#s4.8
234
- #
235
- # @param zone [String]
236
- # @param value [Boolean]
237
-
238
- def ipv46(zone, value)
239
- send_req({a: :ipv46, z: zone, v: value ? 1 : 0})
240
- end
241
-
242
- # This function changes Rocket Loader setting.
243
- #
244
- # @see http://www.cloudflare.com/docs/client-api.html#s4.9
245
- #
246
- # @param zone [String]
247
- # @param value [Integer or String] values: 0|a|m
248
-
249
- def async(zone, value)
250
- send_req({a: :async, z: zone, v: value})
251
- end
252
-
253
- # This function changes minification settings.
254
- #
255
- # @see http://www.cloudflare.com/docs/client-api.html#s4.10
256
- #
257
- # @param zone [String]
258
- # @param value [Integer] values: 0|2|3|4|5|6|7
259
-
260
- def minify(zone, value)
261
- send_req({a: :minify, z: zone, v: value})
262
- end
263
-
264
-
265
- # This function changes mirage2 settings.
266
- #
267
- # @see http://www.cloudflare.com/docs/client-api.html#s4.11
268
- #
269
- # @param zone [String]
270
- # @param value [Integer] values: 0|1
271
-
272
- def mirage2(zone, value)
273
- send_req({a: :mirage2, z: zone, v: value})
274
- end
275
-
276
- # This function creates a new DNS record for your site. This can be either a CNAME or A record.
277
- #
278
- # @see http://www.cloudflare.com/docs/client-api.html#s5.1
279
- #
280
- # @param zone [String]
281
- # @param type [String] values: A|CNAME|MX|TXT|SPF|AAAA|NS|SRV|LOC
282
- # @param name [String]
283
- # @param content [String]
284
- # @param ttl [Integer] values: 1|120...4294967295
285
- # @param prio [Integer] (applies to MX/SRV)
286
- # @param service [String] (applies to SRV)
287
- # @param srvname [String] (applies to SRV)
288
- # @param protocol [Integer] (applies to SRV) values: _tcp|_udp|_tls
289
- # @param weight [Intger] (applies to SRV)
290
- # @param port [Integer] (applies to SRV)
291
- # @param target [String] (applies to SRV)
292
-
293
- def rec_new(zone, type, name, content, ttl, prio = nil, service = nil, srvname = nil, protocol = nil, weight = nil, port = nil, target = nil)
294
- send_req({
295
- a: :rec_new,
296
- z: zone,
297
- type: type,
298
- name: name,
299
- content: content,
300
- ttl: ttl,
301
- prio: prio,
302
- service: service,
303
- srvname: srvname,
304
- protocol: protocol,
305
- weight: weight,
306
- port: port,
307
- target: target
308
- })
309
- end
310
-
311
- # This function edits a DNS record for a zone.
312
- #
313
- # @see http://www.cloudflare.com/docs/client-api.html#s5.2
314
- #
315
- # @param zone [String]
316
- # @param type [String] values: A|CNAME|MX|TXT|SPF|AAAA|NS|SRV|LOC
317
- # @param record_id [Integer]
318
- # @param name [String]
319
- # @param content [String]
320
- # @param ttl [Integer] values: 1|120...4294967295
321
- # @param service_mode [Boolean] (applies to A/AAAA/CNAME)
322
- # @param prio [Integer] (applies to MX/SRV)
323
- # @param service [String] (applies to SRV)
324
- # @param srvname [String] (applies to SRV)
325
- # @param protocol [Integer] (applies to SRV) values: _tcp/_udp/_tls
326
- # @param weight [Intger] (applies to SRV)
327
- # @param port [Integer] (applies to SRV)
328
- # @param target [String] (applies to SRV)
329
-
330
- def rec_edit(zone, type, record_id, name, content, ttl, service_mode = nil, prio = nil, service = nil, srvname = nil, protocol = nil, weight = nil, port = nil, target = nil)
331
- send_req({
332
- a: :rec_edit,
333
- z: zone,
334
- type: type,
335
- id: record_id,
336
- name: name,
337
- content: content,
338
- ttl: ttl,
339
- service_mode: service_mode ? 1 : 0,
340
- prio: prio,
341
- service: service,
342
- srvname: srvname,
343
- protocol: protocol,
344
- weight: weight,
345
- port: port,
346
- target: target
347
- })
348
- end
349
-
350
- # This functon deletes a record for a domain.
351
- #
352
- # @see http://www.cloudflare.com/docs/client-api.html#s5.3
353
- #
354
- # @param zone [String]
355
- # @param zoneid [Integer]
356
-
357
- def rec_delete(zone, zoneid)
358
- send_req({a: :rec_delete, z: zone, id: zoneid})
359
- end
360
-
361
- # HOST
362
-
363
- # This function creates a CloudFlare account mapped to your user.
364
- #
365
- # @see http://www.cloudflare.com/docs/host-api.html#s3.2.1
366
- #
367
- # @param email [String]
368
- # @param pass [String]
369
- # @param login [String] (optional) cloudflare_username
370
- # @param id [Integer] (optional) unique_id
371
- # @param cui [Integer] (optional) clobber_unique_id
372
-
373
- def create_user(email, pass, login = nil, id = nil, cui = nil)
374
- send_req({
375
- act: :user_create,
376
- cloudflare_email: email,
377
- cloudflare_pass: pass,
378
- cloudflare_username: login,
379
- unique_id: id,
380
- clobber_unique_id: cui
381
- })
382
- end
383
-
384
- # This function setups a User's zone for CNAME hosting.
385
- #
386
- # @see http://www.cloudflare.com/docs/host-api.html#s3.2.2
387
- #
388
- # @param user_key [String]
389
- # @param zone [String]
390
- # @param resolve_to [String]
391
- # @param subdomains [String or Array]
392
-
393
- def add_zone(user_key, zone, resolve_to, subdomains)
394
- send_req({
395
- act: :zone_set,
396
- user_key: user_key,
397
- zone_name: zone,
398
- resolve_to: resolve_to,
399
- subdomains: subdomains.kind_of?(Array) ? zones.join(',') : subdomains
400
- })
401
- end
402
-
403
- # This function lookups a user's CloudFlare account information.
404
- #
405
- # @see http://www.cloudflare.com/docs/host-api.html#s3.2.3
406
- #
407
- # *Example:*
408
- #
409
- # cf = CloudFlare('your_host_key')
410
- # cf.user_lookup('unique_id', true)
411
- #
412
- # If +id+ is set to true, email is a unique_id.
413
- #
414
- # @param email [String or Integer]
415
- # @param id [Boolean]
416
-
417
- def user_lookup(email, id = false)
418
- if id
419
- send_req({act: :user_lookup, unique_id: email})
420
- else
421
- send_req({act: :user_lookup, cloudflare_email: email})
422
- end
423
- end
424
-
425
- # This function authorizes access to a user's existing CloudFlare account.
426
- #
427
- # @see http://www.cloudflare.com/docs/host-api.html#s3.2.4
428
- #
429
- # @param email [String]
430
- # @param pass [String]
431
- # @param unique_id [Integer] (optional)
432
- # @param cui [Integer] (optional) clobber_unique_id
433
-
434
- def user_auth(email, pass, id = nil, cui = nil)
435
- send_req({
436
- act: :user_auth,
437
- cloudflare_email: email,
438
- cloudflare_pass: pass,
439
- unique_id: id,
440
- clobber_unique_id: cui
441
- })
442
- end
443
-
444
- # This function lookups a specific user's zone.
445
- #
446
- # @see http://www.cloudflare.com/docs/host-api.html#s3.2.5
447
- #
448
- # @param user_key [String]
449
- # @param zone [String]
450
-
451
- def zone_lookup(user_key, zone)
452
- send_req({act: :zone_lookup, user_key: user_key, zone_name: zone})
453
- end
454
-
455
- # This function deletes a specific zone on behalf of a user.
456
- #
457
- # @see http://www.cloudflare.com/docs/host-api.html#s3.2.6
458
- #
459
- # @param user_key [String]
460
- # @param zone [String]
461
-
462
- def del_zone(user_key, zone)
463
- send_req({act: :zone_delete, user_key: user_key, zone_name: zone})
464
- end
465
-
466
- # This function creates a new child host provider.
467
- #
468
- # @see http://www.cloudflare.com/docs/host-api.html#s3.2.7
469
- #
470
- # @param host_name [String]
471
- # @param pub_name [String]
472
- # @param prefix [String]
473
- # @param website [String]
474
- # @param email [String]
475
-
476
- def host_child_new(host_name, pub_name, prefix, website, email)
477
- send_req({
478
- act: :host_child_new,
479
- pub_name: pub_name,
480
- prefix: prefix,
481
- website: website,
482
- email: email
483
- })
484
- end
485
-
486
- # This function regenerates your host key.
487
- #
488
- # @see http://www.cloudflare.com/docs/host-api.html#s3.2.8
489
-
490
- def host_key_regen
491
- send_req(act: :host_key_regen)
492
- end
493
-
494
- # This function stops a child host provider account.
495
- #
496
- # @see http://www.cloudflare.com/docs/host-api.html#s3.2.9
497
- #
498
- # @param id [Integer] child_id
499
-
500
- def host_child_stop(id)
501
- send_req({act: :host_child_stop, child_id: id})
502
- end
503
-
504
- # This function lists the domains currently active on CloudFlare for the given host.
505
- #
506
- # @see http://www.cloudflare.com/docs/host-api.html#s3.2.10
507
- #
508
- # @param limit [Integer] (optional)
509
- # @param offset [Integer] (optional)
510
- # @param name [String] (optional) zone_name
511
- # @param sub_id [Integer] (optional) sub_id
512
- # @param status [String] (optional) values: V|D|ALL
513
-
514
- def zone_list(limit = 100, offset = 0, name = nil, sub_id = nil, status = nil)
515
- send_req({
516
- act: :zone_list,
517
- offset: offset,
518
- zone_name: name,
519
- sub_id: sub_id,
520
- zone_status: status
521
- })
522
- end
523
-
524
- private
525
-
526
- def send_req(params)
527
- if @params[:email]
528
- params[:tkn] = @params[:api_key]
529
- params[:u] = @params[:email]
530
- uri = URI(URL_API[:client])
531
- else
532
- params[:host_key] = @params[:api_key]
533
- uri = URI(URL_API[:host])
534
- end
535
-
536
- req = Net::HTTP::Post.new(uri.path)
537
- req.set_form_data(params)
538
-
539
- http = Net::HTTP.new(uri.host, uri.port)
540
- http.use_ssl = true
541
- http.read_timeout = TIMEOUT
542
-
543
- res = http.request(req)
544
- out = JSON.parse(res.body)
545
-
546
- # If there is an error, raise an exception:
547
- if out['result'] == 'error'
548
- raise RequestError.new(out['msg'], out)
549
- else
550
- return out
551
- end
552
- end
553
- end
29
+ class RequestError < StandardError
30
+ def initialize(what, response)
31
+ super(what)
32
+
33
+ @response = response
34
+ end
35
+
36
+ attr :response
37
+ end
38
+
39
+ class Connection
40
+ # URL for Client and Host API
41
+ URL_API = {
42
+ client: 'https://www.cloudflare.com/api_json.html',
43
+ host: 'https://api.cloudflare.com/host-gw.html'
44
+ }
45
+
46
+ TIMEOUT = 5 # Default is 5 seconds
47
+
48
+ # @param api_key [String] user or Host API key.
49
+ # @param email [String] it is for a Client API.
50
+ def initialize(api_key, email = nil)
51
+ @params = Hash.new
52
+
53
+ if email.nil?
54
+ @params[:api_key] = api_key
55
+ else
56
+ @params[:api_key] = api_key
57
+ @params[:email] = email
58
+ end
59
+
60
+ end
61
+
62
+ # CLIENT
63
+
64
+ # This function can be used to get currently settings of values such as the security level.
65
+ #
66
+ # @see http://www.cloudflare.com/docs/client-api.html#s3.1
67
+ #
68
+ # @param zone [String]
69
+ # @param interval [Integer]
70
+
71
+ def stats(zone, interval = 20)
72
+ send_req({a: :stats, z: zone, interval: interval})
73
+ end
74
+
75
+ # This function lists all domains in a CloudFlare account along with other data.
76
+ #
77
+ # @see http://www.cloudflare.com/docs/client-api.html#s3.2
78
+
79
+ def zone_load_multi
80
+ send_req(a: :zone_load_multi)
81
+ end
82
+
83
+ # This function lists all of the DNS records from a particular domain in a CloudFlare account.
84
+ #
85
+ # @see http://www.cloudflare.com/docs/client-api.html#s3.3
86
+ #
87
+ # @param zone [String]
88
+
89
+ def rec_load_all(zone, offset = 0)
90
+ send_req({a: :rec_load_all, z: zone, o: offset})
91
+ end
92
+
93
+ # This function checks whether one or more websites/domains are active under an account and return the zone ids (zids) for these.
94
+ #
95
+ # @see http://www.cloudflare.com/docs/client-api.html#s3.4
96
+ #
97
+ # @param zones [String or Array]
98
+
99
+ def zone_check(*zones)
100
+ send_req({a: :zone_check, zones: zones.kind_of?(Array) ? zones.join(',') : zones})
101
+ end
102
+
103
+ # This function pulls recent IPs hitting your site.
104
+ #
105
+ # @see http://www.cloudflare.com/docs/client-api.html#s3.5
106
+ #
107
+ # @param zone [String]
108
+ # @param hours [Integer] max 48
109
+ # @param classification [String] (optional) values: r|c|t
110
+ # @param geo [Fixnum] (optional)
111
+
112
+ def zone_ips(zone, classification = nil, hours = 24, geo = 1)
113
+ send_req({a: :zone_ips, z: zone, hours: hours, "class" => classification, geo: geo})
114
+ end
115
+
116
+ # This function checks the threat score for a given IP.
117
+ #
118
+ # @see http://www.cloudflare.com/docs/client-api.html#s3.6
119
+ #
120
+ # @param ip [String]
121
+
122
+ def ip_lkup(ip)
123
+ send_req({a: :ip_lkup, ip: ip})
124
+ end
125
+
126
+ # This function retrieves all current settings for a given domain.
127
+ #
128
+ # @see http://www.cloudflare.com/docs/client-api.html#s3.7
129
+ #
130
+ # @param zone [String]
131
+
132
+ def zone_settings(zone)
133
+ send_req({a: :zone_settings, z: zone})
134
+ end
135
+
136
+ # This function sets the Basic Security Level to HELP I'M UNDER ATTACK / HIGH / MEDIUM / LOW / ESSENTIALLY OFF.
137
+ #
138
+ # @see http://www.cloudflare.com/docs/client-api.html#s4.1
139
+ #
140
+ # @param zone [String]
141
+ # @param value [String] values: low|med|high|help|eoff
142
+
143
+ def sec_lvl(zone, value)
144
+ send_req({a: :sec_lvl, z: zone, v: value})
145
+ end
146
+
147
+ # This function sets the Caching Level to Aggressive or Basic.
148
+ #
149
+ # @see http://www.cloudflare.com/docs/client-api.html#s4.2
150
+ #
151
+ # @param zone [String]
152
+ # @param value [String] values: agg|basic
153
+
154
+ def cache_lvl(zone, value)
155
+ send_req({a: :cache_lvl, z: zone, v: value})
156
+ end
157
+
158
+ # This function allows you to toggle Development Mode on or off for a particular domain.
159
+ #
160
+ # @see http://www.cloudflare.com/docs/client-api.html#s4.3
161
+ #
162
+ # @param zone [String]
163
+ # @param value [Boolean]
164
+
165
+ def devmode(zone, value)
166
+ send_req({a: :devmode, z: zone, v: value ? 1 : 0})
167
+ end
168
+
169
+ # This function will purge CloudFlare of any cached files.
170
+ #
171
+ # @see http://www.cloudflare.com/docs/client-api.html#s4.4
172
+ #
173
+ # @param zone [String]
174
+
175
+ def fpurge_ts(zone)
176
+ send_req({a: :fpurge_ts, z: zone, v: 1})
177
+ end
178
+
179
+ # This function will purge a single file from CloudFlare's cache.
180
+ #
181
+ # @see http://www.cloudflare.com/docs/client-api.html#s4.5
182
+ #
183
+ # @param zone [String]
184
+ # @param url [String]
185
+
186
+ def zone_file_purge(zone, url)
187
+ send_req({a: :zone_file_purge, z: zone, url: url})
188
+ end
189
+
190
+ # This function updates the snapshot of your site for CloudFlare's challenge page.
191
+ #
192
+ # @see http://www.cloudflare.com/docs/client-api.html#s4.6
193
+ #
194
+ # @param zoneid [Integer]
195
+
196
+ def zone_grab(zoneid)
197
+ send_req({a: :zone_grab, zid: zoneid})
198
+ end
199
+
200
+ # This function adds an IP address to your white lists.
201
+ #
202
+ # @see http://www.cloudflare.com/docs/client-api.html#s4.7
203
+ #
204
+ # @param ip [String]
205
+
206
+ def whitelist(ip)
207
+ send_req({a: :wl, key: ip})
208
+ end
209
+
210
+
211
+ # This function adds an IP address to your black lists.
212
+ #
213
+ # @see http://www.cloudflare.com/docs/client-api.html#s4.7
214
+ #
215
+ # @param ip [String]
216
+
217
+ def blacklist(ip)
218
+ send_req({a: :ban, key: ip})
219
+ end
220
+
221
+ # This function removes the IP from whitelist or blacklist.
222
+ #
223
+ # @see http://www.cloudflare.com/docs/client-api.html#s4.7
224
+ #
225
+ # @param ip [String]
226
+
227
+ def remove_ip(ip)
228
+ send_req({a: :nul, key: ip})
229
+ end
230
+
231
+ # This function toggles IPv6 support.
232
+ #
233
+ # @see http://www.cloudflare.com/docs/client-api.html#s4.8
234
+ #
235
+ # @param zone [String]
236
+ # @param value [Boolean]
237
+
238
+ def ipv46(zone, value)
239
+ send_req({a: :ipv46, z: zone, v: value ? 1 : 0})
240
+ end
241
+
242
+ # This function changes Rocket Loader setting.
243
+ #
244
+ # @see http://www.cloudflare.com/docs/client-api.html#s4.9
245
+ #
246
+ # @param zone [String]
247
+ # @param value [Integer or String] values: 0|a|m
248
+
249
+ def async(zone, value)
250
+ send_req({a: :async, z: zone, v: value})
251
+ end
252
+
253
+ # This function changes minification settings.
254
+ #
255
+ # @see http://www.cloudflare.com/docs/client-api.html#s4.10
256
+ #
257
+ # @param zone [String]
258
+ # @param value [Integer] values: 0|2|3|4|5|6|7
259
+
260
+ def minify(zone, value)
261
+ send_req({a: :minify, z: zone, v: value})
262
+ end
263
+
264
+
265
+ # This function changes mirage2 settings.
266
+ #
267
+ # @see http://www.cloudflare.com/docs/client-api.html#s4.11
268
+ #
269
+ # @param zone [String]
270
+ # @param value [Integer] values: 0|1
271
+
272
+ def mirage2(zone, value)
273
+ send_req({a: :mirage2, z: zone, v: value})
274
+ end
275
+
276
+ # This function creates a new DNS record for your site. This can be either a CNAME or A record.
277
+ #
278
+ # @see http://www.cloudflare.com/docs/client-api.html#s5.1
279
+ #
280
+ # @param zone [String]
281
+ # @param type [String] values: A|CNAME|MX|TXT|SPF|AAAA|NS|SRV|LOC
282
+ # @param name [String]
283
+ # @param content [String]
284
+ # @param ttl [Integer] values: 1|120...4294967295
285
+ # @param prio [Integer] (applies to MX/SRV)
286
+ # @param service [String] (applies to SRV)
287
+ # @param srvname [String] (applies to SRV)
288
+ # @param protocol [Integer] (applies to SRV) values: _tcp|_udp|_tls
289
+ # @param weight [Intger] (applies to SRV)
290
+ # @param port [Integer] (applies to SRV)
291
+ # @param target [String] (applies to SRV)
292
+
293
+ def rec_new(zone, type, name, content, ttl, prio = nil, service = nil, srvname = nil, protocol = nil, weight = nil, port = nil, target = nil)
294
+ send_req({
295
+ a: :rec_new,
296
+ z: zone,
297
+ type: type,
298
+ name: name,
299
+ content: content,
300
+ ttl: ttl,
301
+ prio: prio,
302
+ service: service,
303
+ srvname: srvname,
304
+ protocol: protocol,
305
+ weight: weight,
306
+ port: port,
307
+ target: target,
308
+ service_mode: '1'
309
+ })
310
+ end
311
+
312
+ # This function edits a DNS record for a zone.
313
+ #
314
+ # @see http://www.cloudflare.com/docs/client-api.html#s5.2
315
+ #
316
+ # @param zone [String]
317
+ # @param type [String] values: A|CNAME|MX|TXT|SPF|AAAA|NS|SRV|LOC
318
+ # @param record_id [Integer]
319
+ # @param name [String]
320
+ # @param content [String]
321
+ # @param ttl [Integer] values: 1|120...4294967295
322
+ # @param service_mode [Boolean] (applies to A/AAAA/CNAME)
323
+ # @param prio [Integer] (applies to MX/SRV)
324
+ # @param service [String] (applies to SRV)
325
+ # @param srvname [String] (applies to SRV)
326
+ # @param protocol [Integer] (applies to SRV) values: _tcp/_udp/_tls
327
+ # @param weight [Intger] (applies to SRV)
328
+ # @param port [Integer] (applies to SRV)
329
+ # @param target [String] (applies to SRV)
330
+
331
+ def rec_edit(zone, type, record_id, name, content, ttl, service_mode = nil, prio = nil, service = nil, srvname = nil, protocol = nil, weight = nil, port = nil, target = nil)
332
+ send_req({
333
+ a: :rec_edit,
334
+ z: zone,
335
+ type: type,
336
+ id: record_id,
337
+ name: name,
338
+ content: content,
339
+ ttl: ttl,
340
+ service_mode: service_mode ? 1 : 0,
341
+ prio: prio,
342
+ service: service,
343
+ srvname: srvname,
344
+ protocol: protocol,
345
+ weight: weight,
346
+ port: port,
347
+ target: target
348
+ })
349
+ end
350
+
351
+ # This functon deletes a record for a domain.
352
+ #
353
+ # @see http://www.cloudflare.com/docs/client-api.html#s5.3
354
+ #
355
+ # @param zone [String]
356
+ # @param zoneid [Integer]
357
+
358
+ def rec_delete(zone, zoneid)
359
+ send_req({a: :rec_delete, z: zone, id: zoneid})
360
+ end
361
+
362
+ # HOST
363
+
364
+ # This function creates a CloudFlare account mapped to your user.
365
+ #
366
+ # @see http://www.cloudflare.com/docs/host-api.html#s3.2.1
367
+ #
368
+ # @param email [String]
369
+ # @param pass [String]
370
+ # @param login [String] (optional) cloudflare_username
371
+ # @param id [Integer] (optional) unique_id
372
+ # @param cui [Integer] (optional) clobber_unique_id
373
+
374
+ def create_user(email, pass, login = nil, id = nil, cui = nil)
375
+ send_req({
376
+ act: :user_create,
377
+ cloudflare_email: email,
378
+ cloudflare_pass: pass,
379
+ cloudflare_username: login,
380
+ unique_id: id,
381
+ clobber_unique_id: cui
382
+ })
383
+ end
384
+
385
+ # This function setups a User's zone for CNAME hosting.
386
+ #
387
+ # @see http://www.cloudflare.com/docs/host-api.html#s3.2.2
388
+ #
389
+ # @param user_key [String]
390
+ # @param zone [String]
391
+ # @param resolve_to [String]
392
+ # @param subdomains [String or Array]
393
+
394
+ def add_zone(user_key, zone, resolve_to, subdomains)
395
+ send_req({
396
+ act: :zone_set,
397
+ user_key: user_key,
398
+ zone_name: zone,
399
+ resolve_to: resolve_to,
400
+ subdomains: subdomains.kind_of?(Array) ? zones.join(',') : subdomains
401
+ })
402
+ end
403
+
404
+ # This function lookups a user's CloudFlare account information.
405
+ #
406
+ # @see http://www.cloudflare.com/docs/host-api.html#s3.2.3
407
+ #
408
+ # *Example:*
409
+ #
410
+ # cf = CloudFlare('your_host_key')
411
+ # cf.user_lookup('unique_id', true)
412
+ #
413
+ # If +id+ is set to true, email is a unique_id.
414
+ #
415
+ # @param email [String or Integer]
416
+ # @param id [Boolean]
417
+
418
+ def user_lookup(email, id = false)
419
+ if id
420
+ send_req({act: :user_lookup, unique_id: email})
421
+ else
422
+ send_req({act: :user_lookup, cloudflare_email: email})
423
+ end
424
+ end
425
+
426
+ # This function authorizes access to a user's existing CloudFlare account.
427
+ #
428
+ # @see http://www.cloudflare.com/docs/host-api.html#s3.2.4
429
+ #
430
+ # @param email [String]
431
+ # @param pass [String]
432
+ # @param unique_id [Integer] (optional)
433
+ # @param cui [Integer] (optional) clobber_unique_id
434
+
435
+ def user_auth(email, pass, id = nil, cui = nil)
436
+ send_req({
437
+ act: :user_auth,
438
+ cloudflare_email: email,
439
+ cloudflare_pass: pass,
440
+ unique_id: id,
441
+ clobber_unique_id: cui
442
+ })
443
+ end
444
+
445
+ # This function lookups a specific user's zone.
446
+ #
447
+ # @see http://www.cloudflare.com/docs/host-api.html#s3.2.5
448
+ #
449
+ # @param user_key [String]
450
+ # @param zone [String]
451
+
452
+ def zone_lookup(user_key, zone)
453
+ send_req({act: :zone_lookup, user_key: user_key, zone_name: zone})
454
+ end
455
+
456
+ # This function deletes a specific zone on behalf of a user.
457
+ #
458
+ # @see http://www.cloudflare.com/docs/host-api.html#s3.2.6
459
+ #
460
+ # @param user_key [String]
461
+ # @param zone [String]
462
+
463
+ def del_zone(user_key, zone)
464
+ send_req({act: :zone_delete, user_key: user_key, zone_name: zone})
465
+ end
466
+
467
+ # This function creates a new child host provider.
468
+ #
469
+ # @see http://www.cloudflare.com/docs/host-api.html#s3.2.7
470
+ #
471
+ # @param host_name [String]
472
+ # @param pub_name [String]
473
+ # @param prefix [String]
474
+ # @param website [String]
475
+ # @param email [String]
476
+
477
+ def host_child_new(host_name, pub_name, prefix, website, email)
478
+ send_req({
479
+ act: :host_child_new,
480
+ pub_name: pub_name,
481
+ prefix: prefix,
482
+ website: website,
483
+ email: email
484
+ })
485
+ end
486
+
487
+ # This function regenerates your host key.
488
+ #
489
+ # @see http://www.cloudflare.com/docs/host-api.html#s3.2.8
490
+
491
+ def host_key_regen
492
+ send_req(act: :host_key_regen)
493
+ end
494
+
495
+ # This function stops a child host provider account.
496
+ #
497
+ # @see http://www.cloudflare.com/docs/host-api.html#s3.2.9
498
+ #
499
+ # @param id [Integer] child_id
500
+
501
+ def host_child_stop(id)
502
+ send_req({act: :host_child_stop, child_id: id})
503
+ end
504
+
505
+ # This function lists the domains currently active on CloudFlare for the given host.
506
+ #
507
+ # @see http://www.cloudflare.com/docs/host-api.html#s3.2.10
508
+ #
509
+ # @param limit [Integer] (optional)
510
+ # @param offset [Integer] (optional)
511
+ # @param name [String] (optional) zone_name
512
+ # @param sub_id [Integer] (optional) sub_id
513
+ # @param status [String] (optional) values: V|D|ALL
514
+
515
+ def zone_list(limit = 100, offset = 0, name = nil, sub_id = nil, status = nil)
516
+ send_req({
517
+ act: :zone_list,
518
+ offset: offset,
519
+ zone_name: name,
520
+ sub_id: sub_id,
521
+ zone_status: status
522
+ })
523
+ end
524
+
525
+ private
526
+
527
+ def send_req(params)
528
+ if @params[:email]
529
+ params[:tkn] = @params[:api_key]
530
+ params[:u] = @params[:email]
531
+ uri = URI(URL_API[:client])
532
+ else
533
+ params[:host_key] = @params[:api_key]
534
+ uri = URI(URL_API[:host])
535
+ end
536
+
537
+ req = Net::HTTP::Post.new(uri.path)
538
+ req.set_form_data(params)
539
+
540
+ http = Net::HTTP.new(uri.host, uri.port)
541
+ http.use_ssl = true
542
+ http.read_timeout = TIMEOUT
543
+
544
+ res = http.request(req)
545
+ out = JSON.parse(res.body)
546
+
547
+ # If there is an error, raise an exception:
548
+ if out['result'] == 'error'
549
+ raise RequestError.new(out['msg'], out)
550
+ else
551
+ return out
552
+ end
553
+ end
554
+ end
554
555
  end
@@ -1,15 +1,15 @@
1
1
  # Copyright, 2012, by Marcin Prokop.
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
5
5
  # in the Software without restriction, including without limitation the rights
6
6
  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
7
  # copies of the Software, and to permit persons to whom the Software is
8
8
  # furnished to do so, subject to the following conditions:
9
- #
9
+ #
10
10
  # The above copyright notice and this permission notice shall be included in
11
11
  # all copies or substantial portions of the Software.
12
- #
12
+ #
13
13
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
14
  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
15
  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module CloudFlare
22
- VERSION = '2.0.1'
22
+ VERSION = '2.0.2'
23
23
  end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudflare
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcin Prokop
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-19 00:00:00.000000000 Z
11
+ date: 2014-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: A Ruby wrapper for the CloudFlare API.
@@ -61,19 +61,19 @@ licenses:
61
61
  metadata: {}
62
62
  post_install_message:
63
63
  rdoc_options:
64
- - --main
64
+ - "--main"
65
65
  - README.md
66
- - --charset=UTF-8
66
+ - "--charset=UTF-8"
67
67
  require_paths:
68
68
  - lib
69
69
  required_ruby_version: !ruby/object:Gem::Requirement
70
70
  requirements:
71
- - - '>='
71
+ - - ">="
72
72
  - !ruby/object:Gem::Version
73
73
  version: 1.9.0
74
74
  required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  requirements:
76
- - - '>='
76
+ - - ">="
77
77
  - !ruby/object:Gem::Version
78
78
  version: '0'
79
79
  requirements: []