Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 8a70a8ef40531def06c950bfb4902abc774b5b31 1 parent c0ad5de
@jnunemaker authored
View
2  Rakefile
@@ -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
View
80 lib/core_extensions.rb
@@ -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
4 lib/httparty.rb
@@ -5,8 +5,8 @@
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 @@ def self.included(base)
base.instance_variable_set("@default_options", {})
end
- module ClassMethods
+ module ClassMethods
def default_options
@default_options
end
View
5 lib/httparty/request.rb
@@ -5,8 +5,11 @@ class Request
# 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
2  spec/httparty/request_spec.rb
@@ -84,7 +84,7 @@ def setup_redirect
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
6 spec/spec_helper.rb
@@ -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")
Please sign in to comment.
Something went wrong with that request. Please try again.