cloudflare 2.1.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +4 -0
- data/.travis.yml +19 -0
- data/Gemfile +13 -1
- data/README.md +50 -35
- data/Rakefile +19 -5
- data/cloudflare.gemspec +22 -20
- data/lib/cloudflare.rb +8 -5
- data/lib/cloudflare/connection.rb +31 -520
- data/lib/cloudflare/response.rb +73 -0
- data/lib/cloudflare/rspec/connection.rb +36 -0
- data/lib/cloudflare/user.rb +33 -0
- data/lib/cloudflare/version.rb +3 -2
- data/lib/cloudflare/zone.rb +110 -0
- data/spec/cloudflare/zone_spec.rb +41 -0
- data/spec/spec_helper.rb +30 -0
- metadata +54 -21
- data/LICENSE +0 -8
- data/test/test_cloudflare.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a110e823c75c13f404a65302681c7dfa94259b7
|
4
|
+
data.tar.gz: 9124f505ca1db512e237515ffb5936921a2981b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45ece12909dddffe400565bad14412a58d33d1e062a4744676a4b1a6cc3e33a959aa56ee8a6d5f022c34fa31909edc46a3a9b3f7e56e84a2b4d6fb0d4fe22da2
|
7
|
+
data.tar.gz: 7190a218eeb9dd39b2dc43c1ce4c8ed7b9a5bd20aefdfbd3be583886f16d601360d53eb58d4fd5e4d0f1f92910cbefc9c1372785c4799ecbaac83603502f76e5
|
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
language: ruby
|
2
|
+
sudo: false
|
3
|
+
dist: trusty
|
4
|
+
cache: bundler
|
5
|
+
rvm:
|
6
|
+
- 2.0
|
7
|
+
- 2.1
|
8
|
+
- 2.2
|
9
|
+
- 2.3
|
10
|
+
- 2.4
|
11
|
+
- jruby-head
|
12
|
+
- ruby-head
|
13
|
+
matrix:
|
14
|
+
allow_failures:
|
15
|
+
- rvm: ruby-head
|
16
|
+
- rvm: jruby-head
|
17
|
+
env:
|
18
|
+
global:
|
19
|
+
secure: c5yG7N1r9nYuw47Y90jGeoHNvkL59AAC55dtPAhKP+gjXWW8hKbntj3oj+lVkxEqzRpzEQgYZzUElrP+6mJnb20ldclZg03L56243tMtVEcpGOx/MFhnIBkx3kKu1H6ydKKMxieHxjsLQ3vnpcIZ3p0skTQjYbjdu607tjbyg7s=
|
data/Gemfile
CHANGED
@@ -1,4 +1,16 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
# Specify your gem's dependencies in
|
3
|
+
# Specify your gem's dependencies in utopia.gemspec
|
4
4
|
gemspec
|
5
|
+
|
6
|
+
group :development do
|
7
|
+
gem 'pry'
|
8
|
+
gem 'pry-coolline'
|
9
|
+
|
10
|
+
gem 'tty-prompt'
|
11
|
+
end
|
12
|
+
|
13
|
+
group :test do
|
14
|
+
gem 'simplecov'
|
15
|
+
gem 'coveralls', require: false
|
16
|
+
end
|
data/README.md
CHANGED
@@ -1,60 +1,70 @@
|
|
1
|
-
#
|
1
|
+
# Cloudflare
|
2
2
|
|
3
|
-
It is a Ruby wrapper for the
|
3
|
+
It is a Ruby wrapper for the Cloudflare V4 API. It provides a light weight wrapper using `RestClient::Resource`. The wrapper functionality is limited to zones and DNS records at this time, *PRs welcome*.
|
4
4
|
|
5
|
-
[![Build Status](https://travis-ci.org/
|
6
|
-
|
7
|
-
Official home page is [here](https://github.com/b4k3r/cloudflare). The complete [RDoc](http://rdoc.info/github/b4k3r/cloudflare/) is online.
|
8
|
-
|
9
|
-
Visit also a CloudFlare API documentation:
|
10
|
-
|
11
|
-
- [Client](http://www.cloudflare.com/docs/client-api.html)
|
12
|
-
- [Host](http://www.cloudflare.com/docs/host-api.html)
|
5
|
+
[![Build Status](https://secure.travis-ci.org/ioquatix/cloudflare.svg)](http://travis-ci.org/ioquatix/cloudflare)
|
13
6
|
|
14
7
|
## Installation
|
15
8
|
|
16
9
|
Add this line to your application's Gemfile:
|
17
10
|
|
18
|
-
|
11
|
+
```ruby
|
12
|
+
gem 'cloudflare'
|
13
|
+
```
|
19
14
|
|
20
15
|
And then execute:
|
21
16
|
|
22
|
-
|
17
|
+
```
|
18
|
+
$ bundle
|
19
|
+
```
|
23
20
|
|
24
21
|
Or install it yourself as:
|
25
22
|
|
26
|
-
|
23
|
+
```
|
24
|
+
$ gem install cloudflare
|
25
|
+
```
|
27
26
|
|
28
27
|
## Usage
|
29
28
|
|
30
|
-
|
29
|
+
Prepare a connection to the remote API:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'cloudflare'
|
33
|
+
|
34
|
+
# Grab some details from somewhere:
|
35
|
+
email = ENV['CLOUDFLARE_EMAIL']
|
36
|
+
key = ENV['CLOUDFLARE_KEY']
|
31
37
|
|
32
|
-
|
38
|
+
# Set up the connection:
|
39
|
+
connection = Cloudflare.connect(key: key, email: email)
|
40
|
+
```
|
33
41
|
|
34
|
-
|
42
|
+
Get all available zones:
|
35
43
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
puts e.message # error message
|
40
|
-
else
|
41
|
-
puts 'Successfuly added DNS record'
|
42
|
-
end
|
44
|
+
```ruby
|
45
|
+
zones = connection.zones.all
|
46
|
+
```
|
43
47
|
|
44
|
-
|
48
|
+
Get a specific zone:
|
45
49
|
|
46
|
-
|
50
|
+
```ruby
|
51
|
+
zone = connection.zones.find_by_id("...")
|
52
|
+
zone = connection.zones.find_by_name("example.com")
|
53
|
+
```
|
47
54
|
|
48
|
-
|
55
|
+
Get DNS records for a given zone:
|
49
56
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
57
|
+
```ruby
|
58
|
+
dns_records = zones.first.dns_records.all
|
59
|
+
```
|
60
|
+
|
61
|
+
Show some details of the DNS record:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
dns_record = records.first
|
65
|
+
puts records.first.record[:name]
|
66
|
+
puts records
|
67
|
+
```
|
58
68
|
|
59
69
|
## Contributing
|
60
70
|
|
@@ -64,12 +74,17 @@ Or install it yourself as:
|
|
64
74
|
4. Push to the branch (`git push origin my-new-feature`)
|
65
75
|
5. Create new Pull Request
|
66
76
|
|
77
|
+
## See Also
|
78
|
+
|
79
|
+
- [Cloudflare::DNS::Update](https://github.com/ioquatix/cloudflare-dns-update) - A dynamic DNS updater based on this gem.
|
80
|
+
- [Rubyflare](https://github.com/trev/rubyflare) - Another implementation.
|
81
|
+
|
67
82
|
## License
|
68
83
|
|
69
84
|
Released under the MIT license.
|
70
85
|
|
71
86
|
Copyright, 2012, 2014, by [Marcin Prokop](https://github.com/b4k3r).
|
72
|
-
Copyright,
|
87
|
+
Copyright, 2017, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
|
73
88
|
|
74
89
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
75
90
|
of this software and associated documentation files (the "Software"), to deal
|
data/Rakefile
CHANGED
@@ -1,8 +1,22 @@
|
|
1
|
-
require
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
2
3
|
|
3
|
-
|
4
|
-
t.libs << 'test'
|
5
|
-
end
|
4
|
+
RSpec::Core::RakeTask.new(:test)
|
6
5
|
|
7
|
-
desc "Run tests"
|
8
6
|
task :default => :test
|
7
|
+
|
8
|
+
task :coverage do
|
9
|
+
ENV['COVERAGE'] = 'y'
|
10
|
+
end
|
11
|
+
|
12
|
+
task :console do
|
13
|
+
require 'cloudflare'
|
14
|
+
require 'pry'
|
15
|
+
|
16
|
+
email = ENV['CLOUDFLARE_EMAIL']
|
17
|
+
key = ENV['CLOUDFLARE_KEY']
|
18
|
+
|
19
|
+
connection = Cloudflare::Connection.new(key: key, email: email)
|
20
|
+
|
21
|
+
binding.pry
|
22
|
+
end
|
data/cloudflare.gemspec
CHANGED
@@ -1,25 +1,27 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
require 'cloudflare/version'
|
2
|
+
require_relative 'lib/cloudflare/version'
|
4
3
|
|
5
|
-
Gem::Specification.new do |
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = 'cloudflare'
|
6
|
+
spec.version = Cloudflare::VERSION
|
7
|
+
spec.platform = Gem::Platform::RUBY
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
s.licenses = ['MIT']
|
9
|
+
spec.summary = 'A Ruby wrapper for the Cloudflare API.'
|
10
|
+
spec.authors = ['Marcin Prokop', 'Samuel Williams']
|
11
|
+
spec.email = ['marcin@prokop.co', 'samuel.williams@oriontransfer.co.nz']
|
12
|
+
spec.homepage = 'https://github.com/b4k3r/cloudflare'
|
13
|
+
spec.licenses = ['MIT']
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.required_ruby_version = '>= 2.0.0'
|
21
|
+
|
22
|
+
spec.add_dependency 'rest-client'
|
23
|
+
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.6"
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
26
|
+
spec.add_development_dependency "rake"
|
25
27
|
end
|
data/lib/cloudflare.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# Copyright, 2012, by Marcin Prokop.
|
2
|
+
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
3
|
#
|
3
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -18,10 +19,12 @@
|
|
18
19
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
20
|
# THE SOFTWARE.
|
20
21
|
|
21
|
-
|
22
|
+
require_relative 'cloudflare/connection'
|
23
|
+
require_relative 'cloudflare/zone'
|
24
|
+
require_relative 'cloudflare/user'
|
22
25
|
|
23
|
-
module
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
module Cloudflare
|
27
|
+
def self.connect(**options)
|
28
|
+
Connection.new(**options)
|
29
|
+
end
|
27
30
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# Copyright, 2012, by Marcin Prokop.
|
2
|
+
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
3
|
#
|
3
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -21,524 +22,34 @@
|
|
21
22
|
require 'net/http'
|
22
23
|
require 'json'
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
module
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
@params[:api_key] = api_key
|
55
|
-
else
|
56
|
-
@params[:api_key] = api_key
|
57
|
-
@params[:email] = email
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
# CLIENT
|
62
|
-
|
63
|
-
# This function can be used to get currently settings of values such as the security level.
|
64
|
-
#
|
65
|
-
# @see http://www.cloudflare.com/docs/client-api.html#s3.1
|
66
|
-
#
|
67
|
-
# @param zone [String]
|
68
|
-
# @param interval [Integer]
|
69
|
-
|
70
|
-
def stats(zone, interval = 20)
|
71
|
-
send_req({a: :stats, z: zone, interval: interval})
|
72
|
-
end
|
73
|
-
|
74
|
-
# This function lists all domains in a CloudFlare account along with other data.
|
75
|
-
#
|
76
|
-
# @see http://www.cloudflare.com/docs/client-api.html#s3.2
|
77
|
-
|
78
|
-
def zone_load_multi
|
79
|
-
send_req(a: :zone_load_multi)
|
80
|
-
end
|
81
|
-
|
82
|
-
# This function lists all of the DNS records from a particular domain in a CloudFlare account.
|
83
|
-
#
|
84
|
-
# @see http://www.cloudflare.com/docs/client-api.html#s3.3
|
85
|
-
#
|
86
|
-
# @param zone [String]
|
87
|
-
|
88
|
-
def rec_load_all(zone, offset = 0)
|
89
|
-
send_req({a: :rec_load_all, z: zone, o: offset})
|
90
|
-
end
|
91
|
-
|
92
|
-
# This function checks whether one or more websites/domains are active under an account and return the zone ids (zids) for these.
|
93
|
-
#
|
94
|
-
# @see http://www.cloudflare.com/docs/client-api.html#s3.4
|
95
|
-
#
|
96
|
-
# @param zones [String or Array]
|
97
|
-
|
98
|
-
def zone_check(*zones)
|
99
|
-
send_req({a: :zone_check, zones: zones.kind_of?(Array) ? zones.join(',') : zones})
|
100
|
-
end
|
101
|
-
|
102
|
-
# DEPRECATED!
|
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
|
-
puts 'Warning! This method is deprecated.'
|
114
|
-
send_req({a: :zone_ips, z: zone, hours: hours, "class" => classification, geo: geo})
|
115
|
-
end
|
116
|
-
|
117
|
-
# This function checks the threat score for a given IP.
|
118
|
-
#
|
119
|
-
# @see http://www.cloudflare.com/docs/client-api.html#s3.6
|
120
|
-
#
|
121
|
-
# @param ip [String]
|
122
|
-
|
123
|
-
def ip_lkup(ip)
|
124
|
-
send_req({a: :ip_lkup, ip: ip})
|
125
|
-
end
|
126
|
-
|
127
|
-
# This function retrieves all current settings for a given domain.
|
128
|
-
#
|
129
|
-
# @see http://www.cloudflare.com/docs/client-api.html#s3.7
|
130
|
-
#
|
131
|
-
# @param zone [String]
|
132
|
-
|
133
|
-
def zone_settings(zone)
|
134
|
-
send_req({a: :zone_settings, z: zone})
|
135
|
-
end
|
136
|
-
|
137
|
-
# This function sets the Basic Security Level to HELP I'M UNDER ATTACK / HIGH / MEDIUM / LOW / ESSENTIALLY OFF.
|
138
|
-
#
|
139
|
-
# @see http://www.cloudflare.com/docs/client-api.html#s4.1
|
140
|
-
#
|
141
|
-
# @param zone [String]
|
142
|
-
# @param value [String] values: low|med|high|help|eoff
|
143
|
-
|
144
|
-
def sec_lvl(zone, value)
|
145
|
-
send_req({a: :sec_lvl, z: zone, v: value})
|
146
|
-
end
|
147
|
-
|
148
|
-
# This function sets the Caching Level to Aggressive or Basic.
|
149
|
-
#
|
150
|
-
# @see http://www.cloudflare.com/docs/client-api.html#s4.2
|
151
|
-
#
|
152
|
-
# @param zone [String]
|
153
|
-
# @param value [String] values: agg|basic
|
154
|
-
|
155
|
-
def cache_lvl(zone, value)
|
156
|
-
send_req({a: :cache_lvl, z: zone, v: value})
|
157
|
-
end
|
158
|
-
|
159
|
-
# This function allows you to toggle Development Mode on or off for a particular domain.
|
160
|
-
#
|
161
|
-
# @see http://www.cloudflare.com/docs/client-api.html#s4.3
|
162
|
-
#
|
163
|
-
# @param zone [String]
|
164
|
-
# @param value [Boolean]
|
165
|
-
|
166
|
-
def devmode(zone, value)
|
167
|
-
send_req({a: :devmode, z: zone, v: value ? 1 : 0})
|
168
|
-
end
|
169
|
-
|
170
|
-
# This function will purge CloudFlare of any cached files.
|
171
|
-
#
|
172
|
-
# @see http://www.cloudflare.com/docs/client-api.html#s4.4
|
173
|
-
#
|
174
|
-
# @param zone [String]
|
175
|
-
|
176
|
-
def fpurge_ts(zone)
|
177
|
-
send_req({a: :fpurge_ts, z: zone, v: 1})
|
178
|
-
end
|
179
|
-
|
180
|
-
# This function will purge a single file from CloudFlare's cache.
|
181
|
-
#
|
182
|
-
# @see http://www.cloudflare.com/docs/client-api.html#s4.5
|
183
|
-
#
|
184
|
-
# @param zone [String]
|
185
|
-
# @param url [String]
|
186
|
-
|
187
|
-
def zone_file_purge(zone, url)
|
188
|
-
send_req({a: :zone_file_purge, z: zone, url: url})
|
189
|
-
end
|
190
|
-
|
191
|
-
# This function adds an IP address to your white lists.
|
192
|
-
#
|
193
|
-
# @see http://www.cloudflare.com/docs/client-api.html#s4.6
|
194
|
-
#
|
195
|
-
# @param ip [String]
|
196
|
-
|
197
|
-
def whitelist(ip)
|
198
|
-
send_req({a: :wl, key: ip})
|
199
|
-
end
|
200
|
-
|
201
|
-
|
202
|
-
# This function adds an IP address to your black lists.
|
203
|
-
#
|
204
|
-
# @see http://www.cloudflare.com/docs/client-api.html#s4.6
|
205
|
-
#
|
206
|
-
# @param ip [String]
|
207
|
-
|
208
|
-
def blacklist(ip)
|
209
|
-
send_req({a: :ban, key: ip})
|
210
|
-
end
|
211
|
-
|
212
|
-
# This function removes the IP from whitelist or blacklist.
|
213
|
-
#
|
214
|
-
# @see http://www.cloudflare.com/docs/client-api.html#s4.6
|
215
|
-
#
|
216
|
-
# @param ip [String]
|
217
|
-
|
218
|
-
def remove_ip(ip)
|
219
|
-
send_req({a: :nul, key: ip})
|
220
|
-
end
|
221
|
-
|
222
|
-
# This function toggles IPv6 support.
|
223
|
-
#
|
224
|
-
# @see http://www.cloudflare.com/docs/client-api.html#s4.7
|
225
|
-
#
|
226
|
-
# @param zone [String]
|
227
|
-
# @param value [Boolean]
|
228
|
-
|
229
|
-
def ipv46(zone, value)
|
230
|
-
send_req({a: :ipv46, z: zone, v: value ? 1 : 0})
|
231
|
-
end
|
232
|
-
|
233
|
-
# This function changes Rocket Loader setting.
|
234
|
-
#
|
235
|
-
# @see http://www.cloudflare.com/docs/client-api.html#s4.8
|
236
|
-
#
|
237
|
-
# @param zone [String]
|
238
|
-
# @param value [Integer or String] values: 0|a|m
|
239
|
-
|
240
|
-
def async(zone, value)
|
241
|
-
send_req({a: :async, z: zone, v: value})
|
242
|
-
end
|
243
|
-
|
244
|
-
# This function changes minification settings.
|
245
|
-
#
|
246
|
-
# @see http://www.cloudflare.com/docs/client-api.html#s4.9
|
247
|
-
#
|
248
|
-
# @param zone [String]
|
249
|
-
# @param value [Integer] values: 0|2|3|4|5|6|7
|
250
|
-
|
251
|
-
def minify(zone, value)
|
252
|
-
send_req({a: :minify, z: zone, v: value})
|
253
|
-
end
|
254
|
-
|
255
|
-
|
256
|
-
# This function changes mirage2 settings.
|
257
|
-
#
|
258
|
-
# @see http://www.cloudflare.com/docs/client-api.html#s4.10
|
259
|
-
#
|
260
|
-
# @param zone [String]
|
261
|
-
# @param value [Integer] values: 0|1
|
262
|
-
|
263
|
-
def mirage2(zone, value)
|
264
|
-
send_req({a: :mirage2, z: zone, v: value})
|
265
|
-
end
|
266
|
-
|
267
|
-
# This function creates a new DNS record for your site. This can be either a CNAME or A record.
|
268
|
-
#
|
269
|
-
# @see http://www.cloudflare.com/docs/client-api.html#s5.1
|
270
|
-
#
|
271
|
-
# @param zone [String]
|
272
|
-
# @param type [String] values: A|CNAME|MX|TXT|SPF|AAAA|NS|SRV|LOC
|
273
|
-
# @param name [String]
|
274
|
-
# @param content [String]
|
275
|
-
# @param ttl [Integer] values: 1|120...4294967295
|
276
|
-
# @param prio [Integer] (applies to MX/SRV)
|
277
|
-
# @param service [String] (applies to SRV)
|
278
|
-
# @param srvname [String] (applies to SRV)
|
279
|
-
# @param protocol [Integer] (applies to SRV) values: _tcp|_udp|_tls
|
280
|
-
# @param weight [Intger] (applies to SRV)
|
281
|
-
# @param port [Integer] (applies to SRV)
|
282
|
-
# @param target [String] (applies to SRV)
|
283
|
-
# @param service_mode [Boolean] (applies to A/AAAA/CNAME)
|
284
|
-
|
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)
|
286
|
-
send_req({
|
287
|
-
a: :rec_new,
|
288
|
-
z: zone,
|
289
|
-
type: type,
|
290
|
-
name: name,
|
291
|
-
content: content,
|
292
|
-
ttl: ttl,
|
293
|
-
prio: prio,
|
294
|
-
service: service,
|
295
|
-
srvname: srvname,
|
296
|
-
protocol: protocol,
|
297
|
-
weight: weight,
|
298
|
-
port: port,
|
299
|
-
target: target,
|
300
|
-
service_mode: service_mode ? 1 : 0,
|
301
|
-
})
|
302
|
-
end
|
303
|
-
|
304
|
-
# This function edits a DNS record for a zone.
|
305
|
-
#
|
306
|
-
# @see http://www.cloudflare.com/docs/client-api.html#s5.2
|
307
|
-
#
|
308
|
-
# @param zone [String]
|
309
|
-
# @param type [String] values: A|CNAME|MX|TXT|SPF|AAAA|NS|SRV|LOC
|
310
|
-
# @param record_id [Integer]
|
311
|
-
# @param name [String]
|
312
|
-
# @param content [String]
|
313
|
-
# @param ttl [Integer] values: 1|120...4294967295
|
314
|
-
# @param prio [Integer] (applies to MX/SRV)
|
315
|
-
# @param service [String] (applies to SRV)
|
316
|
-
# @param srvname [String] (applies to SRV)
|
317
|
-
# @param protocol [Integer] (applies to SRV) values: _tcp/_udp/_tls
|
318
|
-
# @param weight [Intger] (applies to SRV)
|
319
|
-
# @param port [Integer] (applies to SRV)
|
320
|
-
# @param target [String] (applies to SRV)
|
321
|
-
# @param service_mode [Boolean] (applies to A/AAAA/CNAME)
|
322
|
-
|
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)
|
324
|
-
send_req({
|
325
|
-
a: :rec_edit,
|
326
|
-
z: zone,
|
327
|
-
type: type,
|
328
|
-
id: record_id,
|
329
|
-
name: name,
|
330
|
-
content: content,
|
331
|
-
ttl: ttl,
|
332
|
-
prio: prio,
|
333
|
-
service: service,
|
334
|
-
srvname: srvname,
|
335
|
-
protocol: protocol,
|
336
|
-
weight: weight,
|
337
|
-
port: port,
|
338
|
-
target: target,
|
339
|
-
service_mode: service_mode ? 1 : 0,
|
340
|
-
})
|
341
|
-
end
|
342
|
-
|
343
|
-
# This functon deletes a record for a domain.
|
344
|
-
#
|
345
|
-
# @see http://www.cloudflare.com/docs/client-api.html#s5.3
|
346
|
-
#
|
347
|
-
# @param zone [String]
|
348
|
-
# @param zoneid [Integer]
|
349
|
-
|
350
|
-
def rec_delete(zone, zoneid)
|
351
|
-
send_req({a: :rec_delete, z: zone, id: zoneid})
|
352
|
-
end
|
353
|
-
|
354
|
-
# HOST
|
355
|
-
|
356
|
-
# This function creates a CloudFlare account mapped to your user.
|
357
|
-
#
|
358
|
-
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.1
|
359
|
-
#
|
360
|
-
# @param email [String]
|
361
|
-
# @param pass [String]
|
362
|
-
# @param login [String] (optional) cloudflare_username
|
363
|
-
# @param id [Integer] (optional) unique_id
|
364
|
-
# @param cui [Integer] (optional) clobber_unique_id
|
365
|
-
|
366
|
-
def create_user(email, pass, login = nil, id = nil, cui = nil)
|
367
|
-
send_req({
|
368
|
-
act: :user_create,
|
369
|
-
cloudflare_email: email,
|
370
|
-
cloudflare_pass: pass,
|
371
|
-
cloudflare_username: login,
|
372
|
-
unique_id: id,
|
373
|
-
clobber_unique_id: cui
|
374
|
-
})
|
375
|
-
end
|
376
|
-
|
377
|
-
# This function setups a User's zone for CNAME hosting.
|
378
|
-
#
|
379
|
-
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.2
|
380
|
-
#
|
381
|
-
# @param user_key [String]
|
382
|
-
# @param zone [String]
|
383
|
-
# @param resolve_to [String]
|
384
|
-
# @param subdomains [String or Array]
|
385
|
-
|
386
|
-
def add_zone(user_key, zone, resolve_to, subdomains)
|
387
|
-
send_req({
|
388
|
-
act: :zone_set,
|
389
|
-
user_key: user_key,
|
390
|
-
zone_name: zone,
|
391
|
-
resolve_to: resolve_to,
|
392
|
-
subdomains: subdomains.kind_of?(Array) ? zones.join(',') : subdomains
|
393
|
-
})
|
394
|
-
end
|
395
|
-
|
396
|
-
# This function adds a zone using the full setup.
|
397
|
-
#
|
398
|
-
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.3
|
399
|
-
#
|
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
|
-
#
|
415
|
-
# *Example:*
|
416
|
-
#
|
417
|
-
# cf = CloudFlare('your_host_key')
|
418
|
-
# cf.user_lookup('unique_id', true)
|
419
|
-
#
|
420
|
-
# If +id+ is set to true, email is a unique_id.
|
421
|
-
#
|
422
|
-
# @param email [String or Integer]
|
423
|
-
# @param id [Boolean]
|
424
|
-
|
425
|
-
def user_lookup(email, id = false)
|
426
|
-
if id
|
427
|
-
send_req({act: :user_lookup, unique_id: email})
|
428
|
-
else
|
429
|
-
send_req({act: :user_lookup, cloudflare_email: email})
|
430
|
-
end
|
431
|
-
end
|
432
|
-
|
433
|
-
# This function authorizes access to a user's existing CloudFlare account.
|
434
|
-
#
|
435
|
-
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.5
|
436
|
-
#
|
437
|
-
# @param email [String]
|
438
|
-
# @param pass [String]
|
439
|
-
# @param unique_id [Integer] (optional)
|
440
|
-
# @param cui [Integer] (optional) clobber_unique_id
|
441
|
-
|
442
|
-
def user_auth(email, pass, id = nil, cui = nil)
|
443
|
-
send_req({
|
444
|
-
act: :user_auth,
|
445
|
-
cloudflare_email: email,
|
446
|
-
cloudflare_pass: pass,
|
447
|
-
unique_id: id,
|
448
|
-
clobber_unique_id: cui
|
449
|
-
})
|
450
|
-
end
|
451
|
-
|
452
|
-
# This function lookups a specific user's zone.
|
453
|
-
#
|
454
|
-
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.6
|
455
|
-
#
|
456
|
-
# @param user_key [String]
|
457
|
-
# @param zone [String]
|
458
|
-
|
459
|
-
def zone_lookup(user_key, zone)
|
460
|
-
send_req({act: :zone_lookup, user_key: user_key, zone_name: zone})
|
461
|
-
end
|
462
|
-
|
463
|
-
# This function deletes a specific zone on behalf of a user.
|
464
|
-
#
|
465
|
-
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.7
|
466
|
-
#
|
467
|
-
# @param user_key [String]
|
468
|
-
# @param zone [String]
|
469
|
-
|
470
|
-
def del_zone(user_key, zone)
|
471
|
-
send_req({act: :zone_delete, user_key: user_key, zone_name: zone})
|
472
|
-
end
|
473
|
-
|
474
|
-
# This function regenerates your host key.
|
475
|
-
#
|
476
|
-
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.8
|
477
|
-
|
478
|
-
def host_key_regen
|
479
|
-
send_req(act: :host_key_regen)
|
480
|
-
end
|
481
|
-
|
482
|
-
# This function stops a child host provider account.
|
483
|
-
#
|
484
|
-
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.9
|
485
|
-
#
|
486
|
-
# @param id [Integer] child_id
|
487
|
-
|
488
|
-
def host_child_stop(id)
|
489
|
-
send_req({act: :host_child_stop, child_id: id})
|
490
|
-
end
|
491
|
-
|
492
|
-
# This function lists the domains currently active on CloudFlare for the given host.
|
493
|
-
#
|
494
|
-
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.10
|
495
|
-
#
|
496
|
-
# @param limit [Integer] (optional)
|
497
|
-
# @param offset [Integer] (optional)
|
498
|
-
# @param name [String] (optional) zone_name
|
499
|
-
# @param sub_id [Integer] (optional) sub_id
|
500
|
-
# @param status [String] (optional) values: V|D|ALL
|
501
|
-
# @param sub_status [String] (optional) values: V|CNL|ALL
|
502
|
-
|
503
|
-
def zone_list(limit = 100, offset = 0, name = nil, sub_id = nil, status = nil, sub_status = nil)
|
504
|
-
send_req({
|
505
|
-
act: :zone_list,
|
506
|
-
offset: offset,
|
507
|
-
zone_name: name,
|
508
|
-
sub_id: sub_id,
|
509
|
-
zone_status: status,
|
510
|
-
sub_status: sub_status
|
511
|
-
})
|
512
|
-
end
|
513
|
-
|
514
|
-
private
|
515
|
-
|
516
|
-
def send_req(params)
|
517
|
-
if @params[:email]
|
518
|
-
params[:tkn] = @params[:api_key]
|
519
|
-
params[:u] = @params[:email]
|
520
|
-
uri = URI(URL_API[:client])
|
521
|
-
else
|
522
|
-
params[:host_key] = @params[:api_key]
|
523
|
-
uri = URI(URL_API[:host])
|
524
|
-
end
|
525
|
-
|
526
|
-
req = Net::HTTP::Post.new(uri.path)
|
527
|
-
req.set_form_data(params.reject{|k, v| v.nil?})
|
528
|
-
|
529
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
530
|
-
http.use_ssl = true
|
531
|
-
http.read_timeout = TIMEOUT
|
532
|
-
|
533
|
-
res = http.request(req)
|
534
|
-
out = JSON.parse(res.body)
|
535
|
-
|
536
|
-
# If there is an error, raise an exception:
|
537
|
-
if out['result'] == 'error'
|
538
|
-
raise RequestError.new(out['msg'], out)
|
539
|
-
else
|
540
|
-
return out
|
541
|
-
end
|
542
|
-
end
|
543
|
-
end
|
25
|
+
require 'rest-client'
|
26
|
+
|
27
|
+
require_relative 'response'
|
28
|
+
|
29
|
+
module Cloudflare
|
30
|
+
DEFAULT_URL = "https://api.cloudflare.com/client/v4/"
|
31
|
+
TIMEOUT = 10 # Default is 5 seconds
|
32
|
+
|
33
|
+
class Resource < RestClient::Resource
|
34
|
+
# @param api_key [String] `X-Auth-Key` or `X-Auth-User-Service-Key` if no email provided.
|
35
|
+
# @param email [String] `X-Auth-Email`, your email address for the account.
|
36
|
+
def initialize(url = DEFAULT_URL, key: nil, email: nil, **options)
|
37
|
+
headers = options[:headers] || {}
|
38
|
+
|
39
|
+
if email.nil?
|
40
|
+
headers['X-Auth-User-Service-Key'] = key
|
41
|
+
else
|
42
|
+
headers['X-Auth-Key'] = key
|
43
|
+
headers['X-Auth-Email'] = email
|
44
|
+
end
|
45
|
+
|
46
|
+
# Convert HTTP API responses to our own internal response class:
|
47
|
+
super(url, headers: headers, accept: 'application/json', **options) do |response|
|
48
|
+
Response.new(response.request.url, response.body)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class Connection < Resource
|
54
|
+
end
|
544
55
|
end
|