encodingdotcom 0.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.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +18 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/encodingdotcom.gemspec +58 -0
- data/lib/encoding_dot_com.rb +5 -0
- data/lib/encoding_dot_com/connection.rb +66 -0
- data/lib/encoding_dot_com/format.rb +192 -0
- data/lib/encoding_dot_com/media.rb +104 -0
- data/lib/encoding_dot_com/thumbnail.rb +21 -0
- data/lib/encodingdotcom.rb +1 -0
- data/test/encodingdotcom_test.rb +7 -0
- data/test/test_helper.rb +9 -0
- metadata +80 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Mick Staugaard
|
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,18 @@
|
|
1
|
+
= encodingdotcom
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but
|
13
|
+
bump version in a commit by itself I can ignore when I pull)
|
14
|
+
* Send me a pull request. Bonus points for topic branches.
|
15
|
+
|
16
|
+
== Copyright
|
17
|
+
|
18
|
+
Copyright (c) 2009 Mick Staugaard. 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 = "encodingdotcom"
|
8
|
+
gem.summary = "a library for integrating with encoding.com"
|
9
|
+
gem.description = "a library for integrating with encoding.com"
|
10
|
+
gem.email = "mick@staugaard.com"
|
11
|
+
gem.homepage = "http://github.com/staugaard/encodingdotcom"
|
12
|
+
gem.authors = ["Mick Staugaard"]
|
13
|
+
gem.add_dependency('httparty', ">= 0.2.10")
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/*_test.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |test|
|
30
|
+
test.libs << 'test'
|
31
|
+
test.pattern = 'test/**/*_test.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
task :test => :check_dependencies
|
41
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
if File.exist?('VERSION')
|
47
|
+
version = File.read('VERSION')
|
48
|
+
else
|
49
|
+
version = ""
|
50
|
+
end
|
51
|
+
|
52
|
+
rdoc.rdoc_dir = 'rdoc'
|
53
|
+
rdoc.title = "encodingdotcom #{version}"
|
54
|
+
rdoc.rdoc_files.include('README*')
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{encodingdotcom}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Mick Staugaard"]
|
12
|
+
s.date = %q{2009-10-11}
|
13
|
+
s.description = %q{a library for integrating with encoding.com}
|
14
|
+
s.email = %q{mick@staugaard.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"encodingdotcom.gemspec",
|
27
|
+
"lib/encoding_dot_com.rb",
|
28
|
+
"lib/encoding_dot_com/connection.rb",
|
29
|
+
"lib/encoding_dot_com/format.rb",
|
30
|
+
"lib/encoding_dot_com/media.rb",
|
31
|
+
"lib/encoding_dot_com/thumbnail.rb",
|
32
|
+
"lib/encodingdotcom.rb",
|
33
|
+
"test/encodingdotcom_test.rb",
|
34
|
+
"test/test_helper.rb"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/staugaard/encodingdotcom}
|
37
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = %q{1.3.5}
|
40
|
+
s.summary = %q{a library for integrating with encoding.com}
|
41
|
+
s.test_files = [
|
42
|
+
"test/encodingdotcom_test.rb",
|
43
|
+
"test/test_helper.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0.2.10"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<httparty>, [">= 0.2.10"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<httparty>, [">= 0.2.10"])
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module EncodingDotCom
|
4
|
+
class EncodingDotComError < StandardError
|
5
|
+
end
|
6
|
+
|
7
|
+
class BadRequestError < EncodingDotComError
|
8
|
+
end
|
9
|
+
|
10
|
+
class AuthenticationError < EncodingDotComError
|
11
|
+
end
|
12
|
+
|
13
|
+
class NotFoundError < EncodingDotComError
|
14
|
+
end
|
15
|
+
|
16
|
+
class BadUrlError < EncodingDotComError
|
17
|
+
end
|
18
|
+
|
19
|
+
class BadSourceUrlError < BadUrlError
|
20
|
+
end
|
21
|
+
|
22
|
+
class BadDestinationUrlError < BadUrlError
|
23
|
+
end
|
24
|
+
|
25
|
+
class Connection
|
26
|
+
include HTTParty
|
27
|
+
base_uri 'manage.encoding.com'
|
28
|
+
|
29
|
+
class << self
|
30
|
+
attr_accessor :user_id, :user_key, :s3_key, :s3_secret, :logger
|
31
|
+
|
32
|
+
def call(request_xml_document)
|
33
|
+
if logger
|
34
|
+
logger.info("Sending encoding.com request:\n#{request_xml_document}")
|
35
|
+
end
|
36
|
+
|
37
|
+
response = post('/', :body => {:xml => request_xml_document})
|
38
|
+
|
39
|
+
if logger
|
40
|
+
logger.info("Received encoding.com response:\n#{response.inspect}")
|
41
|
+
end
|
42
|
+
response = response['response']
|
43
|
+
|
44
|
+
if response['errors']
|
45
|
+
message = response['errors']['error']
|
46
|
+
case message
|
47
|
+
when /Wrong XML/, /No XML/, /Wrong query format/, /Invalid action/, /No formats specified/, /No output format specified/, /Output format .* is not allowed/
|
48
|
+
raise(BadRequestError, message)
|
49
|
+
when /Wrong user id or key/
|
50
|
+
raise(AuthenticationError, message)
|
51
|
+
when /Media ID is not indicated/, /Wrong Media ID/
|
52
|
+
raise(NotFoundError, message)
|
53
|
+
when /Wrong source file url/, /Source file is not indicated/
|
54
|
+
raise(BadSourceUrlError, message)
|
55
|
+
when /Wrong destination file url/
|
56
|
+
raise(BadDestinationUrlError, message)
|
57
|
+
else
|
58
|
+
raise(EncodingDotComError, message)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
response
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
module EncodingDotCom
|
2
|
+
class Format
|
3
|
+
OUTPUTS = [:"3gp", :appletv, :fl9, :flv, :iphone, :ipod, :m4v, :mp3, :mp4, :psp, :wma, :wmv, :zune]
|
4
|
+
VIDEO_CODECS = [:flv, :libx264, :mpeg4, :msmpeg4, :h263, :vp6, :wmv2]
|
5
|
+
AUDIO_CODECS = [:libmp3lame, :libfaac, :wmav2, :libamr_nb]
|
6
|
+
|
7
|
+
BOOLEAN_FIELDS = [:stereo, :two_pass, :constant_bitrate, :deinterlace, :turbo]
|
8
|
+
INTEGER_FIELDS = [:video_bitrate, :framerate, :audio_bitrate, :audio_sample_rate, :max_bitrate, :min_bitrate, :key_frame_interval ]
|
9
|
+
|
10
|
+
attr_accessor :output,
|
11
|
+
:dimensions,
|
12
|
+
:video_bitrate,
|
13
|
+
:framerate,
|
14
|
+
:video_codec,
|
15
|
+
:audio_bitrate,
|
16
|
+
:audio_sample_rate,
|
17
|
+
:audio_codec,
|
18
|
+
:stereo,
|
19
|
+
:two_pass,
|
20
|
+
:constant_bitrate,
|
21
|
+
:max_bitrate,
|
22
|
+
:min_bitrate,
|
23
|
+
:key_frame_interval,
|
24
|
+
:deinterlace,
|
25
|
+
:turbo,
|
26
|
+
:destination
|
27
|
+
|
28
|
+
def initialize(attributes = {})
|
29
|
+
self.output = attributes.delete(:output)
|
30
|
+
attributes.each do |key, value|
|
31
|
+
send("#{key}=", value)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def destination=(destination_url)
|
36
|
+
@destination = Media.media_url_string(URI.parse(destination_url.to_s))
|
37
|
+
end
|
38
|
+
|
39
|
+
def output=(new_output)
|
40
|
+
@output = new_output.to_sym
|
41
|
+
|
42
|
+
case @output
|
43
|
+
when :'3gp'
|
44
|
+
self.dimensions ||= [176, 144]
|
45
|
+
self.video_bitrate ||= 256
|
46
|
+
self.framerate ||= 25
|
47
|
+
self.video_codec ||= :h263
|
48
|
+
self.audio_bitrate ||= 12.2
|
49
|
+
self.audio_sample_rate ||= 8000
|
50
|
+
self.audio_codec ||= :libamr_nb
|
51
|
+
self.stereo = false if self.stereo.nil?
|
52
|
+
when :appletv
|
53
|
+
self.dimensions ||= [710, 480]
|
54
|
+
self.video_bitrate ||= 512
|
55
|
+
self.framerate ||= 25
|
56
|
+
self.video_codec ||= :mpeg4
|
57
|
+
self.audio_bitrate ||= 64
|
58
|
+
self.audio_codec ||= :libfaac
|
59
|
+
when :flv
|
60
|
+
self.video_bitrate ||= 512
|
61
|
+
self.framerate ||= 25
|
62
|
+
self.video_codec ||= :flv
|
63
|
+
self.audio_bitrate ||= 64
|
64
|
+
self.audio_sample_rate ||= 44100
|
65
|
+
self.audio_codec ||= :libmp3lame
|
66
|
+
when :flv9
|
67
|
+
self.video_bitrate ||= 512
|
68
|
+
self.framerate ||= 25
|
69
|
+
self.video_codec ||= :libx264
|
70
|
+
self.audio_bitrate ||= 64
|
71
|
+
self.audio_codec ||= :libfaac
|
72
|
+
when :iphone
|
73
|
+
self.dimensions ||= [480, 368]
|
74
|
+
self.video_bitrate ||= 1024
|
75
|
+
self.framerate ||= 25
|
76
|
+
self.video_codec ||= :mpeg4
|
77
|
+
self.audio_bitrate ||= 128
|
78
|
+
self.audio_codec ||= :libfaac
|
79
|
+
when :ipod
|
80
|
+
self.video_bitrate ||= 1024
|
81
|
+
self.framerate ||= 25
|
82
|
+
self.video_codec ||= :mpeg4
|
83
|
+
self.audio_bitrate ||= 128
|
84
|
+
self.audio_codec ||= :libfaac
|
85
|
+
when :m4v
|
86
|
+
self.video_bitrate ||= 512
|
87
|
+
self.framerate ||= 25
|
88
|
+
self.video_codec ||= :mpeg4
|
89
|
+
self.audio_bitrate ||= 64
|
90
|
+
self.audio_codec ||= :libfaac
|
91
|
+
when :mp3
|
92
|
+
self.audio_bitrate ||= 64
|
93
|
+
self.audio_sample_rate ||= 44100
|
94
|
+
self.audio_codec ||= :libmp3lame
|
95
|
+
when :mp4
|
96
|
+
self.video_bitrate ||= 512
|
97
|
+
self.framerate ||= 25
|
98
|
+
self.video_codec ||= :mpeg4
|
99
|
+
self.audio_bitrate ||= 64
|
100
|
+
self.audio_codec ||= :libfaac
|
101
|
+
when :psp
|
102
|
+
self.dimensions ||= [368, 192]
|
103
|
+
self.video_bitrate ||= 1024
|
104
|
+
self.framerate ||= [30000, 1001]
|
105
|
+
self.video_codec ||= :mpeg4
|
106
|
+
self.audio_bitrate ||= 128
|
107
|
+
self.audio_codec ||= :libfaac
|
108
|
+
when :wma
|
109
|
+
self.audio_bitrate ||= 64
|
110
|
+
when :wmv
|
111
|
+
self.video_bitrate ||= 512
|
112
|
+
self.framerate ||= 25
|
113
|
+
self.video_codec ||= :wmv2
|
114
|
+
self.audio_bitrate ||= 64
|
115
|
+
self.audio_codec ||= :wmav2
|
116
|
+
when :zune
|
117
|
+
self.dimensions ||= [320, 180]
|
118
|
+
self.video_bitrate ||= 512
|
119
|
+
self.framerate ||= 25
|
120
|
+
self.video_codec ||= :wmv2
|
121
|
+
self.audio_bitrate ||= 64
|
122
|
+
self.audio_sample_rate ||= 44100
|
123
|
+
self.audio_codec ||= :wmav2
|
124
|
+
end
|
125
|
+
|
126
|
+
self.stereo = true if self.stereo.nil?
|
127
|
+
self.two_pass = false if self.two_pass.nil?
|
128
|
+
self.constant_bitrate = false if self.constant_bitrate.nil?
|
129
|
+
self.key_frame_interval ||= 300
|
130
|
+
self.deinterlace = false if self.deinterlace.nil?
|
131
|
+
self.turbo = false if self.turbo.nil?
|
132
|
+
end
|
133
|
+
|
134
|
+
[:video_bitrate, :audio_bitrate, :audio_sample_rate, :max_bitrate, :min_bitrate, :key_frame_interval].each do |method_name|
|
135
|
+
define_method("#{method_name}=") do |value|
|
136
|
+
if value.blank?
|
137
|
+
instance_variable_set("@#{method_name}", nil)
|
138
|
+
else
|
139
|
+
instance_variable_set("@#{method_name}", value.to_i)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def to_xml(options = {})
|
145
|
+
xml = options[:builder] ||= ::Builder::XmlMarkup.new(:indent => options[:indent] ||= 2)
|
146
|
+
|
147
|
+
xml.format do
|
148
|
+
xml.output(output.to_s)
|
149
|
+
xml.video_codec(video_codec.to_s) if video_codec
|
150
|
+
xml.audio_codec(audio_codec.to_s) if audio_codec
|
151
|
+
xml.bitrate("#{video_bitrate}k") if video_bitrate
|
152
|
+
xml.audio_bitrate("#{audio_bitrate}k") if audio_bitrate
|
153
|
+
xml.audio_sample_rate(audio_sample_rate.to_s) if audio_sample_rate
|
154
|
+
xml.size("#{dimensions[0]}x#{dimensions[1]}") if dimensions
|
155
|
+
xml.minrate("#{min_bitrate}k") if min_bitrate
|
156
|
+
xml.maxrate("#{max_bitrate}k") if max_bitrate
|
157
|
+
xml.keyframe(key_frame_interval) if key_frame_interval
|
158
|
+
xml.framerate(framerate.is_a?(Array) ? "#{framerate[0]}/#{framerate[1]}" : framerate.to_s) if framerate
|
159
|
+
xml.audio_channels_number(stereo ? '2' : '1') unless stereo.nil?
|
160
|
+
xml.two_pass(two_pass ? 'yes' : 'no') unless two_pass.nil?
|
161
|
+
xml.cbr(constant_bitrate ? 'yes' : 'no') unless constant_bitrate.nil?
|
162
|
+
xml.deinterlacing(deinterlace ? 'yes' : 'no') unless deinterlace.nil?
|
163
|
+
xml.destination(destination) unless destination.nil?
|
164
|
+
xml.turbo(turbo ? 'yes' : 'no') unless turbo.nil?
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def to_hash
|
169
|
+
hash = {
|
170
|
+
:output => output,
|
171
|
+
:stereo => stereo,
|
172
|
+
:turbo => turbo
|
173
|
+
}
|
174
|
+
|
175
|
+
hash[:dimensions] = dimensions unless dimensions.nil?
|
176
|
+
hash[:video_bitrate] = video_bitrate unless video_bitrate.nil?
|
177
|
+
hash[:framerate] = framerate unless framerate.nil?
|
178
|
+
hash[:video_codec] = video_codec unless video_codec.nil?
|
179
|
+
hash[:audio_bitrate] = audio_bitrate unless audio_bitrate.nil?
|
180
|
+
hash[:audio_sample_rate] = audio_sample_rate unless audio_sample_rate.nil?
|
181
|
+
hash[:audio_codec] = audio_codec unless audio_codec.nil?
|
182
|
+
hash[:two_pass] = two_pass unless two_pass.nil?
|
183
|
+
hash[:constant_bitrate] = constant_bitrate unless constant_bitrate.nil?
|
184
|
+
hash[:max_bitrate] = max_bitrate unless max_bitrate.nil?
|
185
|
+
hash[:min_bitrate] = min_bitrate unless min_bitrate.nil?
|
186
|
+
hash[:key_frame_interval] = key_frame_interval unless key_frame_interval.nil?
|
187
|
+
hash[:deinterlace] = deinterlace unless deinterlace.nil?
|
188
|
+
|
189
|
+
hash
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'encoding_dot_com/connection'
|
2
|
+
require 'encoding_dot_com/format'
|
3
|
+
require 'uri'
|
4
|
+
require 'builder'
|
5
|
+
|
6
|
+
module EncodingDotCom
|
7
|
+
class Media
|
8
|
+
attr_reader :id, :source_location, :notify_url, :formats
|
9
|
+
|
10
|
+
def initialize(location_or_id, options = {})
|
11
|
+
if location_or_id.is_a?(Fixnum)
|
12
|
+
@id = location_or_id
|
13
|
+
else
|
14
|
+
@source_location = URI.parse(location_or_id.to_s)
|
15
|
+
@notify_url = options[:notify_url]
|
16
|
+
end
|
17
|
+
@formats = []
|
18
|
+
end
|
19
|
+
|
20
|
+
def new_record?
|
21
|
+
@id.nil?
|
22
|
+
end
|
23
|
+
|
24
|
+
def save
|
25
|
+
create_or_update
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_or_update
|
29
|
+
new_record? ? create : update
|
30
|
+
end
|
31
|
+
|
32
|
+
def create
|
33
|
+
request = to_xml('AddMediaBenchmark') { |xml|
|
34
|
+
xml.source(self.class.media_url_string(@source_location))
|
35
|
+
xml.notify(@notify_url) if @notify_url
|
36
|
+
formats.each do |format|
|
37
|
+
format.to_xml(:builder => xml)
|
38
|
+
end
|
39
|
+
}
|
40
|
+
|
41
|
+
response = Connection.call(request)
|
42
|
+
|
43
|
+
if response['message'] == 'Added' && response['MediaID']
|
44
|
+
@id = response['MediaID'].to_i
|
45
|
+
true
|
46
|
+
else
|
47
|
+
false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def update
|
52
|
+
request = to_xml('UpdateMedia') { |xml|
|
53
|
+
formats.each do |format|
|
54
|
+
format.to_xml(:builder => xml)
|
55
|
+
end
|
56
|
+
}
|
57
|
+
|
58
|
+
response = Connection.call(request)
|
59
|
+
end
|
60
|
+
|
61
|
+
def info
|
62
|
+
Connection.call(to_xml('GetMediaInfo'))
|
63
|
+
end
|
64
|
+
|
65
|
+
def status(reload = false)
|
66
|
+
if !@status || reload
|
67
|
+
@status = Connection.call(to_xml('GetStatus'))
|
68
|
+
end
|
69
|
+
|
70
|
+
@status
|
71
|
+
end
|
72
|
+
|
73
|
+
def to_xml(action, options = {})
|
74
|
+
xml = options[:builder] ||= ::Builder::XmlMarkup.new(:indent => options[:indent])
|
75
|
+
|
76
|
+
xml.instruct!
|
77
|
+
xml.query do
|
78
|
+
xml.userid(Connection.user_id)
|
79
|
+
xml.userkey(Connection.user_key)
|
80
|
+
xml.action(action)
|
81
|
+
xml.mediaid(@id) if @id
|
82
|
+
yield(xml) if block_given?
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
[:created, :started, :downloaded, :finished].each do |event|
|
87
|
+
define_method("#{event}_at") do
|
88
|
+
begin
|
89
|
+
Time.parse("#{status[event.to_s]}-05:00")
|
90
|
+
rescue ArgumentError => e
|
91
|
+
nil
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.media_url_string(url)
|
97
|
+
if Connection.s3_key && Connection.s3_secret && url.host =~ /s3.amazonaws.com/
|
98
|
+
url.user = ERB::Util.url_encode(Connection.s3_key)
|
99
|
+
url.password = ERB::Util.url_encode(Connection.s3_secret)
|
100
|
+
end
|
101
|
+
url.to_s
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module EncodingDotCom
|
2
|
+
class Thumbnail
|
3
|
+
def initialize(time, destination_url, options = {})
|
4
|
+
@time = time
|
5
|
+
@destination = Media.media_url_string(URI.parse(destination_url.to_s))
|
6
|
+
@options = options
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_xml(options = {})
|
10
|
+
xml = options[:builder] ||= ::Builder::XmlMarkup.new(:indent => options[:indent] ||= 2)
|
11
|
+
|
12
|
+
xml.format do
|
13
|
+
xml.output('thumbnail')
|
14
|
+
xml.time(@time)
|
15
|
+
xml.width(@options[:width]) if @options[:width]
|
16
|
+
xml.height(@options[:height]) if @options[:height]
|
17
|
+
xml.destination(@destination) unless @destination.nil?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'encoding_dot_com'
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: encodingdotcom
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mick Staugaard
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-11 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: httparty
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.2.10
|
24
|
+
version:
|
25
|
+
description: a library for integrating with encoding.com
|
26
|
+
email: mick@staugaard.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- VERSION
|
41
|
+
- encodingdotcom.gemspec
|
42
|
+
- lib/encoding_dot_com.rb
|
43
|
+
- lib/encoding_dot_com/connection.rb
|
44
|
+
- lib/encoding_dot_com/format.rb
|
45
|
+
- lib/encoding_dot_com/media.rb
|
46
|
+
- lib/encoding_dot_com/thumbnail.rb
|
47
|
+
- lib/encodingdotcom.rb
|
48
|
+
- test/encodingdotcom_test.rb
|
49
|
+
- test/test_helper.rb
|
50
|
+
has_rdoc: true
|
51
|
+
homepage: http://github.com/staugaard/encodingdotcom
|
52
|
+
licenses: []
|
53
|
+
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options:
|
56
|
+
- --charset=UTF-8
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: "0"
|
70
|
+
version:
|
71
|
+
requirements: []
|
72
|
+
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.3.5
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: a library for integrating with encoding.com
|
78
|
+
test_files:
|
79
|
+
- test/encodingdotcom_test.rb
|
80
|
+
- test/test_helper.rb
|