Sha256: 55c59eeb11a46910a2d3e01e745fd8279811a8610f71e2f08586621daa501cc1

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

require 'net/http' 
require 'hpricot'

module Jkl
  class << self
    
    def post_to(url, post_args = {})
      begin
        uri = URI.parse(url)
        resp, data = Net::HTTP.post_form(uri, post_args)
        data
      rescue  URI::InvalidURIError => e
        puts("WARN: JKL Invalid URI: #{e}")
      rescue SocketError => e
        puts("WARN: JKL Could not connect: #{e}")
      rescue Errno::ECONNREFUSED  => e
        puts("WARN: JKL Connection refused: #{e}")
      end
    end
  
    def get_from(uri)
      begin
        response = Net::HTTP.get_response(URI.parse(uri))
        response.body
      rescue  URI::InvalidURIError => e
        puts("WARN: JKL Invalid URI: #{e}")
      rescue SocketError => e
        puts("WARN: JKL Could not connect: #{e}")
      rescue Errno::ECONNREFUSED  => e
        puts("WARN: JKL Connection refused: #{e}")
      end
    end
    
    def get_from_over_https(host, path)
      http = Net::HTTP.new(host, "443")
      http.use_ssl = true
      http.get2(path) # returns [status, data]
    end
  
    def get_xml_from(uri)
      Hpricot.XML(get_from(uri))
    end
    
    def document_from(text)
      Hpricot(text)
    end
  
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jakal-0.1.96 lib/jkl/rest_client.rb