luigi-httparty 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/.gitignore +6 -0
  2. data/History +141 -0
  3. data/MIT-LICENSE +20 -0
  4. data/Manifest +47 -0
  5. data/README.rdoc +54 -0
  6. data/Rakefile +71 -0
  7. data/VERSION +1 -0
  8. data/bin/httparty +98 -0
  9. data/cucumber.yml +1 -0
  10. data/examples/aaws.rb +32 -0
  11. data/examples/basic.rb +11 -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/twitter.rb +31 -0
  16. data/examples/whoismyrep.rb +10 -0
  17. data/features/basic_authentication.feature +20 -0
  18. data/features/command_line.feature +7 -0
  19. data/features/deals_with_http_error_codes.feature +26 -0
  20. data/features/handles_multiple_formats.feature +34 -0
  21. data/features/steps/env.rb +16 -0
  22. data/features/steps/httparty_response_steps.rb +26 -0
  23. data/features/steps/httparty_steps.rb +19 -0
  24. data/features/steps/mongrel_helper.rb +56 -0
  25. data/features/steps/remote_service_steps.rb +52 -0
  26. data/features/supports_redirection.feature +22 -0
  27. data/features/supports_timeout_option.feature +12 -0
  28. data/httparty.gemspec +110 -0
  29. data/lib/httparty.rb +216 -0
  30. data/lib/httparty/cookie_hash.rb +22 -0
  31. data/lib/httparty/core_extensions.rb +25 -0
  32. data/lib/httparty/exceptions.rb +7 -0
  33. data/lib/httparty/module_inheritable_attributes.rb +25 -0
  34. data/lib/httparty/parsers.rb +31 -0
  35. data/lib/httparty/request.rb +175 -0
  36. data/lib/httparty/response.rb +23 -0
  37. data/lib/httparty/version.rb +3 -0
  38. data/spec/fixtures/delicious.xml +23 -0
  39. data/spec/fixtures/empty.xml +0 -0
  40. data/spec/fixtures/google.html +3 -0
  41. data/spec/fixtures/twitter.json +1 -0
  42. data/spec/fixtures/twitter.xml +403 -0
  43. data/spec/fixtures/undefined_method_add_node_for_nil.xml +2 -0
  44. data/spec/httparty/cookie_hash_spec.rb +71 -0
  45. data/spec/httparty/request_spec.rb +244 -0
  46. data/spec/httparty/response_spec.rb +68 -0
  47. data/spec/httparty_spec.rb +328 -0
  48. data/spec/spec.opts +2 -0
  49. data/spec/spec_helper.rb +24 -0
  50. data/website/css/common.css +47 -0
  51. data/website/index.html +73 -0
  52. metadata +136 -0
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ .DS_Store
2
+ doc/
3
+ tmp/
4
+ log/
5
+ pkg/
6
+ *.swp
data/History ADDED
@@ -0,0 +1,141 @@
1
+ == 0.4.5 2009-09-12
2
+ * bug fixes
3
+ * Fixed class-level headers overwritten by cookie management code. Closes #19
4
+ * Fixed "superclass mismatch for class BlankSlate" error. Closes #20
5
+ * Fixed reading files as post data from the command line (vesan)
6
+ * minor enhancements
7
+ * Timeout option added; will raise a Timeout::Error after the timeout has elapsed (attack). Closes #17
8
+ HTTParty.get "http://github.com", :timeout => 1
9
+ * Building gem with Jeweler
10
+
11
+ == 0.4.4 2009-07-19
12
+ * 2 minor update
13
+ * :query no longer sets form data. Use body and set content type to application/x-www-form-urlencoded if you need it. :query was wrong for that.
14
+ * Fixed a bug in the cookies class method that caused cookies to be forgotten after the first request.
15
+ * Also, some general cleanup of tests and such.
16
+
17
+ == 0.4.3 2009-04-23
18
+ * 1 minor update
19
+ * added message to the response object
20
+
21
+ == 0.4.2 2009-03-30
22
+ * 2 minor changes
23
+ * response code now returns an integer instead of a string (jqr)
24
+ * rubyforge project setup for crack so i'm now depending on that instead of jnunemaker-crack
25
+
26
+ == 0.4.1 2009-03-29
27
+ * 1 minor fix
28
+ * gem 'jnunemaker-crack' instead of gem 'crack'
29
+
30
+ == 0.4.0 2009-03-29
31
+ * 1 minor change
32
+ * Switched xml and json parsing to crack (same code as before just moved to gem for easier reuse in other projects)
33
+
34
+ == 0.3.1 2009-02-10
35
+ * 1 minor fix, 1 minor enhancement
36
+ * Fixed unescaping umlauts (siebertm)
37
+ * Added yaml response parsing (Miha Filej)
38
+
39
+ == 0.3.0 2009-01-31
40
+ * 1 major enhancement, 1 bug fix
41
+ * JSON gem no longer a requirement. It was conflicting with rails json stuff so I just stole ActiveSupport's json decoding and bundled it with HTTParty.
42
+ * Fixed bug where query strings were being duplicated on redirects
43
+ * Added a bunch of specs and moved some code around.
44
+
45
+ == 0.2.10 2009-01-29
46
+ * 1 minor enhancement
47
+ * Made encoding on query parameters treat everything except URI::PATTERN::UNRESERVED as UNSAFE to force encoding of '+' character (Julian Russell)
48
+
49
+ == 0.2.9 2009-01-29
50
+ * 3 minor enhancements
51
+ * Added a 'headers' accessor to the response with a hash of any HTTP headers. (Don Peterson)
52
+ * Add support for a ":cookies" option to be used at the class level, or as an option on any individual call. It should be passed a hash, which will be converted to the proper format and added to the request headers when the call is made. (Don Peterson)
53
+ * Refactored several specs and added a full suite of cucumber features (Don Peterson)
54
+
55
+ == 0.2.8 2009-01-28
56
+ * 1 major fix
57
+ * fixed major bug with response where it wouldn't iterate or really work at all with parsed responses
58
+
59
+ == 0.2.7 2009-01-28
60
+ * 2 minor fixes, 2 minor enhancements, 2 major enhancements
61
+ * fixed undefined method add_node for nil class error that occasionally happened (juliocesar)
62
+ * Handle nil or unexpected values better when typecasting. (Brian Landau)
63
+ * More robust handling of mime types (Alex Vollmer)
64
+ * Fixed support for specifying headers and added support for basic auth to CLI. (Alex Vollmer)
65
+ * Added first class response object that includes original body and status code (Alex Vollmer)
66
+ * Now parsing all response types as some non-200 responses provide important information, this means no more exception raising (Alex Vollmer)
67
+
68
+ == 0.2.6 2009-01-05
69
+ * 1 minor bug fix
70
+ * added explicit require of time as Time#parse failed outside of rails (willcodeforfoo)
71
+
72
+ == 0.2.5 2009-01-05
73
+ * 1 major enhancement
74
+ * Add command line interface to HTTParty (Alex Vollmer)
75
+
76
+ == 0.2.4 2008-12-23
77
+ * 1 bug fix
78
+ * Fixed that mimetype detection was failing if no mimetype was returned from service (skippy)
79
+ == 0.2.3 2008-12-23
80
+ * 1 bug fix
81
+ * Fixed typecasting class variable naming issue
82
+
83
+ == 0.2.2 2008-12-08
84
+ * 1 bug fix
85
+ * Added the missing core extension hash method to_xml_attributes
86
+
87
+ == 0.2.1 2008-12-08
88
+ * 1 bug fix
89
+ * Fixed that HTTParty was borking ActiveSupport and as such Rails (thanks to Rob Sanheim)
90
+
91
+ == 0.2.0 2008-12-07
92
+ * 1 major enhancement
93
+ * Removed ActiveSupport as a dependency. Now requires json gem for json deserialization and uses an included class to do the xml parsing.
94
+
95
+ == 0.1.8 2008-11-30
96
+ * 3 major enhancements
97
+ * Moved base_uri normalization into request class and out of httparty module, fixing
98
+ the problem where base_uri was not always being normalized.
99
+ * Stupid simple support for HTTParty.get/post/put/delete. (jqr)
100
+ * Switched gem management to Echoe from newgem.
101
+
102
+ == 0.1.7 2008-11-30
103
+ * 1 major enhancement
104
+ * fixed multiple class definitions overriding each others options
105
+
106
+ == 0.1.6 2008-11-26
107
+ * 1 major enhancement
108
+ * now passing :query to set_form_data if post request to avoid content length errors
109
+
110
+ == 0.1.5 2008-11-14
111
+ * 2 major enhancements
112
+ * Refactored send request method out into its own object.
113
+ * Added :html format if you just want to do that.
114
+
115
+ == 0.1.4 2008-11-08
116
+ * 3 major enhancements:
117
+ * Removed some cruft
118
+ * Added ability to follow redirects automatically and turn that off (Alex Vollmer)
119
+
120
+ == 0.1.3 2008-08-22
121
+
122
+ * 3 major enhancements:
123
+ * Added http_proxy key for setting proxy server and port (francxk@gmail.com)
124
+ * Now raises exception when http error occurs (francxk@gmail.com)
125
+ * Changed auto format detection from file extension to response content type (Jay Pignata)
126
+
127
+ == 0.1.2 2008-08-09
128
+
129
+ * 1 major enhancement:
130
+ * default_params were not being appended to query string if option[:query] was blank
131
+
132
+ == 0.1.1 2008-07-30
133
+
134
+ * 2 major enhancement:
135
+ * Added :basic_auth key for options when making a request
136
+ * :query and :body both now work with query string or hash
137
+
138
+ == 0.1.0 2008-07-27
139
+
140
+ * 1 major enhancement:
141
+ * Initial release
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 John Nunemaker
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest ADDED
@@ -0,0 +1,47 @@
1
+ bin/httparty
2
+ cucumber.yml
3
+ examples/aaws.rb
4
+ examples/basic.rb
5
+ examples/delicious.rb
6
+ examples/google.rb
7
+ examples/rubyurl.rb
8
+ examples/twitter.rb
9
+ examples/whoismyrep.rb
10
+ features/basic_authentication.feature
11
+ features/command_line.feature
12
+ features/deals_with_http_error_codes.feature
13
+ features/handles_multiple_formats.feature
14
+ features/steps/env.rb
15
+ features/steps/httparty_response_steps.rb
16
+ features/steps/httparty_steps.rb
17
+ features/steps/mongrel_helper.rb
18
+ features/steps/remote_service_steps.rb
19
+ features/supports_redirection.feature
20
+ History
21
+ httparty.gemspec
22
+ lib/httparty/cookie_hash.rb
23
+ lib/httparty/core_extensions.rb
24
+ lib/httparty/exceptions.rb
25
+ lib/httparty/module_inheritable_attributes.rb
26
+ lib/httparty/request.rb
27
+ lib/httparty/response.rb
28
+ lib/httparty/version.rb
29
+ lib/httparty.rb
30
+ Manifest
31
+ MIT-LICENSE
32
+ Rakefile
33
+ README.rdoc
34
+ spec/fixtures/delicious.xml
35
+ spec/fixtures/empty.xml
36
+ spec/fixtures/google.html
37
+ spec/fixtures/twitter.json
38
+ spec/fixtures/twitter.xml
39
+ spec/fixtures/undefined_method_add_node_for_nil.xml
40
+ spec/httparty/cookie_hash_spec.rb
41
+ spec/httparty/request_spec.rb
42
+ spec/httparty/response_spec.rb
43
+ spec/httparty_spec.rb
44
+ spec/spec.opts
45
+ spec/spec_helper.rb
46
+ website/css/common.css
47
+ website/index.html
data/README.rdoc ADDED
@@ -0,0 +1,54 @@
1
+ = httparty
2
+
3
+ Makes http fun again!
4
+
5
+ == Note on Releases
6
+
7
+ Releases are tagged on github and also released as gems on github and rubyforge. Master is pushed to whenever I add a patch or a new feature. To build from master, you can clone the code, generate the updated gemspec, build the gem and install.
8
+
9
+ * rake gemspec
10
+ * gem build httparty.gemspec
11
+ * gem install the gem that was built
12
+
13
+ == Note on Patches/Pull Requests
14
+
15
+ * Fork the project.
16
+ * Make your feature addition or bug fix.
17
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
18
+ * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself in another branch so I can ignore when I pull)
19
+ * Send me a pull request. Bonus points for topic branches.
20
+
21
+ == Features:
22
+
23
+ * Easy get, post requests
24
+ * Basic http authentication
25
+ * Default request query string parameters (ie: for api keys that are needed on each request)
26
+ * Automatic parsing of JSON and XML into ruby hashes based on response content-type
27
+
28
+ == Examples
29
+
30
+ See http://github.com/jnunemaker/httparty/tree/master/examples
31
+
32
+ == Command Line Interface
33
+
34
+ httparty also includes the executable <tt>httparty</tt> which can be
35
+ used to query web services and examine the resulting output. By default
36
+ it will output the response as a pretty-printed Ruby object (useful for
37
+ grokking the structure of output). This can also be overridden to output
38
+ formatted XML or JSON. Execute <tt>httparty --help</tt> for all the
39
+ options. Below is an example of how easy it is.
40
+
41
+ httparty "http://twitter.com/statuses/public_timeline.json"
42
+
43
+ == Requirements
44
+
45
+ * Crack http://github.com/jnunemaker/crack/ - For XML and JSON parsing.
46
+ * You like to party!
47
+
48
+ == Install
49
+
50
+ * sudo gem install httparty
51
+
52
+ == Docs
53
+
54
+ http://rdoc.info/projects/jnunemaker/httparty
data/Rakefile ADDED
@@ -0,0 +1,71 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "luigi-httparty"
8
+ gem.summary = %Q{Makes http fun! Also, makes consuming restful web services dead easy.}
9
+ gem.description = %Q{Makes http fun! Also, makes consuming restful web services dead easy.}
10
+ gem.email = "nunemaker@gmail.com"
11
+ gem.homepage = "http://httparty.rubyforge.org"
12
+ gem.authors = ["John Nunemaker", "Sandro Turriate"]
13
+ gem.add_dependency 'crack', '>= 0.1.1'
14
+ gem.add_development_dependency "rspec", "1.2.8"
15
+ gem.post_install_message = "When you HTTParty, you must party hard!"
16
+ gem.rubyforge_project = 'httparty'
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::RubyforgeTasks.new do |rubyforge|
20
+ rubyforge.doc_task = "rdoc"
21
+ end
22
+ rescue LoadError
23
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
24
+ end
25
+
26
+ require 'spec/rake/spectask'
27
+ Spec::Rake::SpecTask.new(:spec) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.spec_files = FileList['spec/**/*_spec.rb']
30
+ spec.spec_opts = ['--options', 'spec/spec.opts']
31
+ end
32
+
33
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
34
+ spec.libs << 'lib' << 'spec'
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :spec => :check_dependencies
40
+
41
+ begin
42
+ require 'cucumber/rake/task'
43
+ Cucumber::Rake::Task.new(:features)
44
+
45
+ task :features => :check_dependencies
46
+ rescue LoadError
47
+ task :features do
48
+ abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
49
+ end
50
+ end
51
+
52
+ task :default => [:spec, :features]
53
+
54
+ require 'rake/rdoctask'
55
+ Rake::RDocTask.new do |rdoc|
56
+ if File.exist?('VERSION')
57
+ version = File.read('VERSION')
58
+ else
59
+ version = ""
60
+ end
61
+
62
+ rdoc.rdoc_dir = 'rdoc'
63
+ rdoc.title = "httparty #{version}"
64
+ rdoc.rdoc_files.include('README*')
65
+ rdoc.rdoc_files.include('lib/**/*.rb')
66
+ end
67
+
68
+ desc 'Upload website files to rubyforge'
69
+ task :website do
70
+ sh %{rsync -av website/ jnunemaker@rubyforge.org:/var/www/gforge-projects/httparty}
71
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.4.6
data/bin/httparty ADDED
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "optparse"
4
+ require "pp"
5
+
6
+ $:.unshift(File.join(File.dirname(__FILE__), "/../lib"))
7
+ require "httparty"
8
+
9
+ opts = {
10
+ :action => :get,
11
+ :headers => {},
12
+ :verbose => false
13
+ }
14
+
15
+ def die(msg)
16
+ STDERR.puts(msg)
17
+ exit 1
18
+ end
19
+
20
+ OptionParser.new do |o|
21
+ o.banner = "USAGE: #{$0} [options] [url]"
22
+
23
+ o.on("-f",
24
+ "--format [FORMAT]",
25
+ "Output format to use instead of pretty-print ruby: " +
26
+ "plain, json or xml") do |f|
27
+ opts[:output_format] = f.downcase.to_sym
28
+ end
29
+
30
+ o.on("-a",
31
+ "--action [ACTION]",
32
+ "HTTP action: get (default), post, put or delete") do |a|
33
+ opts[:action] = a.downcase.to_sym
34
+ end
35
+
36
+ o.on("-d",
37
+ "--data [BODY]",
38
+ "Data to put in request body (prefix with '@' for file)") do |d|
39
+ if d =~ /^@/
40
+ opts[:data] = open(d[1..-1]).read
41
+ else
42
+ opts[:data] = d
43
+ end
44
+ end
45
+
46
+ o.on("-H", "--header [NAME=VALUE]", "Additional HTTP headers in NAME=VALUE form") do |h|
47
+ die "Invalid header specification, should be Name:Value" unless h =~ /.+:.+/
48
+ name, value = h.split(':')
49
+ opts[:headers][name.strip] = value.strip
50
+ end
51
+
52
+ o.on("-v", "--verbose", "If set, print verbose output") do |v|
53
+ opts[:verbose] = true
54
+ end
55
+
56
+ o.on("-u", "--user [CREDS]", "Use basic authentication. Value should be user:password") do |u|
57
+ die "Invalid credentials format. Must be user:password" unless u =~ /.+:.+/
58
+ user, password = u.split(':')
59
+ opts[:basic_auth] = { :username => user, :password => password }
60
+ end
61
+
62
+ o.on("-h", "--help", "Show help documentation") do |h|
63
+ puts o
64
+ exit
65
+ end
66
+ end.parse!
67
+
68
+ puts "Querying #{ARGV.first} with options: #{opts.inspect}" if opts[:verbose]
69
+
70
+ if ARGV.empty?
71
+ STDERR.puts "You need to provide a URL"
72
+ STDERR.puts "USAGE: #{$0} [options] [url]"
73
+ end
74
+
75
+ if opts[:output_format].nil?
76
+ response = HTTParty.send(opts[:action], ARGV.first, opts)
77
+ puts "Status: #{response.code}"
78
+ pp response
79
+ else
80
+ print_format = opts[:output_format]
81
+ response = HTTParty.send(opts[:action], ARGV.first, opts)
82
+ puts "Status: #{response.code}"
83
+ case opts[:output_format]
84
+ when :json
85
+ begin
86
+ require 'rubygems'
87
+ require 'json'
88
+ puts JSON.pretty_generate(response.delegate)
89
+ rescue LoadError
90
+ puts YAML.dump(response.delegate)
91
+ end
92
+ when :xml
93
+ REXML::Document.new(response.body).write(STDOUT, 2)
94
+ puts
95
+ else
96
+ puts response
97
+ end
98
+ end