Skip to content

Commit d55f897

Browse files
committed
Add/upadate methods to Cloudflare API v1.1.1
* Deprecate zone_ips method * Remove zone_grab method * Fix service_mode in rec_new and rec_edit methods, service_mode parameter takes boolean values * Add full_zone_set API * Remove host_child_new method * Add sub_status parameter to zone_list method
1 parent 91e7182 commit d55f897

4 files changed

Lines changed: 62 additions & 74 deletions

File tree

cloudflare.gemspec

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ $LOAD_PATH.push File.expand_path("../lib", __FILE__)
33
require 'cloudflare/version'
44

55
Gem::Specification.new do |s|
6-
s.name = 'cloudflare'
7-
s.version = CloudFlare::VERSION
8-
s.platform = Gem::Platform::RUBY
6+
s.name = 'cloudflare'
7+
s.version = CloudFlare::VERSION
8+
s.platform = Gem::Platform::RUBY
99

10-
s.description = 'A Ruby wrapper for the CloudFlare API.'
11-
s.summary = 'A Ruby wrapper for the CloudFlare API.'
12-
s.authors = ['Marcin Prokop']
13-
s.email = 'marcin@prokop.co'
14-
s.homepage = 'https://github.com/b4k3r/cloudflare'
15-
s.licenses = ['MIT']
10+
s.description = 'A Ruby wrapper for the CloudFlare API.'
11+
s.summary = 'A Ruby wrapper for the CloudFlare API.'
12+
s.authors = ['Marcin Prokop']
13+
s.email = 'marcin@prokop.co'
14+
s.homepage = 'https://github.com/b4k3r/cloudflare'
15+
s.licenses = ['MIT']
1616

17-
s.files = `git ls-files`.split("\n")
18-
s.test_files = ['test/test_cloudflare.rb']
19-
s.rdoc_options = ['--main', 'README.md', '--charset=UTF-8']
20-
s.extra_rdoc_files = ['README.md', 'LICENSE']
17+
s.files = `git ls-files`.split("\n")
18+
s.test_files = ['test/test_cloudflare.rb']
19+
s.rdoc_options = ['--main', 'README.md', '--charset=UTF-8']
20+
s.extra_rdoc_files = ['README.md', 'LICENSE']
2121

22-
s.required_ruby_version = '>= 1.9.0'
23-
s.add_runtime_dependency 'json', '~> 1'
24-
s.add_development_dependency 'rake'
22+
s.required_ruby_version = '>= 1.9.0'
23+
s.add_runtime_dependency 'json', '~> 1'
24+
s.add_development_dependency 'rake'
2525
end

lib/cloudflare.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Copyright, 2012, by Marcin Prokop.
2-
#
2+
#
33
# Permission is hereby granted, free of charge, to any person obtaining a copy
44
# of this software and associated documentation files (the "Software"), to deal
55
# in the Software without restriction, including without limitation the rights
66
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
77
# copies of the Software, and to permit persons to whom the Software is
88
# furnished to do so, subject to the following conditions:
9-
#
9+
#
1010
# The above copyright notice and this permission notice shall be included in
1111
# all copies or substantial portions of the Software.
12-
#
12+
#
1313
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1414
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1515
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -21,7 +21,7 @@
2121
require 'cloudflare/connection'
2222

2323
module CloudFlare
24-
def self.connection(api_key, email = nil)
25-
Connection.new(api_key, email)
26-
end
24+
def self.connection(api_key, email = nil)
25+
Connection.new(api_key, email)
26+
end
2727
end

lib/cloudflare/connection.rb

Lines changed: 39 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ def initialize(api_key, email = nil)
5656
@params[:api_key] = api_key
5757
@params[:email] = email
5858
end
59-
6059
end
6160

6261
# CLIENT
@@ -100,6 +99,7 @@ def zone_check(*zones)
10099
send_req({a: :zone_check, zones: zones.kind_of?(Array) ? zones.join(',') : zones})
101100
end
102101

102+
# DEPRECATED!
103103
# This function pulls recent IPs hitting your site.
104104
#
105105
# @see http://www.cloudflare.com/docs/client-api.html#s3.5
@@ -110,6 +110,7 @@ def zone_check(*zones)
110110
# @param geo [Fixnum] (optional)
111111

112112
def zone_ips(zone, classification = nil, hours = 24, geo = 1)
113+
puts 'Warning! This method is deprecated.'
113114
send_req({a: :zone_ips, z: zone, hours: hours, "class" => classification, geo: geo})
114115
end
115116

@@ -187,19 +188,9 @@ def zone_file_purge(zone, url)
187188
send_req({a: :zone_file_purge, z: zone, url: url})
188189
end
189190

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-
200191
# This function adds an IP address to your white lists.
201192
#
202-
# @see http://www.cloudflare.com/docs/client-api.html#s4.7
193+
# @see http://www.cloudflare.com/docs/client-api.html#s4.6
203194
#
204195
# @param ip [String]
205196

@@ -210,7 +201,7 @@ def whitelist(ip)
210201

211202
# This function adds an IP address to your black lists.
212203
#
213-
# @see http://www.cloudflare.com/docs/client-api.html#s4.7
204+
# @see http://www.cloudflare.com/docs/client-api.html#s4.6
214205
#
215206
# @param ip [String]
216207

@@ -220,7 +211,7 @@ def blacklist(ip)
220211

221212
# This function removes the IP from whitelist or blacklist.
222213
#
223-
# @see http://www.cloudflare.com/docs/client-api.html#s4.7
214+
# @see http://www.cloudflare.com/docs/client-api.html#s4.6
224215
#
225216
# @param ip [String]
226217

@@ -230,7 +221,7 @@ def remove_ip(ip)
230221

231222
# This function toggles IPv6 support.
232223
#
233-
# @see http://www.cloudflare.com/docs/client-api.html#s4.8
224+
# @see http://www.cloudflare.com/docs/client-api.html#s4.7
234225
#
235226
# @param zone [String]
236227
# @param value [Boolean]
@@ -241,7 +232,7 @@ def ipv46(zone, value)
241232

242233
# This function changes Rocket Loader setting.
243234
#
244-
# @see http://www.cloudflare.com/docs/client-api.html#s4.9
235+
# @see http://www.cloudflare.com/docs/client-api.html#s4.8
245236
#
246237
# @param zone [String]
247238
# @param value [Integer or String] values: 0|a|m
@@ -252,7 +243,7 @@ def async(zone, value)
252243

253244
# This function changes minification settings.
254245
#
255-
# @see http://www.cloudflare.com/docs/client-api.html#s4.10
246+
# @see http://www.cloudflare.com/docs/client-api.html#s4.9
256247
#
257248
# @param zone [String]
258249
# @param value [Integer] values: 0|2|3|4|5|6|7
@@ -264,7 +255,7 @@ def minify(zone, value)
264255

265256
# This function changes mirage2 settings.
266257
#
267-
# @see http://www.cloudflare.com/docs/client-api.html#s4.11
258+
# @see http://www.cloudflare.com/docs/client-api.html#s4.10
268259
#
269260
# @param zone [String]
270261
# @param value [Integer] values: 0|1
@@ -289,9 +280,9 @@ def mirage2(zone, value)
289280
# @param weight [Intger] (applies to SRV)
290281
# @param port [Integer] (applies to SRV)
291282
# @param target [String] (applies to SRV)
292-
# @param service_mode [String]
283+
# @param service_mode [Boolean] (applies to A/AAAA/CNAME)
293284

294-
def rec_new(zone, type, name, content, ttl, prio = nil, service = nil, srvname = nil, protocol = nil, weight = nil, port = nil, target = nil, service_mode = '1')
285+
def rec_new(zone, type, name, content, ttl, prio = nil, service = nil, srvname = nil, protocol = nil, weight = nil, port = nil, target = nil, service_mode = true)
295286
send_req({
296287
a: :rec_new,
297288
z: zone,
@@ -306,7 +297,7 @@ def rec_new(zone, type, name, content, ttl, prio = nil, service = nil, srvname =
306297
weight: weight,
307298
port: port,
308299
target: target,
309-
service_mode: service_mode
300+
service_mode: service_mode ? 1 : 0,
310301
})
311302
end
312303

@@ -320,16 +311,16 @@ def rec_new(zone, type, name, content, ttl, prio = nil, service = nil, srvname =
320311
# @param name [String]
321312
# @param content [String]
322313
# @param ttl [Integer] values: 1|120...4294967295
323-
# @param service_mode [Boolean] (applies to A/AAAA/CNAME)
324314
# @param prio [Integer] (applies to MX/SRV)
325315
# @param service [String] (applies to SRV)
326316
# @param srvname [String] (applies to SRV)
327317
# @param protocol [Integer] (applies to SRV) values: _tcp/_udp/_tls
328318
# @param weight [Intger] (applies to SRV)
329319
# @param port [Integer] (applies to SRV)
330320
# @param target [String] (applies to SRV)
321+
# @param service_mode [Boolean] (applies to A/AAAA/CNAME)
331322

332-
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)
323+
def rec_edit(zone, type, record_id, name, content, ttl, prio = nil, service = nil, srvname = nil, protocol = nil, weight = nil, port = nil, target = nil, service_mode = true)
333324
send_req({
334325
a: :rec_edit,
335326
z: zone,
@@ -338,14 +329,14 @@ def rec_edit(zone, type, record_id, name, content, ttl, service_mode = nil, prio
338329
name: name,
339330
content: content,
340331
ttl: ttl,
341-
service_mode: service_mode ? 1 : 0,
342332
prio: prio,
343333
service: service,
344334
srvname: srvname,
345335
protocol: protocol,
346336
weight: weight,
347337
port: port,
348-
target: target
338+
target: target,
339+
service_mode: service_mode ? 1 : 0,
349340
})
350341
end
351342

@@ -402,10 +393,25 @@ def add_zone(user_key, zone, resolve_to, subdomains)
402393
})
403394
end
404395

405-
# This function lookups a user's CloudFlare account information.
396+
# This function adds a zone using the full setup.
406397
#
407398
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.3
408399
#
400+
# @param user_key [String]
401+
# @param zone [String]
402+
403+
def add_full_zone(user_key, zone)
404+
send_req({
405+
act: :full_zone_set,
406+
user_key: user_key,
407+
zone_name: zone
408+
})
409+
end
410+
411+
# This function lookups a user's CloudFlare account information.
412+
#
413+
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.4
414+
#
409415
# *Example:*
410416
#
411417
# cf = CloudFlare('your_host_key')
@@ -426,7 +432,7 @@ def user_lookup(email, id = false)
426432

427433
# This function authorizes access to a user's existing CloudFlare account.
428434
#
429-
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.4
435+
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.5
430436
#
431437
# @param email [String]
432438
# @param pass [String]
@@ -445,7 +451,7 @@ def user_auth(email, pass, id = nil, cui = nil)
445451

446452
# This function lookups a specific user's zone.
447453
#
448-
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.5
454+
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.6
449455
#
450456
# @param user_key [String]
451457
# @param zone [String]
@@ -456,7 +462,7 @@ def zone_lookup(user_key, zone)
456462

457463
# This function deletes a specific zone on behalf of a user.
458464
#
459-
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.6
465+
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.7
460466
#
461467
# @param user_key [String]
462468
# @param zone [String]
@@ -465,26 +471,6 @@ def del_zone(user_key, zone)
465471
send_req({act: :zone_delete, user_key: user_key, zone_name: zone})
466472
end
467473

468-
# This function creates a new child host provider.
469-
#
470-
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.7
471-
#
472-
# @param host_name [String]
473-
# @param pub_name [String]
474-
# @param prefix [String]
475-
# @param website [String]
476-
# @param email [String]
477-
478-
def host_child_new(host_name, pub_name, prefix, website, email)
479-
send_req({
480-
act: :host_child_new,
481-
pub_name: pub_name,
482-
prefix: prefix,
483-
website: website,
484-
email: email
485-
})
486-
end
487-
488474
# This function regenerates your host key.
489475
#
490476
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.8
@@ -512,14 +498,16 @@ def host_child_stop(id)
512498
# @param name [String] (optional) zone_name
513499
# @param sub_id [Integer] (optional) sub_id
514500
# @param status [String] (optional) values: V|D|ALL
501+
# @param sub_status [String] (optional) values: V|CNL|ALL
515502

516-
def zone_list(limit = 100, offset = 0, name = nil, sub_id = nil, status = nil)
503+
def zone_list(limit = 100, offset = 0, name = nil, sub_id = nil, status = nil, sub_status = nil)
517504
send_req({
518505
act: :zone_list,
519506
offset: offset,
520507
zone_name: name,
521508
sub_id: sub_id,
522-
zone_status: status
509+
zone_status: status,
510+
sub_status: sub_status
523511
})
524512
end
525513

lib/cloudflare/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
# THE SOFTWARE.
2020

2121
module CloudFlare
22-
VERSION = '2.0.3'
22+
VERSION = '2.1.0'
2323
end

0 commit comments

Comments
 (0)