Sha256: b0735089c6203c9d7912727c172cf45d6ae527a240bc379f9151eaf2c35f9fb6

Contents?: true

Size: 817 Bytes

Versions: 4

Compression:

Stored size: 817 Bytes

Contents

require 'net/http' 
require 'hpricot'

module Jkl
  
  def post_to(uri, post_args)
    begin
      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
      res = Net::HTTP.get_response(URI.parse(uri))
      res.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_from_as_xml(uri)
    Hpricot.XML get_from uri
  end
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sshingler-jkl-0.0.2 lib/rest_client.rb
sshingler-jkl-0.0.4 lib/jkl/rest_client.rb
sshingler-jkl-0.0.5 lib/jkl/rest_client.rb
sshingler-jkl-0.0.6 lib/jkl/rest_client.rb