alexvollmer-httparty 0.1.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/History ADDED
@@ -0,0 +1,74 @@
1
+ == 0.2.6 2009-01-05
2
+ * 1 minor bug fix
3
+ * added explicit require of time as Time#parse failed outside of rails (willcodeforfoo)
4
+
5
+ == 0.2.5 2009-01-05
6
+ * 1 major enhancement
7
+ * Add command line interface to HTTParty (Alex Vollmer)
8
+
9
+ == 0.2.4 2008-12-23
10
+ * 1 bug fix
11
+ * Fixed that mimetype detection was failing if no mimetype was returned from service (skippy)
12
+ == 0.2.3 2008-12-23
13
+ * 1 bug fix
14
+ * Fixed typecasting class variable naming issue
15
+
16
+ == 0.2.2 2008-12-08
17
+ * 1 bug fix
18
+ * Added the missing core extension hash method to_xml_attributes
19
+
20
+ == 0.2.1 2008-12-08
21
+ * 1 bug fix
22
+ * Fixed that HTTParty was borking ActiveSupport and as such Rails (thanks to Rob Sanheim)
23
+
24
+ == 0.2.0 2008-12-07
25
+ * 1 major enhancement
26
+ * Removed ActiveSupport as a dependency. Now requires json gem for json deserialization and uses an included class to do the xml parsing.
27
+
28
+ == 0.1.8 2008-11-30
29
+ * 3 major enhancements
30
+ * Moved base_uri normalization into request class and out of httparty module, fixing
31
+ the problem where base_uri was not always being normalized.
32
+ * Stupid simple support for HTTParty.get/post/put/delete. (jqr)
33
+ * Switched gem management to Echoe from newgem.
34
+
35
+ == 0.1.7 2008-11-30
36
+ * 1 major enhancement
37
+ * fixed multiple class definitions overriding each others options
38
+
39
+ == 0.1.6 2008-11-26
40
+ * 1 major enhancement
41
+ * now passing :query to set_form_data if post request to avoid content length errors
42
+
43
+ == 0.1.5 2008-11-14
44
+ * 2 major enhancements
45
+ * Refactored send request method out into its own object.
46
+ * Added :html format if you just want to do that.
47
+
48
+ == 0.1.4 2008-11-08
49
+ * 3 major enhancements:
50
+ * Removed some cruft
51
+ * Added ability to follow redirects automatically and turn that off (Alex Vollmer)
52
+
53
+ == 0.1.3 2008-08-22
54
+
55
+ * 3 major enhancements:
56
+ * Added http_proxy key for setting proxy server and port (francxk@gmail.com)
57
+ * Now raises exception when http error occurs (francxk@gmail.com)
58
+ * Changed auto format detection from file extension to response content type (Jay Pignata)
59
+
60
+ == 0.1.2 2008-08-09
61
+
62
+ * 1 major enhancement:
63
+ * default_params were not being appended to query string if option[:query] was blank
64
+
65
+ == 0.1.1 2008-07-30
66
+
67
+ * 2 major enhancement:
68
+ * Added :basic_auth key for options when making a request
69
+ * :query and :body both now work with query string or hash
70
+
71
+ == 0.1.0 2008-07-27
72
+
73
+ * 1 major enhancement:
74
+ * Initial release
File without changes
@@ -1,31 +1,32 @@
1
- History.txt
2
- License.txt
3
- Manifest.txt
4
- PostInstall.txt
5
- README.txt
6
- Rakefile
7
- config/hoe.rb
8
- config/requirements.rb
1
+ bin/httparty
9
2
  examples/aaws.rb
3
+ examples/basic.rb
10
4
  examples/delicious.rb
11
5
  examples/google.rb
6
+ examples/rubyurl.rb
12
7
  examples/twitter.rb
13
8
  examples/whoismyrep.rb
9
+ History
14
10
  httparty.gemspec
15
- lib/httparty.rb
11
+ lib/core_extensions.rb
12
+ lib/httparty/exceptions.rb
16
13
  lib/httparty/request.rb
17
14
  lib/httparty/version.rb
18
- script/console
19
- script/destroy
20
- script/generate
21
- script/txt2html
15
+ lib/httparty.rb
16
+ lib/module_level_inheritable_attributes.rb
17
+ Manifest
18
+ MIT-LICENSE
19
+ Rakefile
20
+ README
22
21
  setup.rb
22
+ spec/as_buggery_spec.rb
23
+ spec/fixtures/delicious.xml
24
+ spec/fixtures/google.html
25
+ spec/fixtures/twitter.json
26
+ spec/fixtures/twitter.xml
23
27
  spec/httparty/request_spec.rb
24
28
  spec/httparty_spec.rb
25
29
  spec/spec.opts
26
30
  spec/spec_helper.rb
27
- tasks/deployment.rake
28
- tasks/environment.rake
29
- tasks/website.rake
30
31
  website/css/common.css
31
32
  website/index.html
data/README ADDED
@@ -0,0 +1,36 @@
1
+ = httparty
2
+
3
+ == DESCRIPTION:
4
+
5
+ Makes http fun again!
6
+
7
+ == FEATURES:
8
+
9
+ * Easy get, post requests
10
+ * Basic http authentication
11
+ * Default request query string parameters (ie: for api keys that are needed on each request)
12
+ * Automatic parsing of JSON and XML into ruby hashes based on response content-type
13
+
14
+ == EXAMPLES:
15
+
16
+ See http://github.com/jnunemaker/httparty/tree/master/examples
17
+
18
+
19
+ == COMMAND LINE INTERFACE
20
+
21
+ httparty also includes the executable <tt>httparty</tt> which can be
22
+ used to query web services and examine the resulting output. By default
23
+ it will output the response as a pretty-printed Ruby object (useful for
24
+ grokking the structure of output). This can also be overridden to output
25
+ formatted XML or JSON. Execute <tt>httparty --help</tt> for all the
26
+ options. Below is an example of how easy it is.
27
+
28
+ httparty "http://twitter.com/statuses/public_timeline.json" -f json
29
+
30
+ == REQUIREMENTS:
31
+
32
+ * JSON ~> 1.1
33
+
34
+ == INSTALL:
35
+
36
+ * sudo gem install httparty
data/Rakefile CHANGED
@@ -1,11 +1,43 @@
1
- require 'config/requirements'
2
- require 'config/hoe' # setup Hoe + all gem configuration
3
- require "spec/rake/spectask"
1
+ ProjectName = 'httparty'
2
+ WebsitePath = "jnunemaker@rubyforge.org:/var/www/gforge-projects/#{ProjectName}"
4
3
 
5
- Dir['tasks/**/*.rake'].each { |rake| load rake }
4
+ require 'rubygems'
5
+ require 'rake'
6
+ require 'echoe'
7
+ require 'spec/rake/spectask'
8
+ require "lib/#{ProjectName}/version"
6
9
 
7
- task :default => :spec
10
+ Echoe.new(ProjectName, HTTParty::Version) do |p|
11
+ p.description = "Makes http fun! Also, makes consuming restful web services dead easy."
12
+ p.install_message = "When you HTTParty, you must party hard!"
13
+ p.url = "http://#{ProjectName}.rubyforge.org"
14
+ p.author = "John Nunemaker"
15
+ p.email = "nunemaker@gmail.com"
16
+ p.extra_deps = [['json', '~> 1.1']]
17
+ p.need_tar_gz = false
18
+ p.docs_host = WebsitePath
19
+ end
20
+
21
+ desc 'Upload website files to rubyforge'
22
+ task :website do
23
+ sh %{rsync -av website/ #{WebsitePath}}
24
+ Rake::Task['website_docs'].invoke
25
+ end
26
+
27
+ task :website_docs do
28
+ Rake::Task['redocs'].invoke
29
+ sh %{rsync -av doc/ #{WebsitePath}/docs}
30
+ end
8
31
 
32
+ desc 'Preps the gem for a new release'
33
+ task :prepare do
34
+ %w[manifest build_gemspec].each do |task|
35
+ Rake::Task[task].invoke
36
+ end
37
+ end
38
+
39
+ Rake::Task[:default].prerequisites.clear
40
+ task :default => :spec
9
41
  Spec::Rake::SpecTask.new do |t|
10
42
  t.spec_files = FileList["spec/**/*_spec.rb"]
11
43
  end
data/bin/httparty ADDED
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "optparse"
4
+ require "pp"
5
+ require "rexml/document"
6
+
7
+ $:.unshift(File.join(File.dirname(__FILE__), "/../lib"))
8
+ require "httparty"
9
+
10
+ opts = {
11
+ :action => :get,
12
+ :headers => {},
13
+ :keep_body => true,
14
+ :verbose => false,
15
+ :pretty_print => false
16
+ }
17
+
18
+ OptionParser.new do |o|
19
+ o.banner = "USAGE: #{$0} [options] [url]"
20
+ o.on("-f",
21
+ "--format [FORMAT]",
22
+ "Body format: plain, json or xml") do |f|
23
+ opts[:format] = f.downcase.to_sym
24
+ end
25
+ o.on("-r", "--ruby", "Dump output in Ruby pretty-print format") do |r|
26
+ opts[:pretty_print] = true
27
+ end
28
+ o.on("-a",
29
+ "--action [ACTION]",
30
+ "HTTP action: get (default), post, put or delete") do |a|
31
+ opts[:action] = a.downcase.to_sym
32
+ end
33
+ o.on("-d",
34
+ "--data [BODY]",
35
+ "Data to put in request body (prefix with '@' for file)") do |d|
36
+ if d =~ /^@/
37
+ opts[:data] = open(d).read
38
+ else
39
+ opts[:data] = d
40
+ end
41
+ end
42
+ o.on("-H", "--header [NAME=VALUE]", "Additional HTTP headers in NAME=VALUE form") do |h|
43
+ name, value = h.split('=')
44
+ opts[:headers][name] = value
45
+ end
46
+ o.on("-v", "--verbose", "If set, print verbose output") do |v|
47
+ opts[:verbose] = true
48
+ end
49
+ o.on("-h", "--help", "Show help documentation") do |h|
50
+ puts o
51
+ exit
52
+ end
53
+ end.parse!
54
+
55
+ puts "Querying #{ARGV.first} with options: #{opts.inspect}" if opts[:verbose]
56
+
57
+ if ARGV.empty?
58
+ STDERR.puts "You need to provide a URL"
59
+ STDERR.puts "USAGE: #{$0} [options] [url]"
60
+ end
61
+
62
+ # 1.8.6 has mistyping of transitive in if statement
63
+ module REXML
64
+ class Document < Element
65
+ def write( output=$stdout, indent=-1, transitive=false, ie_hack=false )
66
+ if xml_decl.encoding != "UTF-8" && !output.kind_of?(Output)
67
+ output = Output.new( output, xml_decl.encoding )
68
+ end
69
+ formatter = if indent > -1
70
+ if transitive
71
+ REXML::Formatters::Transitive.new( indent, ie_hack )
72
+ else
73
+ REXML::Formatters::Pretty.new( indent, ie_hack )
74
+ end
75
+ else
76
+ REXML::Formatters::Default.new( ie_hack )
77
+ end
78
+ formatter.write( self, output )
79
+ end
80
+ end
81
+ end
82
+
83
+ if opts[:pretty_print] || opts[:format].nil?
84
+ pp HTTParty.send(opts[:action], ARGV.first, opts)
85
+ else
86
+ print_format = opts[:format]
87
+ opts.merge!(:format => :plain) if opts[:format]
88
+ response = HTTParty.send(opts[:action], ARGV.first, opts)
89
+
90
+ if print_format.nil?
91
+ pp response
92
+ else
93
+ case print_format
94
+ when :json
95
+ puts JSON.pretty_generate(response.original_body)
96
+ when :xml
97
+ REXML::Document.new(response.original_body).write(STDOUT, 2)
98
+ puts
99
+ else
100
+ puts response
101
+ end
102
+ end
103
+ end
data/examples/aaws.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'rubygems'
2
+ require 'activesupport'
3
+
1
4
  dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
2
5
  require File.join(dir, 'httparty')
3
6
  require 'pp'
data/examples/basic.rb ADDED
@@ -0,0 +1,6 @@
1
+ dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require File.join(dir, 'httparty')
3
+ require 'pp'
4
+
5
+ # You can also use post, put, delete in the same fashion
6
+ pp HTTParty.get('http://twitter.com/statuses/public_timeline.json')
@@ -18,7 +18,6 @@ class Delicious
18
18
  # ie: posts(:query => {:tag => 'ruby'})
19
19
  def posts(options={})
20
20
  options.merge!({:basic_auth => @auth})
21
- # get posts and convert to structs so we can do .key instead of ['key'] with results
22
21
  self.class.get('/posts/get', options)
23
22
  end
24
23
 
@@ -0,0 +1,14 @@
1
+ dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require File.join(dir, 'httparty')
3
+ require 'pp'
4
+
5
+ class Rubyurl
6
+ include HTTParty
7
+ base_uri 'rubyurl.com'
8
+
9
+ def self.shorten( website_url )
10
+ post( '/api/links.json', :query => { :link => { :website_url => website_url } } )
11
+ end
12
+ end
13
+
14
+ pp Rubyurl.shorten( 'http://istwitterdown.com/' )
data/examples/twitter.rb CHANGED
@@ -28,4 +28,4 @@ twitter = Twitter.new(config['email'], config['password'])
28
28
  pp twitter.timeline
29
29
  # pp twitter.timeline(:friends, :query => {:since_id => 868482746})
30
30
  # pp twitter.timeline(:friends, :query => 'since_id=868482746')
31
- # pp twitter.post('this is a test')
31
+ # pp twitter.post('this is a test of 0.2.0')
@@ -6,4 +6,5 @@ class Rep
6
6
  include HTTParty
7
7
  end
8
8
 
9
- puts Rep.get('http://whoismyrepresentative.com/whoismyrep.php?zip=46544').inspect
9
+ pp Rep.get('http://whoismyrepresentative.com/whoismyrep.php?zip=46544')
10
+ pp Rep.get('http://whoismyrepresentative.com/whoismyrep.php', :query => {:zip => 46544})
data/httparty.gemspec CHANGED
@@ -2,19 +2,21 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{httparty}
5
- s.version = "0.1.5"
5
+ s.version = "0.2.6"
6
6
 
7
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["John Nunemaker"]
9
- s.date = %q{2008-11-14}
9
+ s.date = %q{2009-01-05}
10
+ s.default_executable = %q{httparty}
10
11
  s.description = %q{Makes http fun! Also, makes consuming restful web services dead easy.}
11
- s.email = ["nunemaker@gmail.com"]
12
- s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.txt"]
13
- s.files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.txt", "Rakefile", "config/hoe.rb", "config/requirements.rb", "examples/aaws.rb", "examples/delicious.rb", "examples/google.rb", "examples/twitter.rb", "examples/whoismyrep.rb", "httparty.gemspec", "lib/httparty.rb", "lib/httparty/request.rb", "lib/httparty/version.rb", "script/console", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "spec/httparty/request_spec.rb", "spec/httparty_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/deployment.rake", "tasks/environment.rake", "tasks/website.rake", "website/css/common.css", "website/index.html"]
12
+ s.email = %q{nunemaker@gmail.com}
13
+ s.executables = ["httparty"]
14
+ s.extra_rdoc_files = ["bin/httparty", "lib/core_extensions.rb", "lib/httparty/exceptions.rb", "lib/httparty/request.rb", "lib/httparty/version.rb", "lib/httparty.rb", "lib/module_level_inheritable_attributes.rb", "README"]
15
+ s.files = ["bin/httparty", "examples/aaws.rb", "examples/basic.rb", "examples/delicious.rb", "examples/google.rb", "examples/rubyurl.rb", "examples/twitter.rb", "examples/whoismyrep.rb", "History", "httparty.gemspec", "lib/core_extensions.rb", "lib/httparty/exceptions.rb", "lib/httparty/request.rb", "lib/httparty/version.rb", "lib/httparty.rb", "lib/module_level_inheritable_attributes.rb", "Manifest", "MIT-LICENSE", "Rakefile", "README", "setup.rb", "spec/as_buggery_spec.rb", "spec/fixtures/delicious.xml", "spec/fixtures/google.html", "spec/fixtures/twitter.json", "spec/fixtures/twitter.xml", "spec/httparty/request_spec.rb", "spec/httparty_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "website/css/common.css", "website/index.html"]
14
16
  s.has_rdoc = true
15
17
  s.homepage = %q{http://httparty.rubyforge.org}
16
18
  s.post_install_message = %q{When you HTTParty, you must party hard!}
17
- s.rdoc_options = ["--main", "README.txt"]
19
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Httparty", "--main", "README"]
18
20
  s.require_paths = ["lib"]
19
21
  s.rubyforge_project = %q{httparty}
20
22
  s.rubygems_version = %q{1.3.1}
@@ -25,14 +27,14 @@ Gem::Specification.new do |s|
25
27
  s.specification_version = 2
26
28
 
27
29
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
- s.add_runtime_dependency(%q<activesupport>, [">= 2.1"])
29
- s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
30
+ s.add_runtime_dependency(%q<json>, ["~> 1.1"])
31
+ s.add_development_dependency(%q<echoe>, [">= 0"])
30
32
  else
31
- s.add_dependency(%q<activesupport>, [">= 2.1"])
32
- s.add_dependency(%q<hoe>, [">= 1.8.0"])
33
+ s.add_dependency(%q<json>, ["~> 1.1"])
34
+ s.add_dependency(%q<echoe>, [">= 0"])
33
35
  end
34
36
  else
35
- s.add_dependency(%q<activesupport>, [">= 2.1"])
36
- s.add_dependency(%q<hoe>, [">= 1.8.0"])
37
+ s.add_dependency(%q<json>, ["~> 1.1"])
38
+ s.add_dependency(%q<echoe>, [">= 0"])
37
39
  end
38
- end
40
+ end