./lib/animoto/client.rb in animoto-0.1.1.beta1 vs ./lib/animoto/client.rb in animoto-1.0.0

- old
+ new

@@ -4,11 +4,13 @@ require 'animoto/support/content_type' require 'animoto/support/coverable' require 'animoto/support/dynamic_class_loader' require 'animoto/support/errors' +require 'animoto/support/hash' require 'animoto/support/standard_envelope' +require 'animoto/support/string' require 'animoto/support/visual' require 'animoto/resources/base' require 'animoto/resources/storyboard' require 'animoto/resources/video' @@ -26,22 +28,23 @@ require 'animoto/manifests/base' require 'animoto/manifests/directing' require 'animoto/manifests/directing_and_rendering' require 'animoto/manifests/rendering' -require 'animoto/callbacks/base' -require 'animoto/callbacks/directing' -require 'animoto/callbacks/directing_and_rendering' -require 'animoto/callbacks/rendering' - require 'animoto/http_engines/base' require 'animoto/response_parsers/base' module Animoto class Client + + # The default endpoint where requests go. API_ENDPOINT = "https://api2-sandbox.animoto.com/" + + # The version of the Animoto API this client targets. API_VERSION = 1 + + # The common prefix all vendor-specific Animoto content types share. BASE_CONTENT_TYPE = "application/vnd.animoto" # Your API key. # @return [String] attr_accessor :key @@ -147,57 +150,48 @@ # Finds a resource by its URL. # # @param [Class] klass the resource class you're finding # @param [String] url the URL of the resource you want - # @param [Hash<Symbol,Object>] options + # @param [Hash{Symbol=>Object}] options # @return [Resources::Base] the resource object found def find klass, url, options = {} klass.load(find_request(klass, url, options)) end - - # Returns a callback object of the specified type given the callback body. - # - # @param [Class] klass the callback class - # @param [String] body the HTTP body of the callback - # @return [Callbacks::Base] the callback object - def process_callback klass, body - klass.new(response_parser.parse(body)) - end - + # Sends a request to start directing a storyboard. # # @param [Manifests::Directing] manifest the manifest to direct - # @param [Hash<Symbol,Object>] options + # @param [Hash{Symbol=>Object}] options # @return [Jobs::Directing] a job to monitor the status of the directing def direct! manifest, options = {} Resources::Jobs::Directing.load(send_manifest(manifest, Resources::Jobs::Directing.endpoint, options)) end # Sends a request to start rendering a video. # # @param [Manifests::Rendering] manifest the manifest to render - # @param [Hash<Symbol,Object>] options + # @param [Hash{Symbol=>Object}] options # @return [Jobs::Rendering] a job to monitor the status of the rendering def render! manifest, options = {} Resources::Jobs::Rendering.load(send_manifest(manifest, Resources::Jobs::Rendering.endpoint, options)) end # Sends a request to start directing and rendering a video. # # @param [Manifests::DirectingAndRendering] manifest the manifest to direct and render - # @param [Hash<Symbol,Object>] options + # @param [Hash{Symbol=>Object}] options # @return [Jobs::DirectingAndRendering] a job to monitor the status of the directing and rendering def direct_and_render! manifest, options = {} Resources::Jobs::DirectingAndRendering.load(send_manifest(manifest, Resources::Jobs::DirectingAndRendering.endpoint, options)) end # Update a resource with the latest attributes. Useful to update the state of a Job to # see if it's ready if you are not using HTTP callbacks. # # @param [Resources::Base] resource the resource to update - # @param [Hash<Symbol,Object>] options + # @param [Hash{Symbol=>Object}] options # @return [Resources::Base] the given resource with the latest attributes def reload! resource, options = {} resource.load(find_request(resource.class, resource.url, options)) end @@ -229,22 +223,22 @@ # Builds a request to find a resource. # # @param [Class] klass the Resource class you're looking for # @param [String] url the URL of the resource - # @param [Hash<Symbol,Object>] options - # @return [Hash<String,Object>] deserialized response body + # @param [Hash{Symbol=>Object}] options + # @return [Hash{String=>Object}] deserialized response body def find_request klass, url, options = {} request(:get, url, nil, { "Accept" => content_type_of(klass) }, options) end # Builds a request requiring a manifest. # # @param [Manifests::Base] manifest the manifest being acted on # @param [String] endpoint the endpoint to send the request to - # @param [Hash<Symbol,Object>] options - # @return [Hash<String,Object>] deserialized response body + # @param [Hash{Symbol=>Object}] options + # @return [Hash{String=>Object}] deserialized response body def send_manifest manifest, endpoint, options = {} u = URI.parse(self.endpoint) u.path = endpoint request( :post, @@ -258,13 +252,13 @@ # Makes a request and parses the response. # # @param [Symbol] method which HTTP method to use (should be lowercase, i.e. :get instead of :GET) # @param [String] url the URL of the request # @param [String,nil] body the request body - # @param [Hash<String,String>] headers the request headers (will be sent as-is, which means you should + # @param [Hash{String=>String}] headers the request headers (will be sent as-is, which means you should # specify "Content-Type" => "..." instead of, say, :content_type => "...") - # @param [Hash<Symbol,Object>] options - # @return [Hash<String,Object>] deserialized response body + # @param [Hash{Symbol=>Object}] options + # @return [Hash{String=>Object}] deserialized response body # @raise [Error] def request method, url, body, headers = {}, options = {} code, body = catch(:fail) do options = { :username => @key, :password => @secret }.merge(options) @logger.info "Sending request to #{url.inspect} with body #{body}" \ No newline at end of file