jnunemaker-httparty 0.4.3 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History +7 -1
- data/Manifest +1 -4
- data/README.rdoc +54 -0
- data/httparty.gemspec +5 -5
- data/lib/httparty/core_extensions.rb +6 -2
- data/lib/httparty/request.rb +16 -14
- data/lib/httparty/version.rb +1 -1
- data/lib/httparty.rb +8 -7
- data/spec/httparty/cookie_hash_spec.rb +1 -1
- data/spec/httparty/request_spec.rb +7 -4
- data/spec/httparty/response_spec.rb +1 -1
- data/spec/httparty_spec.rb +9 -2
- data/spec/spec_helper.rb +1 -1
- metadata +5 -8
- data/README +0 -36
- data/setup.rb +0 -1585
- data/spec/hash_spec.rb +0 -49
- data/spec/string_spec.rb +0 -27
data/History
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
== 0.4.
|
1
|
+
== 0.4.4 2009-07-19
|
2
|
+
* 2 minor update
|
3
|
+
* :query no longer sets form data. Use body and set content type to application/x-www-form-urlencoded if you need it. :query was wrong for that.
|
4
|
+
* Fixed a bug in the cookies class method that caused cookies to be forgotten after the first request.
|
5
|
+
* Also, some general cleanup of tests and such.
|
6
|
+
|
7
|
+
== 0.4.3 2009-04-23
|
2
8
|
* 1 minor update
|
3
9
|
* added message to the response object
|
4
10
|
|
data/Manifest
CHANGED
@@ -30,21 +30,18 @@ lib/httparty.rb
|
|
30
30
|
Manifest
|
31
31
|
MIT-LICENSE
|
32
32
|
Rakefile
|
33
|
-
README
|
34
|
-
setup.rb
|
33
|
+
README.rdoc
|
35
34
|
spec/fixtures/delicious.xml
|
36
35
|
spec/fixtures/empty.xml
|
37
36
|
spec/fixtures/google.html
|
38
37
|
spec/fixtures/twitter.json
|
39
38
|
spec/fixtures/twitter.xml
|
40
39
|
spec/fixtures/undefined_method_add_node_for_nil.xml
|
41
|
-
spec/hash_spec.rb
|
42
40
|
spec/httparty/cookie_hash_spec.rb
|
43
41
|
spec/httparty/request_spec.rb
|
44
42
|
spec/httparty/response_spec.rb
|
45
43
|
spec/httparty_spec.rb
|
46
44
|
spec/spec.opts
|
47
45
|
spec/spec_helper.rb
|
48
|
-
spec/string_spec.rb
|
49
46
|
website/css/common.css
|
50
47
|
website/index.html
|
data/README.rdoc
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
= httparty
|
2
|
+
|
3
|
+
Makes http fun again!
|
4
|
+
|
5
|
+
== Note on Releases
|
6
|
+
|
7
|
+
Releases are tagged on github and also released as gems on github and rubyforge. Master is pushed to whenever I add a patch or a new feature. To build from master, you can clone the code, generate the updated gemspec, build the gem and install.
|
8
|
+
|
9
|
+
* rake build_gemspec
|
10
|
+
* gem build httparty.gemspec
|
11
|
+
* gem install the gem that was built
|
12
|
+
|
13
|
+
== Note on Patches/Pull Requests
|
14
|
+
|
15
|
+
* Fork the project.
|
16
|
+
* Make your feature addition or bug fix.
|
17
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
18
|
+
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself in another branch so I can ignore when I pull)
|
19
|
+
* Send me a pull request. Bonus points for topic branches.
|
20
|
+
|
21
|
+
== Features:
|
22
|
+
|
23
|
+
* Easy get, post requests
|
24
|
+
* Basic http authentication
|
25
|
+
* Default request query string parameters (ie: for api keys that are needed on each request)
|
26
|
+
* Automatic parsing of JSON and XML into ruby hashes based on response content-type
|
27
|
+
|
28
|
+
== Examples
|
29
|
+
|
30
|
+
See http://github.com/jnunemaker/httparty/tree/master/examples
|
31
|
+
|
32
|
+
== Command Line Interface
|
33
|
+
|
34
|
+
httparty also includes the executable <tt>httparty</tt> which can be
|
35
|
+
used to query web services and examine the resulting output. By default
|
36
|
+
it will output the response as a pretty-printed Ruby object (useful for
|
37
|
+
grokking the structure of output). This can also be overridden to output
|
38
|
+
formatted XML or JSON. Execute <tt>httparty --help</tt> for all the
|
39
|
+
options. Below is an example of how easy it is.
|
40
|
+
|
41
|
+
httparty "http://twitter.com/statuses/public_timeline.json"
|
42
|
+
|
43
|
+
== Requirements
|
44
|
+
|
45
|
+
* Crack http://github.com/jnunemaker/crack/ - For XML and JSON parsing.
|
46
|
+
* You like to party!
|
47
|
+
|
48
|
+
== Install
|
49
|
+
|
50
|
+
* sudo gem install httparty
|
51
|
+
|
52
|
+
== Docs
|
53
|
+
|
54
|
+
http://rdoc.info/projects/jnunemaker/httparty
|
data/httparty.gemspec
CHANGED
@@ -2,21 +2,21 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{httparty}
|
5
|
-
s.version = "0.4.
|
5
|
+
s.version = "0.4.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["John Nunemaker"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-07-19}
|
10
10
|
s.default_executable = %q{httparty}
|
11
11
|
s.description = %q{Makes http fun! Also, makes consuming restful web services dead easy.}
|
12
12
|
s.email = %q{nunemaker@gmail.com}
|
13
13
|
s.executables = ["httparty"]
|
14
|
-
s.extra_rdoc_files = ["bin/httparty", "lib/httparty/cookie_hash.rb", "lib/httparty/core_extensions.rb", "lib/httparty/exceptions.rb", "lib/httparty/module_inheritable_attributes.rb", "lib/httparty/request.rb", "lib/httparty/response.rb", "lib/httparty/version.rb", "lib/httparty.rb", "README"]
|
15
|
-
s.files = ["bin/httparty", "cucumber.yml", "examples/aaws.rb", "examples/basic.rb", "examples/delicious.rb", "examples/google.rb", "examples/rubyurl.rb", "examples/twitter.rb", "examples/whoismyrep.rb", "features/basic_authentication.feature", "features/command_line.feature", "features/deals_with_http_error_codes.feature", "features/handles_multiple_formats.feature", "features/steps/env.rb", "features/steps/httparty_response_steps.rb", "features/steps/httparty_steps.rb", "features/steps/mongrel_helper.rb", "features/steps/remote_service_steps.rb", "features/supports_redirection.feature", "History", "httparty.gemspec", "lib/httparty/cookie_hash.rb", "lib/httparty/core_extensions.rb", "lib/httparty/exceptions.rb", "lib/httparty/module_inheritable_attributes.rb", "lib/httparty/request.rb", "lib/httparty/response.rb", "lib/httparty/version.rb", "lib/httparty.rb", "Manifest", "MIT-LICENSE", "Rakefile", "README
|
14
|
+
s.extra_rdoc_files = ["bin/httparty", "lib/httparty/cookie_hash.rb", "lib/httparty/core_extensions.rb", "lib/httparty/exceptions.rb", "lib/httparty/module_inheritable_attributes.rb", "lib/httparty/request.rb", "lib/httparty/response.rb", "lib/httparty/version.rb", "lib/httparty.rb", "README.rdoc"]
|
15
|
+
s.files = ["bin/httparty", "cucumber.yml", "examples/aaws.rb", "examples/basic.rb", "examples/delicious.rb", "examples/google.rb", "examples/rubyurl.rb", "examples/twitter.rb", "examples/whoismyrep.rb", "features/basic_authentication.feature", "features/command_line.feature", "features/deals_with_http_error_codes.feature", "features/handles_multiple_formats.feature", "features/steps/env.rb", "features/steps/httparty_response_steps.rb", "features/steps/httparty_steps.rb", "features/steps/mongrel_helper.rb", "features/steps/remote_service_steps.rb", "features/supports_redirection.feature", "History", "httparty.gemspec", "lib/httparty/cookie_hash.rb", "lib/httparty/core_extensions.rb", "lib/httparty/exceptions.rb", "lib/httparty/module_inheritable_attributes.rb", "lib/httparty/request.rb", "lib/httparty/response.rb", "lib/httparty/version.rb", "lib/httparty.rb", "Manifest", "MIT-LICENSE", "Rakefile", "README.rdoc", "spec/fixtures/delicious.xml", "spec/fixtures/empty.xml", "spec/fixtures/google.html", "spec/fixtures/twitter.json", "spec/fixtures/twitter.xml", "spec/fixtures/undefined_method_add_node_for_nil.xml", "spec/httparty/cookie_hash_spec.rb", "spec/httparty/request_spec.rb", "spec/httparty/response_spec.rb", "spec/httparty_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "website/css/common.css", "website/index.html"]
|
16
16
|
s.has_rdoc = true
|
17
17
|
s.homepage = %q{http://httparty.rubyforge.org}
|
18
18
|
s.post_install_message = %q{When you HTTParty, you must party hard!}
|
19
|
-
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Httparty", "--main", "README"]
|
19
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Httparty", "--main", "README.rdoc"]
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
s.rubyforge_project = %q{httparty}
|
22
22
|
s.rubygems_version = %q{1.3.1}
|
@@ -1,5 +1,9 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
if RUBY_VERSION.to_f == 1.8
|
2
|
+
class BlankSlate #:nodoc:
|
3
|
+
instance_methods.each { |m| undef_method m unless m =~ /^__|instance_eval|object_id/ }
|
4
|
+
end
|
5
|
+
else
|
6
|
+
class BlankSlate < BasicObject; end
|
3
7
|
end
|
4
8
|
|
5
9
|
# 1.8.6 has mistyping of transitive in if statement
|
data/lib/httparty/request.rb
CHANGED
@@ -48,21 +48,23 @@ module HTTParty
|
|
48
48
|
http
|
49
49
|
end
|
50
50
|
|
51
|
-
def
|
52
|
-
|
51
|
+
def body
|
52
|
+
options[:body].is_a?(Hash) ? options[:body].to_params : options[:body]
|
53
|
+
end
|
54
|
+
|
55
|
+
def username
|
56
|
+
options[:basic_auth][:username]
|
57
|
+
end
|
58
|
+
|
59
|
+
def password
|
60
|
+
options[:basic_auth][:password]
|
53
61
|
end
|
54
62
|
|
55
63
|
def setup_raw_request
|
56
64
|
@raw_request = http_method.new(uri.request_uri)
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
@raw_request.body = options[:body].is_a?(Hash) ? options[:body].to_params : options[:body] unless options[:body].blank?
|
63
|
-
@raw_request.initialize_http_header options[:headers]
|
64
|
-
|
65
|
-
configure_basic_auth if options[:basic_auth]
|
65
|
+
@raw_request.body = body if body
|
66
|
+
@raw_request.initialize_http_header(options[:headers])
|
67
|
+
@raw_request.basic_auth(username, password) if options[:basic_auth]
|
66
68
|
end
|
67
69
|
|
68
70
|
def perform_actual_request
|
@@ -77,13 +79,13 @@ module HTTParty
|
|
77
79
|
|
78
80
|
def query_string(uri)
|
79
81
|
query_string_parts = []
|
80
|
-
query_string_parts << uri.query unless uri.query.
|
82
|
+
query_string_parts << uri.query unless uri.query.nil?
|
81
83
|
|
82
84
|
if options[:query].is_a?(Hash)
|
83
85
|
query_string_parts << options[:default_params].merge(options[:query]).to_params
|
84
86
|
else
|
85
|
-
query_string_parts << options[:default_params].to_params unless options[:default_params].
|
86
|
-
query_string_parts << options[:query] unless options[:query].
|
87
|
+
query_string_parts << options[:default_params].to_params unless options[:default_params].nil?
|
88
|
+
query_string_parts << options[:query] unless options[:query].nil?
|
87
89
|
end
|
88
90
|
|
89
91
|
query_string_parts.size > 0 ? query_string_parts.join('&') : nil
|
data/lib/httparty/version.rb
CHANGED
data/lib/httparty.rb
CHANGED
@@ -7,6 +7,8 @@ require 'rubygems'
|
|
7
7
|
gem 'crack'
|
8
8
|
require 'crack'
|
9
9
|
|
10
|
+
require 'httparty/cookie_hash'
|
11
|
+
|
10
12
|
module HTTParty
|
11
13
|
|
12
14
|
AllowedFormats = {
|
@@ -26,7 +28,9 @@ module HTTParty
|
|
26
28
|
base.extend ClassMethods
|
27
29
|
base.send :include, HTTParty::ModuleInheritableAttributes
|
28
30
|
base.send(:mattr_inheritable, :default_options)
|
31
|
+
base.send(:mattr_inheritable, :default_cookies)
|
29
32
|
base.instance_variable_set("@default_options", {})
|
33
|
+
base.instance_variable_set("@default_cookies", CookieHash.new)
|
30
34
|
end
|
31
35
|
|
32
36
|
module ClassMethods
|
@@ -90,8 +94,7 @@ module HTTParty
|
|
90
94
|
|
91
95
|
def cookies(h={})
|
92
96
|
raise ArgumentError, 'Cookies must be a hash' unless h.is_a?(Hash)
|
93
|
-
|
94
|
-
default_options[:cookies].add_cookies(h)
|
97
|
+
default_cookies.add_cookies(h)
|
95
98
|
end
|
96
99
|
|
97
100
|
# Allows setting the format with which to parse.
|
@@ -102,7 +105,7 @@ module HTTParty
|
|
102
105
|
# format :json
|
103
106
|
# end
|
104
107
|
def format(f)
|
105
|
-
raise UnsupportedFormat, "Must be one of: #{AllowedFormats.values.uniq.join(', ')}" unless AllowedFormats.value?(f)
|
108
|
+
raise UnsupportedFormat, "Must be one of: #{AllowedFormats.values.map { |v| v.to_s }.uniq.sort.join(', ')}" unless AllowedFormats.value?(f)
|
106
109
|
default_options[:format] = f
|
107
110
|
end
|
108
111
|
|
@@ -157,11 +160,10 @@ module HTTParty
|
|
157
160
|
end
|
158
161
|
|
159
162
|
def process_cookies(options) #:nodoc:
|
160
|
-
return unless options[:cookies] ||
|
163
|
+
return unless options[:cookies] || default_cookies
|
161
164
|
options[:headers] ||= {}
|
162
|
-
options[:headers]["cookie"] = cookies(options[:cookies] || {}).to_cookie_string
|
165
|
+
options[:headers]["cookie"] = cookies.merge(options[:cookies] || {}).to_cookie_string
|
163
166
|
|
164
|
-
default_options.delete(:cookies)
|
165
167
|
options.delete(:cookies)
|
166
168
|
end
|
167
169
|
end
|
@@ -198,7 +200,6 @@ module HTTParty
|
|
198
200
|
end
|
199
201
|
end
|
200
202
|
|
201
|
-
require 'httparty/cookie_hash'
|
202
203
|
require 'httparty/core_extensions'
|
203
204
|
require 'httparty/exceptions'
|
204
205
|
require 'httparty/request'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
2
|
|
3
3
|
describe HTTParty::Request do
|
4
4
|
def stub_response(body, code = 200)
|
@@ -33,7 +33,12 @@ describe HTTParty::Request do
|
|
33
33
|
|
34
34
|
it 'should not use ssl for port 80' do
|
35
35
|
request = HTTParty::Request.new(Net::HTTP::Get, 'http://foobar.com')
|
36
|
-
|
36
|
+
request.send(:http).use_ssl?.should == false
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should use ssl for https scheme" do
|
40
|
+
request = HTTParty::Request.new(Net::HTTP::Get, 'https://foobar.com')
|
41
|
+
request.send(:http).use_ssl?.should == true
|
37
42
|
end
|
38
43
|
|
39
44
|
it "should use basic auth when configured" do
|
@@ -109,7 +114,6 @@ describe HTTParty::Request do
|
|
109
114
|
end
|
110
115
|
|
111
116
|
describe 'with non-200 responses' do
|
112
|
-
|
113
117
|
it 'should return a valid object for 4xx response' do
|
114
118
|
stub_response '<foo><bar>yes</bar></foo>', 401
|
115
119
|
resp = @request.perform
|
@@ -125,7 +129,6 @@ describe HTTParty::Request do
|
|
125
129
|
resp.body.should == "<foo><bar>error</bar></foo>"
|
126
130
|
resp['foo']['bar'].should == "error"
|
127
131
|
end
|
128
|
-
|
129
132
|
end
|
130
133
|
end
|
131
134
|
|
data/spec/httparty_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
2
|
|
3
3
|
describe HTTParty do
|
4
4
|
before(:each) do
|
@@ -96,6 +96,13 @@ describe HTTParty do
|
|
96
96
|
@klass.get("")
|
97
97
|
end
|
98
98
|
|
99
|
+
it "should pass the proper cookies when requested multiple times" do
|
100
|
+
2.times do
|
101
|
+
expect_cookie_header "type=snickerdoodle"
|
102
|
+
@klass.get("")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
99
106
|
it "should allow the class defaults to be overridden" do
|
100
107
|
expect_cookie_header "type=chocolate_chip"
|
101
108
|
|
@@ -175,7 +182,7 @@ describe HTTParty do
|
|
175
182
|
it 'should only print each format once with an exception' do
|
176
183
|
lambda do
|
177
184
|
@klass.format :foobar
|
178
|
-
end.should raise_error(HTTParty::UnsupportedFormat, "Must be one of: json, plain,
|
185
|
+
end.should raise_error(HTTParty::UnsupportedFormat, "Must be one of: html, json, plain, xml, yaml")
|
179
186
|
end
|
180
187
|
|
181
188
|
end
|
data/spec/spec_helper.rb
CHANGED
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.4.
|
4
|
+
version: 0.4.4
|
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: 2009-
|
12
|
+
date: 2009-07-19 00:00:00 -07:00
|
13
13
|
default_executable: httparty
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -48,7 +48,7 @@ extra_rdoc_files:
|
|
48
48
|
- lib/httparty/response.rb
|
49
49
|
- lib/httparty/version.rb
|
50
50
|
- lib/httparty.rb
|
51
|
-
- README
|
51
|
+
- README.rdoc
|
52
52
|
files:
|
53
53
|
- bin/httparty
|
54
54
|
- cucumber.yml
|
@@ -82,22 +82,19 @@ files:
|
|
82
82
|
- Manifest
|
83
83
|
- MIT-LICENSE
|
84
84
|
- Rakefile
|
85
|
-
- README
|
86
|
-
- setup.rb
|
85
|
+
- README.rdoc
|
87
86
|
- spec/fixtures/delicious.xml
|
88
87
|
- spec/fixtures/empty.xml
|
89
88
|
- spec/fixtures/google.html
|
90
89
|
- spec/fixtures/twitter.json
|
91
90
|
- spec/fixtures/twitter.xml
|
92
91
|
- spec/fixtures/undefined_method_add_node_for_nil.xml
|
93
|
-
- spec/hash_spec.rb
|
94
92
|
- spec/httparty/cookie_hash_spec.rb
|
95
93
|
- spec/httparty/request_spec.rb
|
96
94
|
- spec/httparty/response_spec.rb
|
97
95
|
- spec/httparty_spec.rb
|
98
96
|
- spec/spec.opts
|
99
97
|
- spec/spec_helper.rb
|
100
|
-
- spec/string_spec.rb
|
101
98
|
- website/css/common.css
|
102
99
|
- website/index.html
|
103
100
|
has_rdoc: true
|
@@ -109,7 +106,7 @@ rdoc_options:
|
|
109
106
|
- --title
|
110
107
|
- Httparty
|
111
108
|
- --main
|
112
|
-
- README
|
109
|
+
- README.rdoc
|
113
110
|
require_paths:
|
114
111
|
- lib
|
115
112
|
required_ruby_version: !ruby/object:Gem::Requirement
|
data/README
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
= httparty
|
2
|
-
|
3
|
-
== DESCRIPTION:
|
4
|
-
|
5
|
-
Makes http fun again!
|
6
|
-
|
7
|
-
== FEATURES:
|
8
|
-
|
9
|
-
* Easy get, post requests
|
10
|
-
* Basic http authentication
|
11
|
-
* Default request query string parameters (ie: for api keys that are needed on each request)
|
12
|
-
* Automatic parsing of JSON and XML into ruby hashes based on response content-type
|
13
|
-
|
14
|
-
== EXAMPLES:
|
15
|
-
|
16
|
-
See http://github.com/jnunemaker/httparty/tree/master/examples
|
17
|
-
|
18
|
-
== COMMAND LINE INTERFACE
|
19
|
-
|
20
|
-
httparty also includes the executable <tt>httparty</tt> which can be
|
21
|
-
used to query web services and examine the resulting output. By default
|
22
|
-
it will output the response as a pretty-printed Ruby object (useful for
|
23
|
-
grokking the structure of output). This can also be overridden to output
|
24
|
-
formatted XML or JSON. Execute <tt>httparty --help</tt> for all the
|
25
|
-
options. Below is an example of how easy it is.
|
26
|
-
|
27
|
-
httparty "http://twitter.com/statuses/public_timeline.json"
|
28
|
-
|
29
|
-
== REQUIREMENTS:
|
30
|
-
|
31
|
-
* Crack http://github.com/jnunemaker/crack/ - For XML and JSON parsing.
|
32
|
-
* You like to party!
|
33
|
-
|
34
|
-
== INSTALL:
|
35
|
-
|
36
|
-
* sudo gem install httparty
|