hdcloud 0.1.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.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/lib/hdcloud.rb +26 -0
- data/lib/hdcloud/base.rb +77 -0
- data/test/hdcloud/base_test.rb +91 -0
- data/test/hdcloud/stores_test.rb +19 -0
- data/test/helper.rb +127 -0
- data/test/test_hdcloud.rb +173 -0
- metadata +122 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Jacqui Maher
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= HDCloud
|
2
|
+
|
3
|
+
A wrapper for interfacing with the HDCloud API
|
4
|
+
|
5
|
+
Note: this is a work-in-progress, use at will!
|
6
|
+
|
7
|
+
== Note on Patches/Pull Requests
|
8
|
+
|
9
|
+
* Fork the project.
|
10
|
+
* Make your feature addition or bug fix.
|
11
|
+
* Add tests for it. This is important so I don't break it in a
|
12
|
+
future version unintentionally.
|
13
|
+
* Commit, do not mess with rakefile, version, or history.
|
14
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
15
|
+
* Send me a pull request. Bonus points for topic branches.
|
16
|
+
|
17
|
+
== Copyright
|
18
|
+
|
19
|
+
Copyright (c) 2010 Jacqui Maher. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "hdcloud"
|
8
|
+
gem.summary = %Q{A wrapper for interfacing with the HDCloud API}
|
9
|
+
gem.description = %Q{An easy-to-use rubygem for managing jobs, profiles and stores in HDCloud (www.hdcloud.com).}
|
10
|
+
gem.email = "jacqui@brighter.net"
|
11
|
+
gem.homepage = "http://github.com/jacqui/hdcloud"
|
12
|
+
gem.authors = ["Jacqui Maher"]
|
13
|
+
gem.add_development_dependency "shoulda", ">= 0"
|
14
|
+
gem.add_development_dependency "httparty", ">= 0"
|
15
|
+
gem.add_development_dependency "mocha", ">= 0"
|
16
|
+
gem.add_development_dependency "fakeweb", ">= 0"
|
17
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
|
+
end
|
19
|
+
Jeweler::GemcutterTasks.new
|
20
|
+
rescue LoadError
|
21
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
Rake::TestTask.new(:test) do |test|
|
26
|
+
test.libs << 'lib' << 'test'
|
27
|
+
test.pattern = 'test/**/test_*.rb'
|
28
|
+
test.verbose = true
|
29
|
+
end
|
30
|
+
|
31
|
+
begin
|
32
|
+
require 'rcov/rcovtask'
|
33
|
+
Rcov::RcovTask.new do |test|
|
34
|
+
test.libs << 'test'
|
35
|
+
test.pattern = 'test/**/test_*.rb'
|
36
|
+
test.verbose = true
|
37
|
+
end
|
38
|
+
rescue LoadError
|
39
|
+
task :rcov do
|
40
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
task :test => :check_dependencies
|
45
|
+
|
46
|
+
task :default => :test
|
47
|
+
|
48
|
+
require 'rake/rdoctask'
|
49
|
+
Rake::RDocTask.new do |rdoc|
|
50
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
51
|
+
|
52
|
+
rdoc.rdoc_dir = 'rdoc'
|
53
|
+
rdoc.title = "hdcloud #{version}"
|
54
|
+
rdoc.rdoc_files.include('README*')
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/hdcloud.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
gem 'httparty', '~> 0.5.2'
|
5
|
+
require 'httparty'
|
6
|
+
|
7
|
+
module HDCloud
|
8
|
+
class HDCloudError < StandardError
|
9
|
+
attr_reader :data
|
10
|
+
|
11
|
+
def initialize(data)
|
12
|
+
@data = data
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Unauthorized < HDCloudError; end
|
18
|
+
class General < HDCloudError; end
|
19
|
+
|
20
|
+
class Unavailable < StandardError; end
|
21
|
+
class NotFound < StandardError; end
|
22
|
+
end
|
23
|
+
|
24
|
+
directory = File.expand_path(File.dirname(__FILE__))
|
25
|
+
|
26
|
+
require File.join(directory, 'hdcloud', 'base')
|
data/lib/hdcloud/base.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
module HDCloud
|
2
|
+
class Base
|
3
|
+
attr_accessor :source_id, :destination_id
|
4
|
+
|
5
|
+
include HTTParty
|
6
|
+
base_uri 'hdcloud.com/api/v1'
|
7
|
+
format :json
|
8
|
+
|
9
|
+
def hd_cloud_stores
|
10
|
+
HD_CLOUD_STORES || {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(key, pass, source_id = nil, destination_id = nil)
|
14
|
+
@source_id = source_id || hd_cloud_stores[:source_id]
|
15
|
+
@destination_id = destination_id || hd_cloud_stores[:destination_id]
|
16
|
+
self.class.default_params 'job[source_id]' => source_id, 'job[destination_id]' => destination_id
|
17
|
+
self.class.basic_auth key, pass
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_job(file_name, encoding_profile_ids = [])
|
21
|
+
response = self.class.post('/jobs.json', :query => { 'files[]' => file_name, 'encoding_profile_ids[]' => encoding_profile_ids })
|
22
|
+
raise_errors(response)
|
23
|
+
response
|
24
|
+
end
|
25
|
+
|
26
|
+
def job_status(status_url)
|
27
|
+
status_url = status_url + '.json' unless status_url.match(/json$/)
|
28
|
+
response = self.class.get(status_url)
|
29
|
+
raise_errors(response)
|
30
|
+
response
|
31
|
+
end
|
32
|
+
|
33
|
+
def jobs
|
34
|
+
response = self.class.get('/jobs.json')
|
35
|
+
raise_errors(response)
|
36
|
+
response
|
37
|
+
end
|
38
|
+
|
39
|
+
def failed_jobs
|
40
|
+
response = self.class.get('/jobs/failed.json')
|
41
|
+
raise_errors(response)
|
42
|
+
response
|
43
|
+
end
|
44
|
+
|
45
|
+
def current_jobs
|
46
|
+
response = self.class.get('/jobs/current.json')
|
47
|
+
raise_errors(response)
|
48
|
+
response
|
49
|
+
end
|
50
|
+
|
51
|
+
def completed_jobs
|
52
|
+
response = self.class.get('/jobs/completed.json')
|
53
|
+
raise_errors(response)
|
54
|
+
response
|
55
|
+
end
|
56
|
+
|
57
|
+
def raise_errors(response)
|
58
|
+
case response.code.to_i
|
59
|
+
when 400
|
60
|
+
data = parse(response)
|
61
|
+
raise RateLimitExceeded.new(data), "(#{response.code}): #{response.message} - #{data['error'] if data}"
|
62
|
+
when 401
|
63
|
+
data = parse(response)
|
64
|
+
raise Unauthorized.new(data), "(#{response.code}): #{response.message} - #{data['error'] if data}"
|
65
|
+
when 403
|
66
|
+
data = parse(response)
|
67
|
+
raise General.new(data), "(#{response.code}): #{response.message} - #{data['error'] if data}"
|
68
|
+
when 404
|
69
|
+
raise NotFound, "(#{response.code}): #{response.message}"
|
70
|
+
when 500
|
71
|
+
raise InformHDCloud, "HDCloud had an internal error. Please let them know in the group. (#{response.code}): #{response.message}"
|
72
|
+
when 502..503
|
73
|
+
raise Unavailable, "(#{response.code}): #{response.message}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../helper'
|
2
|
+
|
3
|
+
class BaseTest < Test::Unit::TestCase
|
4
|
+
context "base" do
|
5
|
+
setup do
|
6
|
+
HDCloud::Base.any_instance.stubs(:hd_cloud_stores).returns({:source_id => 3, :destination_id => 4})
|
7
|
+
end
|
8
|
+
|
9
|
+
should "accept source_id and destination_id as parameters" do
|
10
|
+
hd = HDCloud::Base.new('foo', 'bar', 1, 2)
|
11
|
+
assert_equal 1, hd.source_id
|
12
|
+
assert_equal 2, hd.destination_id
|
13
|
+
end
|
14
|
+
|
15
|
+
should "use the constant otherwise" do
|
16
|
+
hd = HDCloud::Base.new('foo', 'bar')
|
17
|
+
assert_equal 3, hd.source_id
|
18
|
+
assert_equal 4, hd.destination_id
|
19
|
+
end
|
20
|
+
|
21
|
+
should "login with key and pass" do
|
22
|
+
HDCloud::Base.expects(:basic_auth).with('foo', 'bar')
|
23
|
+
HDCloud::Base.new('foo', 'bar')
|
24
|
+
end
|
25
|
+
|
26
|
+
context "once initialized" do
|
27
|
+
setup do
|
28
|
+
@hd = HDCloud::Base.new('foo', 'bar', 1, 2)
|
29
|
+
end
|
30
|
+
|
31
|
+
context "#create_job" do
|
32
|
+
setup do
|
33
|
+
FakeWeb.register_uri(:post, %r|http://foo:bar@hdcloud.com/api/v1/jobs|, :body => create_job_success, :content_type => 'application/json')
|
34
|
+
end
|
35
|
+
should "post to HDCloud" do
|
36
|
+
assert_equal 'waiting_for_file', @hd.create_job('foo.mp4').first["job"]["current_step"]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "#job_status" do
|
41
|
+
setup do
|
42
|
+
FakeWeb.register_uri(:get, %r|http://foo:bar@hdcloud.com/api/v1/jobs/1|, :body => job_status_success, :content_type => 'application/json')
|
43
|
+
end
|
44
|
+
|
45
|
+
should "submit a get request to the job's status url" do
|
46
|
+
@hd.job_status('http://hdcloud.com/api/v1/jobs/1')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "#jobs" do
|
51
|
+
setup do
|
52
|
+
FakeWeb.register_uri(:get, %r|http://foo:bar@hdcloud.com/api/v1/jobs|, :body => jobs_success, :content_type => "application/json")
|
53
|
+
end
|
54
|
+
|
55
|
+
should "submit a get request to jobs" do
|
56
|
+
assert_equal 1, @hd.jobs.first["job"]["id"]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "#current_jobs" do
|
61
|
+
setup do
|
62
|
+
FakeWeb.register_uri(:get, %r|http://foo:bar@hdcloud.com/api/v1/jobs/current|, :body => current_jobs_success, :content_type => 'application/json')
|
63
|
+
end
|
64
|
+
|
65
|
+
should "submit a get request to jobs/current" do
|
66
|
+
assert_equal 1, @hd.current_jobs.first["job"]["id"]
|
67
|
+
assert_equal 'encoding', @hd.current_jobs.first["job"]["current_step"]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
context "#completed_jobs" do
|
71
|
+
setup do
|
72
|
+
FakeWeb.register_uri(:get, %r|http://foo:bar@hdcloud.com/api/v1/jobs/complete|, :body => completed_jobs_success, :content_type => 'application/json')
|
73
|
+
end
|
74
|
+
|
75
|
+
should "submit a get request to jobs/completed" do
|
76
|
+
assert_equal 1, @hd.completed_jobs.first["job"]["id"]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
context "#failed_jobs" do
|
80
|
+
setup do
|
81
|
+
FakeWeb.register_uri(:get, %r|http://foo:bar@hdcloud.com/api/v1/jobs/failed|, :body => failed_jobs_success, :content_type => 'application/json')
|
82
|
+
end
|
83
|
+
|
84
|
+
should "submit a get request to jobs/failed" do
|
85
|
+
assert_equal 1, @hd.failed_jobs.first["job"]["id"]
|
86
|
+
assert_equal 'failed', @hd.failed_jobs.first["job"]["current_status"]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../helper'
|
2
|
+
|
3
|
+
class BaseTest < Test::Unit::TestCase
|
4
|
+
context "base" do
|
5
|
+
setup do
|
6
|
+
HDCloud::Base.any_instance.stubs(:hd_cloud_stores).returns({:source_id => 3, :destination_id => 4})
|
7
|
+
@hd = HDCloud::Base.new('foo', 'bar', 1, 2)
|
8
|
+
end
|
9
|
+
|
10
|
+
context "#stores" do
|
11
|
+
setup do
|
12
|
+
FakeWeb.register_uri(:post, %r|http://foo:bar@hdcloud.com/api/v1/stores|, :body => stores_success, :content_type => 'application/json')
|
13
|
+
end
|
14
|
+
should "submit a get request to stores" do
|
15
|
+
assert_equal "Example Store", @hd.stores.first["store"]["name"]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'mocha'
|
5
|
+
require 'fakeweb'
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
8
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
9
|
+
require 'hdcloud'
|
10
|
+
|
11
|
+
class Test::Unit::TestCase
|
12
|
+
FakeWeb.allow_net_connect = false
|
13
|
+
def create_job_success
|
14
|
+
<<-END
|
15
|
+
[{"job":
|
16
|
+
{"source_filename": "beer-drinking-pig.mpg",
|
17
|
+
"encoding_profile_id": nil,
|
18
|
+
"current_step": "waiting_for_file",
|
19
|
+
"resolution": nil,
|
20
|
+
"status_url": "http://example.com/api/v1/jobs/1.json",
|
21
|
+
"id": 1,
|
22
|
+
"bitrate": nil,
|
23
|
+
"current_status": "waiting for file",
|
24
|
+
"current_progress": nil,
|
25
|
+
"remote_id": "my-own-remote-id"}}]
|
26
|
+
END
|
27
|
+
end
|
28
|
+
|
29
|
+
def job_status_success
|
30
|
+
<<-END
|
31
|
+
{"job":
|
32
|
+
{"source_filename": "beer-drinking-pig.mpg",
|
33
|
+
"encoding_profile_id": nil,
|
34
|
+
"current_step": "encoding",
|
35
|
+
"resolution": nil,
|
36
|
+
"status_url": "http://example.com/api/v1/jobs/1.json",
|
37
|
+
"id": 1,
|
38
|
+
"bitrate": nil,
|
39
|
+
"current_status": "Encoding: Pass 1",
|
40
|
+
"current_progress": 42,
|
41
|
+
"remote_id": "my-own-remote-id"}}
|
42
|
+
END
|
43
|
+
end
|
44
|
+
|
45
|
+
def jobs_success
|
46
|
+
<<-END
|
47
|
+
[{"job":
|
48
|
+
{"source_filename": "beer-drinking-pig.mpg",
|
49
|
+
"encoding_profile_id": nil,
|
50
|
+
"current_step": "encoding",
|
51
|
+
"resolution": nil,
|
52
|
+
"status_url": "http://example.com/api/v1/jobs/1.json",
|
53
|
+
"id": 1,
|
54
|
+
"bitrate": nil,
|
55
|
+
"current_status": "Encoding: Pass 1",
|
56
|
+
"current_progress": 42,
|
57
|
+
"remote_id": "my-own-remote-id"}}]
|
58
|
+
END
|
59
|
+
end
|
60
|
+
def current_jobs_success
|
61
|
+
<<-END
|
62
|
+
[{"job":
|
63
|
+
{"source_filename": "beer-drinking-pig.mpg",
|
64
|
+
"encoding_profile_id": nil,
|
65
|
+
"current_step": "encoding",
|
66
|
+
"resolution": nil,
|
67
|
+
"status_url": "http://example.com/api/v1/jobs/1.json",
|
68
|
+
"id": 1,
|
69
|
+
"bitrate": nil,
|
70
|
+
"current_status": "Encoding: Pass 1",
|
71
|
+
"current_progress": 42,
|
72
|
+
"remote_id": "my-own-remote-id"}}]
|
73
|
+
END
|
74
|
+
end
|
75
|
+
def completed_jobs_success
|
76
|
+
<<-END
|
77
|
+
[{"job":
|
78
|
+
{"source_filename": "beer-drinking-pig.mpg",
|
79
|
+
"encoding_profile_id": nil,
|
80
|
+
"current_step": nil,
|
81
|
+
"resolution": nil,
|
82
|
+
"status_url": "http://example.com/api/v1/jobs/1.json",
|
83
|
+
"id": 1,
|
84
|
+
"complete?": true,
|
85
|
+
"encoded_filename": "beer-drinking-pig_1_800_1920x1080.mp4",
|
86
|
+
"bitrate": nil,
|
87
|
+
"current_status": "completed",
|
88
|
+
"current_progress": nil,
|
89
|
+
"remote_id": "my-own-remote-id"}}]
|
90
|
+
END
|
91
|
+
end
|
92
|
+
def failed_jobs_success
|
93
|
+
<<-END
|
94
|
+
[{"job":
|
95
|
+
{"source_filename": "beer-drinking-pig.mpg",
|
96
|
+
"encoding_profile_id": nil,
|
97
|
+
"current_step": "failed",
|
98
|
+
"resolution": nil,
|
99
|
+
"status_url": "http://example.com/api/v1/jobs/1.json",
|
100
|
+
"failed?": true,
|
101
|
+
"id": 1,
|
102
|
+
"bitrate": nil,
|
103
|
+
"current_status": "failed",
|
104
|
+
"failure_code": 500,
|
105
|
+
"failure_message":
|
106
|
+
"An unexpected application error occurred. Please contact support.",
|
107
|
+
"current_progress": nil,
|
108
|
+
"remote_id": "my-own-remote-id"}}]
|
109
|
+
END
|
110
|
+
end
|
111
|
+
def stores_success
|
112
|
+
<<-END
|
113
|
+
{"stores":
|
114
|
+
[{"name": "Example Store",
|
115
|
+
"cdn": "S3",
|
116
|
+
"username": "123abc",
|
117
|
+
"auth_token": nil,
|
118
|
+
"description": "Example Store",
|
119
|
+
"deleted": false,
|
120
|
+
"host": nil,
|
121
|
+
"ref": "example-bucket",
|
122
|
+
"user_id": 1,
|
123
|
+
"authorized": false,
|
124
|
+
"password": "cba321"}]}
|
125
|
+
END
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class BaseTest < Test::Unit::TestCase
|
4
|
+
context "HDCloudApi" do
|
5
|
+
setup do
|
6
|
+
HDCloudApi.any_instance.stubs(:hd_cloud_stores).returns({:source_id => 3, :destination_id => 4})
|
7
|
+
end
|
8
|
+
should "accept source_id and destination_id as parameters" do
|
9
|
+
hd = HDCloudApi.new('foo', 'bar', 1, 2)
|
10
|
+
assert_equal 1, hd.source_id
|
11
|
+
assert_equal 2, hd.destination_id
|
12
|
+
end
|
13
|
+
should "use the constant otherwise" do
|
14
|
+
hd = HDCloudApi.new('foo', 'bar')
|
15
|
+
assert_equal 3, hd.source_id
|
16
|
+
assert_equal 4, hd.destination_id
|
17
|
+
end
|
18
|
+
should "login with key and pass" do
|
19
|
+
HDCloudApi.expects(:basic_auth).with('foo', 'bar')
|
20
|
+
HDCloudApi.new('foo', 'bar')
|
21
|
+
end
|
22
|
+
|
23
|
+
context "#create_job" do
|
24
|
+
setup do
|
25
|
+
@hd = HDCloudApi.new('foo', 'bar')
|
26
|
+
@success = <<-END
|
27
|
+
[{"job":
|
28
|
+
{"source_filename": "beer-drinking-pig.mpg",
|
29
|
+
"encoding_profile_id": nil,
|
30
|
+
"current_step": "waiting_for_file",
|
31
|
+
"resolution": nil,
|
32
|
+
"status_url": "http://example.com/api/v1/jobs/1.json",
|
33
|
+
"id": 1,
|
34
|
+
"bitrate": nil,
|
35
|
+
"current_status": "waiting for file",
|
36
|
+
"current_progress": nil,
|
37
|
+
"remote_id": "my-own-remote-id"}}]
|
38
|
+
END
|
39
|
+
FakeWeb.register_uri(:post, %r|http://foo:bar@hdcloud.com/api/v1/jobs|, :body => @success, :content_type => 'application/json')
|
40
|
+
end
|
41
|
+
should "post to HDCloud" do
|
42
|
+
HDCloudApi.expects(:post)
|
43
|
+
@hd.create_job('foo.mp4')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "#job_status" do
|
48
|
+
setup do
|
49
|
+
@hd = HDCloudApi.new('foo', 'bar')
|
50
|
+
@success = <<-END
|
51
|
+
{"job":
|
52
|
+
{"source_filename": "beer-drinking-pig.mpg",
|
53
|
+
"encoding_profile_id": nil,
|
54
|
+
"current_step": "encoding",
|
55
|
+
"resolution": nil,
|
56
|
+
"status_url": "http://example.com/api/v1/jobs/1.json",
|
57
|
+
"id": 1,
|
58
|
+
"bitrate": nil,
|
59
|
+
"current_status": "Encoding: Pass 1",
|
60
|
+
"current_progress": 42,
|
61
|
+
"remote_id": "my-own-remote-id"}}
|
62
|
+
END
|
63
|
+
FakeWeb.register_uri(:get, %r|http://foo:bar@hdcloud.com/api/v1/jobs/1|, :body => @success, :content_type => 'application/json')
|
64
|
+
end
|
65
|
+
|
66
|
+
should "submit a get request to the job's status url" do
|
67
|
+
@hd.job_status('http://hdcloud.com/api/v1/jobs/1')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "#jobs" do
|
72
|
+
setup do
|
73
|
+
@hd = HDCloudApi.new('foo', 'bar')
|
74
|
+
@success = <<-END
|
75
|
+
[{"job":
|
76
|
+
{"source_filename": "beer-drinking-pig.mpg",
|
77
|
+
"encoding_profile_id": nil,
|
78
|
+
"current_step": "encoding",
|
79
|
+
"resolution": nil,
|
80
|
+
"status_url": "http://example.com/api/v1/jobs/1.json",
|
81
|
+
"id": 1,
|
82
|
+
"bitrate": nil,
|
83
|
+
"current_status": "Encoding: Pass 1",
|
84
|
+
"current_progress": 42,
|
85
|
+
"remote_id": "my-own-remote-id"}}]
|
86
|
+
END
|
87
|
+
FakeWeb.register_uri(:get, %r|http://foo:bar@hdcloud.com/api/v1/jobs|, :body => @success, :content_type => "application/json")
|
88
|
+
end
|
89
|
+
|
90
|
+
should "submit a get request to jobs" do
|
91
|
+
assert_equal 1, @hd.jobs.first["job"]["id"]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context "#current_jobs" do
|
96
|
+
setup do
|
97
|
+
@hd = HDCloudApi.new('foo', 'bar')
|
98
|
+
@success = <<-END
|
99
|
+
[{"job":
|
100
|
+
{"source_filename": "beer-drinking-pig.mpg",
|
101
|
+
"encoding_profile_id": nil,
|
102
|
+
"current_step": "encoding",
|
103
|
+
"resolution": nil,
|
104
|
+
"status_url": "http://example.com/api/v1/jobs/1.json",
|
105
|
+
"id": 1,
|
106
|
+
"bitrate": nil,
|
107
|
+
"current_status": "Encoding: Pass 1",
|
108
|
+
"current_progress": 42,
|
109
|
+
"remote_id": "my-own-remote-id"}}]
|
110
|
+
END
|
111
|
+
FakeWeb.register_uri(:get, %r|http://foo:bar@hdcloud.com/api/v1/jobs/current|, :body => @success, :content_type => 'application/json')
|
112
|
+
end
|
113
|
+
|
114
|
+
should "submit a get request to jobs/current" do
|
115
|
+
assert_equal 1, @hd.current_jobs.first["job"]["id"]
|
116
|
+
assert_equal 'encoding', @hd.current_jobs.first["job"]["current_step"]
|
117
|
+
end
|
118
|
+
end
|
119
|
+
context "#completed_jobs" do
|
120
|
+
setup do
|
121
|
+
@hd = HDCloudApi.new('foo', 'bar')
|
122
|
+
@success = <<-END
|
123
|
+
[{"job":
|
124
|
+
{"source_filename": "beer-drinking-pig.mpg",
|
125
|
+
"encoding_profile_id": nil,
|
126
|
+
"current_step": nil,
|
127
|
+
"resolution": nil,
|
128
|
+
"status_url": "http://example.com/api/v1/jobs/1.json",
|
129
|
+
"id": 1,
|
130
|
+
"complete?": true,
|
131
|
+
"encoded_filename": "beer-drinking-pig_1_800_1920x1080.mp4",
|
132
|
+
"bitrate": nil,
|
133
|
+
"current_status": "completed",
|
134
|
+
"current_progress": nil,
|
135
|
+
"remote_id": "my-own-remote-id"}}]
|
136
|
+
END
|
137
|
+
FakeWeb.register_uri(:get, %r|http://foo:bar@hdcloud.com/api/v1/jobs/complete|, :body => @success, :content_type => 'application/json')
|
138
|
+
end
|
139
|
+
|
140
|
+
should "submit a get request to jobs/completed" do
|
141
|
+
assert_equal 1, @hd.completed_jobs.first["job"]["id"]
|
142
|
+
end
|
143
|
+
end
|
144
|
+
context "#failed_jobs" do
|
145
|
+
setup do
|
146
|
+
@hd = HDCloudApi.new('foo', 'bar')
|
147
|
+
response = <<-END
|
148
|
+
[{"job":
|
149
|
+
{"source_filename": "beer-drinking-pig.mpg",
|
150
|
+
"encoding_profile_id": nil,
|
151
|
+
"current_step": "failed",
|
152
|
+
"resolution": nil,
|
153
|
+
"status_url": "http://example.com/api/v1/jobs/1.json",
|
154
|
+
"failed?": true,
|
155
|
+
"id": 1,
|
156
|
+
"bitrate": nil,
|
157
|
+
"current_status": "failed",
|
158
|
+
"failure_code": 500,
|
159
|
+
"failure_message":
|
160
|
+
"An unexpected application error occurred. Please contact support.",
|
161
|
+
"current_progress": nil,
|
162
|
+
"remote_id": "my-own-remote-id"}}]
|
163
|
+
END
|
164
|
+
FakeWeb.register_uri(:get, %r|http://foo:bar@hdcloud.com/api/v1/jobs/failed|, :body => response, :content_type => 'application/json')
|
165
|
+
end
|
166
|
+
|
167
|
+
should "submit a get request to jobs/failed" do
|
168
|
+
assert_equal 1, @hd.failed_jobs.first["job"]["id"]
|
169
|
+
assert_equal 'failed', @hd.failed_jobs.first["job"]["current_status"]
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hdcloud
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Jacqui Maher
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-03-27 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: shoulda
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :development
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: httparty
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :development
|
43
|
+
version_requirements: *id002
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: mocha
|
46
|
+
prerelease: false
|
47
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
type: :development
|
55
|
+
version_requirements: *id003
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: fakeweb
|
58
|
+
prerelease: false
|
59
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
type: :development
|
67
|
+
version_requirements: *id004
|
68
|
+
description: An easy-to-use rubygem for managing jobs, profiles and stores in HDCloud (www.hdcloud.com).
|
69
|
+
email: jacqui@brighter.net
|
70
|
+
executables: []
|
71
|
+
|
72
|
+
extensions: []
|
73
|
+
|
74
|
+
extra_rdoc_files:
|
75
|
+
- LICENSE
|
76
|
+
- README.rdoc
|
77
|
+
files:
|
78
|
+
- .document
|
79
|
+
- .gitignore
|
80
|
+
- LICENSE
|
81
|
+
- README.rdoc
|
82
|
+
- Rakefile
|
83
|
+
- VERSION
|
84
|
+
- lib/hdcloud.rb
|
85
|
+
- lib/hdcloud/base.rb
|
86
|
+
- test/hdcloud/base_test.rb
|
87
|
+
- test/helper.rb
|
88
|
+
has_rdoc: true
|
89
|
+
homepage: http://github.com/jacqui/hdcloud
|
90
|
+
licenses: []
|
91
|
+
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options:
|
94
|
+
- --charset=UTF-8
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
version: "0"
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
version: "0"
|
111
|
+
requirements: []
|
112
|
+
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 1.3.6
|
115
|
+
signing_key:
|
116
|
+
specification_version: 3
|
117
|
+
summary: A wrapper for interfacing with the HDCloud API
|
118
|
+
test_files:
|
119
|
+
- test/hdcloud/base_test.rb
|
120
|
+
- test/hdcloud/stores_test.rb
|
121
|
+
- test/helper.rb
|
122
|
+
- test/test_hdcloud.rb
|