lib/httparty.rb in alexvollmer-httparty-0.3.1 vs lib/httparty.rb in alexvollmer-httparty-0.4.3
- old
+ new
@@ -1,11 +1,13 @@
$:.unshift(File.dirname(__FILE__))
require 'net/http'
require 'net/https'
-require 'core_extensions'
require 'httparty/module_inheritable_attributes'
+require 'rubygems'
+gem 'crack'
+require 'crack'
module HTTParty
AllowedFormats = {
'text/xml' => :xml,
@@ -14,11 +16,12 @@
'text/json' => :json,
'application/javascript' => :json,
'text/javascript' => :json,
'text/html' => :html,
'application/x-yaml' => :yaml,
- 'text/yaml' => :yaml
+ 'text/yaml' => :yaml,
+ 'text/plain' => :plain
} unless defined?(AllowedFormats)
def self.included(base)
base.extend ClassMethods
base.send :include, HTTParty::ModuleInheritableAttributes
@@ -97,11 +100,11 @@
# class Foo
# include HTTParty
# format :json
# end
def format(f)
- raise UnsupportedFormat, "Must be one of: #{AllowedFormats.values.join(', ')}" unless AllowedFormats.value?(f)
+ raise UnsupportedFormat, "Must be one of: #{AllowedFormats.values.uniq.join(', ')}" unless AllowedFormats.value?(f)
default_options[:format] = f
end
# Allows making a get request to a url.
#
@@ -162,17 +165,18 @@
options.delete(:cookies)
end
end
def self.normalize_base_uri(url) #:nodoc:
- use_ssl = (url =~ /^https/) || url.include?(':443')
- ends_with_slash = url =~ /\/$/
+ normalized_url = url.dup
+ use_ssl = (normalized_url =~ /^https/) || normalized_url.include?(':443')
+ ends_with_slash = normalized_url =~ /\/$/
- url.chop! if ends_with_slash
- url.gsub!(/^https?:\/\//i, '')
+ normalized_url.chop! if ends_with_slash
+ normalized_url.gsub!(/^https?:\/\//i, '')
- "http#{'s' if use_ssl}://#{url}"
+ "http#{'s' if use_ssl}://#{normalized_url}"
end
class Basement #:nodoc:
include HTTParty
end
@@ -193,9 +197,9 @@
Basement.delete(*args)
end
end
require 'httparty/cookie_hash'
+require 'httparty/core_extensions'
require 'httparty/exceptions'
require 'httparty/request'
require 'httparty/response'
-require 'httparty/parsers'