A Ruby client library for Cloudflare API v4.
Add this line to your application's Gemfile:
gem 'cloudflare'And then execute:
$ bundle
Or install it yourself as:
$ gem install cloudflare
zones = Cloudflare::Client.new(api_token: '[API_TOKEN]').zones.list
zones.each do |zone|
puts zone.id
endzones = Cloudflare::Client.new(api_token: '[API_TOKEN]').zones.retrieve(zone_id: '[ZONE_ID]')rules = Cloudflare::Client.new(api_token: '[API_TOKEN]').firewall_rules.list(zone_id: '[ZONE_ID]')
rules.each do |rule|
puts rule.id
endrule = Cloudflare::Client.new(api_token: '[API_TOKEN]').firewall_rules.retrieve(zone_id: '[ZONE_ID]', id: '[RULE_ID]')client = Cloudflare::Client.new(auth_emai: '[EMAIL]', auth_key: '[AUTH_KEY]')
rule = client.firewall_rules.create(zone_id: '[ZONE_ID]',
filter_id: '[FILTER_ID]',
action: 'block',
description: 'Block traffic from...')client = Cloudflare::Client.new(auth_emai: '[EMAIL]', auth_key: '[AUTH_KEY]')
rule = client.firewall_rules.create_with_filter(zone_id: '[ZONE_ID]',
filter_id: {description: 'Stop Russian hackers', expression: '(ip.geoip.country eq "RU")'},
action: 'block',
description: 'Block traffic from...')client = Cloudflare::Client.new(auth_emai: '[EMAIL]', auth_key: '[AUTH_KEY]')
client.firewall_rules.delete(zone_id: '[ZONE_ID]', id: '[RULE_ID]')filters = Cloudflare::Client.new(api_token: '[API_TOKEN]').filters.list(zone_id: '[ZONE_ID]')filter = = Cloudflare::Client.new(api_token: '[API_TOKEN]').filters.retrieve(zone_id: '[ZONE_ID]', id: '[FILTER_ID]')client = Cloudflare::Client.new(auth_emai: '[EMAIL]', auth_key: '[AUTH_KEY]')
filter = client.filters.create(zone_id: '[ZONE_ID]', expression: '(ip.geoip.country eq "RU")', description: 'Country is Russia')client = Cloudflare::Client.new(auth_emai: '[EMAIL]', auth_key: '[AUTH_KEY]')
client.filters.delete(zone_id: '[ZONE_ID]', id: '[FILTER_ID]')After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/dsgraham/cloudflare.
The gem is available as open source under the terms of the MIT License.