voxdolo-httparty 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History +108 -0
- data/MIT-LICENSE +20 -0
- data/Manifest +55 -0
- data/README +35 -0
- data/Rakefile +47 -0
- data/bin/httparty +98 -0
- data/cucumber.yml +1 -0
- data/examples/aaws.rb +32 -0
- data/examples/basic.rb +11 -0
- data/examples/delicious.rb +37 -0
- data/examples/google.rb +16 -0
- data/examples/rubyurl.rb +14 -0
- data/examples/twitter.rb +31 -0
- data/examples/whoismyrep.rb +10 -0
- data/features/basic_authentication.feature +20 -0
- data/features/command_line.feature +7 -0
- data/features/deals_with_http_error_codes.feature +26 -0
- data/features/handles_multiple_formats.feature +34 -0
- data/features/steps/env.rb +15 -0
- data/features/steps/httparty_response_steps.rb +26 -0
- data/features/steps/httparty_steps.rb +15 -0
- data/features/steps/mongrel_helper.rb +55 -0
- data/features/steps/remote_service_steps.rb +47 -0
- data/features/supports_redirection.feature +22 -0
- data/httparty.gemspec +37 -0
- data/lib/core_extensions.rb +175 -0
- data/lib/httparty/cookie_hash.rb +9 -0
- data/lib/httparty/exceptions.rb +7 -0
- data/lib/httparty/module_inheritable_attributes.rb +25 -0
- data/lib/httparty/parsers/json.rb +74 -0
- data/lib/httparty/parsers/xml.rb +209 -0
- data/lib/httparty/parsers.rb +4 -0
- data/lib/httparty/request.rb +139 -0
- data/lib/httparty/response.rb +17 -0
- data/lib/httparty/version.rb +3 -0
- data/lib/httparty.rb +201 -0
- data/setup.rb +1585 -0
- data/spec/fixtures/delicious.xml +23 -0
- data/spec/fixtures/empty.xml +0 -0
- data/spec/fixtures/google.html +3 -0
- data/spec/fixtures/twitter.json +1 -0
- data/spec/fixtures/twitter.xml +403 -0
- data/spec/fixtures/undefined_method_add_node_for_nil.xml +2 -0
- data/spec/hash_spec.rb +49 -0
- data/spec/httparty/cookie_hash_spec.rb +38 -0
- data/spec/httparty/parsers/json_spec.rb +42 -0
- data/spec/httparty/parsers/xml_spec.rb +445 -0
- data/spec/httparty/request_spec.rb +205 -0
- data/spec/httparty/response_spec.rb +53 -0
- data/spec/httparty_spec.rb +259 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/string_spec.rb +27 -0
- data/website/css/common.css +47 -0
- data/website/index.html +74 -0
- metadata +133 -0
@@ -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
|
@@ -0,0 +1,259 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe HTTParty do
|
4
|
+
before(:each) do
|
5
|
+
@klass = Class.new
|
6
|
+
@klass.instance_eval { include HTTParty }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "base uri" do
|
10
|
+
before(:each) do
|
11
|
+
@klass.base_uri('api.foo.com/v1')
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should have reader" do
|
15
|
+
@klass.base_uri.should == 'http://api.foo.com/v1'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should have writer' do
|
19
|
+
@klass.base_uri('http://api.foobar.com')
|
20
|
+
@klass.base_uri.should == 'http://api.foobar.com'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#normalize_base_uri" do
|
25
|
+
it "should add http if not present for non ssl requests" do
|
26
|
+
uri = HTTParty.normalize_base_uri('api.foobar.com')
|
27
|
+
uri.should == 'http://api.foobar.com'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should add https if not present for ssl requests" do
|
31
|
+
uri = HTTParty.normalize_base_uri('api.foo.com/v1:443')
|
32
|
+
uri.should == 'https://api.foo.com/v1:443'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should not remove https for ssl requests" do
|
36
|
+
uri = HTTParty.normalize_base_uri('https://api.foo.com/v1:443')
|
37
|
+
uri.should == 'https://api.foo.com/v1:443'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "headers" do
|
42
|
+
it "should default to empty hash" do
|
43
|
+
@klass.headers.should == {}
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should be able to be updated" do
|
47
|
+
init_headers = {:foo => 'bar', :baz => 'spax'}
|
48
|
+
@klass.headers init_headers
|
49
|
+
@klass.headers.should == init_headers
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "cookies" do
|
54
|
+
def expect_cookie_header(s)
|
55
|
+
HTTParty::Request.should_receive(:new) \
|
56
|
+
.with(anything, anything, hash_including({ :headers => { "cookie" => s } })) \
|
57
|
+
.and_return(mock("mock response", :perform => nil))
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should not be in the headers by default" do
|
61
|
+
HTTParty::Request.stub!(:new).and_return(stub(nil, :perform => nil))
|
62
|
+
@klass.get("")
|
63
|
+
@klass.headers.keys.should_not include("cookie")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should raise an ArgumentError if passed a non-Hash" do
|
67
|
+
lambda do
|
68
|
+
@klass.cookies("nonsense")
|
69
|
+
end.should raise_error(ArgumentError)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should allow a cookie to be specified with a one-off request" do
|
73
|
+
expect_cookie_header "type=snickerdoodle"
|
74
|
+
@klass.get("", :cookies => { :type => "snickerdoodle" })
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "when a cookie is set at the class level" do
|
78
|
+
before(:each) do
|
79
|
+
@klass.cookies({ :type => "snickerdoodle" })
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should include that cookie in the request" do
|
83
|
+
expect_cookie_header "type=snickerdoodle"
|
84
|
+
@klass.get("")
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should allow the class defaults to be overridden" do
|
88
|
+
expect_cookie_header "type=chocolate_chip"
|
89
|
+
|
90
|
+
@klass.get("", :cookies => { :type => "chocolate_chip" })
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "in a class with multiple methods that use different cookies" do
|
95
|
+
before(:each) do
|
96
|
+
@klass.instance_eval do
|
97
|
+
def first_method
|
98
|
+
get("first_method", :cookies => { :first_method_cookie => "foo" })
|
99
|
+
end
|
100
|
+
|
101
|
+
def second_method
|
102
|
+
get("second_method", :cookies => { :second_method_cookie => "foo" })
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should not allow cookies used in one method to carry over into other methods" do
|
108
|
+
expect_cookie_header "first_method_cookie=foo"
|
109
|
+
@klass.first_method
|
110
|
+
|
111
|
+
expect_cookie_header "second_method_cookie=foo"
|
112
|
+
@klass.second_method
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "default params" do
|
118
|
+
it "should default to empty hash" do
|
119
|
+
@klass.default_params.should == {}
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should be able to be updated" do
|
123
|
+
new_defaults = {:foo => 'bar', :baz => 'spax'}
|
124
|
+
@klass.default_params new_defaults
|
125
|
+
@klass.default_params.should == new_defaults
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "basic http authentication" do
|
130
|
+
it "should work" do
|
131
|
+
@klass.basic_auth 'foobar', 'secret'
|
132
|
+
@klass.default_options[:basic_auth].should == {:username => 'foobar', :password => 'secret'}
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "format" do
|
137
|
+
it "should allow xml" do
|
138
|
+
@klass.format :xml
|
139
|
+
@klass.default_options[:format].should == :xml
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should allow json" do
|
143
|
+
@klass.format :json
|
144
|
+
@klass.default_options[:format].should == :json
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should allow yaml" do
|
148
|
+
@klass.format :yaml
|
149
|
+
@klass.default_options[:format].should == :yaml
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'should not allow funky format' do
|
153
|
+
lambda do
|
154
|
+
@klass.format :foobar
|
155
|
+
end.should raise_error(HTTParty::UnsupportedFormat)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "with explicit override of automatic redirect handling" do
|
160
|
+
|
161
|
+
it "should fail with redirected GET" do
|
162
|
+
lambda do
|
163
|
+
@klass.get('/foo', :no_follow => true)
|
164
|
+
end.should raise_error(HTTParty::RedirectionTooDeep)
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should fail with redirected POST" do
|
168
|
+
lambda do
|
169
|
+
@klass.post('/foo', :no_follow => true)
|
170
|
+
end.should raise_error(HTTParty::RedirectionTooDeep)
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should fail with redirected DELETE" do
|
174
|
+
lambda do
|
175
|
+
@klass.delete('/foo', :no_follow => true)
|
176
|
+
end.should raise_error(HTTParty::RedirectionTooDeep)
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should fail with redirected PUT" do
|
180
|
+
lambda do
|
181
|
+
@klass.put('/foo', :no_follow => true)
|
182
|
+
end.should raise_error(HTTParty::RedirectionTooDeep)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe "with multiple class definitions" do
|
187
|
+
before(:each) do
|
188
|
+
@klass.instance_eval do
|
189
|
+
base_uri "http://first.com"
|
190
|
+
default_params :one => 1
|
191
|
+
end
|
192
|
+
|
193
|
+
@additional_klass = Class.new
|
194
|
+
@additional_klass.instance_eval do
|
195
|
+
include HTTParty
|
196
|
+
base_uri "http://second.com"
|
197
|
+
default_params :two => 2
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should not run over each others options" do
|
202
|
+
@klass.default_options.should == { :base_uri => 'http://first.com', :default_params => { :one => 1 } }
|
203
|
+
@additional_klass.default_options.should == { :base_uri => 'http://second.com', :default_params => { :two => 2 } }
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe "#get" do
|
208
|
+
it "should be able to get html" do
|
209
|
+
stub_http_response_with('google.html')
|
210
|
+
HTTParty.get('http://www.google.com').should == file_fixture('google.html')
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should be able parse response type json automatically" do
|
214
|
+
stub_http_response_with('twitter.json')
|
215
|
+
tweets = HTTParty.get('http://twitter.com/statuses/public_timeline.json')
|
216
|
+
tweets.size.should == 20
|
217
|
+
tweets.first['user'].should == {
|
218
|
+
"name" => "Pyk",
|
219
|
+
"url" => nil,
|
220
|
+
"id" => "7694602",
|
221
|
+
"description" => nil,
|
222
|
+
"protected" => false,
|
223
|
+
"screen_name" => "Pyk",
|
224
|
+
"followers_count" => 1,
|
225
|
+
"location" => "Opera Plaza, California",
|
226
|
+
"profile_image_url" => "http://static.twitter.com/images/default_profile_normal.png"
|
227
|
+
}
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should be able parse response type xml automatically" do
|
231
|
+
stub_http_response_with('twitter.xml')
|
232
|
+
tweets = HTTParty.get('http://twitter.com/statuses/public_timeline.xml')
|
233
|
+
tweets['statuses'].size.should == 20
|
234
|
+
tweets['statuses'].first['user'].should == {
|
235
|
+
"name" => "Magic 8 Bot",
|
236
|
+
"url" => nil,
|
237
|
+
"id" => "17656026",
|
238
|
+
"description" => "ask me a question",
|
239
|
+
"protected" => "false",
|
240
|
+
"screen_name" => "magic8bot",
|
241
|
+
"followers_count" => "90",
|
242
|
+
"profile_image_url" => "http://s3.amazonaws.com/twitter_production/profile_images/65565851/8ball_large_normal.jpg",
|
243
|
+
"location" => nil
|
244
|
+
}
|
245
|
+
end
|
246
|
+
|
247
|
+
it "should not get undefined method add_node for nil class for the following xml" do
|
248
|
+
stub_http_response_with('undefined_method_add_node_for_nil.xml')
|
249
|
+
result = HTTParty.get('http://foobar.com')
|
250
|
+
result.should == {"Entities"=>{"href"=>"https://s3-sandbox.parature.com/api/v1/5578/5633/Account", "results"=>"0", "total"=>"0", "page_size"=>"25", "page"=>"1"}}
|
251
|
+
end
|
252
|
+
|
253
|
+
it "should parse empty response fine" do
|
254
|
+
stub_http_response_with('empty.xml')
|
255
|
+
result = HTTParty.get('http://foobar.com')
|
256
|
+
result.should == nil
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
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
|
8
|
+
end
|
9
|
+
|
10
|
+
def stub_http_response_with(filename)
|
11
|
+
format = filename.split('.').last.intern
|
12
|
+
data = file_fixture(filename)
|
13
|
+
|
14
|
+
response = Net::HTTPOK.new("1.1", 200, "Content for you")
|
15
|
+
response.stub!(:body).and_return(data)
|
16
|
+
|
17
|
+
http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', :format => format)
|
18
|
+
http_request.stub!(:perform_actual_request).and_return(response)
|
19
|
+
|
20
|
+
HTTParty::Request.should_receive(:new).and_return(http_request)
|
21
|
+
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
|
@@ -0,0 +1,47 @@
|
|
1
|
+
@media screen, projection {
|
2
|
+
/*
|
3
|
+
Copyright (c) 2007, Yahoo! Inc. All rights reserved.
|
4
|
+
Code licensed under the BSD License:
|
5
|
+
http://developer.yahoo.net/yui/license.txt
|
6
|
+
version: 2.2.0
|
7
|
+
*/
|
8
|
+
body {font:13px arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small;}table {font-size:inherit;font:100%;}select, input, textarea {font:99% arial,helvetica,clean,sans-serif;}pre, code {font:115% monospace;*font-size:100%;}body * {line-height:1.22em;}
|
9
|
+
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}/*ol,ul {list-style:none;}*/caption,th {text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym {border:0;}
|
10
|
+
/* end of yahoo reset and fonts */
|
11
|
+
|
12
|
+
body {color:#333; background:#4b1a1a; line-height:1.3;}
|
13
|
+
p {margin:0 0 20px;}
|
14
|
+
a {color:#4b1a1a;}
|
15
|
+
a:hover {text-decoration:none;}
|
16
|
+
strong {font-weight:bold;}
|
17
|
+
em {font-style:italics;}
|
18
|
+
h1,h2,h3,h4,h5,h6 {font-weight:bold;}
|
19
|
+
h1 {font-size:197%; margin:30px 0; color:#4b1a1a;}
|
20
|
+
h2 {font-size:174%; margin:20px 0; color:#b8111a;}
|
21
|
+
h3 {font-size:152%; margin:10px 0;}
|
22
|
+
h4 {font-size:129%; margin:10px 0;}
|
23
|
+
pre {background:#eee; margin:0 0 20px; padding:20px; border:1px solid #ccc; font-size:100%; overflow:auto;}
|
24
|
+
code {font-size:100%; margin:0; padding:0;}
|
25
|
+
ul, ol {margin:10px 0 10px 25px;}
|
26
|
+
ol li {margin:0 0 10px;}
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
div#wrapper {background:#fff; width:560px; margin:0 auto; padding:20px; border:10px solid #bc8c46; border-width:0 10px;}
|
33
|
+
div#header {position:relative; border-bottom:1px dotted; margin:0 0 10px; padding:0 0 10px;}
|
34
|
+
div#header p {margin:0; padding:0;}
|
35
|
+
div#header h1 {margin:0; padding:0;}
|
36
|
+
ul#nav {position:absolute; top:0; right:0; list-style:none; margin:0; padding:0;}
|
37
|
+
ul#nav li {display:inline; padding:0 0 0 5px;}
|
38
|
+
ul#nav li a {}
|
39
|
+
div#content {}
|
40
|
+
div#footer {margin:40px 0 0; border-top:1px dotted; padding:10px 0 0;}
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
}
|
data/website/index.html
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
2
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
5
|
+
<title>HTTParty by John Nunemaker</title>
|
6
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
|
10
|
+
<div id="wrapper">
|
11
|
+
<div id="header">
|
12
|
+
<h1>HTTParty</h1>
|
13
|
+
<p>Tonight we're gonna HTTParty like it's 1999!</p>
|
14
|
+
|
15
|
+
<ul id="nav">
|
16
|
+
<li><a href="rdoc/">Docs</a></li>
|
17
|
+
<li><a href="http://github.com/jnunemaker/httparty">Github</a></li>
|
18
|
+
<li><a href="http://jnunemaker.lighthouseapp.com/projects/14842-httparty/tickets">Lighthouse</a></li>
|
19
|
+
<li><a href="http://rubyforge.org/projects/httparty/">Rubyforge</a></li>
|
20
|
+
</ul>
|
21
|
+
</div>
|
22
|
+
|
23
|
+
<div id="content">
|
24
|
+
<h2>Install</h2>
|
25
|
+
<pre><code>$ sudo gem install httparty</code></pre>
|
26
|
+
|
27
|
+
<h2>Some Quick Examples</h2>
|
28
|
+
|
29
|
+
<p>The following is a simple example of wrapping Twitter's API for posting updates.</p>
|
30
|
+
|
31
|
+
<pre><code>class Twitter
|
32
|
+
include HTTParty
|
33
|
+
base_uri 'twitter.com'
|
34
|
+
basic_auth 'username', 'password'
|
35
|
+
end
|
36
|
+
|
37
|
+
Twitter.post('/statuses/update.json', :query => {:status => "It's an HTTParty and everyone is invited!"})</code></pre>
|
38
|
+
|
39
|
+
<p>That is really it! The object returned is a ruby hash that is decoded from Twitter's json response. JSON parsing is used because of the .json extension in the path of the request. You can also explicitly set a format (see the examples). </p>
|
40
|
+
|
41
|
+
<p>That works and all but what if you don't want to embed your username and password in the class? Below is an example to fix that:</p>
|
42
|
+
|
43
|
+
<pre><code>class Twitter
|
44
|
+
include HTTParty
|
45
|
+
base_uri 'twitter.com'
|
46
|
+
|
47
|
+
def initialize(u, p)
|
48
|
+
@auth = {:username => u, :password => p}
|
49
|
+
end
|
50
|
+
|
51
|
+
def post(text)
|
52
|
+
options = { :query => {:status => text}, :basic_auth => @auth }
|
53
|
+
self.class.post('/statuses/update.json', options)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
Twitter.new('username', 'password').post("It's an HTTParty and everyone is invited!")</code></pre>
|
58
|
+
|
59
|
+
<p><strong>More Examples:</strong> There are <a href="http://github.com/jnunemaker/httparty/tree/master/examples/">several examples in the gem itself</a>.</p>
|
60
|
+
|
61
|
+
<h2>Support</h2>
|
62
|
+
<p>Conversations welcome in the <a href="http://groups.google.com/group/httparty-gem">google group</a> and bugs/features over at <a href="http://jnunemaker.lighthouseapp.com/projects/14842-httparty/overview">Lightouse</a>.</p>
|
63
|
+
|
64
|
+
|
65
|
+
</div>
|
66
|
+
|
67
|
+
<div id="footer">
|
68
|
+
<p>Created by <a href="http://addictedtonew.com/about/">John Nunemaker</a> |
|
69
|
+
<a href="http://orderedlist.com/">Hire Me at Ordered List</a></p>
|
70
|
+
</div>
|
71
|
+
</div>
|
72
|
+
|
73
|
+
</body>
|
74
|
+
</html>
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: voxdolo-httparty
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Nunemaker
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-02-10 00:00:00 -08:00
|
13
|
+
default_executable: httparty
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: echoe
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: Makes http fun! Also, makes consuming restful web services dead easy.
|
26
|
+
email: nunemaker@gmail.com
|
27
|
+
executables:
|
28
|
+
- httparty
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- bin/httparty
|
33
|
+
- lib/core_extensions.rb
|
34
|
+
- lib/httparty/cookie_hash.rb
|
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
|
40
|
+
- lib/httparty/request.rb
|
41
|
+
- lib/httparty/response.rb
|
42
|
+
- lib/httparty/version.rb
|
43
|
+
- lib/httparty.rb
|
44
|
+
- README
|
45
|
+
files:
|
46
|
+
- bin/httparty
|
47
|
+
- cucumber.yml
|
48
|
+
- examples/aaws.rb
|
49
|
+
- examples/basic.rb
|
50
|
+
- examples/delicious.rb
|
51
|
+
- examples/google.rb
|
52
|
+
- examples/rubyurl.rb
|
53
|
+
- examples/twitter.rb
|
54
|
+
- examples/whoismyrep.rb
|
55
|
+
- features/basic_authentication.feature
|
56
|
+
- features/command_line.feature
|
57
|
+
- features/deals_with_http_error_codes.feature
|
58
|
+
- features/handles_multiple_formats.feature
|
59
|
+
- features/steps/env.rb
|
60
|
+
- features/steps/httparty_response_steps.rb
|
61
|
+
- features/steps/httparty_steps.rb
|
62
|
+
- features/steps/mongrel_helper.rb
|
63
|
+
- features/steps/remote_service_steps.rb
|
64
|
+
- features/supports_redirection.feature
|
65
|
+
- History
|
66
|
+
- httparty.gemspec
|
67
|
+
- lib/core_extensions.rb
|
68
|
+
- lib/httparty/cookie_hash.rb
|
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
|
74
|
+
- lib/httparty/request.rb
|
75
|
+
- lib/httparty/response.rb
|
76
|
+
- lib/httparty/version.rb
|
77
|
+
- lib/httparty.rb
|
78
|
+
- Manifest
|
79
|
+
- MIT-LICENSE
|
80
|
+
- Rakefile
|
81
|
+
- README
|
82
|
+
- setup.rb
|
83
|
+
- spec/fixtures/delicious.xml
|
84
|
+
- spec/fixtures/empty.xml
|
85
|
+
- spec/fixtures/google.html
|
86
|
+
- spec/fixtures/twitter.json
|
87
|
+
- spec/fixtures/twitter.xml
|
88
|
+
- spec/fixtures/undefined_method_add_node_for_nil.xml
|
89
|
+
- spec/hash_spec.rb
|
90
|
+
- spec/httparty/cookie_hash_spec.rb
|
91
|
+
- spec/httparty/parsers/json_spec.rb
|
92
|
+
- spec/httparty/parsers/xml_spec.rb
|
93
|
+
- spec/httparty/request_spec.rb
|
94
|
+
- spec/httparty/response_spec.rb
|
95
|
+
- spec/httparty_spec.rb
|
96
|
+
- spec/spec.opts
|
97
|
+
- spec/spec_helper.rb
|
98
|
+
- spec/string_spec.rb
|
99
|
+
- website/css/common.css
|
100
|
+
- website/index.html
|
101
|
+
has_rdoc: true
|
102
|
+
homepage: http://httparty.rubyforge.org
|
103
|
+
post_install_message: When you HTTParty, you must party hard!
|
104
|
+
rdoc_options:
|
105
|
+
- --line-numbers
|
106
|
+
- --inline-source
|
107
|
+
- --title
|
108
|
+
- Httparty
|
109
|
+
- --main
|
110
|
+
- README
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: "0"
|
118
|
+
version:
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: "1.2"
|
124
|
+
version:
|
125
|
+
requirements: []
|
126
|
+
|
127
|
+
rubyforge_project: httparty
|
128
|
+
rubygems_version: 1.2.0
|
129
|
+
signing_key:
|
130
|
+
specification_version: 2
|
131
|
+
summary: Makes http fun! Also, makes consuming restful web services dead easy.
|
132
|
+
test_files: []
|
133
|
+
|