httparty 0.6.1 → 0.7.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/.gitignore CHANGED
@@ -5,3 +5,4 @@ tmp/
5
5
  log/
6
6
  pkg/
7
7
  *.swp
8
+ /.bundle
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm gemset use httparty
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
@@ -0,0 +1,47 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ httparty (0.6.1)
5
+ crack (= 0.1.8)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activesupport (2.3.10)
11
+ builder (2.1.2)
12
+ cgi_multipart_eof_fix (2.5.0)
13
+ crack (0.1.8)
14
+ cucumber (0.9.2)
15
+ builder (~> 2.1.2)
16
+ diff-lcs (~> 1.1.2)
17
+ gherkin (~> 2.2.5)
18
+ json (~> 1.4.6)
19
+ term-ansicolor (~> 1.0.5)
20
+ daemons (1.1.0)
21
+ diff-lcs (1.1.2)
22
+ fakeweb (1.3.0)
23
+ fastthread (1.0.7)
24
+ gem_plugin (0.2.3)
25
+ gherkin (2.2.9)
26
+ json (~> 1.4.6)
27
+ term-ansicolor (~> 1.0.5)
28
+ json (1.4.6)
29
+ mongrel (1.1.5)
30
+ cgi_multipart_eof_fix (>= 2.4)
31
+ daemons (>= 1.0.3)
32
+ fastthread (>= 1.0.1)
33
+ gem_plugin (>= 0.2.3)
34
+ rspec (1.3.1)
35
+ term-ansicolor (1.0.5)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ activesupport (~> 2.3)
42
+ crack (= 0.1.8)
43
+ cucumber (~> 0.7)
44
+ fakeweb (~> 1.2)
45
+ httparty!
46
+ mongrel (~> 1.1)
47
+ rspec (~> 1.3)
data/History CHANGED
@@ -1,4 +1,20 @@
1
- == 0.6.1
1
+ == 0.7.0 2010-01-18
2
+ * minor enhancements
3
+ * Added query methods for HTTP status codes, i.e. response.success?
4
+ response.created? (thanks citizenparker)
5
+ * Added support for ssl_ca_file and ssl_ca_path (dlitz)
6
+ * Allow custom query string normalization. gh-8
7
+ * Unlock private keys with password (freerange)
8
+ * Added high level request documentation (phildarnowsky)
9
+ * Added basic post example (pbuckley)
10
+ * Response object has access to its corresponding request object
11
+ * Added example of siginin into tripit.com
12
+ * Added option to follow redirects (rkj). gh-56
13
+ * bug fixes
14
+ * Fixed superclass mismatch exception while running tests
15
+ (thanks dlitz http://github.com/dlitz/httparty/commit/48224f0615b32133afcff4718ad426df7a4b401b)
16
+
17
+ == 0.6.1 2010-07-07
2
18
  * minor enhancements
3
19
  * updated to crack 0.1.8
4
20
  * bug fixes
data/Rakefile CHANGED
@@ -19,13 +19,10 @@ begin
19
19
  gem.add_development_dependency "fakeweb", "~>1.2"
20
20
  gem.add_development_dependency "mongrel", "~>1.1"
21
21
  gem.add_development_dependency "rspec", "~>1.3"
22
+ gem.add_development_dependency "jeweler", "~>1.5"
22
23
  gem.post_install_message = "When you HTTParty, you must party hard!"
23
- gem.rubyforge_project = 'httparty'
24
24
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
25
25
  end
26
- Jeweler::RubyforgeTasks.new do |rubyforge|
27
- rubyforge.doc_task = "rdoc"
28
- end
29
26
  Jeweler::GemcutterTasks.new
30
27
  rescue LoadError
31
28
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
@@ -45,13 +42,10 @@ Spec::Rake::SpecTask.new(:rcov) do |spec|
45
42
  spec.rcov = true
46
43
  end
47
44
 
48
- task :spec => :check_dependencies
49
-
50
45
  begin
51
46
  require 'cucumber/rake/task'
52
47
  Cucumber::Rake::Task.new(:features)
53
48
 
54
- task :features => :check_dependencies
55
49
  rescue LoadError
56
50
  task :features do
57
51
  abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
@@ -75,11 +69,6 @@ Rake::RDocTask.new do |rdoc|
75
69
  rdoc.rdoc_files.include('lib/httparty.rb')
76
70
  end
77
71
 
78
- desc 'Upload website files to rubyforge'
79
- task :website do
80
- sh %{rsync -av website/ jnunemaker@rubyforge.org:/var/www/gforge-projects/httparty}
81
- end
82
-
83
72
  begin
84
73
  require 'yard'
85
74
  YARD::Rake::YardocTask.new do |t|
@@ -9,3 +9,24 @@ puts response.body, response.code, response.message, response.headers.inspect
9
9
  response.each do |item|
10
10
  puts item['user']['screen_name']
11
11
  end
12
+
13
+ # An example post to a minimal rails app in the development environment
14
+ # Note that "skip_before_filter :verify_authenticity_token" must be set in the
15
+ # "pears" controller for this example
16
+
17
+ class Partay
18
+ include HTTParty
19
+ base_uri 'http://localhost:3000'
20
+ end
21
+
22
+ options = {
23
+ :body => {
24
+ :pear => { # your resource
25
+ :foo => '123', # your columns/data
26
+ :bar => 'second',
27
+ :baz => 'last thing'
28
+ }
29
+ }
30
+ }
31
+
32
+ pp Partay.post('/pears.xml', options)
@@ -0,0 +1,33 @@
1
+ dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require File.join(dir, 'httparty')
3
+
4
+ class TripIt
5
+ include HTTParty
6
+ base_uri 'http://www.tripit.com'
7
+ debug_output
8
+
9
+ def initialize(email, password)
10
+ @email = email
11
+ response = self.class.get('/account/login')
12
+ response = self.class.post(
13
+ '/account/login',
14
+ :body => {
15
+ :login_email_address => email,
16
+ :login_password => password
17
+ },
18
+ :headers => {'Cookie' => response.headers['Set-Cookie']}
19
+ )
20
+ @cookie = response.request.options[:headers]['Cookie']
21
+ end
22
+
23
+ def account_settings
24
+ self.class.get('/account/edit', :headers => {'Cookie' => @cookie})
25
+ end
26
+
27
+ def logged_in?
28
+ account_settings.include? "You're logged in as #{@email}"
29
+ end
30
+ end
31
+
32
+ tripit = TripIt.new('email', 'password')
33
+ puts "Logged in: #{tripit.logged_in?}"
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{httparty}
8
- s.version = "0.6.1"
8
+ s.version = "0.7.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Nunemaker", "Sandro Turriate"]
12
- s.date = %q{2010-07-07}
12
+ s.date = %q{2011-01-18}
13
13
  s.default_executable = %q{httparty}
14
14
  s.description = %q{Makes http fun! Also, makes consuming restful web services dead easy.}
15
15
  s.email = %q{nunemaker@gmail.com}
@@ -19,12 +19,14 @@ Gem::Specification.new do |s|
19
19
  ]
20
20
  s.files = [
21
21
  ".gitignore",
22
+ ".rvmrc",
23
+ "Gemfile",
24
+ "Gemfile.lock",
22
25
  "History",
23
26
  "MIT-LICENSE",
24
27
  "Manifest",
25
28
  "README.rdoc",
26
29
  "Rakefile",
27
- "VERSION",
28
30
  "bin/httparty",
29
31
  "cucumber.yml",
30
32
  "examples/aaws.rb",
@@ -33,6 +35,7 @@ Gem::Specification.new do |s|
33
35
  "examples/delicious.rb",
34
36
  "examples/google.rb",
35
37
  "examples/rubyurl.rb",
38
+ "examples/tripit_sign_in.rb",
36
39
  "examples/twitter.rb",
37
40
  "examples/whoismyrep.rb",
38
41
  "features/basic_authentication.feature",
@@ -61,6 +64,15 @@ Gem::Specification.new do |s|
61
64
  "spec/fixtures/delicious.xml",
62
65
  "spec/fixtures/empty.xml",
63
66
  "spec/fixtures/google.html",
67
+ "spec/fixtures/ssl/generate.sh",
68
+ "spec/fixtures/ssl/generated/1fe462c2.0",
69
+ "spec/fixtures/ssl/generated/bogushost.crt",
70
+ "spec/fixtures/ssl/generated/ca.crt",
71
+ "spec/fixtures/ssl/generated/ca.key",
72
+ "spec/fixtures/ssl/generated/selfsigned.crt",
73
+ "spec/fixtures/ssl/generated/server.crt",
74
+ "spec/fixtures/ssl/generated/server.key",
75
+ "spec/fixtures/ssl/openssl-exts.cnf",
64
76
  "spec/fixtures/twitter.json",
65
77
  "spec/fixtures/twitter.xml",
66
78
  "spec/fixtures/undefined_method_add_node_for_nil.xml",
@@ -68,9 +80,12 @@ Gem::Specification.new do |s|
68
80
  "spec/httparty/parser_spec.rb",
69
81
  "spec/httparty/request_spec.rb",
70
82
  "spec/httparty/response_spec.rb",
83
+ "spec/httparty/ssl_spec.rb",
71
84
  "spec/httparty_spec.rb",
72
85
  "spec/spec.opts",
73
86
  "spec/spec_helper.rb",
87
+ "spec/support/ssl_test_helper.rb",
88
+ "spec/support/ssl_test_server.rb",
74
89
  "spec/support/stub_response.rb",
75
90
  "website/css/common.css",
76
91
  "website/index.html"
@@ -79,16 +94,18 @@ Gem::Specification.new do |s|
79
94
  s.post_install_message = %q{When you HTTParty, you must party hard!}
80
95
  s.rdoc_options = ["--charset=UTF-8"]
81
96
  s.require_paths = ["lib"]
82
- s.rubyforge_project = %q{httparty}
83
- s.rubygems_version = %q{1.3.6}
97
+ s.rubygems_version = %q{1.3.7}
84
98
  s.summary = %q{Makes http fun! Also, makes consuming restful web services dead easy.}
85
99
  s.test_files = [
86
100
  "spec/httparty/cookie_hash_spec.rb",
87
101
  "spec/httparty/parser_spec.rb",
88
102
  "spec/httparty/request_spec.rb",
89
103
  "spec/httparty/response_spec.rb",
104
+ "spec/httparty/ssl_spec.rb",
90
105
  "spec/httparty_spec.rb",
91
106
  "spec/spec_helper.rb",
107
+ "spec/support/ssl_test_helper.rb",
108
+ "spec/support/ssl_test_server.rb",
92
109
  "spec/support/stub_response.rb",
93
110
  "examples/aaws.rb",
94
111
  "examples/basic.rb",
@@ -96,6 +113,7 @@ Gem::Specification.new do |s|
96
113
  "examples/delicious.rb",
97
114
  "examples/google.rb",
98
115
  "examples/rubyurl.rb",
116
+ "examples/tripit_sign_in.rb",
99
117
  "examples/twitter.rb",
100
118
  "examples/whoismyrep.rb"
101
119
  ]
@@ -104,13 +122,14 @@ Gem::Specification.new do |s|
104
122
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
105
123
  s.specification_version = 3
106
124
 
107
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
125
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
108
126
  s.add_runtime_dependency(%q<crack>, ["= 0.1.8"])
109
127
  s.add_development_dependency(%q<activesupport>, ["~> 2.3"])
110
128
  s.add_development_dependency(%q<cucumber>, ["~> 0.7"])
111
129
  s.add_development_dependency(%q<fakeweb>, ["~> 1.2"])
112
130
  s.add_development_dependency(%q<mongrel>, ["~> 1.1"])
113
131
  s.add_development_dependency(%q<rspec>, ["~> 1.3"])
132
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5"])
114
133
  else
115
134
  s.add_dependency(%q<crack>, ["= 0.1.8"])
116
135
  s.add_dependency(%q<activesupport>, ["~> 2.3"])
@@ -118,6 +137,7 @@ Gem::Specification.new do |s|
118
137
  s.add_dependency(%q<fakeweb>, ["~> 1.2"])
119
138
  s.add_dependency(%q<mongrel>, ["~> 1.1"])
120
139
  s.add_dependency(%q<rspec>, ["~> 1.3"])
140
+ s.add_dependency(%q<jeweler>, ["~> 1.5"])
121
141
  end
122
142
  else
123
143
  s.add_dependency(%q<crack>, ["= 0.1.8"])
@@ -126,6 +146,7 @@ Gem::Specification.new do |s|
126
146
  s.add_dependency(%q<fakeweb>, ["~> 1.2"])
127
147
  s.add_dependency(%q<mongrel>, ["~> 1.1"])
128
148
  s.add_dependency(%q<rspec>, ["~> 1.3"])
149
+ s.add_dependency(%q<jeweler>, ["~> 1.5"])
129
150
  end
130
151
  end
131
152
 
@@ -11,8 +11,9 @@ require dir + 'httparty/module_inheritable_attributes'
11
11
  require dir + 'httparty/cookie_hash'
12
12
  require dir + 'httparty/net_digest_auth'
13
13
 
14
+ # @see HTTParty::ClassMethods
14
15
  module HTTParty
15
- VERSION = "0.6.1".freeze
16
+ VERSION = "0.7.0".freeze
16
17
  CRACK_DEPENDENCY = "0.1.8".freeze
17
18
 
18
19
  module AllowedFormatsDeprecation
@@ -37,7 +38,32 @@ module HTTParty
37
38
  base.instance_variable_set("@default_cookies", CookieHash.new)
38
39
  end
39
40
 
41
+ # == Common Request Options
42
+ # Request methods (get, post, put, delete, head, options) all take a common set of options. These are:
43
+ #
44
+ # [:+body+:] Body of the request. If passed a Hash, will try to normalize it first, by default passing it to ActiveSupport::to_params. Any other kind of object will get used as-is.
45
+ # [:+http_proxyaddr+:] Address of proxy server to use.
46
+ # [:+http_proxyport+:] Port of proxy server to use.
47
+ # [:+limit+:] Maximum number of redirects to follow. Takes precedences over :+no_follow+.
48
+ # [:+query+:] Query string, or a Hash representing it. Normalized according to the same rules as :+body+. If you specify this on a POST, you must use a Hash. See also HTTParty::ClassMethods.default_params.
49
+ # [:+timeout+:] Timeout for opening connection and reading data.
50
+ #
51
+ # There are also another set of options with names corresponding to various class methods. The methods in question are those that let you set a class-wide default, and the options override the defaults on a request-by-request basis. Those options are:
52
+ # * :+base_uri+: see HTTParty::ClassMethods.base_uri.
53
+ # * :+basic_auth+: see HTTParty::ClassMethods.basic_auth. Only one of :+basic_auth+ and :+digest_auth+ can be used at a time; if you try using both, you'll get an ArgumentError.
54
+ # * :+debug_output+: see HTTParty::ClassMethods.debug_output.
55
+ # * :+digest_auth+: see HTTParty::ClassMethods.digest_auth. Only one of :+basic_auth+ and :+digest_auth+ can be used at a time; if you try using both, you'll get an ArgumentError.
56
+ # * :+format+: see HTTParty::ClassMethods.format.
57
+ # * :+headers+: see HTTParty::ClassMethods.headers. Must be a Hash.
58
+ # * :+maintain_method_across_redirects+: see HTTParty::ClassMethods.maintain_method_across_redirects.
59
+ # * :+no_follow+: see HTTParty::ClassMethods.no_follow.
60
+ # * :+parser+: see HTTParty::ClassMethods.parser.
61
+ # * :+pem+: see HTTParty::ClassMethods.pem.
62
+ # * :+query_string_normalizer+: see HTTParty::ClassMethods.query_string_normalizer
63
+ # * :+ssl_ca_file+: see HTTParty::ClassMethods.ssl_ca_file.
64
+
40
65
  module ClassMethods
66
+
41
67
  extend AllowedFormatsDeprecation
42
68
 
43
69
  # Allows setting http proxy information to be used
@@ -83,6 +109,28 @@ module HTTParty
83
109
  default_options[:digest_auth] = {:username => u, :password => p}
84
110
  end
85
111
 
112
+ # Do not send rails style query strings.
113
+ # Specically, don't use bracket notation when sending an array
114
+ #
115
+ # For a query:
116
+ # get '/', :query => {:selected_ids => [1,2,3]}
117
+ #
118
+ # The default query string looks like this:
119
+ # /?selected_ids[]=1&selected_ids[]=2&selected_ids[]=3
120
+ #
121
+ # Call `disable_rails_query_string_format` to transform the query string
122
+ # into:
123
+ # /?selected_ids=1&selected_ids=2&selected_ids=3
124
+ #
125
+ # @example
126
+ # class Foo
127
+ # include HTTParty
128
+ # disable_rails_query_string_format
129
+ # end
130
+ def disable_rails_query_string_format
131
+ query_string_normalizer Request::NON_RAILS_QUERY_STRING_NORMALIZER
132
+ end
133
+
86
134
  # Allows setting default parameters to be appended to each request.
87
135
  # Great for api keys and such.
88
136
  #
@@ -136,6 +184,19 @@ module HTTParty
136
184
  default_cookies.add_cookies(h)
137
185
  end
138
186
 
187
+ # Proceed to the location header when an HTTP response dictates a redirect.
188
+ # Redirects are always followed by default.
189
+ #
190
+ # @example
191
+ # class Foo
192
+ # include HTTParty
193
+ # base_uri 'http://google.com'
194
+ # follow_redirects true
195
+ # end
196
+ def follow_redirects(value = true)
197
+ default_options[:follow_redirects] = value
198
+ end
199
+
139
200
  # Allows setting the format with which to parse.
140
201
  # Must be one of the allowed formats ie: json, xml
141
202
  #
@@ -195,10 +256,63 @@ module HTTParty
195
256
  #
196
257
  # class Foo
197
258
  # include HTTParty
198
- # pem File.read('/home/user/my.pem')
259
+ # pem File.read('/home/user/my.pem'), "optional password"
199
260
  # end
200
- def pem(pem_contents)
261
+ def pem(pem_contents, password=nil)
201
262
  default_options[:pem] = pem_contents
263
+ default_options[:pem_password] = password
264
+ end
265
+
266
+ # Override the way query strings are normalized.
267
+ # Helpful for overriding the default rails normalization of Array queries.
268
+ #
269
+ # For a query:
270
+ # get '/', :query => {:selected_ids => [1,2,3]}
271
+ #
272
+ # The default query string normalizer returns:
273
+ # /?selected_ids[]=1&selected_ids[]=2&selected_ids[]=3
274
+ #
275
+ # Let's change it to this:
276
+ # /?selected_ids=1&selected_ids=2&selected_ids=3
277
+ #
278
+ # Pass a Proc to the query normalizer which accepts the yielded query.
279
+ #
280
+ # @example Modifying Array query strings
281
+ # class ServiceWrapper
282
+ # include HTTParty
283
+ #
284
+ # query_string_normalizer proc { |query|
285
+ # query.map do |key, value|
286
+ # value.map {|v| "#{key}=#{v}"}
287
+ # end.join('&')
288
+ # }
289
+ # end
290
+ #
291
+ # @param [Proc] normalizer custom query string normalizer.
292
+ # @yield [Hash, String] query string
293
+ # @yieldreturn [Array] an array that will later be joined with '&'
294
+ def query_string_normalizer(normalizer)
295
+ default_options[:query_string_normalizer] = normalizer
296
+ end
297
+
298
+ # Allows setting an OpenSSL certificate authority file
299
+ #
300
+ # class Foo
301
+ # include HTTParty
302
+ # ssl_ca_file '/etc/ssl/certs/ca-certificates.crt'
303
+ # end
304
+ def ssl_ca_file(path)
305
+ default_options[:ssl_ca_file] = path
306
+ end
307
+
308
+ # Allows setting an OpenSSL certificate authority path (directory)
309
+ #
310
+ # class Foo
311
+ # include HTTParty
312
+ # ssl_ca_path '/etc/ssl/certs/'
313
+ # end
314
+ def ssl_ca_path(path)
315
+ default_options[:ssl_ca_path] = path
202
316
  end
203
317
 
204
318
  # Allows setting a custom parser for the response.