coconutrb 2.2.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/coconutrb.rb +54 -1
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 829f77888da3a43ad1e96692cbdd9ebad0285914
4
- data.tar.gz: b9e83f5f453620333b8fcf3291ca9c45e52b1f82
3
+ metadata.gz: 5d080f48508838a97c4a7aa3d7022008741ca5b2
4
+ data.tar.gz: be3d0ec286c2d79774e68edec3b9c1634d1dd32b
5
5
  SHA512:
6
- metadata.gz: 8492e6a8c1264ba269c96e67385f042219df7aa4fda0258eb656be15c0ca4685fd7e26a1e53f3c64ce07ecbf3be053e58602de7d4f6ea6002e38026448a25263
7
- data.tar.gz: ec5fead340bf6c0638217a1cd16fbe4c6c883642fbd69a680e2a0449d08e6a0a6776b20911582c79609722449af84a2dcaea03732cf73fc4d16966c1ba26c4f1
6
+ metadata.gz: bd2260ce0933b9bbcc6906285c1fa3416caf08845e7ee4b30f22ed29c912e67dde5abe17b1c6b669072bcc281b216275f520496e7efd8f6d97de9030988c34b1
7
+ data.tar.gz: 12825f9470666421d7dbbb5755f035eb818dd17454d9307cf6e83f71c94dd37f1755d5ed479cd631c17303d4a2fc4789befcfa4dd460b07353272a46daadc78a
@@ -6,7 +6,7 @@ module Coconut
6
6
  class Error < RuntimeError; end
7
7
 
8
8
  COCONUT_URL = ENV["COCONUT_URL"] || "https://api.coconut.co"
9
- USER_AGENT = "Coconut/2.2.0 (Ruby)"
9
+ USER_AGENT = "Coconut/2.4.0 (Ruby)"
10
10
 
11
11
  API_KEY = ENV["COCONUT_API_KEY"] unless const_defined?(:COCONUT_API_KEY)
12
12
 
@@ -35,6 +35,25 @@ module Coconut
35
35
  end
36
36
  end
37
37
 
38
+ def self.get(path, api_key=nil)
39
+ api_key ||= API_KEY
40
+ uri = URI("#{COCONUT_URL}#{path}")
41
+ headers = {"User-Agent" => USER_AGENT, "Content-Type" => "text/plain", "Accept" => "application/json"}
42
+
43
+ req = Net::HTTP::Get.new(uri.path, headers)
44
+ req.basic_auth api_key, ''
45
+
46
+ response = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme.include?("https")) do |http|
47
+ http.request(req)
48
+ end
49
+
50
+ if response.code.to_i != 200
51
+ return nil
52
+ else
53
+ return MultiJson.decode(response.body)
54
+ end
55
+ end
56
+
38
57
  def self.config(options={})
39
58
  if conf_file = options[:conf]
40
59
  raise Error, "Config file `#{conf_file}' not found" if ! File.exists?(conf_file)
@@ -54,11 +73,23 @@ module Coconut
54
73
  end
55
74
 
56
75
  if webhook = options[:webhook]
76
+ if webhook.is_a?(Hash)
77
+ webhook = hash_params_to_string(webhook)
78
+ end
79
+
57
80
  conf << "set webhook = #{webhook}"
58
81
  end
59
82
 
83
+ if api_version = options[:api_version]
84
+ conf << "set api_version = #{api_version}"
85
+ end
86
+
60
87
  if outputs = options[:outputs]
61
88
  outputs.each do |format, cdn|
89
+ if cdn.is_a?(Hash)
90
+ cdn = hash_params_to_string(cdn)
91
+ end
92
+
62
93
  conf << "-> #{format} = #{cdn}"
63
94
  end
64
95
  end
@@ -74,9 +105,31 @@ module Coconut
74
105
  return new_conf.join("\n")
75
106
  end
76
107
 
108
+ def self.hash_params_to_string(params)
109
+ params.map{|k,v|
110
+ if k.to_s == "url"
111
+ "#{v}"
112
+ else
113
+ "#{k}=#{v}"
114
+ end
115
+ }.join(", ")
116
+ end
117
+
77
118
  class Job
78
119
  def self.create(options={})
79
120
  Coconut.submit(Coconut.config(options), options[:api_key])
80
121
  end
122
+
123
+ def self.get(jid, api_key=nil)
124
+ Coconut.get("/v1/jobs/#{jid}", api_key)
125
+ end
126
+
127
+ def self.get_all_metadata(jid, api_key=nil)
128
+ Coconut.get("/v1/metadata/jobs/#{jid}", api_key)
129
+ end
130
+
131
+ def self.get_metadata_for(jid, source_or_output, api_key=nil)
132
+ Coconut.get("/v1/metadata/jobs/#{jid}/#{source_or_output}", api_key)
133
+ end
81
134
  end
82
135
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coconutrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Celeste
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-25 00:00:00.000000000 Z
11
+ date: 2019-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  version: '0'
52
52
  requirements: []
53
53
  rubyforge_project:
54
- rubygems_version: 2.4.3
54
+ rubygems_version: 2.5.2.3
55
55
  signing_key:
56
56
  specification_version: 4
57
57
  summary: Client library to transcode videos with coconut.co