cloudflare 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README.md +21 -9
- data/lib/cloudflare.rb +505 -316
- data/test/test_cloudflare.rb +1 -1
- metadata +11 -7
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2012 Marcin "B4k3r" Prokop
|
1
|
+
Copyright (c) 2012-2013 Marcin "B4k3r" Prokop
|
2
2
|
|
3
3
|
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:
|
4
4
|
|
data/README.md
CHANGED
@@ -1,13 +1,25 @@
|
|
1
|
+
NOTICE
|
2
|
+
======
|
3
|
+
|
4
|
+
In version v1.1.0 I renamed some functions in Client API.
|
5
|
+
|
6
|
+
- threat_score -> ip_lkup
|
7
|
+
- set_cache_lvl -> cache_lvl
|
8
|
+
- set_security_lvl -> sec_lvl
|
9
|
+
- purge_cache -> fpurge_ts
|
10
|
+
- update_image -> zone_grab
|
11
|
+
|
12
|
+
|
1
13
|
CloudFlare
|
2
14
|
==========
|
3
15
|
|
4
16
|
It is a Ruby wrapper for the CloudFlare API.
|
5
17
|
|
6
|
-
Official home page is [here](
|
18
|
+
Official home page is [here](https://github.com/B4k3r/cloudflare). The complete [RDoc](http://rdoc.info/github/B4k3r/cloudflare/) is online.
|
7
19
|
|
8
20
|
Visit also a CloudFlare API documentation:
|
9
21
|
|
10
|
-
- [Client](http://www.cloudflare.com/
|
22
|
+
- [Client](http://www.cloudflare.com/docs/client-api.html)
|
11
23
|
- [Host](http://www.cloudflare.com/docs/host-api.html)
|
12
24
|
|
13
25
|
Installation
|
@@ -35,9 +47,9 @@ cf = CloudFlare.new('user_api_key', 'user_email')
|
|
35
47
|
output = cf.add_rec('domain.com', 'A', '212.11.6.211', 'subdomain.domain.com', true)
|
36
48
|
|
37
49
|
if output['result'] == 'success'
|
38
|
-
|
50
|
+
puts 'Successfuly added DNS record'
|
39
51
|
else
|
40
|
-
|
52
|
+
puts output['msg'] # error message
|
41
53
|
end
|
42
54
|
```
|
43
55
|
|
@@ -47,20 +59,20 @@ end
|
|
47
59
|
require 'cloudflare'
|
48
60
|
|
49
61
|
cf = CloudFlare.new('host_api_key')
|
50
|
-
output = cf.create_user('
|
62
|
+
output = cf.create_user('john@example.com', 'secret', 'john')
|
51
63
|
|
52
64
|
if output['result'] == 'success'
|
53
|
-
|
54
|
-
|
65
|
+
puts output['msg']
|
66
|
+
puts "Your login is #{output['response']['cloudflare_username']}" # => john
|
55
67
|
else
|
56
|
-
|
68
|
+
puts output['msg'] # error message
|
57
69
|
end
|
58
70
|
```
|
59
71
|
|
60
72
|
License
|
61
73
|
-------
|
62
74
|
|
63
|
-
Copyright © 2012. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
|
75
|
+
Copyright © 2012 - 2013. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
|
64
76
|
|
65
77
|
|
66
78
|
|
data/lib/cloudflare.rb
CHANGED
@@ -4,323 +4,512 @@ require 'json'
|
|
4
4
|
# All public functions return (Hash) result: success or error with message and error code
|
5
5
|
#
|
6
6
|
# For more information please visit:
|
7
|
-
# - http://www.cloudflare.com/
|
7
|
+
# - http://www.cloudflare.com/docs/client-api.html
|
8
8
|
# - http://www.cloudflare.com/docs/host-api.html
|
9
|
+
#
|
9
10
|
|
10
11
|
class CloudFlare
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
13
|
+
# URL for Client and Host API
|
14
|
+
|
15
|
+
URL_API = {
|
16
|
+
client: 'https://www.cloudflare.com/api_json.html',
|
17
|
+
host: 'https://api.cloudflare.com/host-gw.html'
|
18
|
+
}
|
19
|
+
|
20
|
+
TIMEOUT = 5 # Default is 5 seconds
|
21
|
+
|
22
|
+
# @param api_key [String] user or Host API key.
|
23
|
+
# @param email [String] it is for a Client API.
|
24
|
+
def initialize(api_key, email = nil)
|
25
|
+
@params = Hash.new
|
26
|
+
|
27
|
+
if email.nil?
|
28
|
+
@params[:api_key] = api_key
|
29
|
+
else
|
30
|
+
@params[:api_key] = api_key
|
31
|
+
@params[:email] = email
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
# CLIENT
|
37
|
+
|
38
|
+
# This function can be used to get currently settings of values such as the security level.
|
39
|
+
#
|
40
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s3.1
|
41
|
+
#
|
42
|
+
# @param zone [String]
|
43
|
+
# @param interval [Integer]
|
44
|
+
|
45
|
+
def stats(zone, interval = 20)
|
46
|
+
send_req({a: :stats, z: zone, interval: interval})
|
47
|
+
end
|
48
|
+
|
49
|
+
# This function lists all domains in a CloudFlare account along with other data.
|
50
|
+
#
|
51
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s3.2
|
52
|
+
|
53
|
+
def zone_load_multi
|
54
|
+
send_req(a: :zone_load_multi)
|
55
|
+
end
|
56
|
+
|
57
|
+
# This function lists all of the DNS records from a particular domain in a CloudFlare account.
|
58
|
+
#
|
59
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s3.3
|
60
|
+
#
|
61
|
+
# @param zone [String]
|
62
|
+
|
63
|
+
def rec_load_all(zone)
|
64
|
+
send_req({a: :rec_load_all, z: zone})
|
65
|
+
end
|
66
|
+
|
67
|
+
# This function checks whether one or more websites/domains are active under an account and return the zone ids (zids) for these.
|
68
|
+
#
|
69
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s3.4
|
70
|
+
#
|
71
|
+
# @param zones [String or Array]
|
72
|
+
|
73
|
+
def zone_check(*zones)
|
74
|
+
send_req({a: :zone_check, zones: zones.kind_of?(Array) ? zones.join(',') : zones})
|
75
|
+
end
|
76
|
+
|
77
|
+
# This function pulls recent IPs hitting your site.
|
78
|
+
#
|
79
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s3.5
|
80
|
+
#
|
81
|
+
# @param zone [String]
|
82
|
+
# @param hours [Integer] max 48
|
83
|
+
# @param classification [String] (optional) values: r|c|t
|
84
|
+
# @param geo [Fixnum] (optional)
|
85
|
+
|
86
|
+
def zone_ips(zone, classification = nil, hours = 24, geo = 1)
|
87
|
+
send_req({a: :zone_ips, z: zone, hours: hours, "class" => classification, geo: geo})
|
88
|
+
end
|
89
|
+
|
90
|
+
# This function checks the threat score for a given IP.
|
91
|
+
#
|
92
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s3.6
|
93
|
+
#
|
94
|
+
# @param ip [String]
|
95
|
+
|
96
|
+
def ip_lkup(ip)
|
97
|
+
send_req({a: :ip_lkup, ip: ip})
|
98
|
+
end
|
99
|
+
|
100
|
+
# This function retrieves all current settings for a given domain.
|
101
|
+
#
|
102
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s3.7
|
103
|
+
#
|
104
|
+
# @param zone [String]
|
105
|
+
|
106
|
+
def zone_settings(zone)
|
107
|
+
send_req({a: :zone_settings, z: zone})
|
108
|
+
end
|
109
|
+
|
110
|
+
# This function sets the Basic Security Level to HELP I'M UNDER ATTACK / HIGH / MEDIUM / LOW / ESSENTIALLY OFF.
|
111
|
+
#
|
112
|
+
# @see http://www.cloudflare.com/docs/client-api.html#4.1
|
113
|
+
#
|
114
|
+
# @param zone [String]
|
115
|
+
# @param value [String] values: low|med|high|help|eoff
|
116
|
+
|
117
|
+
def sec_lvl(zone, value)
|
118
|
+
send_req({a: :sec_lvl, z: zone, v: value})
|
119
|
+
end
|
120
|
+
|
121
|
+
# This function sets the Caching Level to Aggressive or Basic.
|
122
|
+
#
|
123
|
+
# @see http://www.cloudflare.com/docs/client-api.html#4.2
|
124
|
+
#
|
125
|
+
# @param zone [String]
|
126
|
+
# @param value [String] values: agg|basic
|
127
|
+
|
128
|
+
def cache_lvl(zone, value)
|
129
|
+
send_req({a: :cache_lvl, z: zone, v: value})
|
130
|
+
end
|
131
|
+
|
132
|
+
# This function allows you to toggle Development Mode on or off for a particular domain.
|
133
|
+
#
|
134
|
+
# @see http://www.cloudflare.com/docs/client-api.html#4.3
|
135
|
+
#
|
136
|
+
# @param zone [String]
|
137
|
+
# @param value [Boolean]
|
138
|
+
|
139
|
+
def devmode(zone, value)
|
140
|
+
send_req({a: :devmode, z: zone, v: value ? 1 : 0})
|
141
|
+
end
|
142
|
+
|
143
|
+
# This function will purge CloudFlare of any cached files.
|
144
|
+
#
|
145
|
+
# @see http://www.cloudflare.com/docs/client-api.html#4.4
|
146
|
+
#
|
147
|
+
# @param zone [String]
|
148
|
+
|
149
|
+
def fpurge_ts(zone)
|
150
|
+
send_req({a: :fpurge_ts, z: zone, v: 1})
|
151
|
+
end
|
152
|
+
|
153
|
+
# This function will purge a single file from CloudFlare's cache.
|
154
|
+
#
|
155
|
+
# @see http://www.cloudflare.com/docs/client-api.html#4.5
|
156
|
+
#
|
157
|
+
# @param zone [String]
|
158
|
+
# @param url [String]
|
159
|
+
|
160
|
+
def zone_file_purge(zone, url)
|
161
|
+
send_req({a: :zone_file_purge, z: zone, url: url})
|
162
|
+
end
|
163
|
+
|
164
|
+
# This function updates the snapshot of your site for CloudFlare's challenge page.
|
165
|
+
#
|
166
|
+
# @see http://www.cloudflare.com/docs/client-api.html#4.6
|
167
|
+
#
|
168
|
+
# @param zoneid [Integer]
|
169
|
+
|
170
|
+
def zone_grab(zoneid)
|
171
|
+
send_req({a: :zone_grab, zid: zoneid})
|
172
|
+
end
|
173
|
+
|
174
|
+
# This function adds an IP address to your white lists.
|
175
|
+
#
|
176
|
+
# @see http://www.cloudflare.com/docs/client-api.html#4.7
|
177
|
+
#
|
178
|
+
# @param ip [String]
|
179
|
+
|
180
|
+
def whitelist(ip)
|
181
|
+
send_req({a: :wl, key: ip})
|
182
|
+
end
|
183
|
+
|
184
|
+
|
185
|
+
# This function adds an IP address to your black lists.
|
186
|
+
#
|
187
|
+
# @see http://www.cloudflare.com/docs/client-api.html#4.7
|
188
|
+
#
|
189
|
+
# @param ip [String]
|
190
|
+
|
191
|
+
def blacklist(ip)
|
192
|
+
send_req({a: :ban, key: ip})
|
193
|
+
end
|
194
|
+
|
195
|
+
# This function removes the IP from whitelist or blacklist.
|
196
|
+
#
|
197
|
+
# @see http://www.cloudflare.com/docs/client-api.html#4.7
|
198
|
+
#
|
199
|
+
# @param ip [String]
|
200
|
+
|
201
|
+
def remove_ip(ip)
|
202
|
+
send_req({a: :nul, key: ip})
|
203
|
+
end
|
204
|
+
|
205
|
+
# This function toggles IPv6 support.
|
206
|
+
#
|
207
|
+
# @see http://www.cloudflare.com/docs/client-api.html#4.8
|
208
|
+
#
|
209
|
+
# @param zone [String]
|
210
|
+
# @param value [Boolean]
|
211
|
+
|
212
|
+
def ipv46(zone, value)
|
213
|
+
send_req({a: :ipv46, z: zone, v: value ? 1 : 0})
|
214
|
+
end
|
215
|
+
|
216
|
+
# This function changes Rocket Loader setting.
|
217
|
+
#
|
218
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s4.9
|
219
|
+
#
|
220
|
+
# @param zone [String]
|
221
|
+
# @param value [Integer or String] values: 0|a|m
|
222
|
+
|
223
|
+
def async(zone, value)
|
224
|
+
send_req({a: :async, z: zone, v: value})
|
225
|
+
end
|
226
|
+
|
227
|
+
# This function changes minification settings.
|
228
|
+
#
|
229
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s4.9
|
230
|
+
#
|
231
|
+
# @param zone [String]
|
232
|
+
# @param value [Integer] values: 0|2|3|4|5|6|7
|
233
|
+
|
234
|
+
def minify(zone, value)
|
235
|
+
send_req({a: :minify, z: zone, v: value})
|
236
|
+
end
|
237
|
+
|
238
|
+
# This function creates a new DNS record for your site. This can be either a CNAME or A record.
|
239
|
+
#
|
240
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s5.1
|
241
|
+
#
|
242
|
+
# @param zone [String]
|
243
|
+
# @param type [String] values: A|CNAME|MX|TXT|SPF|AAAA|NS|SRV|LOC
|
244
|
+
# @param name [String]
|
245
|
+
# @param content [String]
|
246
|
+
# @param ttl [Integer] values: 1|120...4294967295
|
247
|
+
# @param prio [Integer] (applies to MX/SRV)
|
248
|
+
# @param service [String] (applies to SRV)
|
249
|
+
# @param srvname [String] (applies to SRV)
|
250
|
+
# @param protocol [Integer] (applies to SRV) values: _tcp|_udp|_tls
|
251
|
+
# @param weight [Intger] (applies to SRV)
|
252
|
+
# @param port [Integer] (applies to SRV)
|
253
|
+
# @param target [String] (applies to SRV)
|
254
|
+
|
255
|
+
def rec_new(zone, type, name, content, ttl, prio = nil, service = nil, srvname = nil, protocol = nil, weight = nil, port = nil, target = nil)
|
256
|
+
send_req({
|
257
|
+
a: :rec_new,
|
258
|
+
zone: zone,
|
259
|
+
type: type,
|
260
|
+
name: name,
|
261
|
+
content: content,
|
262
|
+
ttl: ttl,
|
263
|
+
prio: prio,
|
264
|
+
service: service,
|
265
|
+
srvname: srvname,
|
266
|
+
protocol: protocol,
|
267
|
+
weight: weight,
|
268
|
+
port: port,
|
269
|
+
target: target
|
270
|
+
})
|
271
|
+
end
|
272
|
+
|
273
|
+
# This function edits a DNS record for a zone.
|
274
|
+
#
|
275
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s5.2
|
276
|
+
#
|
277
|
+
# @param zone [String]
|
278
|
+
# @param type [String] values: A|CNAME|MX|TXT|SPF|AAAA|NS|SRV|LOC
|
279
|
+
# @param zoneid [Integer]
|
280
|
+
# @param name [String]
|
281
|
+
# @param content [String]
|
282
|
+
# @param ttl [Integer] values: 1|120...4294967295
|
283
|
+
# @param service_mode [Boolean] (applies to A/AAAA/CNAME)
|
284
|
+
# @param prio [Integer] (applies to MX/SRV)
|
285
|
+
# @param service [String] (applies to SRV)
|
286
|
+
# @param srvname [String] (applies to SRV)
|
287
|
+
# @param protocol [Integer] (applies to SRV) values: _tcp/_udp/_tls
|
288
|
+
# @param weight [Intger] (applies to SRV)
|
289
|
+
# @param port [Integer] (applies to SRV)
|
290
|
+
# @param target [String] (applies to SRV)
|
291
|
+
|
292
|
+
def rec_edit(zone, type, zoneid, name, content, ttl, service_mode = nil, prio = nil, service = nil, srvname = nil, protocol = nil, weight = nil, port = nil, target = nil)
|
293
|
+
send_req({
|
294
|
+
a: :rec_new,
|
295
|
+
z: zone,
|
296
|
+
type: type,
|
297
|
+
id: zoneid,
|
298
|
+
name: name,
|
299
|
+
content: content,
|
300
|
+
ttl: ttl,
|
301
|
+
service_mode: service_mode ? 1 : 0,
|
302
|
+
prio: prio,
|
303
|
+
service: service,
|
304
|
+
srvname: srvname,
|
305
|
+
protocol: protocol,
|
306
|
+
weight: weight,
|
307
|
+
port: port,
|
308
|
+
target: target
|
309
|
+
})
|
310
|
+
end
|
311
|
+
|
312
|
+
# This functon deletes a record for a domain.
|
313
|
+
#
|
314
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s5.3
|
315
|
+
#
|
316
|
+
# @param zone [String]
|
317
|
+
# @param zoneid [Integer]
|
318
|
+
|
319
|
+
def rec_delete(zone, zoneid)
|
320
|
+
send_req({a: :rec_delete, z: zone, id: zoneid})
|
321
|
+
end
|
322
|
+
|
323
|
+
# HOST
|
324
|
+
|
325
|
+
# This function creates a CloudFlare account mapped to your user.
|
326
|
+
#
|
327
|
+
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.1
|
328
|
+
#
|
329
|
+
# @param email [String]
|
330
|
+
# @param pass [String]
|
331
|
+
# @param login [String] (optional) cloudflare_username
|
332
|
+
# @param id [Integer] (optional) unique_id
|
333
|
+
# @param cui [Integer] (optional) clobber_unique_id
|
334
|
+
|
335
|
+
def create_user(email, pass, login = nil, id = nil, cui = nil)
|
336
|
+
send_req({
|
337
|
+
act: :user_create,
|
338
|
+
cloudflare_email: email,
|
339
|
+
cloudflare_pass: pass,
|
340
|
+
cloudflare_username: login,
|
341
|
+
unique_id: id,
|
342
|
+
clobber_unique_id: cui
|
343
|
+
})
|
344
|
+
end
|
345
|
+
|
346
|
+
# This function setups a User's zone for CNAME hosting.
|
347
|
+
#
|
348
|
+
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.2
|
349
|
+
#
|
350
|
+
# @param user_key [String]
|
351
|
+
# @param zone [String]
|
352
|
+
# @param resolve_to [String]
|
353
|
+
# @param subdomains [String or Array]
|
354
|
+
|
355
|
+
def add_zone(user_key, zone, resolve_to, subdomains)
|
356
|
+
send_req({
|
357
|
+
act: :zone_set,
|
358
|
+
user_key: user_key,
|
359
|
+
zone_name: zone,
|
360
|
+
resolve_to: resolve_to,
|
361
|
+
subdomains: subdomains.kind_of?(Array) ? zones.join(',') : subdomains
|
362
|
+
})
|
363
|
+
end
|
364
|
+
|
365
|
+
# This function lookups a user's CloudFlare account information.
|
366
|
+
#
|
367
|
+
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.3
|
368
|
+
#
|
369
|
+
# *Example:*
|
370
|
+
#
|
371
|
+
# cf = CloudFlare('your_host_key')
|
372
|
+
# cf.user_lookup('unique_id', true)
|
373
|
+
#
|
374
|
+
# If +id+ is set to true, email is a unique_id.
|
375
|
+
#
|
376
|
+
# @param email [String or Integer]
|
377
|
+
# @param id [Boolean]
|
378
|
+
|
379
|
+
def user_lookup(email, id = false)
|
380
|
+
if id
|
381
|
+
send_req({act: :user_lookup, unique_id: email})
|
382
|
+
else
|
383
|
+
send_req({act: :user_lookup, cloudflare_email: email})
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
# This function authorizes access to a user's existing CloudFlare account.
|
388
|
+
#
|
389
|
+
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.4
|
390
|
+
#
|
391
|
+
# @param email [String]
|
392
|
+
# @param pass [String]
|
393
|
+
# @param unique_id [Integer] (optional)
|
394
|
+
# @param cui [Integer] (optional) clobber_unique_id
|
395
|
+
|
396
|
+
def user_auth(email, pass, id = nil, cui = nil)
|
397
|
+
send_req({
|
398
|
+
act: :user_auth,
|
399
|
+
cloudflare_email: email,
|
400
|
+
cloudflare_pass: pass,
|
401
|
+
unique_id: id,
|
402
|
+
clobber_unique_id: cui
|
403
|
+
})
|
404
|
+
end
|
405
|
+
|
406
|
+
# This function lookups a specific user's zone.
|
407
|
+
#
|
408
|
+
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.5
|
409
|
+
#
|
410
|
+
# @param user_key [String]
|
411
|
+
# @param zone [String]
|
412
|
+
|
413
|
+
def zone_lookup(user_key, zone)
|
414
|
+
send_req({act: :zone_lookup, user_key: user_key, zone_name: zone})
|
415
|
+
end
|
416
|
+
|
417
|
+
# This function deletes a specific zone on behalf of a user.
|
418
|
+
#
|
419
|
+
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.6
|
420
|
+
#
|
421
|
+
# @param user_key [String]
|
422
|
+
# @param zone [String]
|
423
|
+
|
424
|
+
def del_zone(user_key, zone)
|
425
|
+
send_req({act: :zone_delete, user_key: user_key, zone_name: zone})
|
426
|
+
end
|
427
|
+
|
428
|
+
# This function creates a new child host provider.
|
429
|
+
#
|
430
|
+
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.7
|
431
|
+
#
|
432
|
+
# @param host_name [String]
|
433
|
+
# @param pub_name [String]
|
434
|
+
# @param prefix [String]
|
435
|
+
# @param website [String]
|
436
|
+
# @param email [String]
|
437
|
+
|
438
|
+
def host_child_new(host_name, pub_name, prefix, website, email)
|
439
|
+
send_req({
|
440
|
+
act: :host_child_new,
|
441
|
+
pub_name: pub_name,
|
442
|
+
prefix: prefix,
|
443
|
+
website: website,
|
444
|
+
email: email
|
445
|
+
})
|
446
|
+
end
|
447
|
+
|
448
|
+
# This function regenerates your host key.
|
449
|
+
#
|
450
|
+
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.8
|
451
|
+
|
452
|
+
def host_key_regen
|
453
|
+
send_req(act: :host_key_regen)
|
454
|
+
end
|
455
|
+
|
456
|
+
# This function stops a child host provider account.
|
457
|
+
#
|
458
|
+
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.9
|
459
|
+
#
|
460
|
+
# @param id [Integer] child_id
|
461
|
+
|
462
|
+
def host_child_stop(id)
|
463
|
+
send_req({act: host_child_stop, child_id: id})
|
464
|
+
end
|
465
|
+
|
466
|
+
# This function lists the domains currently active on CloudFlare for the given host.
|
467
|
+
#
|
468
|
+
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.10
|
469
|
+
#
|
470
|
+
# @param limit [Integer] (optional)
|
471
|
+
# @param offset [Integer] (optional)
|
472
|
+
# @param name [String] (optional) zone_name
|
473
|
+
# @param sub_id [Integer] (optional) sub_id
|
474
|
+
# @param status [String] (optional) values: V|D|ALL
|
475
|
+
|
476
|
+
def zone_list(limit = 100, offset = 0, name = nil, sub_id = nil, status = nil)
|
477
|
+
send_req({
|
478
|
+
act: :zone_list,
|
479
|
+
offset: offset,
|
480
|
+
zone_name: name,
|
481
|
+
sub_id: sub_id,
|
482
|
+
zone_status: status
|
483
|
+
})
|
484
|
+
end
|
485
|
+
|
486
|
+
private
|
487
|
+
|
488
|
+
def send_req(params)
|
489
|
+
|
490
|
+
if @params[:email]
|
491
|
+
params[:tkn] = @params[:api_key]
|
492
|
+
params[:u] = @params[:email]
|
493
|
+
uri = URI(URL_API[:client])
|
494
|
+
else
|
495
|
+
params[:host_key] = @params[:api_key]
|
496
|
+
uri = URI(URL_API[:host])
|
497
|
+
end
|
498
|
+
|
499
|
+
req = Net::HTTP::Post.new(uri.path)
|
500
|
+
req.set_form_data(params)
|
501
|
+
|
502
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
503
|
+
http.use_ssl = true
|
504
|
+
http.read_timeout = TIMEOUT
|
505
|
+
|
506
|
+
begin
|
507
|
+
res = http.request(req)
|
508
|
+
JSON.parse(res.body)
|
509
|
+
rescue => e
|
510
|
+
puts "#{e.class} #{e.message}"
|
511
|
+
end
|
512
|
+
|
513
|
+
end
|
514
|
+
|
515
|
+
end
|
data/test/test_cloudflare.rb
CHANGED
@@ -5,7 +5,7 @@ class HostTest < Test::Unit::TestCase
|
|
5
5
|
|
6
6
|
def test_client_connection
|
7
7
|
cf = CloudFlare.new('example_api', 'example@example.com')
|
8
|
-
assert_equal('E_UNAUTH', cf.
|
8
|
+
assert_equal('E_UNAUTH', cf.ipv46('example.com', true)['err_code'])
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_host_connection
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudflare
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,12 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
description: A Ruby wrapper for the CloudFlare API.
|
26
31
|
email: marcin@prokop.co
|
27
32
|
executables: []
|
@@ -35,7 +40,7 @@ files:
|
|
35
40
|
- test/test_cloudflare.rb
|
36
41
|
- README.md
|
37
42
|
- LICENSE
|
38
|
-
homepage:
|
43
|
+
homepage: https://github.com/B4k3r/cloudflare
|
39
44
|
licenses: []
|
40
45
|
post_install_message:
|
41
46
|
rdoc_options:
|
@@ -58,10 +63,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
63
|
version: '0'
|
59
64
|
requirements: []
|
60
65
|
rubyforge_project:
|
61
|
-
rubygems_version: 1.8.
|
66
|
+
rubygems_version: 1.8.25
|
62
67
|
signing_key:
|
63
68
|
specification_version: 3
|
64
69
|
summary: A Ruby wrapper for the CloudFlare API.
|
65
70
|
test_files:
|
66
71
|
- test/test_cloudflare.rb
|
67
|
-
has_rdoc:
|