cloudflare 3.1.0 → 3.2.0

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
- SHA1:
3
- metadata.gz: 7803b3a770a2ca6cfe874d77a7172bce3b0a3016
4
- data.tar.gz: 8e97d03f70b94c9c6e5534adeff3fd9258c6a56c
2
+ SHA256:
3
+ metadata.gz: 9e424c7c834e532b5a8783095b16ebde0f449ba26c39d33b3cf08042af234e6d
4
+ data.tar.gz: 48d3e57b0ffaafc85633b7ee7d3ac3d65046bcb4d6d563f005f6ae364204275d
5
5
  SHA512:
6
- metadata.gz: df0801c3eaeca54ebdf36c45eecb85ae27f39eeae1163474ace6fda7211357aae6c9ddefee4f4fa12a45a34d99509011965e9d2af4d9e4139f75dbb7ee68c6d4
7
- data.tar.gz: bb7ee1e783f5288612252a2908ef7e1d8b27daa2ba5c96947b09faf35fb6b536c91512d0fda099c6cac3a453ec8db9a8211fa5fcf12069b9a82c382e57b4c562
6
+ metadata.gz: cf74a6f05ab0c6188efadce6a8744b4f46dbec3d8d386c7287274b84e46eb5e9aaa3c40bd51c1e26084d9e86b831d76cdf6471e9c550baf8d30ee04804e04671
7
+ data.tar.gz: f2825bb5f23eb32b12141cf58f05405e38a41bde64a6a3b92ff58934a3f5b36594428caf4d14b69434dbbedf71f8e565bfc3fd01a59fe4af87b86584bf1e0070
@@ -0,0 +1,19 @@
1
+ Naming/UncommunicativeMethodParamName:
2
+ AllowedNames:
3
+ - ip
4
+ - id
5
+
6
+ Style/Documentation:
7
+ Enabled: false
8
+
9
+ Metrics/LineLength:
10
+ Max: 120
11
+
12
+ Metrics/MethodLength:
13
+ Max: 20
14
+
15
+ Lint/Debugger:
16
+ Enabled: false
17
+
18
+ Gemspec/RequiredRubyVersion:
19
+ Enabled: false
@@ -0,0 +1 @@
1
+ 2.5.0
@@ -2,12 +2,16 @@ language: ruby
2
2
  sudo: false
3
3
  dist: trusty
4
4
  cache: bundler
5
+
6
+ before_script:
7
+ - gem update --system
8
+ - gem install bundler
9
+
5
10
  rvm:
6
- - 2.0
7
- - 2.1
8
- - 2.2
9
11
  - 2.3
10
12
  - 2.4
13
+ - 2.5
14
+ - 2.6
11
15
  - jruby-head
12
16
  - ruby-head
13
17
  matrix:
data/README.md CHANGED
@@ -89,6 +89,14 @@ data = {"mode":"block","configuration":{"target":"ip","value":"#{ip}"},"notes":"
89
89
  response = zones.first.firewall_rules.post(data.to_json, content_type: 'application/json')
90
90
  ```
91
91
 
92
+ Add a DNS record dynamically. Here we add an A record for `batman.example.com`:
93
+
94
+ ```ruby
95
+ client = Cloudflare.connect(key: CF_KEY, email: CF_EMAIL)
96
+ zone = client.zones.find_by_name("example.com")
97
+ zone.dns_records.post({"type":"A","name":"batman","content":"127.0.0.1","proxied":false}.to_json, :content_type => "application/json")
98
+ ```
99
+
92
100
  ## Contributing
93
101
 
94
102
  1. Fork it
data/Rakefile CHANGED
@@ -1,22 +1,24 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:test)
5
7
 
6
- task :default => :test
8
+ task default: :test
7
9
 
8
10
  task :coverage do
9
- ENV['COVERAGE'] = 'y'
11
+ ENV['COVERAGE'] = 'y'
10
12
  end
11
13
 
12
14
  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
15
+ require 'cloudflare'
16
+ require 'pry'
17
+
18
+ email = ENV['CLOUDFLARE_EMAIL']
19
+ key = ENV['CLOUDFLARE_KEY']
20
+
21
+ connection = Cloudflare::Connection.new(key: key, email: email)
22
+
23
+ binding.pry
22
24
  end
@@ -1,4 +1,6 @@
1
- # -*- encoding: utf-8 -*-
1
+
2
+ # frozen_string_literal: true
3
+
2
4
  require_relative 'lib/cloudflare/version'
3
5
 
4
6
  Gem::Specification.new do |spec|
@@ -12,16 +14,16 @@ Gem::Specification.new do |spec|
12
14
  spec.homepage = 'https://github.com/b4k3r/cloudflare'
13
15
  spec.licenses = ['MIT']
14
16
 
15
- spec.files = `git ls-files`.split($/)
17
+ spec.files = `git ls-files`.split("\n")
16
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
- spec.require_paths = ["lib"]
19
-
20
+ spec.require_paths = ['lib']
21
+
20
22
  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"
23
+
24
+ spec.add_dependency 'rest-client', '~> 2.0.2'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.3'
27
+ spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'rspec', '~> 3.6'
27
29
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright, 2012, by Marcin Prokop.
2
4
  # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
3
5
  #
@@ -24,7 +26,7 @@ require_relative 'cloudflare/zone'
24
26
  require_relative 'cloudflare/user'
25
27
 
26
28
  module Cloudflare
27
- def self.connect(**options)
28
- Connection.new(**options)
29
- end
29
+ def self.connect(**options)
30
+ Connection.new(**options)
31
+ end
30
32
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright, 2012, by Marcin Prokop.
2
4
  # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
3
5
  #
@@ -23,51 +25,53 @@ require 'net/http'
23
25
  require 'json'
24
26
 
25
27
  require 'rest-client'
28
+ require 'uri'
26
29
 
27
30
  require_relative 'response'
28
31
 
29
32
  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
- include Enumerable
35
-
36
- # @param api_key [String] `X-Auth-Key` or `X-Auth-User-Service-Key` if no email provided.
37
- # @param email [String] `X-Auth-Email`, your email address for the account.
38
- def initialize(url = DEFAULT_URL, key: nil, email: nil, **options)
39
- headers = options[:headers] || {}
40
-
41
- if email.nil?
42
- headers['X-Auth-User-Service-Key'] = key
43
- else
44
- headers['X-Auth-Key'] = key
45
- headers['X-Auth-Email'] = email
46
- end
47
-
48
- # Convert HTTP API responses to our own internal response class:
49
- super(url, headers: headers, accept: 'application/json', **options) do |response|
50
- Response.new(response.request.url, response.body)
51
- end
52
- end
33
+ DEFAULT_URL = 'https://api.cloudflare.com/client/v4/'
34
+ TIMEOUT = 10 # Default is 5 seconds
35
+ DEFAULT_HEADERS = { 'Content-Type' => 'application/json' }.freeze
36
+
37
+ class Resource < RestClient::Resource
38
+ include Enumerable
39
+
40
+ # @param api_key [String] `X-Auth-Key` or `X-Auth-User-Service-Key` if no email provided.
41
+ # @param email [String] `X-Auth-Email`, your email address for the account.
42
+ def initialize(url = DEFAULT_URL, key: nil, email: nil, **options)
43
+ headers = options[:headers] || DEFAULT_HEADERS.dup
44
+
45
+ if email.nil?
46
+ headers['X-Auth-User-Service-Key'] = key
47
+ else
48
+ headers['X-Auth-Key'] = key
49
+ headers['X-Auth-Email'] = email
50
+ end
51
+
52
+ # Convert HTTP API responses to our own internal response class:
53
+ super(url, headers: headers, accept: 'application/json', **options) do |response|
54
+ Response.new(response.request.url, response.body)
55
+ end
56
+ end
57
+
58
+ def paginate(obj, url, url_args = '')
59
+ page = 1
60
+ page_size = 50
61
+ results = []
53
62
 
54
- def paginate(obj, url, url_args = "")
55
- page = 1
56
- page_size = 100
57
- results = []
63
+ # fetch and aggregate all pages
64
+ loop do
65
+ query = URI.encode_www_form scope_type: :organization, per_page: page_size, page: page
66
+ rules = obj.new(concat_urls(url, "?#{query}#{url_args}"), self, **options)
67
+ results += rules.get.results
68
+ break if results.empty? || results.size % page_size != 0
69
+ page += 1
70
+ end
71
+ results
72
+ end
73
+ end
58
74
 
59
- # fetch and aggregate all pages
60
- loop do
61
- rules = obj.new(concat_urls(url, "?scope_type=organization#{url_args}&per_page=#{page_size}&page=#{page}"), self, **options)
62
- results += rules.get.results
63
- break if results.size % page_size != 0
64
- page += 1
65
- end
66
-
67
- return results
68
- end
69
- end
70
-
71
- class Connection < Resource
72
- end
75
+ class Connection < Resource
76
+ end
73
77
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright, 2012, by Marcin Prokop.
2
4
  # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
3
5
  #
@@ -22,52 +24,50 @@
22
24
  require 'json'
23
25
 
24
26
  module Cloudflare
25
- class RequestError < StandardError
26
- def initialize(what, response)
27
- super("#{what}: #{response.errors.join(', ')}")
28
-
29
- @response = response
30
- end
31
-
32
- attr :response
33
- end
34
-
35
- class Response
36
- def initialize(what, content)
37
- @what = what
38
-
39
- @body = JSON.parse(content, symbolize_names: true)
40
- end
41
-
42
- attr :body
27
+ class RequestError < StandardError
28
+ def initialize(what, response)
29
+ super("#{what}: #{response.errors.join(', ')}")
30
+
31
+ @response = response
32
+ end
33
+
34
+ attr_reader :response
35
+ end
36
+
37
+ class Response
38
+ def initialize(what, content)
39
+ @what = what
40
+
41
+ @body = JSON.parse(content, symbolize_names: true)
42
+ end
43
+
44
+ attr_reader :body
45
+
46
+ def result
47
+ raise RequestError.new(@what, self) unless successful?
43
48
 
44
- def result
45
- unless successful?
46
- raise RequestError.new(@what, self)
47
- end
48
-
49
- body[:result]
50
- end
49
+ body[:result]
50
+ end
51
51
 
52
- # Treat result as an array (often it is).
53
- def results
54
- Array(result)
55
- end
52
+ # Treat result as an array (often it is).
53
+ def results
54
+ Array(result)
55
+ end
56
56
 
57
- def empty?
58
- result.empty?
59
- end
57
+ def empty?
58
+ result.empty?
59
+ end
60
60
 
61
- def successful?
62
- body[:success]
63
- end
61
+ def successful?
62
+ body[:success]
63
+ end
64
64
 
65
- def errors
66
- body[:errors]
67
- end
65
+ def errors
66
+ body[:errors]
67
+ end
68
68
 
69
- def messages
70
- body[:messages]
71
- end
72
- end
69
+ def messages
70
+ body[:messages]
71
+ end
72
+ end
73
73
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
4
  #
3
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -21,16 +23,16 @@
21
23
  require_relative '../../cloudflare'
22
24
 
23
25
  module Cloudflare
24
- module RSpec
25
- module Connection
26
- end
27
-
28
- RSpec.shared_context Connection do
29
- # You must specify these in order for the tests to run.
30
- let(:email) {ENV['CLOUDFLARE_EMAIL']}
31
- let(:key) {ENV['CLOUDFLARE_KEY']}
32
-
33
- let(:connection) {Cloudflare.connect(key: key, email: email)}
34
- end
35
- end
26
+ module RSpec
27
+ module Connection
28
+ end
29
+
30
+ RSpec.shared_context Connection do
31
+ # You must specify these in order for the tests to run.
32
+ let(:email) { 'jake@example.net' }
33
+ let(:key) { '5up3rS3cr3tAuthK3y' }
34
+
35
+ let(:connection) { Cloudflare.connect(key: key, email: email) }
36
+ end
37
+ end
36
38
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright, 2012, by Marcin Prokop.
2
4
  # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
3
5
  #
@@ -22,12 +24,12 @@
22
24
  require_relative 'connection'
23
25
 
24
26
  module Cloudflare
25
- class Connection < Resource
26
- def user
27
- @user ||= User.new(concat_urls(url, 'user'), options)
28
- end
29
- end
27
+ class Connection < Resource
28
+ def user
29
+ @user ||= User.new(concat_urls(url, 'user'), options)
30
+ end
31
+ end
30
32
 
31
- class User < Resource
32
- end
33
+ class User < Resource
34
+ end
33
35
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright, 2012, by Marcin Prokop.
2
4
  # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
3
5
  #
@@ -20,5 +22,5 @@
20
22
  # THE SOFTWARE.
21
23
 
22
24
  module Cloudflare
23
- VERSION = '3.1.0'
25
+ VERSION = '3.2.0'
24
26
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright, 2012, by Marcin Prokop.
2
4
  # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
3
5
  # Copyright, 2017, by David Rosenbloom. <http://artifactory.com>
@@ -23,167 +25,178 @@
23
25
  require_relative 'connection'
24
26
 
25
27
  module Cloudflare
26
- class Connection < Resource
27
- def zones
28
- @zones ||= Zones.new(concat_urls(url, 'zones'), options)
29
- end
30
- end
31
-
32
- class DNSRecord < Resource
33
- def initialize(url, record = nil, **options)
34
- super(url, **options)
35
-
36
- @record = record || self.get.result
37
- end
38
-
39
- def update_content(content)
40
- response = self.put({type: @record[:type], name: @record[:name], content: content}.to_json, content_type: 'application/json')
41
- response.successful?
42
- end
43
-
44
- attr :record
45
-
46
- def to_s
47
- "#{@record[:name]} #{@record[:type]} #{@record[:content]}"
48
- end
49
- end
50
-
51
- class DNSRecords < Resource
52
- def initialize(url, zone, **options)
53
- super(url, **options)
54
-
55
- @zone = zone
56
- end
57
-
58
- attr :zone
59
-
60
- def all
61
- results = paginate(DNSRecords, url)
62
- results.map{|record| DNSRecord.new(concat_urls(url, record[:id]), record, **options)}
63
- end
64
-
65
- def find_by_name(name)
66
- response = self.get(params: {name: name})
67
-
68
- unless response.empty?
69
- record = response.results.first
70
-
71
- DNSRecord.new(concat_urls(url, record[:id]), record, **options)
72
- end
73
- end
74
-
75
- def find_by_id(id)
76
- DNSRecord.new(concat_urls(url, id), **options)
77
- end
78
- end
79
-
80
- class FirewallRule < Resource
81
- def initialize(url, record = nil, **options)
82
- super(url, **options)
83
-
84
- @record = record || self.get.result
85
- end
86
-
87
- attr :record
88
-
89
- def to_s
90
- "#{@record[:configuration][:value]} - #{@record[:mode]} - #{@record[:notes]}"
91
- end
92
- end
93
-
94
- class FirewallRules < Resource
95
- def initialize(url, zone, **options)
96
- super(url, **options)
97
-
98
- @zone = zone
99
- end
100
-
101
- attr :zone
102
-
103
- def all(mode = nil, ip = nil, notes = nil)
104
- url_args = ""
105
- url_args.concat("&mode=#{mode}") if mode
106
- url_args.concat("&configuration_value=#{ip}") if ip
107
- url_args.concat("&notes=#{notes}") if notes
108
-
109
- results = paginate(FirewallRules, url, url_args)
110
- results.map{|record| FirewallRule.new(concat_urls(url, record[:id]), record, **options)}
111
- end
112
-
113
- def firewalled_ips(rules)
114
- rules.collect {|r| r.record[:configuration][:value]}
115
- end
116
-
117
- def blocked_ips
118
- firewalled_ips(all("block"))
119
- end
120
-
121
- def set(mode, ip, note)
122
- data = {
123
- mode: mode.to_s,
124
- configuration: {
125
- target: "ip",
126
- value: ip.to_s,
127
- notes: "cloudflare gem firewall_rules [#{mode}] #{note} #{Time.now.strftime("%m/%d/%y")}"
128
- }
129
- }
130
-
131
- post(data.to_json, content_type: 'application/json')
132
- end
133
-
134
- def unset(mode, value)
135
- rule = send("find_by_#{mode}", value)
136
- rule.delete
137
- end
138
-
139
- def find_by_id(id)
140
- FirewallRule.new(concat_urls(url, id), **options)
141
- end
142
-
143
- def find_by_ip(ip)
144
- rule = FirewallRule.new(concat_urls(url, "?configuration_value=#{ip}"), **options)
145
- FirewallRule.new(concat_urls(url, rule.record.first[:id]), **options)
146
- end
147
- end
148
-
149
- class Zone < Resource
150
- def initialize(url, record = nil, **options)
151
- super(url, **options)
152
- @record = record || self.get.result
153
- end
154
-
155
- attr :record
156
-
157
- def dns_records
158
- @dns_records ||= DNSRecords.new(concat_urls(url, 'dns_records'), self, **options)
159
- end
160
-
161
- def firewall_rules
162
- @firewall_rules ||= FirewallRules.new(concat_urls(url, "firewall/access_rules/rules"), self, **options)
163
- end
164
-
165
- def to_s
166
- @record[:name]
167
- end
168
- end
169
-
170
- class Zones < Resource
171
- def all
172
- self.get.results.map{|record| Zone.new(concat_urls(url, record[:id]), record, **options)}
173
- end
174
-
175
- def find_by_name(name)
176
- response = self.get(params: {name: name})
177
-
178
- unless response.empty?
179
- record = response.results.first
180
-
181
- Zone.new(concat_urls(url, record[:id]), record, **options)
182
- end
183
- end
184
-
185
- def find_by_id(id)
186
- Zone.new(concat_urls(url, id), **options)
187
- end
188
- end
28
+ class Connection < Resource
29
+ def zones
30
+ @zones ||= Zones.new(concat_urls(url, 'zones'), options)
31
+ end
32
+ end
33
+
34
+ class DNSRecord < Resource
35
+ def initialize(url, record = nil, **options)
36
+ super(url, **options)
37
+
38
+ @record = record || get.result
39
+ end
40
+
41
+ def update_content(content)
42
+ response = put({ type: @record[:type],
43
+ name: @record[:name],
44
+ content: content }.to_json,
45
+ content_type: 'application/json')
46
+ response.successful?
47
+ end
48
+
49
+ attr_reader :record
50
+
51
+ def to_s
52
+ "#{@record[:name]} #{@record[:type]} #{@record[:content]}"
53
+ end
54
+ end
55
+
56
+ class DNSRecords < Resource
57
+ def initialize(url, zone, **options)
58
+ super(url, **options)
59
+
60
+ @zone = zone
61
+ end
62
+
63
+ attr_reader :zone
64
+
65
+ def all
66
+ results = paginate(DNSRecords, url)
67
+ results.map { |record| DNSRecord.new(concat_urls(url, record[:id]), record, **options) }
68
+ end
69
+
70
+ def find_by_name(name)
71
+ response = get(params: { name: name })
72
+
73
+ return if response.empty?
74
+ record = response.results.first
75
+
76
+ DNSRecord.new(concat_urls(url, record[:id]), record, **options)
77
+ end
78
+
79
+ def find_by_id(id)
80
+ DNSRecord.new(concat_urls(url, id), **options)
81
+ end
82
+ end
83
+
84
+ class FirewallRule < Resource
85
+ def initialize(url, record = nil, **options)
86
+ super(url, **options)
87
+
88
+ @record = record || get.result
89
+ end
90
+
91
+ attr_reader :record
92
+
93
+ def to_s
94
+ "#{@record[:configuration][:value]} - #{@record[:mode]} - #{@record[:notes]}"
95
+ end
96
+ end
97
+
98
+ class FirewallRules < Resource
99
+ def initialize(url, zone, **options)
100
+ super(url, **options)
101
+
102
+ @zone = zone
103
+ end
104
+
105
+ attr_reader :zone
106
+
107
+ def all(mode = nil, ip = nil, notes = nil)
108
+ url_args = ''
109
+ url_args.concat("&mode=#{mode}") if mode
110
+ url_args.concat("&configuration_value=#{ip}") if ip
111
+ url_args.concat("&notes=#{notes}") if notes
112
+
113
+ results = paginate(FirewallRules, url, url_args)
114
+ results.map { |record| FirewallRule.new(concat_urls(url, record[:id]), record, **options) }
115
+ end
116
+
117
+ def firewalled_ips(rules)
118
+ rules.collect { |r| r.record[:configuration][:value] }
119
+ end
120
+
121
+ def blocked_ips
122
+ firewalled_ips(all('block'))
123
+ end
124
+
125
+ def set(mode, ip, note)
126
+ data = {
127
+ mode: mode.to_s,
128
+ configuration: {
129
+ target: 'ip',
130
+ value: ip.to_s,
131
+ notes: "cloudflare gem firewall_rules [#{mode}] #{note} #{Time.now.strftime('%m/%d/%y')}"
132
+ }
133
+ }
134
+
135
+ post(data.to_json, content_type: 'application/json')
136
+ end
137
+
138
+ def unset(mode, value)
139
+ rule = send("find_by_#{mode}", value)
140
+ rule.delete
141
+ end
142
+
143
+ def find_by_id(id)
144
+ FirewallRule.new(concat_urls(url, id), **options)
145
+ end
146
+
147
+ def find_by_ip(ip)
148
+ rule = FirewallRule.new(concat_urls(url, "?configuration_value=#{ip}"), **options)
149
+ FirewallRule.new(concat_urls(url, rule.record.first[:id]), **options)
150
+ end
151
+ end
152
+
153
+ class Zone < Resource
154
+ DEFAULT_PURGE_CACHE_PARAMS = {
155
+ purge_everything: true
156
+ }.freeze
157
+
158
+ def initialize(url, record = nil, preload = false, **options)
159
+ super(url, **options)
160
+ @record = record || get.result if preload
161
+ end
162
+
163
+ attr_reader :record
164
+
165
+ def dns_records
166
+ @dns_records ||= DNSRecords.new(concat_urls(url, 'dns_records'), self, **options)
167
+ end
168
+
169
+ def firewall_rules
170
+ @firewall_rules ||= FirewallRules.new(concat_urls(url, 'firewall/access_rules/rules'), self, **options)
171
+ end
172
+
173
+ def purge_cache(params = DEFAULT_PURGE_CACHE_PARAMS)
174
+ response = self['purge_cache'].post(params&.to_json || {})
175
+ response.successful?
176
+ end
177
+
178
+ def to_s
179
+ @record[:name]
180
+ end
181
+ end
182
+
183
+ class Zones < Resource
184
+ def all
185
+ results = paginate(Zone, url)
186
+ results.map { |record| Zone.new(concat_urls(url, record[:id]), record, **options) }
187
+ end
188
+
189
+ def find_by_name(name)
190
+ response = get(params: { name: name })
191
+
192
+ return if response.empty?
193
+ record = response.results.first
194
+
195
+ Zone.new(concat_urls(url, record[:id]), record, true, **options)
196
+ end
197
+
198
+ def find_by_id(id)
199
+ Zone.new(concat_urls(url, id), **options)
200
+ end
201
+ end
189
202
  end