Sha256: d70aa4e581ee11bc7a61db1d275cfeb2450a7fba78c94fdd3758a093382075ad

Contents?: true

Size: 1000 Bytes

Versions: 7

Compression:

Stored size: 1000 Bytes

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: Invalid URI: #{e}")
      rescue SocketError => e
        puts("WARN: Could not connect: #{e}")
      rescue Errno::ECONNREFUSED  => e
        puts("WARN: 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: Invalid URI: #{e}")
      rescue SocketError => e
        puts("WARN: Could not connect: #{e}")
      rescue Errno::ECONNREFUSED  => e
        puts("WARN: Connection refused: #{e}")
      end
    end
  
    def get_xml_from(uri)
      Hpricot.XML(get_from(uri))
    end
    
    def document_from(text)
      Hpricot(text)
    end
  
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
jakal-0.1.95 lib/jkl/rest_client.rb
jakal-0.1.94 lib/jkl/rest_client.rb
jakal-0.1.93 lib/jkl/rest_client.rb
jakal-0.1.92 lib/jkl/rest_client.rb
jakal-0.1.91 lib/jkl/rest_client.rb
jakal-0.1.9 lib/jkl/rest_client.rb
jakal-0.1.8 lib/jkl/rest_client.rb