jnunemaker-httparty 0.3.0 → 0.3.1
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 +5 -0
- data/Manifest +0 -1
- data/httparty.gemspec +3 -3
- data/lib/httparty/parsers/json.rb +8 -1
- data/lib/httparty/request.rb +2 -0
- data/lib/httparty/version.rb +1 -1
- data/lib/httparty.rb +3 -1
- data/spec/hash_spec.rb +5 -0
- data/spec/httparty/parsers/json_spec.rb +10 -9
- data/spec/httparty/request_spec.rb +6 -0
- data/spec/httparty/response_spec.rb +53 -0
- data/spec/httparty_spec.rb +5 -0
- metadata +3 -3
- data/spec/core_extensions_spec.rb +0 -30
data/History
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
== 0.3.1 2009-02-10
|
2
|
+
* 1 minor fix, 1 minor enhancement
|
3
|
+
* Fixed unescaping umlauts (siebertm)
|
4
|
+
* Added yaml response parsing (Miha Filej)
|
5
|
+
|
1
6
|
== 0.3.0 2009-01-31
|
2
7
|
* 1 major enhancement, 1 bug fix
|
3
8
|
* JSON gem no longer a requirement. It was conflicting with rails json stuff so I just stole ActiveSupport's json decoding and bundled it with HTTParty.
|
data/Manifest
CHANGED
data/httparty.gemspec
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{httparty}
|
5
|
-
s.version = "0.3.
|
5
|
+
s.version = "0.3.1"
|
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-02-10}
|
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
14
|
s.extra_rdoc_files = ["bin/httparty", "lib/core_extensions.rb", "lib/httparty/cookie_hash.rb", "lib/httparty/exceptions.rb", "lib/httparty/module_inheritable_attributes.rb", "lib/httparty/parsers/json.rb", "lib/httparty/parsers/xml.rb", "lib/httparty/parsers.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/core_extensions.rb", "lib/httparty/cookie_hash.rb", "lib/httparty/exceptions.rb", "lib/httparty/module_inheritable_attributes.rb", "lib/httparty/parsers/json.rb", "lib/httparty/parsers/xml.rb", "lib/httparty/parsers.rb", "lib/httparty/request.rb", "lib/httparty/response.rb", "lib/httparty/version.rb", "lib/httparty.rb", "Manifest", "MIT-LICENSE", "Rakefile", "README", "setup.rb", "spec/
|
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/core_extensions.rb", "lib/httparty/cookie_hash.rb", "lib/httparty/exceptions.rb", "lib/httparty/module_inheritable_attributes.rb", "lib/httparty/parsers/json.rb", "lib/httparty/parsers/xml.rb", "lib/httparty/parsers.rb", "lib/httparty/request.rb", "lib/httparty/response.rb", "lib/httparty/version.rb", "lib/httparty.rb", "Manifest", "MIT-LICENSE", "Rakefile", "README", "setup.rb", "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/hash_spec.rb", "spec/httparty/cookie_hash_spec.rb", "spec/httparty/parsers/json_spec.rb", "spec/httparty/parsers/xml_spec.rb", "spec/httparty/request_spec.rb", "spec/httparty/response_spec.rb", "spec/httparty_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/string_spec.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!}
|
@@ -13,12 +13,19 @@ module HTTParty
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.decode(json)
|
16
|
-
YAML.load(convert_json_to_yaml(json))
|
16
|
+
YAML.load(unescape(convert_json_to_yaml(json)))
|
17
17
|
rescue ArgumentError => e
|
18
18
|
raise ParseError, "Invalid JSON string"
|
19
19
|
end
|
20
20
|
|
21
21
|
protected
|
22
|
+
|
23
|
+
def self.unescape(str)
|
24
|
+
str.gsub(/\\u([0-9a-f]{4})/) {
|
25
|
+
[$1.hex].pack("U")
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
22
29
|
# matches YAML-formatted dates
|
23
30
|
DATE_REGEX = /^\d{4}-\d{2}-\d{2}|\d{4}-\d{1,2}-\d{1,2}[ \t]+\d{1,2}:\d{2}:\d{2}(\.[0-9]*)?(([ \t]*)Z|[-+]\d{2}?(:\d{2})?)?$/
|
24
31
|
|
data/lib/httparty/request.rb
CHANGED
data/lib/httparty/version.rb
CHANGED
data/lib/httparty.rb
CHANGED
@@ -14,7 +14,9 @@ module HTTParty
|
|
14
14
|
'text/json' => :json,
|
15
15
|
'application/javascript' => :json,
|
16
16
|
'text/javascript' => :json,
|
17
|
-
'text/html' => :html
|
17
|
+
'text/html' => :html,
|
18
|
+
'application/x-yaml' => :yaml,
|
19
|
+
'text/yaml' => :yaml
|
18
20
|
} unless defined?(AllowedFormats)
|
19
21
|
|
20
22
|
def self.included(base)
|
data/spec/hash_spec.rb
CHANGED
@@ -41,4 +41,9 @@ describe Hash, 'to_params' do
|
|
41
41
|
it 'should not leave a trailing &' do
|
42
42
|
{ :name => 'Bob', :address => { :street => '111 Ruby Ave.', :city => 'Ruby Central', :phones => ['111-111-1111', '222-222-2222'] } }.to_params.should_not match(/&$/)
|
43
43
|
end
|
44
|
+
|
45
|
+
it 'should URL encode unsafe characters' do
|
46
|
+
{:q => "?&\" +"}.to_params.should == "q=%3F%26%22%20%2B"
|
47
|
+
end
|
48
|
+
|
44
49
|
end
|
@@ -2,18 +2,19 @@ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
|
|
2
2
|
|
3
3
|
describe HTTParty::Parsers::JSON do
|
4
4
|
TESTS = {
|
5
|
+
%q({"data": "G\u00fcnter"}) => {"data" => "Günter"},
|
5
6
|
%q({"returnTo":{"\/categories":"\/"}}) => {"returnTo" => {"/categories" => "/"}},
|
6
7
|
%q({returnTo:{"\/categories":"\/"}}) => {"returnTo" => {"/categories" => "/"}},
|
7
8
|
%q({"return\\"To\\":":{"\/categories":"\/"}}) => {"return\"To\":" => {"/categories" => "/"}},
|
8
|
-
%q({"returnTo":{"\/categories":1}})
|
9
|
-
%({"returnTo":[1,"a"]})
|
10
|
-
%({"returnTo":[1,"\\"a\\",", "b"]})
|
11
|
-
%({a: "'", "b": "5,000"})
|
12
|
-
%({a: "a's, b's and c's", "b": "5,000"})
|
13
|
-
%({a: "2007-01-01"})
|
14
|
-
%({a: "2007-01-01 01:12:34 Z"})
|
15
|
-
# no time zone
|
16
|
-
%({a: "2007-01-01 01:12:34"})
|
9
|
+
%q({"returnTo":{"\/categories":1}}) => {"returnTo" => {"/categories" => 1}},
|
10
|
+
%({"returnTo":[1,"a"]}) => {"returnTo" => [1, "a"]},
|
11
|
+
%({"returnTo":[1,"\\"a\\",", "b"]}) => {"returnTo" => [1, "\"a\",", "b"]},
|
12
|
+
%({a: "'", "b": "5,000"}) => {"a" => "'", "b" => "5,000"},
|
13
|
+
%({a: "a's, b's and c's", "b": "5,000"}) => {"a" => "a's, b's and c's", "b" => "5,000"},
|
14
|
+
%({a: "2007-01-01"}) => {'a' => Date.new(2007, 1, 1)},
|
15
|
+
%({a: "2007-01-01 01:12:34 Z"}) => {'a' => Time.utc(2007, 1, 1, 1, 12, 34)},
|
16
|
+
# no time zone
|
17
|
+
%({a: "2007-01-01 01:12:34"}) => {'a' => "2007-01-01 01:12:34"},
|
17
18
|
%([]) => [],
|
18
19
|
%({}) => {},
|
19
20
|
%(1) => 1,
|
@@ -94,6 +94,12 @@ describe HTTParty::Request do
|
|
94
94
|
@request.send(:parse_response, json).should == {'books' => {'book' => {'id' => '1234', 'name' => 'Foo Bar!'}}}
|
95
95
|
end
|
96
96
|
|
97
|
+
it 'should handle yaml automatically' do
|
98
|
+
yaml = "books: \n book: \n name: Foo Bar!\n id: \"1234\"\n"
|
99
|
+
@request.options[:format] = :yaml
|
100
|
+
@request.send(:parse_response, yaml).should == {'books' => {'book' => {'id' => '1234', 'name' => 'Foo Bar!'}}}
|
101
|
+
end
|
102
|
+
|
97
103
|
it "should include any HTTP headers in the returned response" do
|
98
104
|
@request.options[:format] = :html
|
99
105
|
response = stub_response "Content"
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe HTTParty::Response do
|
4
|
+
describe "initialization" do
|
5
|
+
before do
|
6
|
+
@response_object = {'foo' => 'bar'}
|
7
|
+
@body = "{foo:'bar'}"
|
8
|
+
@code = 200
|
9
|
+
@response = HTTParty::Response.new(@response_object, @body, @code)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should set delegate" do
|
13
|
+
@response.delegate.should == @response_object
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should set body" do
|
17
|
+
@response.body.should == @body
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should set code" do
|
21
|
+
@response.code.should == @code
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should be able to set headers during initialization" do
|
26
|
+
response = HTTParty::Response.new({'foo' => 'bar'}, "{foo:'bar'}", 200, {'foo' => 'bar'})
|
27
|
+
response.headers.should == {'foo' => 'bar'}
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should send missing methods to delegate" do
|
31
|
+
response = HTTParty::Response.new({'foo' => 'bar'}, "{foo:'bar'}", 200)
|
32
|
+
response['foo'].should == 'bar'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should be able to iterate delegate if it is array" do
|
36
|
+
response = HTTParty::Response.new([{'foo' => 'bar'}, {'foo' => 'baz'}], "[{foo:'bar'}, {foo:'baz'}]", 200)
|
37
|
+
response.size.should == 2
|
38
|
+
lambda {
|
39
|
+
response.each { |item| }
|
40
|
+
}.should_not raise_error
|
41
|
+
end
|
42
|
+
|
43
|
+
xit "should allow hashes to be accessed with dot notation" do
|
44
|
+
response = HTTParty::Response.new({'foo' => 'bar'}, "{foo:'bar'}", 200)
|
45
|
+
response.foo.should == 'bar'
|
46
|
+
end
|
47
|
+
|
48
|
+
xit "should allow nested hashes to be accessed with dot notation" do
|
49
|
+
response = HTTParty::Response.new({'foo' => {'bar' => 'baz'}}, "{foo: {bar:'baz'}}", 200)
|
50
|
+
response.foo.should == {'bar' => 'baz'}
|
51
|
+
response.foo.bar.should == 'baz'
|
52
|
+
end
|
53
|
+
end
|
data/spec/httparty_spec.rb
CHANGED
@@ -144,6 +144,11 @@ describe HTTParty do
|
|
144
144
|
@klass.default_options[:format].should == :json
|
145
145
|
end
|
146
146
|
|
147
|
+
it "should allow yaml" do
|
148
|
+
@klass.format :yaml
|
149
|
+
@klass.default_options[:format].should == :yaml
|
150
|
+
end
|
151
|
+
|
147
152
|
it 'should not allow funky format' do
|
148
153
|
lambda do
|
149
154
|
@klass.format :foobar
|
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.3.
|
4
|
+
version: 0.3.1
|
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-02-10 00:00:00 -08:00
|
13
13
|
default_executable: httparty
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -79,7 +79,6 @@ files:
|
|
79
79
|
- Rakefile
|
80
80
|
- README
|
81
81
|
- setup.rb
|
82
|
-
- spec/core_extensions_spec.rb
|
83
82
|
- spec/fixtures/delicious.xml
|
84
83
|
- spec/fixtures/empty.xml
|
85
84
|
- spec/fixtures/google.html
|
@@ -91,6 +90,7 @@ files:
|
|
91
90
|
- spec/httparty/parsers/json_spec.rb
|
92
91
|
- spec/httparty/parsers/xml_spec.rb
|
93
92
|
- spec/httparty/request_spec.rb
|
93
|
+
- spec/httparty/response_spec.rb
|
94
94
|
- spec/httparty_spec.rb
|
95
95
|
- spec/spec.opts
|
96
96
|
- spec/spec_helper.rb
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
|
3
|
-
describe "Core Extensions" do
|
4
|
-
describe Hash do
|
5
|
-
describe "#to_params" do
|
6
|
-
def should_be_same_params(query_string, expected)
|
7
|
-
query_string.split(/&/).sort.should == expected.split(/&/).sort
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should encode characters in URL parameters" do
|
11
|
-
{:q => "?&\" +"}.to_params.should == "q=%3F%26%22%20%2B"
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should handle multiple parameters" do
|
15
|
-
should_be_same_params({:q1 => "p1", :q2 => "p2"}.to_params, "q1=p1&q2=p2")
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should handle nested hashes like rails does" do
|
19
|
-
should_be_same_params({
|
20
|
-
:name => "Bob",
|
21
|
-
:address => {
|
22
|
-
:street => '111 Ruby Ave.',
|
23
|
-
:city => 'Ruby Central',
|
24
|
-
:phones => ['111-111-1111', '222-222-2222']
|
25
|
-
}
|
26
|
-
}.to_params, "name=Bob&address[city]=Ruby%20Central&address[phones][]=111-111-1111&address[phones][]=222-222-2222&address[street]=111%20Ruby%20Ave.")
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|