animoto 0.1.1.beta1 → 1.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.
Files changed (49) hide show
  1. data/README.md +8 -4
  2. data/lib/animoto.rb +1 -1
  3. data/lib/animoto/assets/base.rb +1 -1
  4. data/lib/animoto/assets/footage.rb +1 -1
  5. data/lib/animoto/assets/image.rb +1 -1
  6. data/lib/animoto/assets/song.rb +1 -1
  7. data/lib/animoto/assets/title_card.rb +1 -1
  8. data/lib/animoto/client.rb +21 -27
  9. data/lib/animoto/http_engines/base.rb +15 -7
  10. data/lib/animoto/http_engines/curl_adapter.rb +3 -4
  11. data/lib/animoto/http_engines/net_http_adapter.rb +3 -5
  12. data/lib/animoto/http_engines/patron_adapter.rb +2 -4
  13. data/lib/animoto/http_engines/rest_client_adapter.rb +1 -3
  14. data/lib/animoto/http_engines/typhoeus_adapter.rb +1 -3
  15. data/lib/animoto/manifests/base.rb +1 -1
  16. data/lib/animoto/manifests/directing.rb +1 -1
  17. data/lib/animoto/manifests/directing_and_rendering.rb +55 -28
  18. data/lib/animoto/manifests/rendering.rb +7 -6
  19. data/lib/animoto/resources/base.rb +8 -8
  20. data/lib/animoto/resources/jobs/base.rb +2 -2
  21. data/lib/animoto/resources/jobs/directing.rb +7 -2
  22. data/lib/animoto/resources/jobs/directing_and_rendering.rb +34 -8
  23. data/lib/animoto/resources/jobs/rendering.rb +17 -3
  24. data/lib/animoto/resources/storyboard.rb +20 -4
  25. data/lib/animoto/resources/video.rb +33 -11
  26. data/lib/animoto/response_parsers/base.rb +13 -8
  27. data/lib/animoto/response_parsers/json_adapter.rb +2 -4
  28. data/lib/animoto/response_parsers/yajl_adapter.rb +2 -4
  29. data/lib/animoto/support/content_type.rb +1 -0
  30. data/lib/animoto/support/coverable.rb +1 -1
  31. data/lib/animoto/support/dynamic_class_loader.rb +82 -141
  32. data/lib/animoto/support/errors.rb +4 -0
  33. data/lib/animoto/support/hash.rb +25 -0
  34. data/lib/animoto/support/standard_envelope.rb +70 -19
  35. data/lib/animoto/support/string.rb +31 -0
  36. data/lib/animoto/support/visual.rb +1 -1
  37. data/spec/animoto/client_spec.rb +1 -25
  38. data/spec/animoto/http_engines/base_spec.rb +1 -1
  39. data/spec/animoto/resources/base_spec.rb +8 -7
  40. data/spec/spec_helper.rb +1 -0
  41. metadata +12 -21
  42. data/lib/animoto/callbacks/base.rb +0 -45
  43. data/lib/animoto/callbacks/directing.rb +0 -7
  44. data/lib/animoto/callbacks/directing_and_rendering.rb +0 -7
  45. data/lib/animoto/callbacks/rendering.rb +0 -7
  46. data/spec/animoto/callbacks/base_spec.rb +0 -76
  47. data/spec/animoto/callbacks/directing_and_rendering_spec.rb +0 -5
  48. data/spec/animoto/callbacks/directing_spec.rb +0 -5
  49. data/spec/animoto/callbacks/rendering_spec.rb +0 -5
@@ -8,7 +8,7 @@ module Animoto
8
8
  attr_accessor :resolution
9
9
 
10
10
  # The framerate of the rendered video. Valid values are 12, 15, 24 or 30.
11
- # @return [Fixnum]
11
+ # @return [Integer]
12
12
  attr_accessor :framerate
13
13
 
14
14
  # The format of the rendered video. Valid values are 'h264', 'h264-iphone', 'flv' or 'iso'.
@@ -30,15 +30,16 @@ module Animoto
30
30
  # Creates a new rendering manifest.
31
31
  #
32
32
  # @param [Resources::Storyboard] storyboard the storyboard for this rendering
33
- # @param [Hash<Symbol,Object>] options
33
+ # @param [Hash{Symbol=>Object}] options
34
34
  # @option options [String] :resolution the vertical resolution of the rendered video
35
35
  # @option options [Integer] :framerate the framerate of the rendered video
36
36
  # @option options [String] :format the format of the rendered video
37
37
  # @option options [String] :http_callback_url a URL to receive a callback when this job is done
38
38
  # @option options [String] :http_callback_format the format of the callback
39
39
  # @return [Manifests::Rendering] the manifest
40
- def initialize storyboard, options = {}
41
- @storyboard = storyboard
40
+ def initialize *args
41
+ options = args.last.is_a?(Hash) ? args.pop : {}
42
+ @storyboard = args.shift
42
43
  @resolution = options[:resolution]
43
44
  @framerate = options[:framerate]
44
45
  @format = options[:format]
@@ -48,7 +49,7 @@ module Animoto
48
49
 
49
50
  # Returns a representation of this manifest as a Hash.
50
51
  #
51
- # @return [Hash<String,String>] this manifest as a Hash
52
+ # @return [Hash{String=>Object}] this manifest as a Hash
52
53
  # @raise [ArgumentError] if a callback URL was specified but not the format
53
54
  def to_hash
54
55
  hash = { 'rendering_job' => { 'rendering_manifest' => { 'rendering_parameters' => {} } } }
@@ -59,7 +60,7 @@ module Animoto
59
60
  job['http_callback_format'] = http_callback_format
60
61
  end
61
62
  manifest = job['rendering_manifest']
62
- manifest['storyboard_url'] = storyboard.url
63
+ manifest['storyboard_url'] = storyboard.url if storyboard
63
64
  params = manifest['rendering_parameters']
64
65
  params['resolution'] = resolution
65
66
  params['framerate'] = framerate
@@ -1,7 +1,7 @@
1
1
  module Animoto
2
2
  module Resources
3
3
 
4
- # @abstract Set {#endpoint} and maybe override {Support::StandardEnvelope#unpack_standard_envelope} to subclass.
4
+ # @abstract Set {#endpoint} and maybe override {Support::StandardEnvelope::ClassMethods#unpack_standard_envelope} to subclass.
5
5
  class Base
6
6
  include Support::StandardEnvelope
7
7
 
@@ -34,7 +34,7 @@ module Animoto
34
34
  # raise an error.
35
35
  #
36
36
  # @private
37
- # @param [Hash<String,Object>] body the deserialized response body
37
+ # @param [Hash{String=>Object}] body the deserialized response body
38
38
  # @return [Resources::Base] an instance of this class
39
39
  def self.load body
40
40
  new unpack_standard_envelope(body)
@@ -52,7 +52,7 @@ module Animoto
52
52
  # storyboard2 = client.find! Animoto::Resources::Storyboard, "https://api.animoto.com/storyboards/1"
53
53
  # storyboard1.equal?(storyboard2) # => true
54
54
  #
55
- # @param [Hash<String,Object>] attributes a hash of attributes for this resource
55
+ # @param [Hash{String=>Object}] attributes a hash of attributes for this resource
56
56
  # @return [Resources::Base] either a new Resource instance, or an existing one with updated
57
57
  # attributes
58
58
  alias_method :original_new, :new
@@ -79,7 +79,7 @@ module Animoto
79
79
 
80
80
  # Returns (or vivifies) the identity map for this class.
81
81
  #
82
- # @return [Hash<String,Resources::Base>] the identity map
82
+ # @return [Hash{String=>Resources::Base}] the identity map
83
83
  def instances
84
84
  @instances ||= {}
85
85
  end
@@ -89,7 +89,7 @@ module Animoto
89
89
 
90
90
  # Creates a new resource.
91
91
  #
92
- # @param [Hash<String,Object>] attributes hash of attributes for this resource
92
+ # @param [Hash{String=>Object}] attributes hash of attributes for this resource
93
93
  # @see #instantiate
94
94
  # @return [Resources::Base] the resource
95
95
  def initialize attributes = {}
@@ -99,7 +99,7 @@ module Animoto
99
99
  # Update this instance with new attributes from the response body.
100
100
  #
101
101
  # @private
102
- # @param [Hash<String,Object>] body deserialized from a response body
102
+ # @param [Hash{String=>Object}] body deserialized from a response body
103
103
  # @return [self] this instance, updated
104
104
  def load body = {}
105
105
  instantiate unpack_standard_envelope(body)
@@ -110,7 +110,7 @@ module Animoto
110
110
  # of #initialize.
111
111
  #
112
112
  # @private
113
- # @param [Hash<Symbol,Object>] attributes hash of attributes for this resource
113
+ # @param [Hash{Symbol=>Object}] attributes hash of attributes for this resource
114
114
  # @return [self] this instance
115
115
  def instantiate attributes = {}
116
116
  @errors = (attributes[:errors] || []).collect { |e| wrap_error e }
@@ -123,7 +123,7 @@ module Animoto
123
123
 
124
124
  # Turns an error from a response body into a Ruby object.
125
125
  #
126
- # @param [Hash<String,Object>] error the error "object" from a response body
126
+ # @param [Hash{String=>Object}] error the error "object" from a response body
127
127
  # @return [Animoto::Error] a Ruby error object
128
128
  def wrap_error error
129
129
  Animoto::Error.new error['message']
@@ -5,9 +5,9 @@ module Animoto
5
5
  # @abstract
6
6
  class Base < Animoto::Resources::Base
7
7
 
8
- # @return [Hash<Symbol,Object>]
8
+ # @return [Hash{Symbol=>Object}]
9
9
  def self.unpack_standard_envelope body
10
- super.merge(:state => body['response']['payload'][payload_key]['state'])
10
+ super.merge(:state => unpack_payload(body)['state'])
11
11
  end
12
12
 
13
13
  # @return [String]
@@ -5,13 +5,18 @@ module Animoto
5
5
 
6
6
  endpoint '/jobs/directing'
7
7
 
8
- # @return [Hash<Symbol,Object>]
8
+ # @return [Hash{Symbol=>Object}]
9
9
  # @see Animoto::Support::StandardEnvelope::ClassMethods#unpack_standard_envelope
10
10
  def self.unpack_standard_envelope body
11
- super.merge(:storyboard_url => body['response']['payload'][payload_key]['links']['storyboard'])
11
+ super.merge(:storyboard_url => unpack_links(body)['storyboard'])
12
12
  end
13
13
 
14
+ # The Storyboard created by this job.
15
+ # @return [Resources::Storyboard]
14
16
  attr_reader :storyboard
17
+
18
+ # The URL for this storyboard resource created by this job.
19
+ # @return [String]
15
20
  attr_reader :storyboard_url
16
21
 
17
22
  # @return [Jobs::Directing]
@@ -5,20 +5,46 @@ module Animoto
5
5
 
6
6
  endpoint '/jobs/directing_and_rendering'
7
7
 
8
- # @return [Hash<Symbol,Object>]
8
+ # @return [Hash{Symbol=>Object}]
9
9
  # @see Animoto::Support::StandardEnvelope::ClassMethods#unpack_standard_envelope
10
- def self.unpack_standard_envelope body
11
- super.merge(:video_url => body['response']['payload'][payload_key]['links']['video'])
10
+ def self.unpack_standard_envelope body = {}
11
+ links = unpack_links(body)
12
+ super.merge({
13
+ :storyboard_url => links['storyboard'],
14
+ :video_url => links['video']
15
+ })
12
16
  end
13
-
14
- attr_reader :video
17
+
18
+ # The URL for the storyboard created for this job. This storyboard can be
19
+ # used into future rendering jobs to produce different formats, resolutions,
20
+ # etc.
21
+ # @return [String]
22
+ attr_reader :storyboard_url
23
+
24
+ # A Storyboard object for this job.
25
+ # @return [Resources::Storyboard]
26
+ attr_reader :storyboard
27
+
28
+ # The URL for the video created. Note that this is for the video *resource* and not
29
+ # the URL to the actual video *file* (though requesting the resource will give you
30
+ # the URL to the file).
31
+ # @return [String]
15
32
  attr_reader :video_url
16
-
33
+
34
+ # A Video object for this job.
35
+ #
36
+ # @note this object may not have all the most recent attributes, namely the download_url
37
+ # attribute. Use {Client#reload!} to update the object.
38
+ # @return [Resources::Video]
39
+ attr_reader :video
40
+
17
41
  # @return [Jobs::DirectingAndRendering]
18
42
  # @see Animoto::Jobs::Base#instantiate
19
43
  def instantiate attributes = {}
20
- @video_url = attributes[:video_url]
21
- @video = Animoto::Resources::Video.new(:url => @video_url) if @video_url
44
+ @storyboard_url = attributes[:storyboard_url]
45
+ @storyboard = Animoto::Resources::Storyboard.new(:url => @storyboard_url) if @storyboard_url
46
+ @video_url = attributes[:video_url]
47
+ @video = Animoto::Resources::Video.new(:url => @video_url) if @video_url
22
48
  super
23
49
  end
24
50
 
@@ -5,18 +5,32 @@ module Animoto
5
5
 
6
6
  endpoint '/jobs/rendering'
7
7
 
8
- # @return [Hash<Symbol,Object>]
8
+ # @return [Hash{Symbol=>Object}]
9
9
  # @see Animoto::Support::StandardEvelope::ClassMethods#unpack_standard_envelope
10
10
  def self.unpack_standard_envelope body
11
+ links = unpack_links(body)
11
12
  super.merge({
12
- :storyboard_url => body['response']['payload'][payload_key]['links']['storyboard'],
13
- :video_url => body['response']['payload'][payload_key]['links']['video']
13
+ :storyboard_url => links['storyboard'],
14
+ :video_url => links['video']
14
15
  })
15
16
  end
16
17
 
18
+ # The Storyboard this job will render a video from.
19
+ # @return [Resources::Storyboard]
17
20
  attr_reader :storyboard
21
+
22
+ # The URL to the storyboard resource.
23
+ # @return [String]
18
24
  attr_reader :storyboard_url
25
+
26
+ # The Video created by this job.
27
+ # @return [Resources::Video]
19
28
  attr_reader :video
29
+
30
+ # The URL to the video resource.
31
+ #
32
+ # @note This URL points to the video *resource* and not the actual video *file*.
33
+ # @return [String]
20
34
  attr_reader :video_url
21
35
 
22
36
  # @return [Jobs::Rendering]
@@ -2,18 +2,34 @@ module Animoto
2
2
  module Resources
3
3
  class Storyboard < Animoto::Resources::Base
4
4
 
5
- # @return [Hash<Symbol,Object>]
5
+ # @private
6
+ # @return [Hash{String=>Object}]
7
+ # @see Animoto::Support::Support::ClassMethods#unpack_standard_envelope
8
+ def self.unpack_metadata body = {}
9
+ unpack_payload(body)['metadata'] || {}
10
+ end
11
+
12
+ # @return [Hash{Symbol=>Object}]
6
13
  # @see Animoto::Support::StandardEnvelope::ClassMethods#unpack_standard_envelope
7
14
  def self.unpack_standard_envelope body = {}
15
+ metadata = unpack_metadata(body)
8
16
  super.merge({
9
- :duration => body['response']['payload'][payload_key]['metadata']['duration'],
10
- :visuals_count => body['response']['payload'][payload_key]['metadata']['visuals_count'],
11
- :preview_url => body['response']['payload'][payload_key]['links']['preview']
17
+ :duration => metadata['duration'],
18
+ :visuals_count => metadata['visuals_count'],
19
+ :preview_url => unpack_links(body)['preview']
12
20
  })
13
21
  end
14
22
 
23
+ # The duration (in seconds) that the video, once rendered, will be.
24
+ # @return [Float]
15
25
  attr_reader :duration
26
+
27
+ # The number of visuals (title cards, images, etc.) in this storyboard.
28
+ # @return [Integer]
16
29
  attr_reader :visuals_count
30
+
31
+ # If available, the URL to the low-resolution 'preview' video.
32
+ # @return [String]
17
33
  attr_reader :preview_url
18
34
 
19
35
  # Sets the attributes for a new storyboard.
@@ -1,34 +1,57 @@
1
1
  module Animoto
2
2
  module Resources
3
3
  class Video < Animoto::Resources::Base
4
+
5
+ # @private
6
+ # @return [Hash{String=>Object}]
7
+ # @see Animoto::Support::StandardEnvelope::ClassMethods#unpack_standard_envelope
8
+ def self.unpack_rendering_parameters body
9
+ (unpack_payload(body)['metadata'] || {})['rendering_parameters']
10
+ end
4
11
 
5
- # @return [Hash<Symbol,Object>]
12
+ # @return [Hash{Symbol=>Object}]
6
13
  # @see Animoto::Support::StandardEnvelope::ClassMethods#unpack_standard_envelope
7
14
  def self.unpack_standard_envelope body
15
+ links = unpack_links(body)
16
+ params = unpack_rendering_parameters(body)
8
17
  super.merge({
9
- :download_url => body['response']['payload'][payload_key]['links']['file'],
10
- :storyboard_url => body['response']['payload'][payload_key]['links']['storyboard'],
11
- :duration => body['response']['payload'][payload_key]['metadata']['duration'],
12
- :format => body['response']['payload'][payload_key]['metadata']['format'],
13
- :framerate => body['response']['payload'][payload_key]['metadata']['framerate'],
14
- :resolution => body['response']['payload'][payload_key]['metadata']['vertical_resolution']
18
+ :download_url => links['file'],
19
+ :storyboard_url => links['storyboard'],
20
+ :format => params['format'],
21
+ :framerate => params['framerate'],
22
+ :resolution => params['resolution']
15
23
  })
16
24
  end
17
25
 
26
+ # The URL to the video file.
27
+ # @return [String]
18
28
  attr_reader :download_url
29
+
30
+ # The URL to the storyboard resource this video was rendered from.
31
+ # @return [String]
19
32
  attr_reader :storyboard_url
33
+
34
+ # The Storyboard object this video was rendered from.
35
+ # @return [Resources::Storyboard]
20
36
  attr_reader :storyboard
21
- attr_reader :duration
37
+
38
+ # The format of the video.
39
+ # @return [String]
22
40
  attr_reader :format
41
+
42
+ # The framerate of the video.
43
+ # @return [Integer]
23
44
  attr_reader :framerate
45
+
46
+ # The resolution of the video.
47
+ # @return [String]
24
48
  attr_reader :resolution
25
49
 
26
50
  # Sets the attributes on a new video.
27
51
  #
28
- # @param [Hash<Symbol,Object>] attributes
52
+ # @param [Hash{Symbol=>Object}] attributes
29
53
  # @option attributes [String] :download_url the URL where this video can be downloaded
30
54
  # @option attributes [String] :storyboard_url the URL for this video's storyboard
31
- # @option attributes [Integer] :duration the duration (in seconds) of this video
32
55
  # @option attributes [String] :format the format of this video
33
56
  # @option attributes [Integer] :framerate the framerate of this video
34
57
  # @option attributes [String] :resolution the vertical resolution of this video
@@ -38,7 +61,6 @@ module Animoto
38
61
  @download_url = attributes[:download_url]
39
62
  @storyboard_url = attributes[:storyboard_url]
40
63
  @storyboard = Animoto::Resources::Storyboard.new(:url => @storyboard_url) if @storyboard_url
41
- @duration = attributes[:duration]
42
64
  @format = attributes[:format]
43
65
  @framerate = attributes[:framerate]
44
66
  @resolution = attributes[:resolution]
@@ -1,8 +1,13 @@
1
1
  module Animoto
2
2
  module ResponseParsers
3
- extend Support::DynamicClassLoader(File.expand_path(File.dirname(__FILE__)))
3
+ extend Support::DynamicClassLoader
4
4
 
5
- # @abstract Override {#parse} and {#unparse} to subclass.
5
+ dynamic_class_path File.expand_path(File.dirname(__FILE__))
6
+
7
+ adapter 'JSON'
8
+ adapter 'Yajl'
9
+
10
+ # @abstract Override {#parse}, {#unparse}, and {#format} (or set @format on the class) to subclass.
6
11
  class Base
7
12
 
8
13
  # Returns the format of this parser class.
@@ -23,20 +28,20 @@ module Animoto
23
28
  #
24
29
  # @abstract
25
30
  # @param [String] body the HTTP response body
26
- # @return [Hash<String,Object>] the parsed response
27
- # @raise [NotImplementedError] if called on the abstract class
31
+ # @return [Hash{String=>Object}] the parsed response
32
+ # @raise [AbstractMethodError] if called on the abstract class
28
33
  def parse body
29
- raise NotImplementedError
34
+ raise AbstractMethodError
30
35
  end
31
36
 
32
37
  # Serializes a Hash into the format for this parser.
33
38
  #
34
39
  # @abstract
35
- # @param [Hash<Object,Object>] hash the hash to serialize
40
+ # @param [Hash{Object=>Object}] hash the hash to serialize
36
41
  # @return [String] the serialized data
37
- # @raise [NotImplementedError] if called on the abstract class
42
+ # @raise [AbstractMethodError] if called on the abstract class
38
43
  def unparse hash
39
- raise NotImplementedError
44
+ raise AbstractMethodError
40
45
  end
41
46
 
42
47
  end
@@ -6,7 +6,7 @@ module Animoto
6
6
 
7
7
  @format = 'json'
8
8
 
9
- # @return [Hash<String,Object>]
9
+ # @return [Hash{String=>Object}]
10
10
  def parse string
11
11
  ::JSON.parse string
12
12
  end
@@ -15,8 +15,6 @@ module Animoto
15
15
  def unparse object
16
16
  ::JSON.unparse object
17
17
  end
18
- end
19
-
20
- adapter_map.merge! :json => JSONAdapter
18
+ end
21
19
  end
22
20
  end
@@ -6,7 +6,7 @@ module Animoto
6
6
 
7
7
  @format = 'json'
8
8
 
9
- # @return [Hash<String,Object>]
9
+ # @return [Hash{String=>Object}]
10
10
  def parse string
11
11
  ::Yajl::Parser.parse string
12
12
  end
@@ -15,8 +15,6 @@ module Animoto
15
15
  def unparse object
16
16
  ::Yajl::Encoder.encode object
17
17
  end
18
- end
19
-
20
- adapter_map.merge! :yajl => YajlAdapter
18
+ end
21
19
  end
22
20
  end
@@ -4,6 +4,7 @@ module Animoto
4
4
 
5
5
  # When included, includes the InstanceMethods module and extends the
6
6
  # ClassMethods module.
7
+ # @return [void]
7
8
  def self.included base
8
9
  base.class_eval {
9
10
  include Animoto::Support::ContentType::InstanceMethods