bunny_cdn 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +11 -7
- data/bunny_cdn.gemspec +4 -2
- data/lib/bunny_cdn/configuration.rb +3 -2
- data/lib/bunny_cdn/pullzone.rb +20 -1
- data/lib/bunny_cdn/storage.rb +72 -6
- data/lib/bunny_cdn/version.rb +1 -1
- metadata +13 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7c39cfb456030b3e4c3d329031894dbb9280ed683857cc87c9415ffaf9af5a6b
|
|
4
|
+
data.tar.gz: 1e9d967f43084c2c95fff77d546e8eb7662204c2c81107e58583fa5a9e3c14fe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5eef510c1c3ac8e9faaaef962e22659d36e677d3f5f3845419279a7ab883d58b14aa9dec2fbd5c750a5ab8dab6261ba85bf12c6090921127e15dc94279d96cb9
|
|
7
|
+
data.tar.gz: 3427d6dd04a628fac91c642c62a26c2627ae9ee7fb14f659e37c80057c28795fcbd72c012e52c866df6398e9d6b8e33506869195d1a7f25cb37d9825e2914ded
|
data/README.md
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
[](https://badge.fury.io/rb/bunny_cdn)
|
|
1
2
|
[](https://app.codeship.com/projects/390509)
|
|
3
|
+
[](https://codeclimate.com/github/brandon-meeks/bunny_cdn/maintainability)
|
|
2
4
|
|
|
3
5
|
# BunnyCdn
|
|
4
6
|
|
|
@@ -32,22 +34,24 @@ Create the initializer `config/initializers/bunny_cdn.rb` and set the configurat
|
|
|
32
34
|
BunnyCdn.configure do |config|
|
|
33
35
|
config.apiKey = # The API key for your BunnyCDN account
|
|
34
36
|
config.storageZone = # The storage zone you want to work with
|
|
37
|
+
config.region = # the region of the storage zone. Options are 'eu' for Falkenstein, 'ny' for New York, 'la' for Los Angeles, or 'sg' for Asia
|
|
35
38
|
config.accessKey = # The password for your storage zone
|
|
36
39
|
end
|
|
37
40
|
```
|
|
38
41
|
|
|
39
|
-
###
|
|
42
|
+
### File Uploads
|
|
40
43
|
|
|
41
|
-
|
|
44
|
+
New to v1.2.0, there are now two methods for handling file uploads.
|
|
42
45
|
|
|
46
|
+
To upload a file from a file input on a form, simply use
|
|
43
47
|
```ruby
|
|
44
|
-
BunnyCdn.
|
|
45
|
-
config.apiKey = # The API key for your BunnyCDN account
|
|
46
|
-
config.storageZone = # The storage zone you want to work with
|
|
47
|
-
config.accessKey = # The password for your storage zone
|
|
48
|
-
end
|
|
48
|
+
BunnyCdn::Storage.uploadFormFile(path, file)
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
+
To upload a file to BunnyCDN that already exists on the system, or to upload a file as a secondary option to storing it on the system use
|
|
52
|
+
```ruby
|
|
53
|
+
BunnyCdn::Storage.uploadFile(path, file)
|
|
54
|
+
```
|
|
51
55
|
## Development
|
|
52
56
|
|
|
53
57
|
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.
|
data/bunny_cdn.gemspec
CHANGED
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
|
17
17
|
|
|
18
18
|
spec.metadata["homepage_uri"] = spec.homepage
|
|
19
19
|
spec.metadata["source_code_uri"] = "https://github.com/brandon-meeks/bunny_cdn_gem"
|
|
20
|
-
|
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/brandon-meeks/bunny_cdn/releases"
|
|
21
21
|
|
|
22
22
|
# Specify which files should be added to the gem when it is released.
|
|
23
23
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
@@ -32,7 +32,9 @@ Gem::Specification.new do |spec|
|
|
|
32
32
|
spec.add_dependency 'json', '~> 2.3'
|
|
33
33
|
|
|
34
34
|
spec.add_development_dependency "bundler", "~> 2.0"
|
|
35
|
-
spec.add_development_dependency "rake", "~>
|
|
35
|
+
spec.add_development_dependency "rake", "~> 12.3", ">= 12.3.3"
|
|
36
36
|
spec.add_development_dependency "rspec", "~> 3.0"
|
|
37
37
|
spec.add_development_dependency "webmock", '~> 3.8', '>= 3.8.3'
|
|
38
|
+
|
|
39
|
+
spec.required_ruby_version = '>= 2.0.1'
|
|
38
40
|
end
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
module BunnyCdn
|
|
2
2
|
class Configuration
|
|
3
|
-
attr_accessor :storageZone, :accessKey, :apiKey
|
|
3
|
+
attr_accessor :storageZone, :region, :accessKey, :apiKey
|
|
4
4
|
|
|
5
|
+
# Sets the configuration variables upon calling BunnyCdn::Configuration.new
|
|
5
6
|
def initialize
|
|
6
7
|
@storageZone = nil
|
|
8
|
+
@region = nil # Options are: eu, ny, la or sg (Asia)
|
|
7
9
|
@accessKey = nil
|
|
8
10
|
@apiKey = nil
|
|
9
11
|
end
|
|
@@ -13,7 +15,6 @@ module BunnyCdn
|
|
|
13
15
|
@configuration ||= Configuration.new
|
|
14
16
|
end
|
|
15
17
|
|
|
16
|
-
# Set BunnyCdn's configuration
|
|
17
18
|
def self.configuration=(config)
|
|
18
19
|
@configuration = config
|
|
19
20
|
end
|
data/lib/bunny_cdn/pullzone.rb
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
module BunnyCdn
|
|
2
2
|
class Pullzone
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
RestClient.log = STDOUT # enables RestClient logging
|
|
5
5
|
|
|
6
|
+
BASE_URL = 'https://bunnycdn.com/api/pullzone' # URL to for BunnyCDN's Pullzone API
|
|
7
|
+
|
|
8
|
+
# Sets the apiKey to that in configuration
|
|
6
9
|
def self.apiKey
|
|
7
10
|
@apiKey = BunnyCdn.configuration.apiKey
|
|
8
11
|
end
|
|
9
12
|
|
|
13
|
+
# Sets the necessary headers to make requests to the BunnyCDN API
|
|
10
14
|
def self.headers
|
|
11
15
|
{
|
|
12
16
|
:accesskey => apiKey,
|
|
@@ -15,6 +19,7 @@ module BunnyCdn
|
|
|
15
19
|
}
|
|
16
20
|
end
|
|
17
21
|
|
|
22
|
+
# Gets all Pull Zones from BunnyCDN
|
|
18
23
|
def self.getAllPullzones
|
|
19
24
|
begin
|
|
20
25
|
response = RestClient.get(BASE_URL, headers)
|
|
@@ -24,6 +29,11 @@ module BunnyCdn
|
|
|
24
29
|
return response
|
|
25
30
|
end
|
|
26
31
|
|
|
32
|
+
# Creates a new pullzone
|
|
33
|
+
# Params:
|
|
34
|
+
# +name+:: the name of the new Pull Zone
|
|
35
|
+
# +type+:: the pricing type of the pull zone you wish to add. 0 = Standard, 1 = High Volume
|
|
36
|
+
# originURL+:: the origin URL where the pull zone files are pulled from.
|
|
27
37
|
def self.createPullzone(name, type = 0, originUrl)
|
|
28
38
|
values = {
|
|
29
39
|
:name => name,
|
|
@@ -38,6 +48,9 @@ module BunnyCdn
|
|
|
38
48
|
return response
|
|
39
49
|
end
|
|
40
50
|
|
|
51
|
+
# Gets the details of the pull zone using the given ID
|
|
52
|
+
# Params:
|
|
53
|
+
# +id+:: the ID of the Pull Zone to return
|
|
41
54
|
def self.getSinglePullzone(id)
|
|
42
55
|
begin
|
|
43
56
|
response = RestClient.get("#{BASE_URL}/#{id}", headers)
|
|
@@ -47,6 +60,9 @@ module BunnyCdn
|
|
|
47
60
|
return response
|
|
48
61
|
end
|
|
49
62
|
|
|
63
|
+
# Deletes the pull zone using the given ID
|
|
64
|
+
# Params:
|
|
65
|
+
# +id+:: the ID of the Pull Zone to delete
|
|
50
66
|
def self.deletePullzone(id)
|
|
51
67
|
begin
|
|
52
68
|
response = RestClient.delete("#{BASE_URL}/#{id}", headers)
|
|
@@ -56,6 +72,9 @@ module BunnyCdn
|
|
|
56
72
|
return response
|
|
57
73
|
end
|
|
58
74
|
|
|
75
|
+
# Purges the cache for the Pull Zone using the given ID
|
|
76
|
+
# Params:
|
|
77
|
+
# +id+:: the ID of the zone which should have the cache purged
|
|
59
78
|
def self.purgeCache(id)
|
|
60
79
|
begin
|
|
61
80
|
response = RestClient.post("#{BASE_URL}/#{id}/purgeCache", {}.to_json, headers)
|
data/lib/bunny_cdn/storage.rb
CHANGED
|
@@ -1,44 +1,110 @@
|
|
|
1
1
|
module BunnyCdn
|
|
2
2
|
class Storage
|
|
3
|
+
|
|
4
|
+
RestClient.log = STDOUT # enables RestClient logging
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
# Sets the storage zone as set in configuration
|
|
6
7
|
def self.storageZone
|
|
7
8
|
BunnyCdn.configuration.storageZone
|
|
8
9
|
end
|
|
9
10
|
|
|
11
|
+
# Sets the proper URL based on the region set in configuration
|
|
12
|
+
def self.set_region_url
|
|
13
|
+
case BunnyCdn.configuration.region
|
|
14
|
+
when nil || 'eu'
|
|
15
|
+
'https://storage.bunnycdn.com'
|
|
16
|
+
when 'ny'
|
|
17
|
+
'https://ny.storage.bunnycdn.com'
|
|
18
|
+
when 'la'
|
|
19
|
+
'https://la.storage.bunnycdn.com'
|
|
20
|
+
when 'sg'
|
|
21
|
+
'https://sg.storage.bunnycdn.com'
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Sets the apiKey to that in configuration
|
|
10
26
|
def self.apiKey
|
|
11
27
|
BunnyCdn.configuration.accessKey
|
|
12
28
|
end
|
|
13
29
|
|
|
30
|
+
# Sets the necessary headers to make requests to the BunnyCDN API
|
|
14
31
|
def self.headers
|
|
15
32
|
{
|
|
16
33
|
:accesskey => apiKey
|
|
17
34
|
}
|
|
18
35
|
end
|
|
19
36
|
|
|
37
|
+
# Gets all the files from the storage zone
|
|
38
|
+
# Params:
|
|
39
|
+
# +path+:: desired path to get files
|
|
20
40
|
def self.getZoneFiles(path= '')
|
|
21
|
-
|
|
41
|
+
begin
|
|
42
|
+
response = RestClient.get("#{set_region_url}/#{storageZone}/#{path}", headers)
|
|
43
|
+
rescue RestClient::ExceptionWithResponse => exception
|
|
44
|
+
return exception
|
|
45
|
+
end
|
|
22
46
|
return response.body
|
|
23
47
|
end
|
|
24
48
|
|
|
49
|
+
# Gets a single file from the storage zone
|
|
50
|
+
# Params:
|
|
51
|
+
# +path+:: desired path to get file
|
|
52
|
+
# +file+:: specific file to get from storage zone
|
|
25
53
|
def self.getFile(path= '', file)
|
|
26
|
-
|
|
54
|
+
begin
|
|
55
|
+
response = RestClient.get("#{set_region_url}/#{storageZone}/#{path}/#{file}", headers)
|
|
56
|
+
rescue RestClient::ExceptionWithResponse => exception
|
|
57
|
+
return exception
|
|
58
|
+
end
|
|
27
59
|
return response.body
|
|
28
60
|
end
|
|
29
61
|
|
|
62
|
+
# Uploads a file on the system to the storage zone
|
|
63
|
+
# Params:
|
|
64
|
+
# +path+:: desired path to upload file
|
|
65
|
+
# +file+:: specific file to upload to storage zone
|
|
30
66
|
def self.uploadFile(path= '', file)
|
|
31
67
|
fileName = File.basename(file)
|
|
32
68
|
headers = {
|
|
33
69
|
:accessKey => apiKey,
|
|
34
70
|
:checksum => ''
|
|
35
71
|
}
|
|
36
|
-
|
|
72
|
+
begin
|
|
73
|
+
response = RestClient.put("#{set_region_url}/#{storageZone}/#{path}/#{fileName}", File.read(file), headers)
|
|
74
|
+
rescue RestClient::ExceptionWithResponse => exception
|
|
75
|
+
return exception
|
|
76
|
+
end
|
|
77
|
+
return response.body
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Uploads a file from a file input to the storage zone
|
|
81
|
+
# Params:
|
|
82
|
+
# +path+:: desired path to upload file
|
|
83
|
+
# +file+:: specific file to upload to storage zone
|
|
84
|
+
def self.uploadFormFile(path= '', file)
|
|
85
|
+
fileName = file.original_filename
|
|
86
|
+
headers = {
|
|
87
|
+
:accessKey => apiKey,
|
|
88
|
+
:checksum => ''
|
|
89
|
+
}
|
|
90
|
+
begin
|
|
91
|
+
response = RestClient.put("#{set_region_url}/#{storageZone}/#{path}/#{fileName}", File.read(file.tempfile), headers)
|
|
92
|
+
rescue RestClient::ExceptionWithResponse => exception
|
|
93
|
+
return exception
|
|
94
|
+
end
|
|
37
95
|
return response.body
|
|
38
96
|
end
|
|
39
97
|
|
|
98
|
+
# Deletes a file from the storage zone
|
|
99
|
+
# Params:
|
|
100
|
+
# +path+:: path to delete file from
|
|
101
|
+
# +file+:: specific file to delete from storage zone
|
|
40
102
|
def self.deleteFile(path= '', file)
|
|
41
|
-
|
|
103
|
+
begin
|
|
104
|
+
response = RestClient.delete("#{set_region_url}/#{storageZone}/#{path}/#{file}", headers)
|
|
105
|
+
rescue RestClient::ExceptionWithResponse => exception
|
|
106
|
+
return exception
|
|
107
|
+
end
|
|
42
108
|
return response.body
|
|
43
109
|
end
|
|
44
110
|
|
data/lib/bunny_cdn/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bunny_cdn
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brandon Meeks
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-02-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rest-client
|
|
@@ -58,14 +58,20 @@ dependencies:
|
|
|
58
58
|
requirements:
|
|
59
59
|
- - "~>"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '
|
|
61
|
+
version: '12.3'
|
|
62
|
+
- - ">="
|
|
63
|
+
- !ruby/object:Gem::Version
|
|
64
|
+
version: 12.3.3
|
|
62
65
|
type: :development
|
|
63
66
|
prerelease: false
|
|
64
67
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
68
|
requirements:
|
|
66
69
|
- - "~>"
|
|
67
70
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '
|
|
71
|
+
version: '12.3'
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: 12.3.3
|
|
69
75
|
- !ruby/object:Gem::Dependency
|
|
70
76
|
name: rspec
|
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -128,6 +134,7 @@ licenses:
|
|
|
128
134
|
metadata:
|
|
129
135
|
homepage_uri: https://github.com/brandon-meeks/bunny_cdn_gem
|
|
130
136
|
source_code_uri: https://github.com/brandon-meeks/bunny_cdn_gem
|
|
137
|
+
changelog_uri: https://github.com/brandon-meeks/bunny_cdn/releases
|
|
131
138
|
post_install_message:
|
|
132
139
|
rdoc_options: []
|
|
133
140
|
require_paths:
|
|
@@ -136,14 +143,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
136
143
|
requirements:
|
|
137
144
|
- - ">="
|
|
138
145
|
- !ruby/object:Gem::Version
|
|
139
|
-
version:
|
|
146
|
+
version: 2.0.1
|
|
140
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
148
|
requirements:
|
|
142
149
|
- - ">="
|
|
143
150
|
- !ruby/object:Gem::Version
|
|
144
151
|
version: '0'
|
|
145
152
|
requirements: []
|
|
146
|
-
rubygems_version: 3.0.
|
|
153
|
+
rubygems_version: 3.0.3
|
|
147
154
|
signing_key:
|
|
148
155
|
specification_version: 4
|
|
149
156
|
summary: Gem to work with BunnyCDN
|