httparty 0.1.8 → 0.2.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.

@@ -5,27 +5,9 @@ describe HTTParty::Request do
5
5
  @request = HTTParty::Request.new(Net::HTTP::Get, 'http://api.foo.com/v1', :format => :xml)
6
6
  end
7
7
 
8
- describe "#normalize_base_uri" do
9
- it "should add http if not present for non ssl requests" do
10
- uri = HTTParty::Request.normalize_base_uri('api.foobar.com')
11
- uri.should == 'http://api.foobar.com'
12
- end
13
-
14
- it "should add https if not present for ssl requests" do
15
- uri = HTTParty::Request.normalize_base_uri('api.foo.com/v1:443')
16
- uri.should == 'https://api.foo.com/v1:443'
17
- end
18
-
19
- it "should not remove https for ssl requests" do
20
- uri = HTTParty::Request.normalize_base_uri('https://api.foo.com/v1:443')
21
- uri.should == 'https://api.foo.com/v1:443'
22
- end
23
- end
24
-
25
- describe "uri" do
26
- it "should be normalized" do
27
- request = HTTParty::Request.new(Net::HTTP::Get, '', :base_uri => 'api.foo.com')
28
- request.uri.to_s.should == 'http://api.foo.com'
8
+ describe "#format" do
9
+ it "should return the correct parsing format" do
10
+ @request.format.should == :xml
29
11
  end
30
12
  end
31
13
 
@@ -78,7 +60,7 @@ describe HTTParty::Request do
78
60
 
79
61
  def setup_ok_response
80
62
  @ok = Net::HTTPOK.new("1.1", 200, "Content for you")
81
- @ok.stub!(:body).and_return({"foo" => "bar"}.to_xml)
63
+ @ok.stub!(:body).and_return('<hash><foo>bar</foo></hash>')
82
64
  @http.should_receive(:request).and_return(@redirect, @ok)
83
65
  @request.options[:format] = :xml
84
66
  end
@@ -25,7 +25,7 @@ describe HTTParty do
25
25
  end
26
26
 
27
27
  it "should have reader" do
28
- Foo.base_uri.should == 'api.foo.com/v1'
28
+ Foo.base_uri.should == 'http://api.foo.com/v1'
29
29
  end
30
30
 
31
31
  it 'should have writer' do
@@ -34,6 +34,23 @@ describe HTTParty do
34
34
  end
35
35
  end
36
36
 
37
+ describe "#normalize_base_uri" do
38
+ it "should add http if not present for non ssl requests" do
39
+ uri = HTTParty.normalize_base_uri('api.foobar.com')
40
+ uri.should == 'http://api.foobar.com'
41
+ end
42
+
43
+ it "should add https if not present for ssl requests" do
44
+ uri = HTTParty.normalize_base_uri('api.foo.com/v1:443')
45
+ uri.should == 'https://api.foo.com/v1:443'
46
+ end
47
+
48
+ it "should not remove https for ssl requests" do
49
+ uri = HTTParty.normalize_base_uri('https://api.foo.com/v1:443')
50
+ uri.should == 'https://api.foo.com/v1:443'
51
+ end
52
+ end
53
+
37
54
  describe "headers" do
38
55
  it "should default to empty hash" do
39
56
  Foo.headers.should == {}
@@ -112,8 +129,49 @@ describe HTTParty do
112
129
 
113
130
  describe "with multiple class definitions" do
114
131
  it "should not run over each others options" do
115
- HRest.default_options.should == {:base_uri => 'hrest.com', :default_params => {:two => 'three'}}
116
- GRest.default_options.should == {:base_uri => 'grest.com', :default_params => {:one => 'two'}}
132
+ HRest.default_options.should == {:base_uri => 'http://hrest.com', :default_params => {:two => 'three'}}
133
+ GRest.default_options.should == {:base_uri => 'http://grest.com', :default_params => {:one => 'two'}}
134
+ end
135
+ end
136
+
137
+ describe "#get" do
138
+ it "should be able to get html" do
139
+ stub_http_response_with('google.html')
140
+ HTTParty.get('http://www.google.com').should == file_fixture('google.html')
141
+ end
142
+
143
+ it "should be able parse response type json automatically" do
144
+ stub_http_response_with('twitter.json')
145
+ tweets = HTTParty.get('http://twitter.com/statuses/public_timeline.json')
146
+ tweets.size.should == 20
147
+ tweets.first['user'].should == {
148
+ "name" => "Pyk",
149
+ "url" => nil,
150
+ "id" => "7694602",
151
+ "description" => nil,
152
+ "protected" => false,
153
+ "screen_name" => "Pyk",
154
+ "followers_count" => 1,
155
+ "location" => "Opera Plaza, California",
156
+ "profile_image_url" => "http://static.twitter.com/images/default_profile_normal.png"
157
+ }
158
+ end
159
+
160
+ it "should be able parse response type xml automatically" do
161
+ stub_http_response_with('twitter.xml')
162
+ tweets = HTTParty.get('http://twitter.com/statuses/public_timeline.xml')
163
+ tweets['statuses'].size.should == 20
164
+ tweets['statuses'].first['user'].should == {
165
+ "name" => "Magic 8 Bot",
166
+ "url" => nil,
167
+ "id" => "17656026",
168
+ "description" => "ask me a question",
169
+ "protected" => "false",
170
+ "screen_name" => "magic8bot",
171
+ "followers_count" => "90",
172
+ "profile_image_url" => "http://s3.amazonaws.com/twitter_production/profile_images/65565851/8ball_large_normal.jpg",
173
+ "location" => nil
174
+ }
117
175
  end
118
176
  end
119
177
  end
@@ -1,9 +1,24 @@
1
- begin
2
- require 'spec'
3
- rescue LoadError
4
- require 'rubygems'
5
- gem 'rspec'
6
- require 'spec'
1
+ require 'rubygems'
2
+ gem 'rspec'
3
+ require 'spec'
4
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'httparty')
5
+
6
+ def file_fixture(filename)
7
+ open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename.to_s}")).read
7
8
  end
8
9
 
9
- require File.join(File.dirname(__FILE__), '..', 'lib', 'httparty')
10
+ def stub_http_response_with(filename)
11
+ format = filename.split('.').last.intern
12
+ data = file_fixture(filename)
13
+ http = Net::HTTP.new('localhost', 80)
14
+
15
+ response = Net::HTTPOK.new("1.1", 200, "Content for you")
16
+ response.stub!(:body).and_return(data)
17
+ http.stub!(:request).and_return(response)
18
+
19
+ http_request = HTTParty::Request.new(Net::HTTP::Get, '')
20
+ http_request.stub!(:get_response).and_return(response)
21
+ http_request.stub!(:format).and_return(format)
22
+
23
+ HTTParty::Request.should_receive(:new).and_return(http_request)
24
+ 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.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -9,18 +9,18 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-05 00:00:00 -05:00
12
+ date: 2008-12-07 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: activesupport
16
+ name: json
17
17
  type: :runtime
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
- - - ">="
21
+ - - ~>
22
22
  - !ruby/object:Gem::Version
23
- version: "2.1"
23
+ version: "1.1"
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: echoe
@@ -39,9 +39,12 @@ executables: []
39
39
  extensions: []
40
40
 
41
41
  extra_rdoc_files:
42
+ - lib/core_extensions.rb
43
+ - lib/httparty/exceptions.rb
42
44
  - lib/httparty/request.rb
43
45
  - lib/httparty/version.rb
44
46
  - lib/httparty.rb
47
+ - lib/module_level_inheritable_attributes.rb
45
48
  - README
46
49
  files:
47
50
  - examples/aaws.rb
@@ -53,14 +56,21 @@ files:
53
56
  - examples/whoismyrep.rb
54
57
  - History
55
58
  - httparty.gemspec
59
+ - lib/core_extensions.rb
60
+ - lib/httparty/exceptions.rb
56
61
  - lib/httparty/request.rb
57
62
  - lib/httparty/version.rb
58
63
  - lib/httparty.rb
64
+ - lib/module_level_inheritable_attributes.rb
59
65
  - Manifest
60
66
  - MIT-LICENSE
61
67
  - Rakefile
62
68
  - README
63
69
  - setup.rb
70
+ - spec/fixtures/delicious.xml
71
+ - spec/fixtures/google.html
72
+ - spec/fixtures/twitter.json
73
+ - spec/fixtures/twitter.xml
64
74
  - spec/httparty/request_spec.rb
65
75
  - spec/httparty_spec.rb
66
76
  - spec/spec.opts