httparty 0.2.10 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of httparty might be problematic. Click here for more details.
- data/History +6 -0
- data/Manifest +9 -2
- data/README +2 -2
- data/Rakefile +0 -1
- data/bin/httparty +13 -29
- data/httparty.gemspec +4 -7
- data/lib/core_extensions.rb +42 -220
- data/lib/httparty.rb +76 -16
- data/lib/httparty/cookie_hash.rb +1 -1
- data/lib/httparty/exceptions.rb +3 -0
- data/lib/httparty/module_inheritable_attributes.rb +25 -0
- data/lib/httparty/parsers.rb +4 -0
- data/lib/httparty/parsers/json.rb +67 -0
- data/lib/httparty/parsers/xml.rb +209 -0
- data/lib/httparty/request.rb +19 -13
- data/lib/httparty/response.rb +3 -2
- data/lib/httparty/version.rb +2 -2
- data/spec/hash_spec.rb +44 -0
- data/spec/httparty/parsers/json_spec.rb +41 -0
- data/spec/httparty/parsers/xml_spec.rb +445 -0
- data/spec/httparty/response_spec.rb +53 -0
- data/spec/string_spec.rb +27 -0
- metadata +15 -15
- data/lib/module_level_inheritable_attributes.rb +0 -25
- data/spec/as_buggery_spec.rb +0 -16
@@ -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/string_spec.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
describe String, "#snake_case" do
|
2
|
+
it "lowercases one word CamelCase" do
|
3
|
+
"Merb".snake_case.should == "merb"
|
4
|
+
end
|
5
|
+
|
6
|
+
it "makes one underscore snake_case two word CamelCase" do
|
7
|
+
"MerbCore".snake_case.should == "merb_core"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "handles CamelCase with more than 2 words" do
|
11
|
+
"SoYouWantContributeToMerbCore".snake_case.should == "so_you_want_contribute_to_merb_core"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "handles CamelCase with more than 2 capital letter in a row" do
|
15
|
+
"CNN".snake_case.should == "cnn"
|
16
|
+
"CNNNews".snake_case.should == "cnn_news"
|
17
|
+
"HeadlineCNNNews".snake_case.should == "headline_cnn_news"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "does NOT change one word lowercase" do
|
21
|
+
"merb".snake_case.should == "merb"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "leaves snake_case as is" do
|
25
|
+
"merb_core".snake_case.should == "merb_core"
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httparty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
@@ -9,19 +9,9 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-01-
|
12
|
+
date: 2009-01-31 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name: json
|
17
|
-
type: :runtime
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ~>
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: "1.1"
|
24
|
-
version:
|
25
15
|
- !ruby/object:Gem::Dependency
|
26
16
|
name: echoe
|
27
17
|
type: :development
|
@@ -43,11 +33,14 @@ extra_rdoc_files:
|
|
43
33
|
- lib/core_extensions.rb
|
44
34
|
- lib/httparty/cookie_hash.rb
|
45
35
|
- lib/httparty/exceptions.rb
|
36
|
+
- lib/httparty/module_inheritable_attributes.rb
|
37
|
+
- lib/httparty/parsers/json.rb
|
38
|
+
- lib/httparty/parsers/xml.rb
|
39
|
+
- lib/httparty/parsers.rb
|
46
40
|
- lib/httparty/request.rb
|
47
41
|
- lib/httparty/response.rb
|
48
42
|
- lib/httparty/version.rb
|
49
43
|
- lib/httparty.rb
|
50
|
-
- lib/module_level_inheritable_attributes.rb
|
51
44
|
- README
|
52
45
|
files:
|
53
46
|
- bin/httparty
|
@@ -74,17 +67,19 @@ files:
|
|
74
67
|
- lib/core_extensions.rb
|
75
68
|
- lib/httparty/cookie_hash.rb
|
76
69
|
- lib/httparty/exceptions.rb
|
70
|
+
- lib/httparty/module_inheritable_attributes.rb
|
71
|
+
- lib/httparty/parsers/json.rb
|
72
|
+
- lib/httparty/parsers/xml.rb
|
73
|
+
- lib/httparty/parsers.rb
|
77
74
|
- lib/httparty/request.rb
|
78
75
|
- lib/httparty/response.rb
|
79
76
|
- lib/httparty/version.rb
|
80
77
|
- lib/httparty.rb
|
81
|
-
- lib/module_level_inheritable_attributes.rb
|
82
78
|
- Manifest
|
83
79
|
- MIT-LICENSE
|
84
80
|
- Rakefile
|
85
81
|
- README
|
86
82
|
- setup.rb
|
87
|
-
- spec/as_buggery_spec.rb
|
88
83
|
- spec/core_extensions_spec.rb
|
89
84
|
- spec/fixtures/delicious.xml
|
90
85
|
- spec/fixtures/empty.xml
|
@@ -92,11 +87,16 @@ files:
|
|
92
87
|
- spec/fixtures/twitter.json
|
93
88
|
- spec/fixtures/twitter.xml
|
94
89
|
- spec/fixtures/undefined_method_add_node_for_nil.xml
|
90
|
+
- spec/hash_spec.rb
|
95
91
|
- spec/httparty/cookie_hash_spec.rb
|
92
|
+
- spec/httparty/parsers/json_spec.rb
|
93
|
+
- spec/httparty/parsers/xml_spec.rb
|
96
94
|
- spec/httparty/request_spec.rb
|
95
|
+
- spec/httparty/response_spec.rb
|
97
96
|
- spec/httparty_spec.rb
|
98
97
|
- spec/spec.opts
|
99
98
|
- spec/spec_helper.rb
|
99
|
+
- spec/string_spec.rb
|
100
100
|
- website/css/common.css
|
101
101
|
- website/index.html
|
102
102
|
has_rdoc: true
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module ModuleLevelInheritableAttributes
|
2
|
-
def self.included(base)
|
3
|
-
base.extend(ClassMethods)
|
4
|
-
end
|
5
|
-
|
6
|
-
module ClassMethods
|
7
|
-
def mattr_inheritable(*args)
|
8
|
-
@mattr_inheritable_attrs ||= [:mattr_inheritable_attrs]
|
9
|
-
@mattr_inheritable_attrs += args
|
10
|
-
args.each do |arg|
|
11
|
-
module_eval %(
|
12
|
-
class << self; attr_accessor :#{arg} end
|
13
|
-
)
|
14
|
-
end
|
15
|
-
@mattr_inheritable_attrs
|
16
|
-
end
|
17
|
-
|
18
|
-
def inherited(subclass)
|
19
|
-
@mattr_inheritable_attrs.each do |inheritable_attribute|
|
20
|
-
instance_var = "@#{inheritable_attribute}"
|
21
|
-
subclass.instance_variable_set(instance_var, instance_variable_get(instance_var))
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/spec/as_buggery_spec.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
|
3
|
-
require 'activesupport'
|
4
|
-
|
5
|
-
describe Hash do
|
6
|
-
describe "#from_xml" do
|
7
|
-
it "should be able to convert xml with datetimes" do
|
8
|
-
xml =<<EOL
|
9
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
10
|
-
<created-at type="datetime">2008-12-01T20:00:00-05:00</created-at>
|
11
|
-
EOL
|
12
|
-
hsh = Hash.from_xml(xml)
|
13
|
-
hsh["created_at"].should == Time.parse("December 01st, 2008 20:00:00")
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|