Class: Cloudflare::Firewall::Rules

Inherits:
Representation
  • Object
show all
Includes:
Paginate
Defined in:
lib/cloudflare/firewall.rb

Constant Summary

Constants inherited from Representation

Representation::WRAPPER

Instance Method Summary collapse

Methods included from Paginate

#each, #empty?, #find_by_id

Methods inherited from Representation

#errors, #messages, #represent, #represent_message, #result, #results, #success?, #to_hash, #to_id

Instance Method Details

#each_by_value(value, &block) ⇒ Object



57
58
59
# File 'lib/cloudflare/firewall.rb', line 57

def each_by_value(value, &block)
	each(configuration_value: value, &block)
end

#representationObject



35
36
37
# File 'lib/cloudflare/firewall.rb', line 35

def representation
	Rule
end

#set(mode, value, notes: nil, target: "ip") ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cloudflare/firewall.rb', line 39

def set(mode, value, notes: nil, target: "ip")
	notes ||= "cloudflare gem [#{mode}] #{Time.now.strftime('%m/%d/%y')}"
	
	payload = {mode: mode.to_s, notes: notes, configuration: {target: target, value: value.to_s}}
	
	Rule.post(@resource, payload) do |resource, response|
		value = response.read
		result = value[:result]
		 = response.headers
		
		if id = result[:id]
			resource = resource.with(path: id)
		end
		
		Rule.new(resource, value: value, metadata: )
	end
end