Sha256: 684b083f775fea777b0956032a41867a35c4f8f218480ae34029fb8dbb06e46d

Contents?: true

Size: 1.71 KB

Versions: 12

Compression:

Stored size: 1.71 KB

Contents

module Animoto
  module Resources
    module Jobs

      # @abstract
      class Base < Animoto::Resources::Base
        
        # @return [Hash{Symbol=>Object}]
        def self.unpack_standard_envelope body
          super.merge(:state => unpack_payload(body)['state'])
        end
        
        # @return [String]
        def self.infer_content_type
          super + '_job'
        end
        
        def self.endpoint path = nil
          super || infer_endpoint
        end
        
        def self.infer_endpoint
          "/jobs/#{name.split('::').last.underscore}"
        end
        
        # The URL for this job.
        # @return [String]
        attr_reader :url
        
        # The state of this job.
        # @return [String]
        attr_reader :state
        
        # Errors associated with this job.
        # @return [Array<Animoto::Error>]
        attr_reader :errors
    
        # Returns true if the state of this job is 'failed'.
        #
        # @return [Boolean] whether or not the job has failed.
        def failed?
          @state == 'failed'
        end
    
        # Returns true if the state of this job is 'completed'.
        #
        # @return [Boolean] whether or not the job is completed
        def completed?
          @state == 'completed'
        end
    
        # Returns true if the job is neither failed or completed.
        #
        # @return [Boolean] whether or not the job is still pending
        def pending?
          !failed? && !completed?
        end

        # @return [Jobs::Base]
        # @see Animoto::Resources::Base#instantiate
        def instantiate attributes = {}
          @state  = attributes[:state]
          super
        end
    
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
animoto-1.5.6 ./lib/animoto/resources/jobs/base.rb
animoto-1.5.5 ./lib/animoto/resources/jobs/base.rb
animoto-1.5.4 ./lib/animoto/resources/jobs/base.rb
animoto-1.5.3 ./lib/animoto/resources/jobs/base.rb
animoto-1.5.2 ./lib/animoto/resources/jobs/base.rb
animoto-1.5.1 ./lib/animoto/resources/jobs/base.rb
animoto-1.5.0 ./lib/animoto/resources/jobs/base.rb
animoto-1.3.1 ./lib/animoto/resources/jobs/base.rb
animoto-1.3.0 ./lib/animoto/resources/jobs/base.rb
animoto-1.2.0 ./lib/animoto/resources/jobs/base.rb
animoto-1.1.1 ./lib/animoto/resources/jobs/base.rb
animoto-1.1.0 ./lib/animoto/resources/jobs/base.rb