enigmamachine 0.3.4 → 0.4.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/README.rdoc CHANGED
@@ -32,6 +32,7 @@ with good threading support it still sort of sucks. With Enigmamachine, all you
32
32
  need to do to trigger encoding of a video is shoot off an HTTP request, and
33
33
  everything else is handled for you.
34
34
 
35
+
35
36
  == Using it
36
37
 
37
38
  Once you've installed the gem (see below), you can do something like:
@@ -82,9 +83,12 @@ Programmatic requests in Ruby might look something like this:
82
83
  @auth = encode_credentials(u, p)
83
84
  end
84
85
 
85
- def post(path_to_video, encoder_id)
86
+ def post(path_to_video, encoder_id, callback_url)
86
87
  self.class.post("/videos", {
87
- :body => {:video => {:file => path_to_video}, :encoder_id => encoder_id},
88
+ :body => {:video => {
89
+ :file => path_to_video,
90
+ :callback_url => callback_url
91
+ }, :encoder_id => encoder_id},
88
92
  :basic_auth => @auth})
89
93
  end
90
94
 
@@ -101,12 +105,12 @@ Programmatic requests in Ruby might look something like this:
101
105
  #
102
106
  irb
103
107
  require 'enigma_client'
104
- EnigmaClient.new("admin", "admin").post("/path/to/your/uploaded/video.mp4", 1)
108
+ EnigmaClient.new("admin", "admin").post("/path/to/your/uploaded/video.mp4", 1, "http://example.org/call/back/id")
105
109
 
106
110
 
107
111
  A simpler, wget-based approach might look like this:
108
112
 
109
- wget http://admin:admin@localhost:2002/videos --post-data 'video[file]=/path/to/your/video.mp4&encoder_id=1'
113
+ wget http://admin:admin@localhost:2002/videos --post-data 'video[file]=/path/to/your/video.mp4&video[callback_url]=http://example.org/call/back/id&encoder_id=1'
110
114
 
111
115
  <b>Don't use wget like this on a shared host, it's insecure</b> (read the wget
112
116
  docs for more on this). This wget example is just to show you what's going on
@@ -205,9 +209,9 @@ system).
205
209
 
206
210
  == Status
207
211
 
208
- This thing is still pre-release.
212
+ This thing is still pre-release, but it is usable in a basic form now.
209
213
 
210
- I'm just working on getting the gem dependencies correct, so you may need to
214
+ I'm still working on getting the gem dependencies correct, so you may need to
211
215
  manually install a few things to get it to work. You'll also need a working
212
216
  copy of ffmpeg available on your path.
213
217
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.4.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{enigmamachine}
8
- s.version = "0.3.4"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dave Hrycyszyn"]
12
- s.date = %q{2010-07-12}
12
+ s.date = %q{2010-07-20}
13
13
  s.default_executable = %q{enigmamachine}
14
14
  s.description = %q{A RESTful video encoder which you can use as either a front-end to ffmpeg or headless on a server.}
15
15
  s.email = %q{dave@caprica}
@@ -1,4 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/video'
2
+ require 'net/http'
3
+ require 'uri'
2
4
 
3
5
  # An encoding profile which can be applied to a video. It has a name and is
4
6
  # composed of a bunch of EncodingTasks.
@@ -45,6 +47,7 @@ class Encoder
45
47
  if task == encoding_tasks.last
46
48
  video.state = "complete"
47
49
  video.save
50
+ video.notify_complete
48
51
  else
49
52
  next_task_index = current_task_index + 1
50
53
  next_task = encoding_tasks[next_task_index]
@@ -14,21 +14,42 @@ class Video
14
14
  property :created_at, DateTime
15
15
  property :updated_at, DateTime
16
16
  property :encoder_id, Integer, :required => true
17
+ property :callback_url, String
17
18
 
18
19
  belongs_to :encoder
19
20
 
21
+ # Notifies a calling application that processing has completed by sending
22
+ # a GET request to the video's callback_url.
23
+ #
24
+ def notify_complete
25
+ begin
26
+ Net::HTTP.get(URI.parse(video.callback_url)) unless callback_url.nil?
27
+ rescue
28
+ end
29
+ end
30
+
31
+
32
+ # Named scope for all videos which are waiting to start encoding.
33
+ #
20
34
  def self.unencoded
21
35
  all(:state => 'unencoded')
22
36
  end
23
37
 
38
+ # Named scope for all videos which are currently encoding. Theoretically
39
+ # there should only ever be one.
40
+ #
24
41
  def self.encoding
25
42
  all(:state => 'encoding')
26
43
  end
27
44
 
45
+ # Named scope giving back all videos with encoding errors.
46
+ #
28
47
  def self.with_errors
29
48
  all(:state => 'error')
30
49
  end
31
50
 
51
+ # Named scope giving back all videos which have completed encoding.
52
+ #
32
53
  def self.complete
33
54
  all(:state => 'complete', :order => [:updated_at.desc])
34
55
  end
@@ -8,6 +8,13 @@
8
8
  <option value="<%= e.id %>"><%= e.name %></option>
9
9
  <% end %>
10
10
  </select>
11
+
12
+ <p>
13
+ <strong>Callback url:</strong>
14
+ <br/>
15
+ <input name="video[callback_url]" id="video_callback_url" value="<%= @video.callback_url %>" size="50"></input>
16
+ </p>
17
+
11
18
  <input type="submit" value="Save"/>
12
19
  <p>
13
20
  <a href="/videos">cancel</a>
@@ -10,6 +10,7 @@ Video.blueprint do
10
10
  encoder
11
11
  file { File.dirname(__FILE__) + "/afile.mpg" }
12
12
  state { "unencoded" }
13
+ callback_url { "http://example.org/call/back/id" }
13
14
  created_at DateTime.now
14
15
  updated_at DateTime.now
15
16
  end
data/test/test_video.rb CHANGED
@@ -6,13 +6,27 @@ class TestVideo < Test::Unit::TestCase
6
6
  context "A Video instance" do
7
7
 
8
8
  should "be invalid without a file path" do
9
- resource = ::Video.make_unsaved
9
+ resource = ::Video.make
10
10
  resource.file = ""
11
11
  assert !resource.valid?
12
12
  resource.file = nil
13
13
  assert !resource.valid?
14
14
  end
15
15
 
16
+ should "be valid without a callback_url" do
17
+ resource = ::Video.make
18
+ resource.callback_url = ""
19
+ assert resource.valid?
20
+ resource.callback_url = nil
21
+ assert resource.valid?
22
+ end
23
+
24
+ should "be valid with a callback_url" do
25
+ resource = ::Video.make
26
+ resource.callback_url = "blah"
27
+ assert resource.valid?
28
+ end
29
+
16
30
  should "be valid with a file path" do
17
31
  resource = ::Video.make
18
32
  resource.file = "foo.mpg"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enigmamachine
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
9
8
  - 4
10
- version: 0.3.4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dave Hrycyszyn
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-12 00:00:00 +01:00
18
+ date: 2010-07-20 00:00:00 +01:00
19
19
  default_executable: enigmamachine
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency