bunny_stream 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.tool-versions +1 -0
- data/Gemfile +3 -0
- data/README.md +18 -0
- data/bunny_stream.gemspec +40 -0
- data/lib/bunny_stream/storage.rb +62 -0
- data/lib/bunny_stream/version.rb +3 -0
- data/lib/bunny_stream.rb +34 -0
- metadata +183 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8c2d4f4f5ceb326cc69a6764083949117ae3b921c351052a7b933988fd889783
|
4
|
+
data.tar.gz: 02bb71b764804c8c6f1ebe064497e6628be603801ec266432a0808a67282575e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c5cdb6a4ea844eeeca866f33d0c40ac6ededb4993614e80177f842317d18a3419d99da804cec7f2e39de8a91f14da696eb9b527a34ebd693a1cd79052d27743e
|
7
|
+
data.tar.gz: bd4d33f089a5c24816fcff46bb434c71271b31872976f10669db203c73d1531b6e99fd8e6c80ee1b3d190bd67741b94d506eeb9d62bcb9d3a3cc7791c178198b
|
data/.gitignore
ADDED
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.1.4
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# BunnyStream
|
2
|
+
|
3
|
+
This is the most basic library ever. No tests needed.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
BunnyStream.configure do |c|
|
9
|
+
c.library_id = 123
|
10
|
+
c.access_key = "123-123-123-123-123-123"
|
11
|
+
end
|
12
|
+
|
13
|
+
video_id = BunnyStream::Storage.create_video({title: "test"})
|
14
|
+
|
15
|
+
BunnyStream::Storage.upload_video(video_id, File.open("sample.mp4"))
|
16
|
+
|
17
|
+
BunnyStream::Storage.delete_video(video_id)
|
18
|
+
```
|
@@ -0,0 +1,40 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "bunny_stream/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "bunny_stream"
|
7
|
+
spec.version = BunnyStream::VERSION
|
8
|
+
spec.authors = "Joakim Nylén"
|
9
|
+
spec.email = "rubygems@joakim.nylen.nu"
|
10
|
+
|
11
|
+
spec.summary = %q{RubyGem to manage files on Bunny Stream}
|
12
|
+
spec.description = %q{RubyGem to manage files on Bunny Stream.}
|
13
|
+
spec.homepage = "https://github.com/OutdoorMap/bunny_stream_gem"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/OutdoorMap/bunny_stream_gem"
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/OutdoorMap/bunny_stream/releases"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_dependency 'http', '~> 5.1', '>= 5.1.1'
|
30
|
+
spec.add_dependency 'dry-configurable', '~> 1.1'
|
31
|
+
spec.add_dependency 'oj', '~> 3.16', '>= 3.16.1'
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
34
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
spec.add_development_dependency "webmock", '~> 3.8', '>= 3.8.3'
|
37
|
+
spec.add_development_dependency "pry"
|
38
|
+
|
39
|
+
spec.required_ruby_version = '>= 2.0.1'
|
40
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module BunnyStream
|
2
|
+
class Storage
|
3
|
+
def self.create_video(values)
|
4
|
+
response = BunnyStream.http().post(
|
5
|
+
"https://video.bunnycdn.com/library/#{BunnyStream.config.library_id}/videos",
|
6
|
+
json: values
|
7
|
+
)
|
8
|
+
|
9
|
+
response_body = Oj.load(response.body.to_s)
|
10
|
+
|
11
|
+
if response.status == 200
|
12
|
+
response_body["guid"]
|
13
|
+
elsif response_body.is_a?(Hash)
|
14
|
+
response_body["errors"]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.upload_video(video_id, file)
|
19
|
+
response = BunnyStream.http().put(
|
20
|
+
"https://video.bunnycdn.com/library/#{BunnyStream.config.library_id}/videos/#{video_id}",
|
21
|
+
body: file
|
22
|
+
)
|
23
|
+
|
24
|
+
response_body = Oj.load(response.body.to_s)
|
25
|
+
|
26
|
+
if response.status == 200
|
27
|
+
true
|
28
|
+
else
|
29
|
+
response_body["errors"]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def self.get_video(video_id)
|
35
|
+
response = BunnyStream.http().get(
|
36
|
+
"https://video.bunnycdn.com/library/#{BunnyStream.config.library_id}/videos/#{video_id}"
|
37
|
+
)
|
38
|
+
|
39
|
+
response_body = Oj.load(response.body.to_s)
|
40
|
+
|
41
|
+
if response.status == 200
|
42
|
+
response_body
|
43
|
+
else
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.delete_video(video_id)
|
49
|
+
response = BunnyStream.http().delete(
|
50
|
+
"https://video.bunnycdn.com/library/#{BunnyStream.config.library_id}/videos/#{video_id}"
|
51
|
+
)
|
52
|
+
|
53
|
+
response_body = Oj.load(response.body.to_s)
|
54
|
+
|
55
|
+
if response.status == 200
|
56
|
+
true
|
57
|
+
else
|
58
|
+
response_body["errors"]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/bunny_stream.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "http"
|
2
|
+
require "oj"
|
3
|
+
require "dry-configurable"
|
4
|
+
require "bunny_stream/version"
|
5
|
+
require_relative "bunny_stream/storage"
|
6
|
+
|
7
|
+
module BunnyStream
|
8
|
+
extend Dry::Configurable
|
9
|
+
|
10
|
+
|
11
|
+
setting :library_id
|
12
|
+
setting :access_key
|
13
|
+
|
14
|
+
def self.http(access_key = nil)
|
15
|
+
default_options = {
|
16
|
+
headers: {
|
17
|
+
accept: 'application/json',
|
18
|
+
content_type: 'application/json',
|
19
|
+
user_agent: "BunnyStream Ruby Client #{BunnyStream::VERSION}",
|
20
|
+
},
|
21
|
+
timeout_class: HTTP::Timeout::Global,
|
22
|
+
timeout_options: { global_timeout: 120 }
|
23
|
+
}
|
24
|
+
|
25
|
+
default_options = HTTP::Options.new(default_options)
|
26
|
+
|
27
|
+
# .use(:auto_inflate) doesn't seem to work here
|
28
|
+
@http ||= HTTP::Client.new(default_options).headers(
|
29
|
+
{
|
30
|
+
'AccessKey' => (access_key || BunnyStream.config.access_key)
|
31
|
+
}
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bunny_stream
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joakim Nylén
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-11-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: http
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 5.1.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 5.1.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: dry-configurable
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.1'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.1'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: oj
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.16'
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 3.16.1
|
57
|
+
type: :runtime
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '3.16'
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 3.16.1
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: bundler
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - "~>"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '2.0'
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - "~>"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '2.0'
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rake
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '13.0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - "~>"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '13.0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: rspec
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '3.0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - "~>"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '3.0'
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: webmock
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '3.8'
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 3.8.3
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '3.8'
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: 3.8.3
|
129
|
+
- !ruby/object:Gem::Dependency
|
130
|
+
name: pry
|
131
|
+
requirement: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
type: :development
|
137
|
+
prerelease: false
|
138
|
+
version_requirements: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
description: RubyGem to manage files on Bunny Stream.
|
144
|
+
email: rubygems@joakim.nylen.nu
|
145
|
+
executables: []
|
146
|
+
extensions: []
|
147
|
+
extra_rdoc_files: []
|
148
|
+
files:
|
149
|
+
- ".gitignore"
|
150
|
+
- ".tool-versions"
|
151
|
+
- Gemfile
|
152
|
+
- README.md
|
153
|
+
- bunny_stream.gemspec
|
154
|
+
- lib/bunny_stream.rb
|
155
|
+
- lib/bunny_stream/storage.rb
|
156
|
+
- lib/bunny_stream/version.rb
|
157
|
+
homepage: https://github.com/OutdoorMap/bunny_stream_gem
|
158
|
+
licenses:
|
159
|
+
- MIT
|
160
|
+
metadata:
|
161
|
+
homepage_uri: https://github.com/OutdoorMap/bunny_stream_gem
|
162
|
+
source_code_uri: https://github.com/OutdoorMap/bunny_stream_gem
|
163
|
+
changelog_uri: https://github.com/OutdoorMap/bunny_stream/releases
|
164
|
+
post_install_message:
|
165
|
+
rdoc_options: []
|
166
|
+
require_paths:
|
167
|
+
- lib
|
168
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: 2.0.1
|
173
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - ">="
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '0'
|
178
|
+
requirements: []
|
179
|
+
rubygems_version: 3.3.26
|
180
|
+
signing_key:
|
181
|
+
specification_version: 4
|
182
|
+
summary: RubyGem to manage files on Bunny Stream
|
183
|
+
test_files: []
|