Skip to content

Commit

Permalink
Add/upadate methods to Cloudflare API v1.1.1
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
b4k3r committed May 17, 2016
1 parent 91e7182 commit d55f897
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 74 deletions.
32 changes: 16 additions & 16 deletions cloudflare.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ $LOAD_PATH.push File.expand_path("../lib", __FILE__)
require 'cloudflare/version'

Gem::Specification.new do |s|
s.name = 'cloudflare'
s.version = CloudFlare::VERSION
s.platform = Gem::Platform::RUBY
s.name = 'cloudflare'
s.version = CloudFlare::VERSION
s.platform = Gem::Platform::RUBY

s.description = 'A Ruby wrapper for the CloudFlare API.'
s.summary = 'A Ruby wrapper for the CloudFlare API.'
s.authors = ['Marcin Prokop']
s.email = '[email protected]'
s.homepage = 'https://github.com/b4k3r/cloudflare'
s.licenses = ['MIT']
s.description = 'A Ruby wrapper for the CloudFlare API.'
s.summary = 'A Ruby wrapper for the CloudFlare API.'
s.authors = ['Marcin Prokop']
s.email = '[email protected]'
s.homepage = 'https://github.com/b4k3r/cloudflare'
s.licenses = ['MIT']

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

s.required_ruby_version = '>= 1.9.0'
s.add_runtime_dependency 'json', '~> 1'
s.add_development_dependency 'rake'
s.required_ruby_version = '>= 1.9.0'
s.add_runtime_dependency 'json', '~> 1'
s.add_development_dependency 'rake'
end
12 changes: 6 additions & 6 deletions lib/cloudflare.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Copyright, 2012, by Marcin Prokop.
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -21,7 +21,7 @@
require 'cloudflare/connection'

module CloudFlare
def self.connection(api_key, email = nil)
Connection.new(api_key, email)
end
def self.connection(api_key, email = nil)
Connection.new(api_key, email)
end
end
90 changes: 39 additions & 51 deletions lib/cloudflare/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def initialize(api_key, email = nil)
@params[:api_key] = api_key
@params[:email] = email
end

end

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

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

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

Expand Down Expand Up @@ -187,19 +188,9 @@ def zone_file_purge(zone, url)
send_req({a: :zone_file_purge, z: zone, url: url})
end

# This function updates the snapshot of your site for CloudFlare's challenge page.
#
# @see http://www.cloudflare.com/docs/client-api.html#s4.6
#
# @param zoneid [Integer]

def zone_grab(zoneid)
send_req({a: :zone_grab, zid: zoneid})
end

# This function adds an IP address to your white lists.
#
# @see http://www.cloudflare.com/docs/client-api.html#s4.7
# @see http://www.cloudflare.com/docs/client-api.html#s4.6
#
# @param ip [String]

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

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

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

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

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

# This function toggles IPv6 support.
#
# @see http://www.cloudflare.com/docs/client-api.html#s4.8
# @see http://www.cloudflare.com/docs/client-api.html#s4.7
#
# @param zone [String]
# @param value [Boolean]
Expand All @@ -241,7 +232,7 @@ def ipv46(zone, value)

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

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

# This function changes mirage2 settings.
#
# @see http://www.cloudflare.com/docs/client-api.html#s4.11
# @see http://www.cloudflare.com/docs/client-api.html#s4.10
#
# @param zone [String]
# @param value [Integer] values: 0|1
Expand All @@ -289,9 +280,9 @@ def mirage2(zone, value)
# @param weight [Intger] (applies to SRV)
# @param port [Integer] (applies to SRV)
# @param target [String] (applies to SRV)
# @param service_mode [String]
# @param service_mode [Boolean] (applies to A/AAAA/CNAME)

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')
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)
send_req({
a: :rec_new,
z: zone,
Expand All @@ -306,7 +297,7 @@ def rec_new(zone, type, name, content, ttl, prio = nil, service = nil, srvname =
weight: weight,
port: port,
target: target,
service_mode: service_mode
service_mode: service_mode ? 1 : 0,
})
end

Expand All @@ -320,16 +311,16 @@ def rec_new(zone, type, name, content, ttl, prio = nil, service = nil, srvname =
# @param name [String]
# @param content [String]
# @param ttl [Integer] values: 1|120...4294967295
# @param service_mode [Boolean] (applies to A/AAAA/CNAME)
# @param prio [Integer] (applies to MX/SRV)
# @param service [String] (applies to SRV)
# @param srvname [String] (applies to SRV)
# @param protocol [Integer] (applies to SRV) values: _tcp/_udp/_tls
# @param weight [Intger] (applies to SRV)
# @param port [Integer] (applies to SRV)
# @param target [String] (applies to SRV)
# @param service_mode [Boolean] (applies to A/AAAA/CNAME)

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)
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)
send_req({
a: :rec_edit,
z: zone,
Expand All @@ -338,14 +329,14 @@ def rec_edit(zone, type, record_id, name, content, ttl, service_mode = nil, prio
name: name,
content: content,
ttl: ttl,
service_mode: service_mode ? 1 : 0,
prio: prio,
service: service,
srvname: srvname,
protocol: protocol,
weight: weight,
port: port,
target: target
target: target,
service_mode: service_mode ? 1 : 0,
})
end

Expand Down Expand Up @@ -402,10 +393,25 @@ def add_zone(user_key, zone, resolve_to, subdomains)
})
end

# This function lookups a user's CloudFlare account information.
# This function adds a zone using the full setup.
#
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.3
#
# @param user_key [String]
# @param zone [String]

def add_full_zone(user_key, zone)
send_req({
act: :full_zone_set,
user_key: user_key,
zone_name: zone
})
end

# This function lookups a user's CloudFlare account information.
#
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.4
#
# *Example:*
#
# cf = CloudFlare('your_host_key')
Expand All @@ -426,7 +432,7 @@ def user_lookup(email, id = false)

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

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

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

# This function creates a new child host provider.
#
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.7
#
# @param host_name [String]
# @param pub_name [String]
# @param prefix [String]
# @param website [String]
# @param email [String]

def host_child_new(host_name, pub_name, prefix, website, email)
send_req({
act: :host_child_new,
pub_name: pub_name,
prefix: prefix,
website: website,
email: email
})
end

# This function regenerates your host key.
#
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.8
Expand Down Expand Up @@ -512,14 +498,16 @@ def host_child_stop(id)
# @param name [String] (optional) zone_name
# @param sub_id [Integer] (optional) sub_id
# @param status [String] (optional) values: V|D|ALL
# @param sub_status [String] (optional) values: V|CNL|ALL

def zone_list(limit = 100, offset = 0, name = nil, sub_id = nil, status = nil)
def zone_list(limit = 100, offset = 0, name = nil, sub_id = nil, status = nil, sub_status = nil)
send_req({
act: :zone_list,
offset: offset,
zone_name: name,
sub_id: sub_id,
zone_status: status
zone_status: status,
sub_status: sub_status
})
end

Expand Down
2 changes: 1 addition & 1 deletion lib/cloudflare/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
# THE SOFTWARE.

module CloudFlare
VERSION = '2.0.3'
VERSION = '2.1.0'
end

0 comments on commit d55f897

Please sign in to comment.