class CloudflareClient::Zone::PageRule

Constants

DOC_URL
VALID_ORDERS
VALID_STATUSES

Public Instance Methods

create(targets:, actions:, priority: 1, status: 'disabled') click to toggle source

create zone_page_rule

# 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:) click to toggle source

delete a zone page rule

# 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') click to toggle source

list all the page rules for a zone

# 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:) click to toggle source

page rule details

# 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') click to toggle source

update a page rule

# 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