Sha256: 0e56de6a41f635cefabcaf5a47eefaaed6cfc541191424b9a8d404b5a17bab2c

Contents?: true

Size: 1.25 KB

Versions: 6

Compression:

Stored size: 1.25 KB

Contents

module Animoto
  class HTTPEngine
    extend DynamicClassLoader
    
    # Make a request.
    #
    # @param [Symbol] method the HTTP method to use, should be lower-case (that is, :get
    #   instead of :GET)
    # @param [String] url the URL to request
    # @param [String,nil] body the request body
    # @param [Hash<String,String>] headers request headers to send; names will be sent as-is
    #   (for example, use keys like "Content-Type" and not :content_type)
    # @param [Hash<Symbol,Object>] options
    #   @option options :timeout set a timeout
    #   @option options :username the authentication username
    #   @option options :password the authentication password
    # @return [String] the response body
    # @raise [NotImplementedError] if called on the abstract class
    def request method, url, body = nil, headers = {}, options = {}
      raise NotImplementedError
    end
    
    private
    
    # Checks the response and raises an error if the status isn't success.
    #
    # @param [Fixnum] code the HTTP status code
    # @param [String] body the HTTP response body
    # @raise [Animoto::Error] if the status isn't between 200 and 299
    def check_response code, body
      throw(:fail, body) unless (200..299).include?(code)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
animoto-0.0.0.alpha9 ./lib/animoto/http_engine.rb
animoto-0.0.0.alpha8 ./lib/animoto/http_engine.rb
animoto-0.0.0.alpha7 ./lib/animoto/http_engine.rb
animoto-0.0.0.alpha6 ./lib/animoto/http_engine.rb
animoto-0.0.0.alpha5 ./lib/animoto/http_engine.rb
animoto-0.0.0.alpha4 ./lib/animoto/http_engine.rb