editframe 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +8 -0
- data/.gitignore +10 -0
- data/.travis.yml +6 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/editframe.gemspec +31 -0
- data/lib/editframe.rb +31 -0
- data/lib/editframe/api_resource.rb +47 -0
- data/lib/editframe/resources.rb +2 -0
- data/lib/editframe/resources/application.rb +7 -0
- data/lib/editframe/resources/video.rb +23 -0
- data/lib/editframe/util.rb +30 -0
- data/lib/editframe/version.rb +3 -0
- data/lib/editframe/video/builder.rb +74 -0
- data/lib/editframe/video/clip.rb +89 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1a85cce0aa23b0b803d73b2a846ec714675da8a33821b4f44e6a9964b6fb97e5
|
4
|
+
data.tar.gz: bd35d0d4fce47c9f07fb240e80c3694367ddf7d825a0aa638904eb3c25ae9150
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d973fefea0b70442d8ab838432ce2c15ecc46038f4d51b4977a0b71cc779c7de535341be2093069e64a77bc157f999cf025e9700cf6512a1d3b5902a9bec6f38
|
7
|
+
data.tar.gz: 71f0976ac0b3bd5f4f861d0593daab7b2b7c172eb2f074ad7fc26a70837a89b3ca23b8212db9d2d7f42cb07ba53f975c8cf8789744775aa991c6e24cdcefa8de
|
data/.editorconfig
ADDED
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Editframe, Inc.
|
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,37 @@
|
|
1
|
+
# Editframe
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/editframe`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'editframe'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle install
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install editframe
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
TODO: Write usage instructions here
|
23
|
+
|
24
|
+
## Development
|
25
|
+
|
26
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
27
|
+
|
28
|
+
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](https://rubygems.org).
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/editframe/editframe-ruby.
|
33
|
+
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "editframe"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/editframe.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'lib/editframe/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "editframe"
|
5
|
+
spec.version = Editframe::VERSION
|
6
|
+
spec.authors = ["Bryce"]
|
7
|
+
spec.email = ["bryce@brycedev.com"]
|
8
|
+
|
9
|
+
spec.summary = "Ruby bindings for the Editframe API"
|
10
|
+
spec.description = "Official Rails library for interacting with the Editframe.com API"
|
11
|
+
spec.homepage = "https://editframe.com/docs/sdk/ruby"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/editframe/editframe-ruby"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/editframe/editframe-ruby/CHANGELOG.md"
|
20
|
+
|
21
|
+
spec.add_dependency "faraday", "~> 1.5"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
end
|
data/lib/editframe.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "json"
|
2
|
+
require "uri"
|
3
|
+
|
4
|
+
require "editframe/api_resource"
|
5
|
+
require "editframe/resources"
|
6
|
+
require "editframe/util"
|
7
|
+
require "editframe/version"
|
8
|
+
|
9
|
+
require "editframe/video/builder"
|
10
|
+
require "editframe/video/clip"
|
11
|
+
|
12
|
+
module Editframe
|
13
|
+
@api_host = 'api.editframe.com'
|
14
|
+
@api_key = nil
|
15
|
+
@api_version = '2'
|
16
|
+
@client_id = nil
|
17
|
+
|
18
|
+
class << self
|
19
|
+
attr_accessor :api_key, :client_id
|
20
|
+
attr_reader :api_host, :api_version
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.set_api_host(host)
|
25
|
+
@api_host = host
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.set_api_version(version)
|
29
|
+
@api_version = version.to_s
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Editframe
|
5
|
+
class APIResource
|
6
|
+
def self.base_url
|
7
|
+
"https://#{Editframe::api_host}/v#{Editframe::api_version}/#{self::OBJECT_PATH}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.all
|
11
|
+
perform_get_request()['data']
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.find(identifier)
|
15
|
+
perform_get_request("#{identifier}")['data']
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.perform_get_request(url = '', params: {}, options: {})
|
19
|
+
response = Faraday.new(url: base_url, params: params, headers: retrieve_headers).get(url)
|
20
|
+
JSON.parse(response.body)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.perform_post_request(url = '', body: {}, options: {}, is_form: false)
|
24
|
+
headers = retrieve_headers
|
25
|
+
request = Faraday.new(url: base_url, headers: headers)
|
26
|
+
if is_form
|
27
|
+
headers.delete('Accept')
|
28
|
+
headers.delete('Content-Type')
|
29
|
+
request = Faraday.new(url: base_url, headers: headers) do |f|
|
30
|
+
f.request :multipart
|
31
|
+
end
|
32
|
+
end
|
33
|
+
request = request.post(url, body)
|
34
|
+
JSON.parse(request.body)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.retrieve_headers
|
38
|
+
headers = {
|
39
|
+
'Accept' => 'application/json',
|
40
|
+
'Content-Type' => 'application/json',
|
41
|
+
'Authorization' => "Bearer #{Editframe::api_key}",
|
42
|
+
'Editframe-Client-Id' => "#{Editframe.client_id}"
|
43
|
+
}
|
44
|
+
headers
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Editframe
|
2
|
+
class Video < APIResource
|
3
|
+
|
4
|
+
OBJECT_PATH = 'videos/'
|
5
|
+
|
6
|
+
def self.build(options)
|
7
|
+
VideoBuilder.new options
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.encode(body)
|
11
|
+
self.perform_post_request(body: body, is_form: true)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.encode_from_clip(body)
|
15
|
+
self.perform_post_request('clip', body: body, is_form: true)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.from_clip(options)
|
19
|
+
VideoClip.new options
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
module Editframe
|
4
|
+
class Util
|
5
|
+
def self.dimensions_for_aspect_ratio(aspect_ratio, hd = false)
|
6
|
+
case aspect_ratio
|
7
|
+
when '1:1'
|
8
|
+
hd ? { :width => 1024, :height => 1024 } : { :width => 700, :height => 700 }
|
9
|
+
when '16:9'
|
10
|
+
hd ? { :width => 1920, :height => 1080 } : { :width => 1024, :height => 576 }
|
11
|
+
when '5:4'
|
12
|
+
hd ? { :width => 1280, :height => 1024 } : { :width => 640, :height => 512 }
|
13
|
+
when '4:5'
|
14
|
+
hd ? { :width => 1024, :height => 1280 } : { :width => 512, :height => 640 }
|
15
|
+
when '9:16'
|
16
|
+
hd ? { :width => 1080, :height => 1920 } : { :width => 576, :height => 1024 }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.dimensions_for_resolution(resolution = '700x700')
|
21
|
+
return {} unless !resolution.nil?
|
22
|
+
values = resolution.split('x')
|
23
|
+
{ width: values[0].to_i, height: values[1].to_i }
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.uuid
|
27
|
+
SecureRandom.uuid.slice(0,6)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Editframe
|
2
|
+
class VideoBuilder
|
3
|
+
|
4
|
+
attr_reader :layers
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
@form = {}
|
8
|
+
@layers = []
|
9
|
+
@options = options || { background_color: 'black', resolution: '700x700', duration: 10 }
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_audio(source, options = {})
|
13
|
+
layer = add_layer({ :type => 'audio', **options })
|
14
|
+
add_asset(layer[:id], source)
|
15
|
+
layer
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_image(source, options = {})
|
19
|
+
layer = add_layer({ :type => 'image', **options })
|
20
|
+
add_asset(layer[:id], source)
|
21
|
+
layer
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_text(text, options = {})
|
25
|
+
layer = add_layer({ :type => 'waveform', :text => text, **options })
|
26
|
+
layer
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_video(source, options = {})
|
30
|
+
layer = add_layer({ :type => 'video', **options })
|
31
|
+
add_asset(layer[:id], source)
|
32
|
+
layer
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_waveform(options = {})
|
36
|
+
layer = add_layer({ :type => 'waveform', **options })
|
37
|
+
layer
|
38
|
+
end
|
39
|
+
|
40
|
+
def encode
|
41
|
+
@form[:config] = Faraday::ParamPart.new(generate_config, 'application/json')
|
42
|
+
Editframe::Video.encode(@form)
|
43
|
+
end
|
44
|
+
|
45
|
+
private def add_asset(id, source)
|
46
|
+
case source
|
47
|
+
when String
|
48
|
+
@form["url#{id}"] = source
|
49
|
+
when File
|
50
|
+
@form["file#{id}"] = Faraday::FilePart.new source, 'application/octet-stream'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private def add_layer(options = {})
|
55
|
+
layer = { id: Util::uuid, **options }
|
56
|
+
@layers.push layer
|
57
|
+
layer
|
58
|
+
end
|
59
|
+
|
60
|
+
private def generate_config
|
61
|
+
options = @options
|
62
|
+
dimensions = Util::dimensions_for_resolution options[:resolution]
|
63
|
+
if options.key? :aspect_ratio
|
64
|
+
hd = options.key? :hd ? options[:hd] : false
|
65
|
+
dimensions = Util::dimensions_for_aspect_ratio(options[:aspect_ratio], hd)
|
66
|
+
end
|
67
|
+
options[:hd] = dimensions[:width] >= 1024
|
68
|
+
options.delete(:resolution)
|
69
|
+
options.stringify_keys!
|
70
|
+
options.deep_transform_keys! { |key| key.camelize :lower }
|
71
|
+
{ **options, :dimensions => dimensions, :layers => @layers }.to_json
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Editframe
|
2
|
+
class VideoClip
|
3
|
+
|
4
|
+
attr_reader :layers
|
5
|
+
|
6
|
+
def initialize(source, options = {})
|
7
|
+
@id = Util.uuid
|
8
|
+
@form = {}
|
9
|
+
@filters = []
|
10
|
+
@layers = []
|
11
|
+
@options = options || { }
|
12
|
+
@resolution = { width: nil, height: nil }
|
13
|
+
@trim = { start: 0, end: nil }
|
14
|
+
@volume = 1.0
|
15
|
+
configure_source source
|
16
|
+
end
|
17
|
+
|
18
|
+
def filter(name, options = {})
|
19
|
+
@filters.push({ :name => name, :options => { **options } })
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def resize(resolution)
|
24
|
+
return unless !resolution.nil?
|
25
|
+
set_resolution resolution
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
def set_resolution(resolution)
|
30
|
+
return unless !resolution.nil?
|
31
|
+
values = resolution.split('x')
|
32
|
+
@resolution = { width: values[0].to_i, height: values[1].to_i }
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
def set_volume(volume)
|
37
|
+
@volume = volume.to_f
|
38
|
+
if volume > 1 then @volume = 1.0 end
|
39
|
+
if volume < 1 then @volume = 0.0 end
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
def trim(trim_start, trim_end)
|
44
|
+
@trim[:start] = trim_start
|
45
|
+
@trim[:end] = trim_end
|
46
|
+
if @trim[:start] < 0
|
47
|
+
@trim[:start] = 0
|
48
|
+
end
|
49
|
+
if @trim[:end] < 0
|
50
|
+
@trim.delete(:end)
|
51
|
+
end
|
52
|
+
self
|
53
|
+
end
|
54
|
+
|
55
|
+
def mute
|
56
|
+
set_volume 0
|
57
|
+
self
|
58
|
+
end
|
59
|
+
|
60
|
+
def encode
|
61
|
+
@form[:config] = Faraday::ParamPart.new(generate_config, 'application/json')
|
62
|
+
Editframe::Video.encode_from_clip(@form)
|
63
|
+
end
|
64
|
+
|
65
|
+
private def configure_source(source)
|
66
|
+
case source
|
67
|
+
when String
|
68
|
+
@form["url#{@id}"] = source
|
69
|
+
when File
|
70
|
+
@form["file#{@id}"] = Faraday::FilePart.new source, 'application/octet-stream'
|
71
|
+
end
|
72
|
+
@source = source
|
73
|
+
end
|
74
|
+
|
75
|
+
private def generate_config
|
76
|
+
clip = { :id => @id, :filters => @filters, :volume => @volume }
|
77
|
+
options = @options
|
78
|
+
if !@trim[:end].nil?
|
79
|
+
clip[:trim] = @trim
|
80
|
+
end
|
81
|
+
if (!@resolution[:width].nil?) and (!@resolution[:height].nil?)
|
82
|
+
clip[:resolution] = @resolution
|
83
|
+
end
|
84
|
+
options.stringify_keys!
|
85
|
+
options.deep_transform_keys! { |key| key.camelize :lower }
|
86
|
+
{ **options, :layers => @layers, :clip => clip }.to_json
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: editframe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bryce
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-07-29 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: '1.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
description: Official Rails library for interacting with the Editframe.com API
|
28
|
+
email:
|
29
|
+
- bryce@brycedev.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".editorconfig"
|
35
|
+
- ".gitignore"
|
36
|
+
- ".travis.yml"
|
37
|
+
- Gemfile
|
38
|
+
- LICENSE.txt
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- bin/console
|
42
|
+
- bin/setup
|
43
|
+
- editframe.gemspec
|
44
|
+
- lib/editframe.rb
|
45
|
+
- lib/editframe/api_resource.rb
|
46
|
+
- lib/editframe/resources.rb
|
47
|
+
- lib/editframe/resources/application.rb
|
48
|
+
- lib/editframe/resources/video.rb
|
49
|
+
- lib/editframe/util.rb
|
50
|
+
- lib/editframe/version.rb
|
51
|
+
- lib/editframe/video/builder.rb
|
52
|
+
- lib/editframe/video/clip.rb
|
53
|
+
homepage: https://editframe.com/docs/sdk/ruby
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
metadata:
|
57
|
+
allowed_push_host: https://rubygems.org
|
58
|
+
homepage_uri: https://editframe.com/docs/sdk/ruby
|
59
|
+
source_code_uri: https://github.com/editframe/editframe-ruby
|
60
|
+
changelog_uri: https://github.com/editframe/editframe-ruby/CHANGELOG.md
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.3.0
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubygems_version: 3.2.24
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Ruby bindings for the Editframe API
|
80
|
+
test_files: []
|