jnunemaker-httparty 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +1 -0
- data/examples/rubyurl.rb +14 -0
- data/httparty.gemspec +3 -3
- data/lib/httparty/request.rb +7 -1
- data/lib/httparty/version.rb +1 -1
- data/spec/httparty/request_spec.rb +8 -0
- metadata +3 -2
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/examples/rubyurl.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
require File.join(dir, 'httparty')
|
3
|
+
|
4
|
+
class Rubyurl
|
5
|
+
include HTTParty
|
6
|
+
base_uri 'rubyurl.com'
|
7
|
+
|
8
|
+
def self.shorten(website_url)
|
9
|
+
xml = post('/api/links.json', :query => {'link[website_url]' => website_url})
|
10
|
+
xml['link'] && xml['link']['permalink']
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
puts Rubyurl.shorten( 'http://istwitterdown.com/' ).inspect
|
data/httparty.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{httparty}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.6"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["John Nunemaker"]
|
9
|
-
s.date = %q{2008-11-
|
9
|
+
s.date = %q{2008-11-26}
|
10
10
|
s.description = %q{Makes http fun! Also, makes consuming restful web services dead easy.}
|
11
11
|
s.email = ["nunemaker@gmail.com"]
|
12
12
|
s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.txt"]
|
13
|
-
s.files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.txt", "Rakefile", "config/hoe.rb", "config/requirements.rb", "examples/aaws.rb", "examples/delicious.rb", "examples/google.rb", "examples/twitter.rb", "examples/whoismyrep.rb", "httparty.gemspec", "lib/httparty.rb", "lib/httparty/request.rb", "lib/httparty/version.rb", "script/console", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "spec/httparty/request_spec.rb", "spec/httparty_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/deployment.rake", "tasks/environment.rake", "tasks/website.rake", "website/css/common.css", "website/index.html"]
|
13
|
+
s.files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.txt", "Rakefile", "config/hoe.rb", "config/requirements.rb", "examples/aaws.rb", "examples/delicious.rb", "examples/google.rb", "examples/rubyurl.rb", "examples/twitter.rb", "examples/whoismyrep.rb", "httparty.gemspec", "lib/httparty.rb", "lib/httparty/request.rb", "lib/httparty/version.rb", "script/console", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "spec/httparty/request_spec.rb", "spec/httparty_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/deployment.rake", "tasks/environment.rake", "tasks/website.rake", "website/css/common.css", "website/index.html"]
|
14
14
|
s.has_rdoc = true
|
15
15
|
s.homepage = %q{http://httparty.rubyforge.org}
|
16
16
|
s.post_install_message = %q{When you HTTParty, you must party hard!}
|
data/lib/httparty/request.rb
CHANGED
@@ -37,7 +37,8 @@ module HTTParty
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def get_response(uri) #:nodoc:
|
40
|
-
request = http_method.new(uri.request_uri)
|
40
|
+
request = http_method.new(uri.request_uri)
|
41
|
+
request.set_form_data(options[:query]) if post? && options[:query]
|
41
42
|
request.body = options[:body].is_a?(Hash) ? options[:body].to_query : options[:body] unless options[:body].blank?
|
42
43
|
request.initialize_http_header options[:headers]
|
43
44
|
request.basic_auth(options[:basic_auth][:username], options[:basic_auth][:password]) if options[:basic_auth]
|
@@ -99,6 +100,11 @@ module HTTParty
|
|
99
100
|
raise ArgumentError, 'only get, post, put and delete methods are supported' unless SupportedHTTPMethods.include?(http_method)
|
100
101
|
raise ArgumentError, ':headers must be a hash' if options[:headers] && !options[:headers].is_a?(Hash)
|
101
102
|
raise ArgumentError, ':basic_auth must be a hash' if options[:basic_auth] && !options[:basic_auth].is_a?(Hash)
|
103
|
+
raise ArgumentError, ':query must be hash if using HTTP Post' if post? && !options[:query].nil? && !options[:query].is_a?(Hash)
|
104
|
+
end
|
105
|
+
|
106
|
+
def post?
|
107
|
+
Net::HTTP::Post == http_method
|
102
108
|
end
|
103
109
|
end
|
104
110
|
end
|
data/lib/httparty/version.rb
CHANGED
@@ -105,3 +105,11 @@ describe HTTParty::Request do
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
end
|
108
|
+
|
109
|
+
describe HTTParty::Request, "with POST http method" do
|
110
|
+
it "should raise argument error if query is not a hash" do
|
111
|
+
lambda {
|
112
|
+
HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', :format => :xml, :query => 'astring').perform
|
113
|
+
}.should raise_error(ArgumentError)
|
114
|
+
end
|
115
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jnunemaker-httparty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-11-
|
12
|
+
date: 2008-11-26 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- examples/aaws.rb
|
56
56
|
- examples/delicious.rb
|
57
57
|
- examples/google.rb
|
58
|
+
- examples/rubyurl.rb
|
58
59
|
- examples/twitter.rb
|
59
60
|
- examples/whoismyrep.rb
|
60
61
|
- httparty.gemspec
|