Class: CloudflareClient::Zone::PageRule
- Inherits:
-
Base
- Object
- CloudflareClient
- CloudflareClient::Zone
- Base
- CloudflareClient::Zone::PageRule
- Defined in:
- lib/cloudflare_client/zone/page_rule.rb
Constant Summary collapse
- VALID_STATUSES =
%w[active disabled].freeze
- VALID_ORDERS =
%w[status priority].freeze
- DOC_URL =
'https://api.cloudflare.com/#page-rules-for-a-zone-create-a-page-rule'.freeze
Constants inherited from CloudflareClient::Zone
Constants inherited from CloudflareClient
API_BASE, POSSIBLE_API_SETTINGS, VALID_BUNDLE_METHODS, VALID_DIRECTIONS, VALID_MATCHES, VERSION
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#create(targets:, actions:, priority: 1, status: 'disabled') ⇒ Object
create zone_page_rule.
-
#delete(id:) ⇒ Object
delete a zone page rule.
-
#list(status: 'active', order: 'priority', direction: 'desc', match: 'all') ⇒ Object
list all the page rules for a zone.
-
#show(id:) ⇒ Object
page rule details.
-
#update(id:, targets: [], actions: [], priority: 1, status: 'disabled') ⇒ Object
update a page rule.
Methods inherited from Base
Methods inherited from CloudflareClient::Zone
#create_zone, #delete_zone, #edit_zone, #purge_zone_cache, #update_zone_settings, #zone, #zone_activation_check, #zone_setting, #zone_settings, #zones
Methods inherited from CloudflareClient
Constructor Details
This class inherits a constructor from CloudflareClient::Zone::Base
Instance Method Details
#create(targets:, actions:, priority: 1, status: 'disabled') ⇒ Object
create zone_page_rule
11 12 13 14 15 16 17 18 19 |
# File 'lib/cloudflare_client/zone/page_rule.rb', line 11 def create(targets:, actions:, priority: 1, status: 'disabled') raise "targets must be an array of targets #{DOC_URL}" if !targets.is_a?(Array) || targets.empty? raise "actions must be an array of actions #{DOC_URL}" if !actions.is_a?(Array) || actions.empty? valid_value_check(:status, status, VALID_STATUSES) data = {targets: targets, actions: actions, priority: priority, status: status} cf_post(path: "/zones/#{zone_id}/pagerules", data: data) end |
#delete(id:) ⇒ Object
delete a zone page rule
59 60 61 62 63 |
# File 'lib/cloudflare_client/zone/page_rule.rb', line 59 def delete(id:) id_check('id', id) cf_delete(path: "/zones/#{zone_id}/pagerules/#{id}") end |
#list(status: 'active', order: 'priority', direction: 'desc', match: 'all') ⇒ Object
list all the page rules for a zone
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cloudflare_client/zone/page_rule.rb', line 23 def list(status: 'active', order: 'priority', direction: 'desc', match: 'all') valid_value_check(:status, status, VALID_STATUSES) valid_value_check(:order, order, VALID_ORDERS) valid_value_check(:direction, direction, VALID_DIRECTIONS) valid_value_check(:match, match, VALID_MATCHES) params = {status: status, order: order, direction: direction, match: match} cf_get(path: "/zones/#{zone_id}/pagerules", params: params) end |
#show(id:) ⇒ Object
page rule details
36 37 38 39 40 |
# File 'lib/cloudflare_client/zone/page_rule.rb', line 36 def show(id:) id_check('id', id) cf_get(path: "/zones/#{zone_id}/pagerules/#{id}") end |
#update(id:, targets: [], actions: [], priority: 1, status: 'disabled') ⇒ Object
update a page rule
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/cloudflare_client/zone/page_rule.rb', line 46 def update(id:, targets: [], actions: [], priority: 1, status: 'disabled') id_check('id', id) raise "targets must be an array of targets #{DOC_URL}" if !targets.is_a?(Array) || targets.empty? raise "actions must be an array of actions #{DOC_URL}" if !actions.is_a?(Array) || actions.empty? valid_value_check(:status, status, VALID_STATUSES) data = {targets: targets, actions: actions, priority: priority, status: status} cf_patch(path: "/zones/#{zone_id}/pagerules/#{id}", data: data) end |