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

Removed active support. Added json. Added some core extensions.

This commit is contained in:
John Nunemaker 2008-12-06 22:47:01 -05:00
parent c0ad5dece3
commit 8a70a8ef40
6 changed files with 91 additions and 8 deletions

View file

@ -13,7 +13,7 @@ Echoe.new(ProjectName, HTTParty::Version) do |p|
p.url = "http://#{ProjectName}.rubyforge.org"
p.author = "John Nunemaker"
p.email = "nunemaker@gmail.com"
p.extra_deps = [['activesupport', '>= 2.1']]
p.extra_deps = [['json', '~> 1.1']]
p.need_tar_gz = false
p.docs_host = WebsitePath
end

80
lib/core_extensions.rb Normal file
View file

@ -0,0 +1,80 @@
# Copyright (c) 2008 Sam Smoot.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class Object
# @return <TrueClass, FalseClass>
#
# @example [].blank? #=> true
# @example [1].blank? #=> false
# @example [nil].blank? #=> false
#
# Returns true if the object is nil or empty (if applicable)
def blank?
nil? || (respond_to?(:empty?) && empty?)
end
end # class Object
class Numeric
# @return <TrueClass, FalseClass>
#
# Numerics can't be blank
def blank?
false
end
end # class Numeric
class NilClass
# @return <TrueClass, FalseClass>
#
# Nils are always blank
def blank?
true
end
end # class NilClass
class TrueClass
# @return <TrueClass, FalseClass>
#
# True is not blank.
def blank?
false
end
end # class TrueClass
class FalseClass
# False is always blank.
def blank?
true
end
end # class FalseClass
class String
# @example "".blank? #=> true
# @example " ".blank? #=> true
# @example " hey ho ".blank? #=> false
#
# @return <TrueClass, FalseClass>
#
# Strips out whitespace then tests if the string is empty.
def blank?
strip.empty?
end
end # class String

View file

@ -5,8 +5,8 @@ require 'net/https'
require 'rubygems'
gem 'json', '>= 1.1.3'
require 'json'
require 'active_support'
require 'module_level_inheritable_attributes'
require 'core_extensions'
module HTTParty
AllowedFormats = {:xml => 'text/xml', :json => 'application/json', :html => 'text/html'}
@ -18,7 +18,7 @@ module HTTParty
base.instance_variable_set("@default_options", {})
end
module ClassMethods
module ClassMethods
def default_options
@default_options
end

View file

@ -5,8 +5,11 @@ module HTTParty
# Makes it so uri is sure to parse stuff like google.com without the http
def self.normalize_base_uri(url) #:nodoc:
use_ssl = (url =~ /^https/) || url.include?(':443')
url.chop! if url.ends_with?('/')
ends_with_slash = url =~ /\/$/
url.chop! if ends_with_slash
url.gsub!(/^https?:\/\//i, '')
"http#{'s' if use_ssl}://#{url}"
end

View file

@ -84,7 +84,7 @@ describe HTTParty::Request do
def setup_ok_response
@ok = Net::HTTPOK.new("1.1", 200, "Content for you")
@ok.stub!(:body).and_return({"foo" => "bar"}.to_xml)
@ok.stub!(:body).and_return('<hash><foo>bar</foo></hash>')
@http.should_receive(:request).and_return(@redirect, @ok)
@request.options[:format] = :xml
end

View file

@ -7,9 +7,9 @@ def file_fixture(filename)
open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename.to_s}")).read
end
def stub_http_response_with(fixture_name)
format = fixture_name.split('.').last.intern
data = file_fixture(fixture_name)
def stub_http_response_with(filename)
format = filename.split('.').last.intern
data = file_fixture(filename)
http = Net::HTTP.new('localhost', 80)
response = Net::HTTPOK.new("1.1", 200, "Content for you")