httparty2 0.7.10

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.
Files changed (71) hide show
  1. data/.gitignore +9 -0
  2. data/Gemfile +6 -0
  3. data/History +253 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.rdoc +54 -0
  6. data/Rakefile +13 -0
  7. data/bin/httparty +108 -0
  8. data/cucumber.yml +1 -0
  9. data/examples/aaws.rb +32 -0
  10. data/examples/basic.rb +32 -0
  11. data/examples/custom_parsers.rb +67 -0
  12. data/examples/delicious.rb +37 -0
  13. data/examples/google.rb +16 -0
  14. data/examples/rubyurl.rb +14 -0
  15. data/examples/tripit_sign_in.rb +33 -0
  16. data/examples/twitter.rb +31 -0
  17. data/examples/whoismyrep.rb +10 -0
  18. data/features/basic_authentication.feature +20 -0
  19. data/features/command_line.feature +7 -0
  20. data/features/deals_with_http_error_codes.feature +26 -0
  21. data/features/digest_authentication.feature +20 -0
  22. data/features/handles_compressed_responses.feature +19 -0
  23. data/features/handles_multiple_formats.feature +34 -0
  24. data/features/steps/env.rb +22 -0
  25. data/features/steps/httparty_response_steps.rb +26 -0
  26. data/features/steps/httparty_steps.rb +27 -0
  27. data/features/steps/mongrel_helper.rb +94 -0
  28. data/features/steps/remote_service_steps.rb +69 -0
  29. data/features/supports_redirection.feature +22 -0
  30. data/features/supports_timeout_option.feature +13 -0
  31. data/httparty.gemspec +31 -0
  32. data/lib/httparty.rb +455 -0
  33. data/lib/httparty/cookie_hash.rb +22 -0
  34. data/lib/httparty/core_extensions.rb +9 -0
  35. data/lib/httparty/exceptions.rb +26 -0
  36. data/lib/httparty/module_inheritable_attributes.rb +34 -0
  37. data/lib/httparty/net_digest_auth.rb +71 -0
  38. data/lib/httparty/parser.rb +140 -0
  39. data/lib/httparty/request.rb +252 -0
  40. data/lib/httparty/response.rb +85 -0
  41. data/lib/httparty/version.rb +3 -0
  42. data/spec/fixtures/delicious.xml +23 -0
  43. data/spec/fixtures/empty.xml +0 -0
  44. data/spec/fixtures/google.html +3 -0
  45. data/spec/fixtures/ssl/generate.sh +29 -0
  46. data/spec/fixtures/ssl/generated/1fe462c2.0 +16 -0
  47. data/spec/fixtures/ssl/generated/bogushost.crt +13 -0
  48. data/spec/fixtures/ssl/generated/ca.crt +16 -0
  49. data/spec/fixtures/ssl/generated/ca.key +15 -0
  50. data/spec/fixtures/ssl/generated/selfsigned.crt +14 -0
  51. data/spec/fixtures/ssl/generated/server.crt +13 -0
  52. data/spec/fixtures/ssl/generated/server.key +15 -0
  53. data/spec/fixtures/ssl/openssl-exts.cnf +9 -0
  54. data/spec/fixtures/twitter.json +1 -0
  55. data/spec/fixtures/twitter.xml +403 -0
  56. data/spec/fixtures/undefined_method_add_node_for_nil.xml +2 -0
  57. data/spec/httparty/cookie_hash_spec.rb +71 -0
  58. data/spec/httparty/net_digest_auth_spec.rb +93 -0
  59. data/spec/httparty/parser_spec.rb +155 -0
  60. data/spec/httparty/request_spec.rb +496 -0
  61. data/spec/httparty/response_spec.rb +193 -0
  62. data/spec/httparty/ssl_spec.rb +54 -0
  63. data/spec/httparty_spec.rb +621 -0
  64. data/spec/spec.opts +3 -0
  65. data/spec/spec_helper.rb +23 -0
  66. data/spec/support/ssl_test_helper.rb +25 -0
  67. data/spec/support/ssl_test_server.rb +69 -0
  68. data/spec/support/stub_response.rb +30 -0
  69. data/website/css/common.css +47 -0
  70. data/website/index.html +73 -0
  71. metadata +206 -0
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --format documentation
3
+ --backtrace
@@ -0,0 +1,23 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ require 'httparty'
4
+ require 'fakeweb'
5
+
6
+ def file_fixture(filename)
7
+ open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename.to_s}")).read
8
+ end
9
+
10
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
11
+
12
+ RSpec.configure do |config|
13
+ config.include HTTParty::StubResponse
14
+ config.include HTTParty::SSLTestHelper
15
+
16
+ config.before(:suite) do
17
+ FakeWeb.allow_net_connect = false
18
+ end
19
+
20
+ config.after(:suite) do
21
+ FakeWeb.allow_net_connect = true
22
+ end
23
+ end
@@ -0,0 +1,25 @@
1
+ module HTTParty
2
+ module SSLTestHelper
3
+ def ssl_verify_test(mode, ca_basename, server_cert_filename)
4
+ test_server = nil
5
+ begin
6
+ # Start an HTTPS server
7
+ test_server = SSLTestServer.new(
8
+ :rsa_key => File.read(File.expand_path("../../fixtures/ssl/generated/server.key", __FILE__)),
9
+ :cert => File.read(File.expand_path("../../fixtures/ssl/generated/#{server_cert_filename}", __FILE__)))
10
+ test_server.start
11
+
12
+ # Build a request
13
+ if mode
14
+ ca_path = File.expand_path("../../fixtures/ssl/generated/#{ca_basename}", __FILE__)
15
+ raise ArgumentError.new("#{ca_path} does not exist") unless File.exist?(ca_path)
16
+ return HTTParty.get("https://localhost:#{test_server.port}/", :format => :json, :timeout=>30, mode => ca_path)
17
+ else
18
+ return HTTParty.get("https://localhost:#{test_server.port}/", :format => :json, :timeout=>30)
19
+ end
20
+ ensure
21
+ test_server.stop if test_server
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,69 @@
1
+ require 'openssl'
2
+ require 'socket'
3
+ require 'thread'
4
+
5
+ # NOTE: This code is garbage. It probably has deadlocks, it might leak
6
+ # threads, and otherwise cause problems in a real system. It's really only
7
+ # intended for testing HTTParty.
8
+ class SSLTestServer
9
+ attr_accessor :ctx # SSLContext object
10
+ attr_reader :port
11
+
12
+ def initialize(options={})
13
+ @ctx = OpenSSL::SSL::SSLContext.new
14
+ @ctx.cert = OpenSSL::X509::Certificate.new(options[:cert])
15
+ @ctx.key = OpenSSL::PKey::RSA.new(options[:rsa_key])
16
+ @ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE # Don't verify client certificate
17
+ @port = options[:port] || 0
18
+ @thread = nil
19
+ @stopping_mutex = Mutex.new
20
+ @stopping = false
21
+ end
22
+
23
+ def start
24
+ @raw_server = TCPServer.new(@port)
25
+ if @port == 0
26
+ @port = Socket::getnameinfo(@raw_server.getsockname, Socket::NI_NUMERICHOST|Socket::NI_NUMERICSERV)[1].to_i
27
+ end
28
+ @ssl_server = OpenSSL::SSL::SSLServer.new(@raw_server, @ctx)
29
+ @stopping_mutex.synchronize{
30
+ return if @stopping
31
+ @thread = Thread.new{ thread_main }
32
+ }
33
+ nil
34
+ end
35
+
36
+ def stop
37
+ @stopping_mutex.synchronize{
38
+ return if @stopping
39
+ @stopping = true
40
+ }
41
+ @thread.join
42
+ end
43
+
44
+ private
45
+
46
+ def thread_main
47
+ until @stopping_mutex.synchronize{ @stopping }
48
+ (rr,ww,ee) = select([@ssl_server.to_io], nil, nil, 0.1)
49
+ next unless rr && rr.include?(@ssl_server.to_io)
50
+ socket = @ssl_server.accept
51
+ Thread.new{
52
+ header = []
53
+ until (line = socket.readline).rstrip.empty?
54
+ header << line
55
+ end
56
+
57
+ socket.write <<'EOF'.gsub(/\r\n/n, "\n").gsub(/\n/n, "\r\n")
58
+ HTTP/1.1 200 OK
59
+ Connection: close
60
+ Content-Type: application/json; charset=UTF-8
61
+
62
+ {"success":true}
63
+ EOF
64
+ socket.close
65
+ }
66
+ end
67
+ @ssl_server.close
68
+ end
69
+ end
@@ -0,0 +1,30 @@
1
+ module HTTParty
2
+ module StubResponse
3
+ def stub_http_response_with(filename)
4
+ format = filename.split('.').last.intern
5
+ data = file_fixture(filename)
6
+
7
+ response = Net::HTTPOK.new("1.1", 200, "Content for you")
8
+ response.stub!(:body).and_return(data)
9
+
10
+ http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', :format => format)
11
+ http_request.stub_chain(:http, :request).and_return(response)
12
+
13
+ HTTParty::Request.should_receive(:new).and_return(http_request)
14
+ end
15
+
16
+ def stub_response(body, code = 200)
17
+ @request.options[:base_uri] ||= 'http://localhost'
18
+ unless defined?(@http) && @http
19
+ @http = Net::HTTP.new('localhost', 80)
20
+ @request.stub!(:http).and_return(@http)
21
+ end
22
+
23
+ response = Net::HTTPResponse::CODE_TO_OBJ[code.to_s].new("1.1", code, body)
24
+ response.stub!(:body).and_return(body)
25
+
26
+ @http.stub!(:request).and_return(response)
27
+ response
28
+ end
29
+ end
30
+ 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
+ }
@@ -0,0 +1,73 @@
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://rubyforge.org/projects/httparty/">Rubyforge</a></li>
19
+ </ul>
20
+ </div>
21
+
22
+ <div id="content">
23
+ <h2>Install</h2>
24
+ <pre><code>$ sudo gem install httparty</code></pre>
25
+
26
+ <h2>Some Quick Examples</h2>
27
+
28
+ <p>The following is a simple example of wrapping Twitter's API for posting updates.</p>
29
+
30
+ <pre><code>class Twitter
31
+ include HTTParty
32
+ base_uri 'twitter.com'
33
+ basic_auth 'username', 'password'
34
+ end
35
+
36
+ Twitter.post('/statuses/update.json', :query => {:status => "It's an HTTParty and everyone is invited!"})</code></pre>
37
+
38
+ <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>
39
+
40
+ <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>
41
+
42
+ <pre><code>class Twitter
43
+ include HTTParty
44
+ base_uri 'twitter.com'
45
+
46
+ def initialize(u, p)
47
+ @auth = {:username => u, :password => p}
48
+ end
49
+
50
+ def post(text)
51
+ options = { :query => {:status => text}, :basic_auth => @auth }
52
+ self.class.post('/statuses/update.json', options)
53
+ end
54
+ end
55
+
56
+ Twitter.new('username', 'password').post("It's an HTTParty and everyone is invited!")</code></pre>
57
+
58
+ <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>
59
+
60
+ <h2>Support</h2>
61
+ <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://github.com/jnunemaker/httparty">Github</a>.</p>
62
+
63
+
64
+ </div>
65
+
66
+ <div id="footer">
67
+ <p>Created by <a href="http://addictedtonew.com/about/">John Nunemaker</a> |
68
+ <a href="http://orderedlist.com/">Hire Me at Ordered List</a></p>
69
+ </div>
70
+ </div>
71
+
72
+ </body>
73
+ </html>
metadata ADDED
@@ -0,0 +1,206 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: httparty2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.10
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Anderson De Andrade
9
+ - John Nunemaker
10
+ - Sandro Turriate
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2011-07-18 00:00:00.000000000Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: activesupport
18
+ requirement: &7916900 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: '3.0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *7916900
27
+ - !ruby/object:Gem::Dependency
28
+ name: multi_json
29
+ requirement: &7916400 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '1.0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *7916400
38
+ - !ruby/object:Gem::Dependency
39
+ name: multi_xml
40
+ requirement: &7915940 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '0.2'
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: *7915940
49
+ - !ruby/object:Gem::Dependency
50
+ name: activesupport
51
+ requirement: &7915480 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: '3.0'
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *7915480
60
+ - !ruby/object:Gem::Dependency
61
+ name: cucumber
62
+ requirement: &7914960 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: '1.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *7914960
71
+ - !ruby/object:Gem::Dependency
72
+ name: fakeweb
73
+ requirement: &7914460 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: '1.2'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *7914460
82
+ - !ruby/object:Gem::Dependency
83
+ name: rspec
84
+ requirement: &7913980 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '2.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: *7913980
93
+ - !ruby/object:Gem::Dependency
94
+ name: mongrel
95
+ requirement: &7913520 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - =
99
+ - !ruby/object:Gem::Version
100
+ version: 1.2.0.pre2
101
+ type: :development
102
+ prerelease: false
103
+ version_requirements: *7913520
104
+ description: Makes http fun! Also, makes consuming restful web services dead easy.
105
+ email:
106
+ - adeandradeds@gmail.com
107
+ executables:
108
+ - httparty
109
+ extensions: []
110
+ extra_rdoc_files: []
111
+ files:
112
+ - .gitignore
113
+ - Gemfile
114
+ - History
115
+ - MIT-LICENSE
116
+ - README.rdoc
117
+ - Rakefile
118
+ - bin/httparty
119
+ - cucumber.yml
120
+ - examples/aaws.rb
121
+ - examples/basic.rb
122
+ - examples/custom_parsers.rb
123
+ - examples/delicious.rb
124
+ - examples/google.rb
125
+ - examples/rubyurl.rb
126
+ - examples/tripit_sign_in.rb
127
+ - examples/twitter.rb
128
+ - examples/whoismyrep.rb
129
+ - features/basic_authentication.feature
130
+ - features/command_line.feature
131
+ - features/deals_with_http_error_codes.feature
132
+ - features/digest_authentication.feature
133
+ - features/handles_compressed_responses.feature
134
+ - features/handles_multiple_formats.feature
135
+ - features/steps/env.rb
136
+ - features/steps/httparty_response_steps.rb
137
+ - features/steps/httparty_steps.rb
138
+ - features/steps/mongrel_helper.rb
139
+ - features/steps/remote_service_steps.rb
140
+ - features/supports_redirection.feature
141
+ - features/supports_timeout_option.feature
142
+ - httparty.gemspec
143
+ - lib/httparty.rb
144
+ - lib/httparty/cookie_hash.rb
145
+ - lib/httparty/core_extensions.rb
146
+ - lib/httparty/exceptions.rb
147
+ - lib/httparty/module_inheritable_attributes.rb
148
+ - lib/httparty/net_digest_auth.rb
149
+ - lib/httparty/parser.rb
150
+ - lib/httparty/request.rb
151
+ - lib/httparty/response.rb
152
+ - lib/httparty/version.rb
153
+ - spec/fixtures/delicious.xml
154
+ - spec/fixtures/empty.xml
155
+ - spec/fixtures/google.html
156
+ - spec/fixtures/ssl/generate.sh
157
+ - spec/fixtures/ssl/generated/1fe462c2.0
158
+ - spec/fixtures/ssl/generated/bogushost.crt
159
+ - spec/fixtures/ssl/generated/ca.crt
160
+ - spec/fixtures/ssl/generated/ca.key
161
+ - spec/fixtures/ssl/generated/selfsigned.crt
162
+ - spec/fixtures/ssl/generated/server.crt
163
+ - spec/fixtures/ssl/generated/server.key
164
+ - spec/fixtures/ssl/openssl-exts.cnf
165
+ - spec/fixtures/twitter.json
166
+ - spec/fixtures/twitter.xml
167
+ - spec/fixtures/undefined_method_add_node_for_nil.xml
168
+ - spec/httparty/cookie_hash_spec.rb
169
+ - spec/httparty/net_digest_auth_spec.rb
170
+ - spec/httparty/parser_spec.rb
171
+ - spec/httparty/request_spec.rb
172
+ - spec/httparty/response_spec.rb
173
+ - spec/httparty/ssl_spec.rb
174
+ - spec/httparty_spec.rb
175
+ - spec/spec.opts
176
+ - spec/spec_helper.rb
177
+ - spec/support/ssl_test_helper.rb
178
+ - spec/support/ssl_test_server.rb
179
+ - spec/support/stub_response.rb
180
+ - website/css/common.css
181
+ - website/index.html
182
+ homepage: https://github.com/adeandrade/httparty
183
+ licenses: []
184
+ post_install_message: When you HTTParty, you must party hard!
185
+ rdoc_options: []
186
+ require_paths:
187
+ - lib
188
+ required_ruby_version: !ruby/object:Gem::Requirement
189
+ none: false
190
+ requirements:
191
+ - - ! '>='
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ required_rubygems_version: !ruby/object:Gem::Requirement
195
+ none: false
196
+ requirements:
197
+ - - ! '>='
198
+ - !ruby/object:Gem::Version
199
+ version: '0'
200
+ requirements: []
201
+ rubyforge_project:
202
+ rubygems_version: 1.8.6
203
+ signing_key:
204
+ specification_version: 3
205
+ summary: Makes http fun! Also, makes consuming restful web services dead easy.
206
+ test_files: []