Sha256: bcddc27bd7dc4dcefa1e6843348ae5704eb6545ab3a03ed4d0c74c23e157d30d

Contents?: true

Size: 903 Bytes

Versions: 3

Compression:

Stored size: 903 Bytes

Contents

require 'patron'

module Animoto
  module HTTPEngines
    class PatronAdapter < Animoto::HTTPEngines::Base
      
      # @return [String]
      def request method, url, body = nil, headers = {}, options = {}
        session = build_session options
        response = session.request method, url, headers, :data => body
        check_response response.status, response.body
        response.body
      end
      
      private
      
      # Builds the Session object.
      #
      # @param [Hash<Symbol,Object>] options options for the Session
      # @return [Patron::Session] the Session object
      def build_session options
        session = ::Patron::Session.new
        session.timeout = options[:timeout]
        session.username = options[:username]
        session.password = options[:password]
        session
      end
    end
    
    adapter_map.merge! :patron => PatronAdapter
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
animoto-0.1.1.beta1 ./lib/animoto/http_engines/patron_adapter.rb
animoto-0.1.0.beta1 ./lib/animoto/http_engines/patron_adapter.rb
animoto-0.1.0.beta0 ./lib/animoto/http_engines/patron_adapter.rb