heywatch 1.2.8 → 2.0.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/lib/heywatch.rb +22 -179
- metadata +13 -29
- data/bin/heywatch +0 -196
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f508e3eb28941bd33d8492abaee36ffe43c4c6ae
|
4
|
+
data.tar.gz: 01c33f25ce83aef17f50911fe08b77cdb7155d79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c69118f29dc4780c3439b385a4e459bbcf0303f7b5f6ee898a38868402dce12b474f6372cdaa42cea26fd9159a1cacd610c1bc97b7181bef2eee425490257b7
|
7
|
+
data.tar.gz: f6a6a87e0287c154a2228c8a57c6205a7b0fef8a5949784ebf9c5383c57698adc5528a7556e9dd54a5d589c76b4f7c5e3cbd648ac0a87bed84c8c16786959d8c
|
data/lib/heywatch.rb
CHANGED
@@ -1,193 +1,36 @@
|
|
1
|
-
require "
|
1
|
+
require "net/http"
|
2
2
|
require "multi_json"
|
3
3
|
require "uri"
|
4
4
|
|
5
|
-
|
6
|
-
class
|
7
|
-
class BadRequest < RuntimeError; end
|
5
|
+
module HeyWatch
|
6
|
+
class Error < RuntimeError; end
|
8
7
|
|
9
|
-
|
10
|
-
|
8
|
+
HEYWATCH_URL = ENV["HEYWATCH_URL"] || "https://heywatch.com"
|
9
|
+
USER_AGENT = "HeyWatch/2.0.0 (Ruby)"
|
11
10
|
|
12
|
-
|
11
|
+
def self.submit(config_content, api_key=nil)
|
12
|
+
api_key ||= ENV["HEYWATCH_API_KEY"]
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
# hw = HeyWatch.new(user, passwd)
|
17
|
-
def initialize(user=nil, password=nil)
|
18
|
-
uri = URI.parse(URL)
|
19
|
-
user = uri.user if !uri.user.nil?
|
20
|
-
password = uri.password if !uri.password.nil?
|
21
|
-
@cli = RestClient::Resource.new(URL, {:user => user, :password => password, :headers =>
|
22
|
-
{:user_agent => "HeyWatch Ruby/#{VERSION}", :accept => "application/json"}})
|
14
|
+
uri = URI("#{HEYWATCH_URL}/api/v1/job")
|
15
|
+
headers = {"User-Agent" => USER_AGENT, "Content-Type" => "text/plain", "Accept" => "application/json"}
|
23
16
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
self
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.register(data={})
|
31
|
-
HeyWatch.new(nil, nil).req("/account", :post, data)
|
32
|
-
end
|
33
|
-
|
34
|
-
# Get a specific field from account
|
35
|
-
#
|
36
|
-
# hw["env"] => "sandbox"
|
37
|
-
# hw["login"] => "bruno"
|
38
|
-
def [](field)
|
39
|
-
@me[field]
|
40
|
-
end
|
41
|
-
|
42
|
-
def inspect # :nodoc:
|
43
|
-
"#<HeyWatch: " + @me.inspect + ">"
|
44
|
-
end
|
45
|
-
|
46
|
-
# Get account information
|
47
|
-
#
|
48
|
-
# hw.account
|
49
|
-
def account
|
50
|
-
@me = req("/account")
|
51
|
-
end
|
52
|
-
|
53
|
-
# Get all from a given resource.
|
54
|
-
# Filters are optional
|
55
|
-
#
|
56
|
-
# hw.all :video
|
57
|
-
# hw.all :format, :owner => true
|
58
|
-
def all(*resource_and_filters)
|
59
|
-
resource, filters = resource_and_filters
|
60
|
-
results = req("/#{resource}")
|
61
|
-
return results if filters.nil? || filters.empty?
|
62
|
-
return filter_all(results, filters)
|
63
|
-
end
|
64
|
-
|
65
|
-
# Get info about a given resource and id
|
66
|
-
#
|
67
|
-
# hw.info :format, 31
|
68
|
-
def info(resource, id)
|
69
|
-
req("/#{resource}/#{id}")
|
70
|
-
end
|
71
|
-
|
72
|
-
# Count objects from a given resources.
|
73
|
-
# Filters are optional
|
74
|
-
#
|
75
|
-
# hw.count :job
|
76
|
-
# hw.count :job, :status => "error"
|
77
|
-
def count(*resource_and_filters)
|
78
|
-
all(*resource_and_filters).size
|
79
|
-
end
|
80
|
-
|
81
|
-
# Get the binary data of a video / encoded_video
|
82
|
-
#
|
83
|
-
# hw.bin :encoded_video, 12345
|
84
|
-
def bin(resource, id, &block)
|
85
|
-
RestClient.get(url(resource, id), :raw_response => true, &block)
|
86
|
-
end
|
87
|
-
|
88
|
-
# Get the real location of the video / encoded_video
|
89
|
-
#
|
90
|
-
# hw.url :encoded_video, 12345
|
91
|
-
def url(resource, id)
|
92
|
-
unless [:encoded_video, :video].include?(resource.to_sym)
|
93
|
-
raise InvalidResource, "Can't retrieve '#{resource}'"
|
94
|
-
end
|
95
|
-
|
96
|
-
info(resource, id)["url"]
|
97
|
-
end
|
98
|
-
|
99
|
-
# Generate thumbnails in the foreground or background via :async => true
|
100
|
-
#
|
101
|
-
# hw.jpg 12345, :start => 2
|
102
|
-
# => thumbnail data
|
103
|
-
#
|
104
|
-
# hw.jpg 12345, :async => true, :number => 6, :s3_directive => "s3://accesskey:secretkey@bucket"
|
105
|
-
# => true
|
106
|
-
def jpg(id, params={})
|
107
|
-
if params.delete(:async) || params.delete("async")
|
108
|
-
return req("/encoded_video/#{id}/thumbnails", :post, params)
|
109
|
-
end
|
17
|
+
req = Net::HTTP::Post.new(uri.path, headers)
|
18
|
+
req.basic_auth api_key, ''
|
19
|
+
req.body = config_content
|
110
20
|
|
111
|
-
|
112
|
-
|
21
|
+
response = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme.include?("https")) do |http|
|
22
|
+
http.request(req)
|
113
23
|
end
|
114
|
-
req("/encoded_video/#{id}.jpg#{params}")
|
115
|
-
end
|
116
|
-
|
117
|
-
# Create a resource with the give data
|
118
|
-
#
|
119
|
-
# hw.create :download, :url => "http://site.com/video.mp4", :title => "testing"
|
120
|
-
def create(resource, data={})
|
121
|
-
req("/#{resource}", :post, data)
|
122
|
-
end
|
123
|
-
|
124
|
-
# Update an object by giving its resource and ID (except account)
|
125
|
-
#
|
126
|
-
# hw.update :format, 9877, :video_bitrate => 890
|
127
|
-
def update(resource, *params)
|
128
|
-
if resource.to_sym == :account
|
129
|
-
return req("/#{resource}", :put, params[0])
|
130
|
-
end
|
131
|
-
|
132
|
-
id, data = params
|
133
|
-
req("/#{resource}/#{id}", :put, data)
|
134
|
-
end
|
135
|
-
|
136
|
-
# Delete a resource
|
137
|
-
#
|
138
|
-
# hw.delete :format, 9807
|
139
|
-
def delete(resource, id)
|
140
|
-
req("/#{resource}/#{id}", :delete)
|
141
|
-
end
|
142
|
-
|
143
|
-
# Upload a video from the disk
|
144
|
-
#
|
145
|
-
# hw.upload "/path/to/video.mp4"
|
146
|
-
def upload(path, params={})
|
147
|
-
req("/upload", :post, params.merge({:data => File.new(path, "rb")}))
|
148
|
-
end
|
149
|
-
|
150
|
-
def req(path, method=:get, params={}, &block) # :nodoc:
|
151
|
-
res = @cli[singularize_resource_in_path(path)].send(method, params, &block)
|
152
|
-
retrieve_credits_or_gb_left(res.headers)
|
153
24
|
|
154
|
-
|
155
|
-
return true
|
156
|
-
end
|
157
|
-
|
158
|
-
if(res.headers[:content_type] =~ /json/ && !res.to_s.strip.empty?)
|
159
|
-
return MultiJson.decode(res)
|
160
|
-
end
|
161
|
-
|
162
|
-
return res.to_s.strip
|
163
|
-
rescue RestClient::BadRequest=> e
|
164
|
-
raise BadRequest, e.http_body
|
165
|
-
end
|
166
|
-
|
167
|
-
private
|
168
|
-
|
169
|
-
def filter_all(results, filters)
|
170
|
-
filters = filters.map{ |f| f.split("=") } if filters.is_a?(Array)
|
171
|
-
filters = Hash[filters.map{ |k, v| [k.to_s, Regexp.new(v.to_s)] }]
|
172
|
-
|
173
|
-
results.select do |result|
|
174
|
-
filters.all?{ |key, matcher| result[key].to_s =~ matcher }
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
def singularize_resource_in_path(path)
|
179
|
-
s_path = path.split("/")
|
180
|
-
if s_path[1] != "hls" && s_path[1][-1..-1] == "s"
|
181
|
-
s_path[1] = s_path[1].slice(0..-2)
|
182
|
-
end
|
183
|
-
return s_path.join("/")
|
25
|
+
return MultiJson.decode(response.body)
|
184
26
|
end
|
185
27
|
|
186
|
-
def
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
28
|
+
def self.submit!(config_content, opts={})
|
29
|
+
result = submit(config_content, opts)
|
30
|
+
if result["status"] == "error"
|
31
|
+
raise Error, "#{result["message"]} (#{result["error_code"]})"
|
32
|
+
else
|
33
|
+
return result
|
191
34
|
end
|
192
35
|
end
|
193
|
-
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,55 +1,39 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heywatch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.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:
|
11
|
+
date: 2015-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rest-client
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - '>='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - '>='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: multi_json
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
|
-
- - ~>
|
17
|
+
- - "~>"
|
32
18
|
- !ruby/object:Gem::Version
|
33
19
|
version: '1.0'
|
34
20
|
type: :runtime
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
|
-
- - ~>
|
24
|
+
- - "~>"
|
39
25
|
- !ruby/object:Gem::Version
|
40
26
|
version: '1.0'
|
41
|
-
description:
|
42
|
-
|
43
|
-
|
44
|
-
executables:
|
45
|
-
- heywatch
|
27
|
+
description: Official client library to transcode videos with heywatch cloud service
|
28
|
+
email: bruno@heywatch.com
|
29
|
+
executables: []
|
46
30
|
extensions: []
|
47
31
|
extra_rdoc_files: []
|
48
32
|
files:
|
49
33
|
- lib/heywatch.rb
|
50
|
-
- bin/heywatch
|
51
34
|
homepage: http://www.heywatchencoding.com
|
52
|
-
licenses:
|
35
|
+
licenses:
|
36
|
+
- MIT
|
53
37
|
metadata: {}
|
54
38
|
post_install_message:
|
55
39
|
rdoc_options: []
|
@@ -57,18 +41,18 @@ require_paths:
|
|
57
41
|
- lib
|
58
42
|
required_ruby_version: !ruby/object:Gem::Requirement
|
59
43
|
requirements:
|
60
|
-
- -
|
44
|
+
- - ">="
|
61
45
|
- !ruby/object:Gem::Version
|
62
46
|
version: '0'
|
63
47
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
48
|
requirements:
|
65
|
-
- -
|
49
|
+
- - ">="
|
66
50
|
- !ruby/object:Gem::Version
|
67
51
|
version: '0'
|
68
52
|
requirements: []
|
69
53
|
rubyforge_project:
|
70
|
-
rubygems_version: 2.
|
54
|
+
rubygems_version: 2.2.2
|
71
55
|
signing_key:
|
72
56
|
specification_version: 4
|
73
|
-
summary: Client library
|
57
|
+
summary: Client library to transcode videos with heywatch
|
74
58
|
test_files: []
|
data/bin/heywatch
DELETED
@@ -1,196 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
$:.unshift File.dirname(__FILE__) + "/../lib"
|
4
|
-
require "rubygems"
|
5
|
-
require "heywatch"
|
6
|
-
|
7
|
-
RestClient.log = "stderr" if ENV["DEBUG"]
|
8
|
-
config_file = "#{ENV["HOME"]}/.heywatch"
|
9
|
-
|
10
|
-
if File.exists?(config_file)
|
11
|
-
user, passwd = File.read(config_file).split("\n")
|
12
|
-
else
|
13
|
-
print "Do you want to create an HeyWatch account? (Y/n) "
|
14
|
-
if $stdin.gets.chomp.downcase == "y"
|
15
|
-
data = {}
|
16
|
-
[:firstname, :lastname, :email, :login].each do |f|
|
17
|
-
print "#{f}: ".capitalize
|
18
|
-
data[f] = $stdin.gets.chomp
|
19
|
-
end
|
20
|
-
|
21
|
-
[:password, :password_confirmation].each do |f|
|
22
|
-
print "#{f}: ".capitalize.gsub("_", " ")
|
23
|
-
system "stty -echo"
|
24
|
-
data[f] = $stdin.gets.chomp
|
25
|
-
system "stty echo"
|
26
|
-
puts
|
27
|
-
end
|
28
|
-
|
29
|
-
print "Is the information correct? (Y/n) "
|
30
|
-
exit if $stdin.gets.chomp.downcase != "y"
|
31
|
-
|
32
|
-
begin
|
33
|
-
HeyWatch.register(data)
|
34
|
-
user, passwd = data[:login], data[:password]
|
35
|
-
rescue => e
|
36
|
-
puts e
|
37
|
-
exit
|
38
|
-
end
|
39
|
-
else
|
40
|
-
print "HeyWatch username: "
|
41
|
-
user = $stdin.gets.chomp
|
42
|
-
print "HeyWatch password: "
|
43
|
-
system "stty -echo"
|
44
|
-
passwd = $stdin.gets.chomp
|
45
|
-
system "stty echo"
|
46
|
-
puts
|
47
|
-
end
|
48
|
-
|
49
|
-
# testing credentials
|
50
|
-
begin
|
51
|
-
HeyWatch.new(user, passwd)
|
52
|
-
File.open(config_file, "w") {|f| f.write("#{user}\n#{passwd}") }
|
53
|
-
File.chmod(0600, config_file)
|
54
|
-
puts "Your credentials have been saved in this file #{config_file} (0600)\n-----\n"
|
55
|
-
rescue => e
|
56
|
-
puts "Wrong login or password."
|
57
|
-
exit
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
hw = HeyWatch.new(user, passwd)
|
62
|
-
|
63
|
-
begin
|
64
|
-
if ARGV.empty?
|
65
|
-
puts %(Usage: heywatch RESOURCE:METHOD [ID] [parameter1=value1 parameter2=value2 ...]
|
66
|
-
|
67
|
-
Resources:
|
68
|
-
|
69
|
-
account # manage account | create, update
|
70
|
-
video # manage video | all, info, delete, count, bin
|
71
|
-
encoded_video # manage encoded video | all, info, delete, count, bin, jpg
|
72
|
-
download # manage download | all, info, delete, count, create
|
73
|
-
job # manage job | all, info, delete, count, create
|
74
|
-
format # manage format | all, info, delete, count, create, update
|
75
|
-
upload # upload a video
|
76
|
-
|
77
|
-
Usage:
|
78
|
-
|
79
|
-
heywatch account
|
80
|
-
heywatch account:update env=sandbox
|
81
|
-
heywatch video:info 123456
|
82
|
-
heywatch job:all
|
83
|
-
heywatch download:create url=http://site.com/video.mp4 title=mytitle
|
84
|
-
heywatch encoded_video:jpg 9882322 start=4 > thumb.jpg
|
85
|
-
heywatch format:all owner=true video_codec=h264
|
86
|
-
heywatch video:all "[0]"
|
87
|
-
heywatch job:all "[0..10]"
|
88
|
-
heywatch format:count owner=true
|
89
|
-
heywatch upload path/to/video.mp4 "title=my title"
|
90
|
-
)
|
91
|
-
exit
|
92
|
-
end
|
93
|
-
|
94
|
-
if ARGV.size == 1 and ARGV[0] == "account"
|
95
|
-
puts MultiJson.dump(hw.account, :pretty => true)
|
96
|
-
exit
|
97
|
-
end
|
98
|
-
|
99
|
-
resource, method = ARGV[0].split(":")
|
100
|
-
params = ARGV[1..-1]
|
101
|
-
if method.nil?
|
102
|
-
if params.size == 1 && params[0].to_i > 0
|
103
|
-
method = "info"
|
104
|
-
else
|
105
|
-
method = "all"
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
$stderr.puts [resource, method, params].inspect if ENV["DEBUG"]
|
110
|
-
|
111
|
-
if resource == "upload"
|
112
|
-
path = ARGV[1]
|
113
|
-
params = Hash[*ARGV[2..-1].map{|p| k,v = p.split("=") }.flatten]
|
114
|
-
puts MultiJson.dump(hw.upload(path, params), :pretty => true)
|
115
|
-
exit
|
116
|
-
end
|
117
|
-
|
118
|
-
if method == "create"
|
119
|
-
params = Hash[*ARGV[1..-1].map{|p| k,v = p.split("=") }.flatten]
|
120
|
-
|
121
|
-
if resource == "account"
|
122
|
-
puts MultiJson.dump(HeyWatch.register(params), :pretty => true)
|
123
|
-
else
|
124
|
-
if resource == "robot/job" # read from STDIN
|
125
|
-
params = $stdin.read
|
126
|
-
end
|
127
|
-
|
128
|
-
res = hw.send(method, *[resource, params])
|
129
|
-
if res.empty?
|
130
|
-
puts "ok"
|
131
|
-
else
|
132
|
-
puts MultiJson.dump(res, :pretty => true)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
exit
|
136
|
-
end
|
137
|
-
|
138
|
-
if method == "update"
|
139
|
-
params = Hash[*ARGV[2..-1].map{|p| k,v = p.split("=") }.flatten]
|
140
|
-
|
141
|
-
hw.send(method, *[resource, ARGV[1], params])
|
142
|
-
puts "ok"
|
143
|
-
exit
|
144
|
-
end
|
145
|
-
|
146
|
-
if method == "jpg"
|
147
|
-
params = Hash[*ARGV[2..-1].map{|p| k,v = p.split("=") }.flatten]
|
148
|
-
puts hw.send(method, *[ARGV[1], params])
|
149
|
-
exit
|
150
|
-
end
|
151
|
-
|
152
|
-
if method == "bin"
|
153
|
-
puts hw.send(method, *[resource, ARGV[1]])
|
154
|
-
exit
|
155
|
-
end
|
156
|
-
|
157
|
-
if params.empty?
|
158
|
-
res = hw.send(method, resource)
|
159
|
-
if method == "count"
|
160
|
-
puts res
|
161
|
-
exit
|
162
|
-
end
|
163
|
-
|
164
|
-
puts MultiJson.dump(res, :pretty => true)
|
165
|
-
exit
|
166
|
-
end
|
167
|
-
|
168
|
-
if params.last =~ /\[([0-9\.-]+)\]/
|
169
|
-
offset = eval($1)
|
170
|
-
params = params[0..-2]
|
171
|
-
end
|
172
|
-
|
173
|
-
res = hw.send(method, *[resource, params[0]])
|
174
|
-
if res == true
|
175
|
-
puts "ok"
|
176
|
-
exit
|
177
|
-
end
|
178
|
-
|
179
|
-
if res.is_a?(Fixnum)
|
180
|
-
puts res
|
181
|
-
exit
|
182
|
-
end
|
183
|
-
|
184
|
-
if res.empty?
|
185
|
-
exit
|
186
|
-
end
|
187
|
-
|
188
|
-
res = res[offset] if offset
|
189
|
-
|
190
|
-
puts MultiJson.dump(res, :pretty => true)
|
191
|
-
exit
|
192
|
-
|
193
|
-
rescue => e
|
194
|
-
puts e
|
195
|
-
puts e.backtrace.join("\n") if ENV["DEBUG"]
|
196
|
-
end
|