jnunemaker-httparty 0.1.8 → 0.2.0

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.
@@ -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
data/spec/spec_helper.rb CHANGED
@@ -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: jnunemaker-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,17 +9,17 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-05 00:00:00 -08:00
12
+ date: 2008-12-07 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: activesupport
16
+ name: json
17
17
  version_requirement:
18
18
  version_requirements: !ruby/object:Gem::Requirement
19
19
  requirements:
20
- - - ">="
20
+ - - ~>
21
21
  - !ruby/object:Gem::Version
22
- version: "2.1"
22
+ version: "1.1"
23
23
  version:
24
24
  - !ruby/object:Gem::Dependency
25
25
  name: echoe
@@ -37,9 +37,12 @@ executables: []
37
37
  extensions: []
38
38
 
39
39
  extra_rdoc_files:
40
+ - lib/core_extensions.rb
41
+ - lib/httparty/exceptions.rb
40
42
  - lib/httparty/request.rb
41
43
  - lib/httparty/version.rb
42
44
  - lib/httparty.rb
45
+ - lib/module_level_inheritable_attributes.rb
43
46
  - README
44
47
  files:
45
48
  - examples/aaws.rb
@@ -51,14 +54,21 @@ files:
51
54
  - examples/whoismyrep.rb
52
55
  - History
53
56
  - httparty.gemspec
57
+ - lib/core_extensions.rb
58
+ - lib/httparty/exceptions.rb
54
59
  - lib/httparty/request.rb
55
60
  - lib/httparty/version.rb
56
61
  - lib/httparty.rb
62
+ - lib/module_level_inheritable_attributes.rb
57
63
  - Manifest
58
64
  - MIT-LICENSE
59
65
  - Rakefile
60
66
  - README
61
67
  - setup.rb
68
+ - spec/fixtures/delicious.xml
69
+ - spec/fixtures/google.html
70
+ - spec/fixtures/twitter.json
71
+ - spec/fixtures/twitter.xml
62
72
  - spec/httparty/request_spec.rb
63
73
  - spec/httparty_spec.rb
64
74
  - spec/spec.opts