encoding-dot-com 0.0.1 → 0.0.2

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{encoding-dot-com}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Roland Swingler", "Alan Kennedy", "Levent Ali"]
12
- s.date = %q{2009-12-07}
12
+ s.date = %q{2009-12-08}
13
13
  s.description = %q{A ruby wrapper for the encoding.com API}
14
14
  s.email = %q{roland.swingler@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
32
32
  "lib/encoding_dot_com/format.rb",
33
33
  "lib/encoding_dot_com/http_adapters/curb_adapter.rb",
34
34
  "lib/encoding_dot_com/http_adapters/net_http_adapter.rb",
35
+ "lib/encoding_dot_com/image_format.rb",
35
36
  "lib/encoding_dot_com/media_info.rb",
36
37
  "lib/encoding_dot_com/media_list_item.rb",
37
38
  "lib/encoding_dot_com/queue.rb",
@@ -41,6 +42,7 @@ Gem::Specification.new do |s|
41
42
  "spec/encoding_dot_com/http_adapters/net_http_adapter_spec.rb",
42
43
  "spec/flv_vp6_format_spec.rb",
43
44
  "spec/format_spec.rb",
45
+ "spec/image_format_spec.rb",
44
46
  "spec/media_list_item_spec.rb",
45
47
  "spec/queue_spec.rb",
46
48
  "spec/spec_helper.rb",
@@ -54,6 +56,7 @@ Gem::Specification.new do |s|
54
56
  s.test_files = [
55
57
  "spec/flv_vp6_format_spec.rb",
56
58
  "spec/spec_helper.rb",
59
+ "spec/image_format_spec.rb",
57
60
  "spec/encoding_dot_com/http_adapters/net_http_adapter_spec.rb",
58
61
  "spec/encoding_dot_com/http_adapters/curb_adapter_spec.rb",
59
62
  "spec/format_spec.rb",
@@ -4,6 +4,7 @@ require 'encoding_dot_com/attribute_restrictions'
4
4
  require 'encoding_dot_com/format'
5
5
  require 'encoding_dot_com/video_format'
6
6
  require 'encoding_dot_com/thumbnail_format'
7
+ require 'encoding_dot_com/image_format'
7
8
  require 'encoding_dot_com/flv_vp6_format'
8
9
  require 'encoding_dot_com/media_list_item'
9
10
  require 'encoding_dot_com/media_info'
@@ -12,6 +12,8 @@ module EncodingDotCom
12
12
  ThumbnailFormat.new(attributes)
13
13
  elsif attributes["output"] == "flv" && attributes["video_codec"] == "vp6"
14
14
  FLVVP6Format.new(attributes)
15
+ elsif attributes["output"] == "image"
16
+ ImageFormat.new(attributes)
15
17
  else
16
18
  VideoFormat.new(attributes)
17
19
  end
@@ -0,0 +1,37 @@
1
+ module EncodingDotCom
2
+ class ImageFormat < Format
3
+ allowed_attributes :output, :image_format, :size, :resize_method, :quality
4
+ boolean_attributes :keep_aspect_ratio
5
+
6
+ def initialize(attributes={})
7
+ @attributes = attributes.merge("output" => "image")
8
+ validate_attributes
9
+ end
10
+
11
+ private
12
+
13
+ def validate_attributes
14
+ validate_image_format
15
+ validate_resize_method
16
+ validate_quality
17
+ end
18
+
19
+ def validate_image_format
20
+ unless image_format.nil? || %w{jpg png gif}.include?(image_format)
21
+ raise IllegalFormatAttribute.new("image_format should be one of jpg, png or gif.")
22
+ end
23
+ end
24
+
25
+ def validate_resize_method
26
+ unless resize_method.nil? || %w{resize crop combine}.include?(resize_method)
27
+ raise IllegalFormatAttribute.new("resize_method should be one of resize, crop or combine.")
28
+ end
29
+ end
30
+
31
+ def validate_quality
32
+ unless quality.nil? || (quality.to_i >= 1 && quality.to_i <= 100)
33
+ raise IllegalFormatAttribute.new("quality should be between 1 and 100.")
34
+ end
35
+ end
36
+ end
37
+ end
@@ -5,16 +5,7 @@ describe "Encoding.com FLV VP6 Format" do
5
5
  it "should have an output attribute of 'thumbnail'" do
6
6
  EncodingDotCom::FLVVP6Format.new.output.should == "flv"
7
7
  end
8
-
9
- it "should return a ThumbnailFormat if the output is 'thumbnail'" do
10
- EncodingDotCom::Format.create("output" => "flv", "video_codec" => "vp6").should be_instance_of(EncodingDotCom::FLVVP6Format)
11
- end
12
-
13
- def format_xml(attributes={})
14
- format = EncodingDotCom::FLVVP6Format.new(attributes)
15
- Nokogiri::XML::Builder.new {|b| format.build_xml(b, "http://example.com") }.to_xml
16
- end
17
-
8
+
18
9
  it "should produce a format node in the xml output" do
19
10
  format_xml.should have_xpath("/format")
20
11
  end
@@ -41,4 +32,9 @@ describe "Encoding.com FLV VP6 Format" do
41
32
  lambda { EncodingDotCom::FLVVP6Format.new("size" => "33x33") }.should raise_error(EncodingDotCom::IllegalFormatAttribute)
42
33
  end
43
34
  end
35
+
36
+ def format_xml(attributes={})
37
+ format = EncodingDotCom::FLVVP6Format.new(attributes)
38
+ Nokogiri::XML::Builder.new {|b| format.build_xml(b, "http://example.com") }.to_xml
39
+ end
44
40
  end
data/spec/format_spec.rb CHANGED
@@ -3,9 +3,17 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
  describe "Encoding.com video format" do
4
4
 
5
5
  describe "#create" do
6
- it "should return a video format" do
6
+ it "should return a VideoFormat when the output type is a video output" do
7
7
  EncodingDotCom::Format.create("output" => "mp4").should be_instance_of(EncodingDotCom::VideoFormat)
8
8
  end
9
+
10
+ it "should return a FLVVP6Format if the output is flv and the video codec is vp6" do
11
+ EncodingDotCom::Format.create("output" => "flv", "video_codec" => "vp6").should be_instance_of(EncodingDotCom::FLVVP6Format)
12
+ end
13
+
14
+ it "should return a ImageFormat when the output type is image" do
15
+ EncodingDotCom::Format.create("output" => "image").should be_instance_of(EncodingDotCom::ImageFormat)
16
+ end
9
17
  end
10
18
 
11
19
  describe "#output" do
@@ -0,0 +1,71 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Encoding.com Image Format" do
4
+
5
+ it "should have an output attribute of 'thumbnail'" do
6
+ EncodingDotCom::ImageFormat.new.output.should == "image"
7
+ end
8
+
9
+ it "should produce an output node in the xml output" do
10
+ format_xml.should have_xpath("/format/output[text()='image']")
11
+ end
12
+
13
+ it "should produce an image format node in the xml output" do
14
+ format_xml("image_format" => "jpg").should have_xpath("/format/image_format[text()='jpg']")
15
+ end
16
+
17
+ it "should produce a size node in the xml output" do
18
+ format_xml("size" => "10x10").should have_xpath("/format/size[text()='10x10']")
19
+ end
20
+
21
+ it "should produce a resize method node in the xml output" do
22
+ format_xml("resize_method" => "crop").should have_xpath("/format/resize_method[text()='crop']")
23
+ end
24
+
25
+ it "should produce a resize method node in the xml output" do
26
+ format_xml("quality" => "90").should have_xpath("/format/quality[text()='90']")
27
+ end
28
+
29
+ it "should produce a keep aspect ratio node in the xml output" do
30
+ format_xml("keep_aspect_ratio" => true).should have_xpath("/format/keep_aspect_ratio[text()='yes']")
31
+ end
32
+
33
+ describe "valid resize method" do
34
+ %w{resize crop combine}.each do |method|
35
+ it "should allow '#{method}'" do
36
+ lambda { format_xml("resize_method" => method) }.should_not raise_error(EncodingDotCom::IllegalFormatAttribute)
37
+ end
38
+ end
39
+
40
+ it "should not allow anything else" do
41
+ lambda { format_xml("resize_method" => "foo") }.should raise_error(EncodingDotCom::IllegalFormatAttribute)
42
+ end
43
+ end
44
+
45
+ describe "valid image format" do
46
+ %w{jpg png gif}.each do |format|
47
+ it "should allow '#{format}'" do
48
+ lambda { format_xml("image_format" => format) }.should_not raise_error(EncodingDotCom::IllegalFormatAttribute)
49
+ end
50
+ end
51
+
52
+ it "should not allow anything else" do
53
+ lambda { format_xml("image_format" => "foo") }.should raise_error(EncodingDotCom::IllegalFormatAttribute)
54
+ end
55
+ end
56
+
57
+ describe "valid quality" do
58
+ it "should be between 1 and 100" do
59
+ lambda { format_xml("quality" => 0) }.should raise_error(EncodingDotCom::IllegalFormatAttribute)
60
+ lambda { format_xml("quality" => 101) }.should raise_error(EncodingDotCom::IllegalFormatAttribute)
61
+ lambda { format_xml("quality" => 1) }.should_not raise_error(EncodingDotCom::IllegalFormatAttribute)
62
+ lambda { format_xml("quality" => 100) }.should_not raise_error(EncodingDotCom::IllegalFormatAttribute)
63
+ end
64
+ end
65
+
66
+ def format_xml(attributes={})
67
+ format = EncodingDotCom::ImageFormat.new(attributes)
68
+ Nokogiri::XML::Builder.new {|b| format.build_xml(b, "http://example.com") }.to_xml
69
+ end
70
+ end
71
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: encoding-dot-com
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roland Swingler
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-12-07 00:00:00 +00:00
14
+ date: 2009-12-08 00:00:00 +00:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -59,6 +59,7 @@ files:
59
59
  - lib/encoding_dot_com/format.rb
60
60
  - lib/encoding_dot_com/http_adapters/curb_adapter.rb
61
61
  - lib/encoding_dot_com/http_adapters/net_http_adapter.rb
62
+ - lib/encoding_dot_com/image_format.rb
62
63
  - lib/encoding_dot_com/media_info.rb
63
64
  - lib/encoding_dot_com/media_list_item.rb
64
65
  - lib/encoding_dot_com/queue.rb
@@ -68,6 +69,7 @@ files:
68
69
  - spec/encoding_dot_com/http_adapters/net_http_adapter_spec.rb
69
70
  - spec/flv_vp6_format_spec.rb
70
71
  - spec/format_spec.rb
72
+ - spec/image_format_spec.rb
71
73
  - spec/media_list_item_spec.rb
72
74
  - spec/queue_spec.rb
73
75
  - spec/spec_helper.rb
@@ -103,6 +105,7 @@ summary: A ruby wrapper for the encoding.com API
103
105
  test_files:
104
106
  - spec/flv_vp6_format_spec.rb
105
107
  - spec/spec_helper.rb
108
+ - spec/image_format_spec.rb
106
109
  - spec/encoding_dot_com/http_adapters/net_http_adapter_spec.rb
107
110
  - spec/encoding_dot_com/http_adapters/curb_adapter_spec.rb
108
111
  - spec/format_spec.rb