require 'httparty'

module Apical

  class HttpAdapter < Adapter
    identifier :http
    include HTTParty

    def initialize(options={})
      self.class.base_uri options[:base_uri]
      @headers = {}
    end

    def header(name, value)
      @headers[name] = value
    end

    def clear_headers!
      @headers = {}
    end

    def method_missing(name, *args)
      self.class.headers(@headers) unless @headers.empty?
      response = self.class.send(name, *args)
      clear_headers!
      return response
    end
  end
  
end
