Skip to content

Commit

Permalink
add readme docs
Browse files Browse the repository at this point in the history
  • Loading branch information
microstudi committed Feb 11, 2025
1 parent 34401e8 commit 19421b6
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,46 @@ Cloudflare.connect(key: key, email: email) do |connection|

# Block an ip:
rule = zone.firewall_rules.set('block', '1.2.3.4', notes: "ssh dictionary attack")

# Get an account
connection.accounts.find_by_id(ENV["CLOUDFLARE_ACCOUNT_ID"]) do |account|
# Find a R2 bucket
bucket = account.r2_buckets.find_by_name("a-s3-compatible-bucket")

# Create a new bucket
bucket = account.r2_buckets.create("another-s3-compatible-bucket")

# Attaching a public domain to a bucket
payload = {
"zoneId" => zone.id,
"enabled" => true
}
bucket.domains.attach("bucket.example.com", **payload)

# Adding a CORS policy to a bucket
rules = [
{
allowed: {
origins: ["domain.tld", "anotherdomain.tld"],
methods: ["GET", "PUT"],
headers: ["*"],
},
exposeHeaders: [
"Origin",
"Content-Type",
"Content-MD5",
"Content-Disposition"
],
maxAgeSeconds: 3600
}
]
payload = {
"account_id" => account.id,
"bucket_name" => "a-nice-bucket",
"rules" => rules
}
bucket.create_cors(**payload)
end
end
```

Expand Down

0 comments on commit 19421b6

Please sign in to comment.