coconutrb 2.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 +7 -0
- data/lib/coconutrb.rb +82 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 829f77888da3a43ad1e96692cbdd9ebad0285914
|
4
|
+
data.tar.gz: b9e83f5f453620333b8fcf3291ca9c45e52b1f82
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8492e6a8c1264ba269c96e67385f042219df7aa4fda0258eb656be15c0ca4685fd7e26a1e53f3c64ce07ecbf3be053e58602de7d4f6ea6002e38026448a25263
|
7
|
+
data.tar.gz: ec5fead340bf6c0638217a1cd16fbe4c6c883642fbd69a680e2a0449d08e6a0a6776b20911582c79609722449af84a2dcaea03732cf73fc4d16966c1ba26c4f1
|
data/lib/coconutrb.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "multi_json"
|
3
|
+
require "uri"
|
4
|
+
|
5
|
+
module Coconut
|
6
|
+
class Error < RuntimeError; end
|
7
|
+
|
8
|
+
COCONUT_URL = ENV["COCONUT_URL"] || "https://api.coconut.co"
|
9
|
+
USER_AGENT = "Coconut/2.2.0 (Ruby)"
|
10
|
+
|
11
|
+
API_KEY = ENV["COCONUT_API_KEY"] unless const_defined?(:COCONUT_API_KEY)
|
12
|
+
|
13
|
+
def self.submit(config_content, api_key=nil)
|
14
|
+
api_key ||= API_KEY
|
15
|
+
uri = URI("#{COCONUT_URL}/v1/job")
|
16
|
+
headers = {"User-Agent" => USER_AGENT, "Content-Type" => "text/plain", "Accept" => "application/json"}
|
17
|
+
|
18
|
+
req = Net::HTTP::Post.new(uri.path, headers)
|
19
|
+
req.basic_auth api_key, ''
|
20
|
+
req.body = config_content
|
21
|
+
|
22
|
+
response = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme.include?("https")) do |http|
|
23
|
+
http.request(req)
|
24
|
+
end
|
25
|
+
|
26
|
+
return MultiJson.decode(response.body)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.submit!(config_content, opts={})
|
30
|
+
result = submit(config_content, opts)
|
31
|
+
if result["status"] == "error"
|
32
|
+
raise Error, "#{result["message"]} (#{result["error_code"]})"
|
33
|
+
else
|
34
|
+
return result
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.config(options={})
|
39
|
+
if conf_file = options[:conf]
|
40
|
+
raise Error, "Config file `#{conf_file}' not found" if ! File.exists?(conf_file)
|
41
|
+
conf = File.read(conf_file).strip.split("\n")
|
42
|
+
else
|
43
|
+
conf = []
|
44
|
+
end
|
45
|
+
|
46
|
+
if vars = options[:vars]
|
47
|
+
vars.each do |name,value|
|
48
|
+
conf << "var #{name} = #{value}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
if source = options[:source]
|
53
|
+
conf << "set source = #{source}"
|
54
|
+
end
|
55
|
+
|
56
|
+
if webhook = options[:webhook]
|
57
|
+
conf << "set webhook = #{webhook}"
|
58
|
+
end
|
59
|
+
|
60
|
+
if outputs = options[:outputs]
|
61
|
+
outputs.each do |format, cdn|
|
62
|
+
conf << "-> #{format} = #{cdn}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
new_conf = []
|
67
|
+
|
68
|
+
new_conf.concat conf.select{|l| l.start_with?("var")}.sort
|
69
|
+
new_conf << ""
|
70
|
+
new_conf.concat conf.select{|l| l.start_with?("set")}.sort
|
71
|
+
new_conf << ""
|
72
|
+
new_conf.concat conf.select{|l| l.start_with?("->")}.sort
|
73
|
+
|
74
|
+
return new_conf.join("\n")
|
75
|
+
end
|
76
|
+
|
77
|
+
class Job
|
78
|
+
def self.create(options={})
|
79
|
+
Coconut.submit(Coconut.config(options), options[:api_key])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coconutrb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bruno Celeste
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: multi_json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
description: Official client library to transcode videos with coconut cloud service
|
28
|
+
email: bruno@coconut.co
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/coconutrb.rb
|
34
|
+
homepage: http://coconut.co
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 2.4.3
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: Client library to transcode videos with coconut.co
|
58
|
+
test_files: []
|