bunnyrb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6798312b6bf1d864caf87e8331507defe7facee7e64457883f67560a4c80e066
4
+ data.tar.gz: 9b5cc5bd385953364c54506745ed2a0f04b5fe9b92644562ad615e094a81df62
5
+ SHA512:
6
+ metadata.gz: 21ef362e4cf360bea1d3aa75fd3375707da629213b0ef439e9f2ee22f56f3d3c06f82a4a9380148e021fcdcd2aa5eac90f12bc570b8de16fa752fedc3731f032
7
+ data.tar.gz: 144602b91d7a09fbba760645dd034fa74b6741bcecbb758936ee0bc2c84963b05137f3d45de6757a200d8ded6605c618b97e68574ce4183a19691f9a8ef7cc80
data/.env.example ADDED
@@ -0,0 +1 @@
1
+ API_KEY=
@@ -0,0 +1 @@
1
+ buy_me_a_coffee: deanpcmad
@@ -0,0 +1,22 @@
1
+ name: CI
2
+ on: push
3
+ jobs:
4
+ test:
5
+ runs-on: ubuntu-latest
6
+ strategy:
7
+ fail-fast: false
8
+ matrix:
9
+ ruby_version:
10
+ - 3.1
11
+ - 3.2
12
+ - 3.3
13
+ steps:
14
+ - uses: actions/checkout@v3
15
+ - uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: ${{ matrix.ruby_version }}
18
+ bundler: default
19
+ bundler-cache: true
20
+
21
+ - name: Run tests
22
+ run: bundle exec rake test
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .env
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in twitch.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "minitest", "~> 5.0"
8
+ gem "dotenv"
9
+
10
+ gem "vcr"
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bunnyrb (0.1.0)
5
+ faraday (~> 2.0)
6
+ faraday-multipart (~> 1.0)
7
+ marcel (~> 1.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ dotenv (3.1.2)
13
+ faraday (2.9.1)
14
+ faraday-net_http (>= 2.0, < 3.2)
15
+ faraday-multipart (1.0.4)
16
+ multipart-post (~> 2)
17
+ faraday-net_http (3.1.0)
18
+ net-http
19
+ marcel (1.0.4)
20
+ minitest (5.23.1)
21
+ multipart-post (2.4.1)
22
+ net-http (0.4.1)
23
+ uri
24
+ rake (12.3.3)
25
+ uri (0.13.0)
26
+ vcr (6.2.0)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ bunnyrb!
33
+ dotenv
34
+ minitest (~> 5.0)
35
+ rake (~> 12.0)
36
+ vcr
37
+
38
+ BUNDLED WITH
39
+ 2.5.7
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Dean Perry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,169 @@
1
+ # BunnyRB
2
+
3
+ BunnyRB is a Ruby library for the Bunny API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem "bunnyrb"
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### Set Client Details
16
+
17
+ Firstly you'll need to grab your API Token on the [Account API Key](https://dash.bunny.net/account/api-key) page
18
+ and then configure it like below.
19
+
20
+ ```ruby
21
+ Bunny.configure do |config|
22
+ config.api_token = ENV["BUNNT_API_KEY"]
23
+ end
24
+ ```
25
+
26
+ ### Countries
27
+
28
+ ```ruby
29
+ Bunny::Country.list
30
+ ```
31
+
32
+ ### Regions
33
+
34
+ ```ruby
35
+ Bunny::Region.list
36
+ ```
37
+
38
+ ### Zones
39
+
40
+ ```ruby
41
+ # Retrieve a list of Zone's
42
+ Bunny::Zone.list
43
+
44
+ # Retrieve a zone
45
+ Bunny::Zone.retrieve id: 123
46
+
47
+ # Create a zone
48
+ Bunny::Zone.create(name: "mydomain.com")
49
+
50
+ # Update a zone
51
+ # API Docs: https://docs.bunny.net/reference/dnszonepublic_update
52
+ Bunny::Zone.update id: 123, LoggingEnabled: true
53
+
54
+ # Delete a zone
55
+ Bunny::Zone.delete id: 123
56
+
57
+ # Export a DNS Zone file
58
+ # Returns a string
59
+ Bunny::Zone.export id: 123
60
+
61
+ # Retrieve DNS Query Statistics for a zone
62
+ Bunny::Zone.stats id: 123
63
+
64
+ # Create a DNS Record for a zone
65
+ # API Docs: https://docs.bunny.net/reference/dnszonepublic_addrecord
66
+ Bunny::Zone.create_record zone: 123, type: "A", value: "1.1.1.1", name: "sub"
67
+
68
+ # Update a DNS Record for a zone
69
+ # API Docs: https://docs.bunny.net/reference/dnszonepublic_updaterecord
70
+ Bunny::Zone.update_record zone: 123, record: 123, value: "1.0.0.1"
71
+
72
+ # Delete a DNS Record for a zone
73
+ Bunny::Zone.delete_record zone: 123, record: 123
74
+ ```
75
+
76
+ ### Pull Zones
77
+
78
+ ```ruby
79
+ # Retrieve a list of Pull Zone's
80
+ Bunny::PullZone.list
81
+
82
+ # Retrieve a pull zone
83
+ Bunny::PullZone.retrieve id: 123
84
+
85
+ # Create a pull zone
86
+ # API Docs: https://docs.bunny.net/reference/pullzonepublic_add
87
+ Bunny::PullZone.create(name: "mypullzone")
88
+
89
+ # Update a pull zone
90
+ # API Docs: https://docs.bunny.net/reference/pullzonepublic_updatepullzone
91
+ Bunny::PullZone.update id: 123, EnableGeoZoneUS: true
92
+
93
+ # Delete a pull zone
94
+ Bunny::PullZone.delete id: 123
95
+
96
+ # Purge a pull zone
97
+ # API Docs: https://docs.bunny.net/reference/pullzonepublic_purgecache
98
+ Bunny::PullZone.purge id: 123
99
+ ```
100
+
101
+ ### Storage Zones
102
+
103
+ ```ruby
104
+ # Retrieve a list of Storage Zone's
105
+ Bunny::StorageZone.list
106
+
107
+ # Retrieve a storage zone
108
+ Bunny::StorageZone.retrieve id: 123
109
+
110
+ # Create a storage zone
111
+ # API Docs: https://docs.bunny.net/reference/storagezonepublic_add
112
+ Bunny::StorageZone.create(name: "mystoragezone", region: "UK", tier: "Standard")
113
+
114
+ # Update a storage zone
115
+ # API Docs: https://docs.bunny.net/reference/storagezonepublic_update
116
+ Bunny::StorageZone.update id: 123, OriginUrl: "https://mysite.com"
117
+
118
+ # Delete a storage zone
119
+ Bunny::StorageZone.delete id: 123
120
+ ```
121
+
122
+ ### Video Libraries
123
+
124
+ ```ruby
125
+ # Retrieve a list of Video Libraries
126
+ Bunny::VideoLibrary.list
127
+
128
+ # Retrieve a video library
129
+ Bunny::VideoLibrary.retrieve id: 123
130
+
131
+ # Create a video library
132
+ # API Docs: https://docs.bunny.net/reference/videolibrarypublic_add
133
+ Bunny::VideoLibrary.create(name: "myvideolibrary")
134
+
135
+ # Update a video library
136
+ # API Docs: https://docs.bunny.net/reference/videolibrarypublic_update
137
+ Bunny::VideoLibrary.update id: 123, EnableDRM: true
138
+
139
+ # Delete a video library
140
+ Bunny::VideoLibrary.delete id: 123
141
+ ```
142
+
143
+ ## Edge API
144
+
145
+ The Edge API is for managing files on the Bunny Edge Storage Service.
146
+
147
+ ```ruby
148
+ # List all files in a zone
149
+ Bunny::Edge::Upload.list(zone: "myzone", path: "/path/to/files")
150
+
151
+ # Create a file
152
+ file = File.new("myfile.txt")
153
+ response = Bunny::Edge::Upload.create(zone: "myzone", path: "/path/to/files", name: "myfile.txt", file: file)
154
+
155
+ # Download a file
156
+ # Returns a Tempfile
157
+ Bunny::Edge::Upload.download(zone: "myzone", path: "/path/to/files", name: "myfile.txt")
158
+
159
+ # Delete a file
160
+ Bunny::Edge::Upload.delete(zone: "myzone", path: "/path/to/files", name: "myfile.txt")
161
+ ```
162
+
163
+ ## Contributing
164
+
165
+ Bug reports and pull requests are welcome on GitHub at https://github.com/deanpcmad/bunnyrb.
166
+
167
+ ## License
168
+
169
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bunny"
5
+
6
+ # Load environment variables from .env file
7
+ require 'dotenv/load'
8
+
9
+ # You can add fixtures and/or initialization code here to make experimenting
10
+ # with your gem easier. You can also use a different console, if you like.
11
+
12
+ # (If you use this, don't forget to add pry to your Gemfile!)
13
+ # require "pry"
14
+ # Pry.start
15
+
16
+ Bunny.configure do |config|
17
+ config.api_token = ENV["API_KEY"]
18
+
19
+ config.edge_api_token = ENV["EDGE_API_KEY"]
20
+ config.edge_region = ENV["EDGE_REGION"]
21
+ end
22
+
23
+ require "irb"
24
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bunnyrb.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ require_relative 'lib/bunny/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "bunnyrb"
5
+ spec.version = Bunny::VERSION
6
+ spec.authors = ["Dean Perry"]
7
+ spec.email = ["dean@deanpcmad.com"]
8
+
9
+ spec.summary = "A Ruby library for the Bunny APIs"
10
+ spec.homepage = "https://deanpcmad.com"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = "https://github.com/deanpcmad/bunnyrb"
16
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_dependency "faraday", "~> 2.0"
28
+ spec.add_dependency "faraday-multipart", "~> 1.0"
29
+ spec.add_dependency "marcel", "~> 1.0"
30
+ end
@@ -0,0 +1,74 @@
1
+ module Bunny
2
+ class Client
3
+
4
+ BASE_URL = "https://api.bunny.net"
5
+
6
+ class << self
7
+
8
+ def connection
9
+ @connection ||= Faraday.new(BASE_URL) do |conn|
10
+ conn.headers = {
11
+ "AccessKey" => Bunny.config.api_token,
12
+ "User-Agent" => "bunnyrb/v#{VERSION} (github.com/deanpcmad/bunnyrb)"
13
+ }
14
+
15
+ conn.request :json
16
+
17
+ conn.response :json, content_type: "application/json"
18
+ end
19
+ end
20
+
21
+ def get_request(url, params: {}, headers: {})
22
+ handle_response connection.get(url, params, headers)
23
+ end
24
+
25
+ def post_request(url, body: {}, headers: {})
26
+ handle_response connection.post(url, body, headers)
27
+ end
28
+
29
+ def put_request(url, body:, headers: {})
30
+ handle_response connection.put(url, body, headers)
31
+ end
32
+
33
+ def patch_request(url, body:, headers: {})
34
+ handle_response connection.patch(url, body, headers)
35
+ end
36
+
37
+ def delete_request(url, headers: {})
38
+ handle_response connection.delete(url, headers)
39
+ end
40
+
41
+ def handle_response(response)
42
+ case response.status
43
+ when 400
44
+ raise Error, "Error 400: Your request was malformed. '#{response.body["Message"]}'"
45
+ when 401
46
+ raise Error, "Error 401: You did not supply valid authentication credentials. '#{response.body["Message"]}'"
47
+ when 403
48
+ raise Error, "Error 403: You are not allowed to perform that action. '#{response.body["Message"]}'"
49
+ when 404
50
+ raise Error, "Error 404: No results were found for your request. '#{response.body["Message"]}'"
51
+ when 405
52
+ raise Error, "Error 405: Method Not Allowed. '#{response.body["Message"]}'"
53
+ when 409
54
+ raise Error, "Error 409: Your request was a conflict. '#{response.body["Message"]}'"
55
+ when 422
56
+ raise Error, "Error 422: Unprocessable Content. '#{response.body["Message"]}'"
57
+ when 429
58
+ raise Error, "Error 429: Your request exceeded the API rate limit. '#{response.body["Message"]}'"
59
+ when 500
60
+ raise Error, "Error 500: We were unable to perform the request due to server-side problems. '#{response.body["Message"]}'"
61
+ when 503
62
+ raise Error, "Error 503: You have been rate limited for sending more than 20 requests per second. '#{response.body["Message"]}'"
63
+ when 501
64
+ raise Error, "Error 501: This resource has not been implemented. '#{response.body["Message"]}'"
65
+ when 204
66
+ return true
67
+ end
68
+
69
+ response
70
+ end
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,25 @@
1
+ module Bunny
2
+ class Collection
3
+ attr_reader :data, :total
4
+
5
+ def self.from_response(response, type:, key: nil)
6
+ body = response.body
7
+
8
+ if key.is_a?(String)
9
+ data = body[key].map { |attrs| type.new(attrs) }
10
+ else
11
+ data = body.map { |attrs| type.new(attrs) }
12
+ end
13
+
14
+ new(
15
+ data: data,
16
+ total: data.count
17
+ )
18
+ end
19
+
20
+ def initialize(data:, total:)
21
+ @data = data
22
+ @total = total
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bunny
4
+ class Configuration
5
+
6
+ attr_accessor :api_token
7
+ attr_accessor :edge_region, :edge_api_token
8
+
9
+ end
10
+ end
@@ -0,0 +1,116 @@
1
+ module Bunny
2
+ module Edge
3
+ class Client
4
+
5
+ class << self
6
+
7
+ def url
8
+ raise "An Edge Region must be specified" unless Bunny.config.edge_region
9
+ case Bunny.config.edge_region.downcase
10
+
11
+ when "de"
12
+ "https://storage.bunnycdn.com"
13
+ when "uk"
14
+ "https://uk.storage.bunnycdn.com"
15
+ when "ny"
16
+ "https://ny.storage.bunnycdn.com"
17
+ when "la"
18
+ "https://la.storage.bunnycdn.com"
19
+ when "sg"
20
+ "https://sg.storage.bunnycdn.com"
21
+ when "se"
22
+ "https://se.storage.bunnycdn.com"
23
+ when "br"
24
+ "https://br.storage.bunnycdn.com"
25
+ when "sa"
26
+ "https://jh.storage.bunnycdn.com"
27
+ when "syd"
28
+ "https://syd.storage.bunnycdn.com"
29
+ else
30
+ "https://storage.bunnycdn.com"
31
+ end
32
+ end
33
+
34
+ def connection
35
+ @connection ||= Faraday.new(url) do |conn|
36
+ conn.headers = {
37
+ "AccessKey" => Bunny.config.edge_api_token,
38
+ "User-Agent" => "bunnyrb/v#{VERSION} (github.com/deanpcmad/bunnyrb)"
39
+ }
40
+
41
+ conn.request :json
42
+
43
+ conn.response :json, content_type: "application/json"
44
+ end
45
+ end
46
+
47
+ def upload_connection
48
+ @connection ||= Faraday.new(url) do |conn|
49
+ conn.headers = {
50
+ "AccessKey" => Bunny.config.edge_api_token,
51
+ "User-Agent" => "bunnyrb/v#{VERSION} (github.com/deanpcmad/bunnyrb)"
52
+ }
53
+
54
+ conn.request :multipart, flat_encode: true
55
+
56
+ # conn.request :json
57
+
58
+ # conn.response :json, content_type: "application/json"
59
+ end
60
+ end
61
+
62
+ def get_request(url, params: {}, headers: {})
63
+ handle_response connection.get(url, params, headers)
64
+ end
65
+
66
+ # def post_request(url, body: {}, headers: {})
67
+ # handle_response connection.post(url, body, headers)
68
+ # end
69
+
70
+ def put_request(url, body:, headers: {})
71
+ handle_response upload_connection.put(url, body, headers)
72
+ end
73
+
74
+ # def patch_request(url, body:, headers: {})
75
+ # handle_response connection.patch(url, body, headers)
76
+ # end
77
+
78
+ def delete_request(url, headers: {})
79
+ handle_response connection.delete(url, headers)
80
+ end
81
+
82
+ def handle_response(response)
83
+ case response.status
84
+ when 400
85
+ raise Error, "Error 400: Your request was malformed. '#{response.body["Message"]}'"
86
+ when 401
87
+ raise Error, "Error 401: You did not supply valid authentication credentials. '#{response.body["Message"]}'"
88
+ when 403
89
+ raise Error, "Error 403: You are not allowed to perform that action. '#{response.body["Message"]}'"
90
+ when 404
91
+ raise Error, "Error 404: No results were found for your request. '#{response.body["Message"]}'"
92
+ when 405
93
+ raise Error, "Error 405: Method Not Allowed. '#{response.body["Message"]}'"
94
+ when 409
95
+ raise Error, "Error 409: Your request was a conflict. '#{response.body["Message"]}'"
96
+ when 422
97
+ raise Error, "Error 422: Unprocessable Content. '#{response.body["Message"]}'"
98
+ when 429
99
+ raise Error, "Error 429: Your request exceeded the API rate limit. '#{response.body["Message"]}'"
100
+ when 500
101
+ raise Error, "Error 500: We were unable to perform the request due to server-side problems. '#{response.body["Message"]}'"
102
+ when 503
103
+ raise Error, "Error 503: You have been rate limited for sending more than 20 requests per second. '#{response.body["Message"]}'"
104
+ when 501
105
+ raise Error, "Error 501: This resource has not been implemented. '#{response.body["Message"]}'"
106
+ when 204
107
+ return true
108
+ end
109
+
110
+ response
111
+ end
112
+ end
113
+
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,41 @@
1
+ module Bunny
2
+ module Edge
3
+ class Upload < Object
4
+
5
+ class << self
6
+
7
+ def list(zone:, path:)
8
+ response = Edge::Client.get_request("#{zone}/#{path}")
9
+ Collection.from_response(response, type: Upload)
10
+ end
11
+
12
+ def create(zone:, path:, name:, file:)
13
+ headers = {
14
+ "Content-Type" => Marcel::MimeType.for(file),
15
+ "Content-Length" => file.size.to_s
16
+ }
17
+ response = Edge::Client.put_request([zone, path, name].join("/"), body: file, headers: headers)
18
+ response.success?
19
+ end
20
+
21
+ def download(zone:, path:, name:)
22
+ response = Edge::Client.get_request([zone, path, name].join("/"))
23
+
24
+ tempfile = Tempfile.new
25
+ tempfile.binmode
26
+ tempfile.write(response.body)
27
+ tempfile.rewind
28
+
29
+ tempfile
30
+ end
31
+
32
+ def delete(zone:, path:, name:)
33
+ response = Edge::Client.delete_request([zone, path, name].join("/"))
34
+ response.success?
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,4 @@
1
+ module Bunny
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ module Bunny
2
+ class Country < Object
3
+
4
+ class << self
5
+
6
+ def list
7
+ response = Client.get_request("country")
8
+ Collection.from_response(response, type: Country)
9
+ end
10
+
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,37 @@
1
+ module Bunny
2
+ class PullZone < Object
3
+
4
+ class << self
5
+
6
+ def list
7
+ response = Client.get_request("pullzone")
8
+ Collection.from_response(response, type: PullZone)
9
+ end
10
+
11
+ def create(name:, **attributes)
12
+ response = Client.post_request("pullzone", body: attributes.merge(name: name))
13
+ PullZone.new(response.body)
14
+ end
15
+
16
+ def retrieve(id:)
17
+ response = Client.get_request("pullzone/#{id}")
18
+ PullZone.new(response.body)
19
+ end
20
+
21
+ def update(id:, **attributes)
22
+ response = Client.post_request("pullzone/#{id}", body: attributes)
23
+ PullZone.new(response.body)
24
+ end
25
+
26
+ def delete(id:)
27
+ Client.delete_request("pullzone/#{id}")
28
+ end
29
+
30
+ def purge(id:)
31
+ Client.post_request("pullzone/#{id}/purgeCache", body: {})
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,4 @@
1
+ module Bunny
2
+ class Record < Object
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ module Bunny
2
+ class Region < Object
3
+
4
+ class << self
5
+
6
+ def list
7
+ response = Client.get_request("region")
8
+ Collection.from_response(response, type: Region)
9
+ end
10
+
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,32 @@
1
+ module Bunny
2
+ class StorageZone < Object
3
+
4
+ class << self
5
+
6
+ def list
7
+ response = Client.get_request("storagezone")
8
+ Collection.from_response(response, type: StorageZone)
9
+ end
10
+
11
+ def create(name:, region:, tier:)
12
+ response = Client.post_request("storagezone", body: { Name: name, Region: region, ZoneTier: tier })
13
+ StorageZone.new(response.body)
14
+ end
15
+
16
+ def retrieve(id:)
17
+ response = Client.get_request("storagezone/#{id}")
18
+ StorageZone.new(response.body)
19
+ end
20
+
21
+ def update(id:, **attributes)
22
+ Client.post_request("storagezone/#{id}", body: attributes)
23
+ end
24
+
25
+ def delete(id:)
26
+ Client.delete_request("storagezone/#{id}")
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,33 @@
1
+ module Bunny
2
+ class VideoLibrary < Object
3
+
4
+ class << self
5
+
6
+ def list
7
+ response = Client.get_request("videolibrary")
8
+ Collection.from_response(response, type: VideoLibrary)
9
+ end
10
+
11
+ def create(name:)
12
+ response = Client.post_request("videolibrary", body: { name: name })
13
+ VideoLibrary.new(response.body)
14
+ end
15
+
16
+ def retrieve(id:)
17
+ response = Client.get_request("videolibrary/#{id}")
18
+ VideoLibrary.new(response.body)
19
+ end
20
+
21
+ def update(id:, **attributes)
22
+ response = Client.post_request("videolibrary/#{id}", body: attributes)
23
+ VideoLibrary.new(response.body)
24
+ end
25
+
26
+ def delete(id:)
27
+ Client.delete_request("videolibrary/#{id}")
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,61 @@
1
+ module Bunny
2
+ class Zone < Object
3
+
4
+ class << self
5
+
6
+ def list
7
+ response = Client.get_request("dnszone")
8
+ Collection.from_response(response, type: Zone, key: "Items")
9
+ end
10
+
11
+ def create(name:)
12
+ response = Client.post_request("dnszone", body: { Domain: name })
13
+ Zone.new(response.body)
14
+ end
15
+
16
+ def retrieve(id:)
17
+ response = Client.get_request("dnszone/#{id}")
18
+ Zone.new(response.body)
19
+ end
20
+
21
+ def update(id:, **attributes)
22
+ response = Client.post_request("dnszone/#{id}", body: attributes)
23
+ Zone.new(response.body)
24
+ end
25
+
26
+ def delete(id:)
27
+ Client.delete_request("dnszone/#{id}")
28
+ end
29
+
30
+ def export(id:)
31
+ response = Client.get_request("dnszone/#{id}/export")
32
+ response.body
33
+ end
34
+
35
+ def stats(id:)
36
+ response = Client.get_request("dnszone/#{id}/statistics")
37
+ ZoneStatistic.new(response.body)
38
+ end
39
+
40
+ def check_availability(name:)
41
+ response = Client.post_request("dnszone/checkavailability", body: { Domain: name })
42
+ response.body["Available"]
43
+ end
44
+
45
+ def create_record(zone:, type:, value:, **attributes)
46
+ response = Client.put_request("dnszone/#{zone}/records", body: attributes.merge(type: type, value: value))
47
+ Record.new(response.body)
48
+ end
49
+
50
+ def update_record(zone:, record:, **attributes)
51
+ Client.post_request("dnszone/#{zone}/records/#{record}", body: attributes)
52
+ end
53
+
54
+ def delete_record(zone:, record:)
55
+ Client.delete_request("dnszone/#{zone}/records/#{record}")
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,4 @@
1
+ module Bunny
2
+ class ZoneStatistic < Object
3
+ end
4
+ end
@@ -0,0 +1,26 @@
1
+ require "ostruct"
2
+
3
+ module Bunny
4
+ class Object < OpenStruct
5
+ def initialize(attributes)
6
+ super to_ostruct(attributes)
7
+ end
8
+
9
+ def to_ostruct(obj)
10
+ if obj.is_a?(Hash)
11
+ OpenStruct.new(obj.map { |key, val| [camel_to_snake(key), to_ostruct(val)] }.to_h)
12
+ elsif obj.is_a?(Array)
13
+ obj.map { |o| to_ostruct(o) }
14
+ else # Assumed to be a primitive value
15
+ obj
16
+ end
17
+ end
18
+
19
+ def camel_to_snake(input)
20
+ str = input.is_a?(Symbol) ? input.to_s : input
21
+ snake_case_str = str.gsub(/([A-Z])/, '_\1').downcase
22
+ snake_case_str.sub!(/^_/, '')
23
+ input.is_a?(Symbol) ? snake_case_str.to_sym : snake_case_str
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Bunny
2
+ VERSION = "0.1.0"
3
+ end
data/lib/bunny.rb ADDED
@@ -0,0 +1,43 @@
1
+ require "faraday"
2
+ require "faraday/multipart"
3
+ require "marcel"
4
+
5
+ require_relative "bunny/version"
6
+
7
+ module Bunny
8
+
9
+ autoload :Configuration, "bunny/configuration"
10
+ autoload :Client, "bunny/client"
11
+ autoload :Collection, "bunny/collection"
12
+ autoload :Error, "bunny/error"
13
+ autoload :Object, "bunny/object"
14
+
15
+ class << self
16
+ attr_writer :config
17
+ end
18
+
19
+ def self.configure
20
+ yield(config) if block_given?
21
+ end
22
+
23
+ def self.config
24
+ @config ||= Bunny::Configuration.new
25
+ end
26
+
27
+ autoload :Country, "bunny/models/country"
28
+ autoload :Region, "bunny/models/region"
29
+ autoload :Zone, "bunny/models/zone"
30
+ autoload :StorageZone, "bunny/models/storage_zone"
31
+ autoload :VideoLibrary, "bunny/models/video_library"
32
+ autoload :PullZone, "bunny/models/pull_zone"
33
+
34
+ autoload :Record, "bunny/models/record"
35
+ autoload :ZoneStatistic, "bunny/models/zone_statistic"
36
+
37
+ # Edge API
38
+ module Edge
39
+ autoload :Client, "bunny/edge/client"
40
+ autoload :Upload, "bunny/edge/models/upload"
41
+ end
42
+
43
+ end
data/lib/bunnyrb.rb ADDED
@@ -0,0 +1 @@
1
+ require "bunny"
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bunnyrb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dean Perry
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-06-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday-multipart
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: marcel
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ description:
56
+ email:
57
+ - dean@deanpcmad.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".env.example"
63
+ - ".github/FUNDING.yml"
64
+ - ".github/workflows/ci.yml"
65
+ - ".gitignore"
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - bunnyrb.gemspec
74
+ - lib/bunny.rb
75
+ - lib/bunny/client.rb
76
+ - lib/bunny/collection.rb
77
+ - lib/bunny/configuration.rb
78
+ - lib/bunny/edge/client.rb
79
+ - lib/bunny/edge/models/upload.rb
80
+ - lib/bunny/error.rb
81
+ - lib/bunny/models/country.rb
82
+ - lib/bunny/models/pull_zone.rb
83
+ - lib/bunny/models/record.rb
84
+ - lib/bunny/models/region.rb
85
+ - lib/bunny/models/storage_zone.rb
86
+ - lib/bunny/models/video_library.rb
87
+ - lib/bunny/models/zone.rb
88
+ - lib/bunny/models/zone_statistic.rb
89
+ - lib/bunny/object.rb
90
+ - lib/bunny/version.rb
91
+ - lib/bunnyrb.rb
92
+ homepage: https://deanpcmad.com
93
+ licenses:
94
+ - MIT
95
+ metadata:
96
+ homepage_uri: https://deanpcmad.com
97
+ source_code_uri: https://github.com/deanpcmad/bunnyrb
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '3.0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubygems_version: 3.5.9
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: A Ruby library for the Bunny APIs
117
+ test_files: []