1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00
httparty/lib/web.rb

41 lines
980 B
Ruby
Raw Normal View History

2008-07-27 11:52:18 -04:00
require 'net/http'
require 'net/https'
require 'uri'
require 'rubygems'
require 'active_support'
$:.unshift(File.dirname(__FILE__)) unless
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
module Web
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def base_uri(base_uri=nil)
if base_uri
@base_uri = URI.parse(ensure_http(base_uri))
else
@base_uri
end
end
def http
if @http.blank?
@http = Net::HTTP.new(base_uri.host, base_uri.port)
@http.use_ssl = (base_uri.port == 443)
end
@http
end
private
# Makes it so uri is sure to parse stuff like google.com with the http
def ensure_http(str)
str =~ /^https?:\/\// ? str : "http#{'s' if str.include?(':443')}://#{str}"
end
end
end
dir = File.expand_path(File.join(File.dirname(__FILE__), 'web'))
2008-07-27 11:52:39 -04:00
require dir + '/callbacks'