jnunemaker-httparty 0.1.1 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,20 @@
1
+ == 0.1.4 2008-11-08
2
+ * 2 major enhancements:
3
+ * Removed some cruft
4
+ * Added ability to follow redirects automatically and turn that off (Alex Vollmer)
5
+
6
+ == 0.1.3 2008-08-22
7
+
8
+ * 3 major enhancements:
9
+ * Added http_proxy key for setting proxy server and port (francxk@gmail.com)
10
+ * Now raises exception when http error occurs (francxk@gmail.com)
11
+ * Changed auto format detection from file extension to response content type (Jay Pignata)
12
+
13
+ == 0.1.2 2008-08-09
14
+
15
+ * 1 major enhancement:
16
+ * default_params were not being appended to query string if option[:query] was blank
17
+
1
18
  == 0.1.1 2008-07-30
2
19
 
3
20
  * 2 major enhancement:
data/Manifest.txt CHANGED
@@ -8,12 +8,11 @@ config/hoe.rb
8
8
  config/requirements.rb
9
9
  examples/aaws.rb
10
10
  examples/delicious.rb
11
+ examples/google.rb
11
12
  examples/twitter.rb
12
13
  examples/whoismyrep.rb
13
14
  httparty.gemspec
14
15
  lib/httparty.rb
15
- lib/httparty/core_ext.rb
16
- lib/httparty/core_ext/hash.rb
17
16
  lib/httparty/version.rb
18
17
  script/console
19
18
  script/destroy
data/README.txt CHANGED
@@ -9,7 +9,7 @@ Makes http fun again!
9
9
  * Easy get, post, put, delete requests
10
10
  * Basic http authentication
11
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
12
+ * Automatic parsing of JSON and XML into ruby hashes based on response content-type
13
13
 
14
14
  == SYNOPSIS:
15
15
 
@@ -30,18 +30,33 @@ That works and all but what if you don't want to embed your username and passwor
30
30
  class Twitter
31
31
  include HTTParty
32
32
  base_uri 'twitter.com'
33
-
34
- def initialize(user, pass)
35
- self.class.basic_auth user, pass
33
+
34
+ def initialize(u, p)
35
+ @auth = {:username => u, :password => p}
36
36
  end
37
-
37
+
38
38
  def post(text)
39
- self.class.post('/statuses/update.json', :query => {:status => text})
39
+ options = { :query => {:status => text}, :basic_auth => @auth }
40
+ self.class.post('/statuses/update.json', options)
40
41
  end
41
42
  end
42
43
 
43
44
  Twitter.new('username', 'password').post("It's an HTTParty and everyone is invited!")
44
45
 
46
+ === REQUEST OPTIONS
47
+
48
+ Each of the HTTP method (get, post, put and delete) each take a hash of options.
49
+ The following keys can be specified in the options:
50
+
51
+ headers:: A <tt>Hash</tt> of header key/value pairs
52
+ query:: A <tt>Hash</tt> of query key/value pairs
53
+ body:: The body of the request. If it's a <tt>Hash</tt>, it is
54
+ converted into query-string format, otherwise it is sent
55
+ as-is.
56
+ basic_auth:: A <tt>Hash</tt> containing keys for <tt>:username</tt> and
57
+ <tt>:password</tt>.
58
+ no_follow:: Turns off automatic redirect following
59
+
45
60
  == REQUIREMENTS:
46
61
 
47
62
  * Active Support >= 2.1
data/Rakefile CHANGED
@@ -1,4 +1,11 @@
1
1
  require 'config/requirements'
2
2
  require 'config/hoe' # setup Hoe + all gem configuration
3
+ require "spec/rake/spectask"
3
4
 
4
- Dir['tasks/**/*.rake'].each { |rake| load rake }
5
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
6
+
7
+ task :default => :spec
8
+
9
+ Spec::Rake::SpecTask.new do |t|
10
+ t.spec_files = FileList["spec/**/*_spec.rb"]
11
+ end
data/examples/aaws.rb CHANGED
@@ -8,7 +8,6 @@ module AAWS
8
8
  include HTTParty
9
9
  base_uri 'http://ecs.amazonaws.com'
10
10
  default_params :Service => 'AWSECommerceService', :Operation => 'ItemSearch', :SearchIndex => 'Books'
11
- format :xml
12
11
 
13
12
  def initialize(key)
14
13
  self.class.default_params :AWSAccessKeyId => key
@@ -6,7 +6,6 @@ config = YAML::load(File.read(File.join(ENV['HOME'], '.delicious')))
6
6
  class Delicious
7
7
  include HTTParty
8
8
  base_uri 'https://api.del.icio.us/v1'
9
- format :xml
10
9
 
11
10
  def initialize(u, p)
12
11
  @auth = {:username => u, :password => p}
@@ -0,0 +1,15 @@
1
+ dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require File.join(dir, 'httparty')
3
+ require 'pp'
4
+
5
+ class Google
6
+ include HTTParty
7
+ end
8
+
9
+ # google.com redirects to www.google.com so this is live test for redirection
10
+ pp Google.get('http://google.com')
11
+
12
+ puts '', '*'*70, ''
13
+
14
+ # check that ssl is requesting right
15
+ pp Google.get('https://www.google.com')
@@ -4,7 +4,6 @@ require 'pp'
4
4
 
5
5
  class Rep
6
6
  include HTTParty
7
- format :xml
8
7
  end
9
8
 
10
9
  puts Rep.get('http://whoismyrepresentative.com/whoismyrep.php?zip=46544').inspect
data/httparty.gemspec CHANGED
@@ -1,14 +1,14 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{httparty}
3
- s.version = "0.1.1"
3
+ s.version = "0.1.4"
4
4
 
5
5
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
6
  s.authors = ["John Nunemaker"]
7
- s.date = %q{2008-07-31}
7
+ s.date = %q{2008-11-08}
8
8
  s.description = %q{Makes http fun! Also, makes consuming restful web services dead easy.}
9
9
  s.email = ["nunemaker@gmail.com"]
10
10
  s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.txt"]
11
- 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/twitter.rb", "examples/whoismyrep.rb", "httparty.gemspec", "lib/httparty.rb", "lib/httparty/core_ext.rb", "lib/httparty/core_ext/hash.rb", "lib/httparty/version.rb", "script/console", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "spec/hash_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"]
11
+ 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/version.rb", "script/console", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "spec/hash_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
12
  s.has_rdoc = true
13
13
  s.homepage = %q{http://httparty.rubyforge.org}
14
14
  s.post_install_message = %q{When you HTTParty, you must party hard!}
@@ -24,10 +24,13 @@ Gem::Specification.new do |s|
24
24
 
25
25
  if current_version >= 3 then
26
26
  s.add_runtime_dependency(%q<activesupport>, [">= 2.1"])
27
+ s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
27
28
  else
28
29
  s.add_dependency(%q<activesupport>, [">= 2.1"])
30
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
29
31
  end
30
32
  else
31
33
  s.add_dependency(%q<activesupport>, [">= 2.1"])
34
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
32
35
  end
33
- end
36
+ end
@@ -2,7 +2,7 @@ module HTTParty
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 1
5
+ TINY = 4
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/httparty.rb CHANGED
@@ -5,26 +5,34 @@ require 'ostruct'
5
5
  require 'rubygems'
6
6
  require 'active_support'
7
7
 
8
- $:.unshift(File.dirname(__FILE__)) unless
9
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
8
+ directory = File.dirname(__FILE__)
9
+ $:.unshift(directory) unless $:.include?(directory) || $:.include?(File.expand_path(directory))
10
10
 
11
- dir = File.expand_path(File.join(File.dirname(__FILE__), 'httparty'))
12
- require dir + '/core_ext'
13
-
14
11
  module HTTParty
12
+ class UnsupportedFormat < StandardError; end
13
+ class RedirectionTooDeep < StandardError; end
14
+
15
15
  def self.included(base)
16
16
  base.extend ClassMethods
17
17
  end
18
18
 
19
- class UnsupportedFormat < StandardError; end
20
-
21
- AllowedFormats = %w[xml json]
19
+ AllowedFormats = {:xml => 'text/xml', :json => 'application/json'}
22
20
 
23
21
  module ClassMethods
22
+ #
23
+ # Set an http proxy
24
+ #
25
+ # class Twitter
26
+ # include HTTParty
27
+ # http_proxy http://myProxy, 1080
28
+ # ....
29
+ def http_proxy(addr=nil, port = nil)
30
+ @http_proxyaddr = addr
31
+ @http_proxyport = port
32
+ end
33
+
24
34
  def base_uri(base_uri=nil)
25
35
  return @base_uri unless base_uri
26
- # don't want this to ever end with /
27
- base_uri = base_uri.ends_with?('/') ? base_uri.chop : base_uri
28
36
  @base_uri = normalize_base_uri(base_uri)
29
37
  end
30
38
 
@@ -52,8 +60,7 @@ module HTTParty
52
60
  end
53
61
 
54
62
  def format(f)
55
- f = f.to_s
56
- raise UnsupportedFormat, "Must be one of: #{AllowedFormats.join(', ')}" unless AllowedFormats.include?(f)
63
+ raise UnsupportedFormat, "Must be one of: #{AllowedFormats.keys.join(', ')}" unless AllowedFormats.key?(f)
57
64
  @format = f
58
65
  end
59
66
 
@@ -78,14 +85,11 @@ module HTTParty
78
85
  end
79
86
 
80
87
  private
81
- def http(uri)
82
- if @http.blank?
83
- @http = Net::HTTP.new(uri.host, uri.port)
84
- @http.use_ssl = (uri.port == 443)
85
- # so we can avoid ssl warnings
86
- @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
87
- end
88
- @http
88
+ def http(uri) #:nodoc:
89
+ http = Net::HTTP.new(uri.host, uri.port, @http_proxyaddr, @http_proxyport)
90
+ http.use_ssl = (uri.port == 443)
91
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
92
+ http
89
93
  end
90
94
 
91
95
  # FIXME: this method is doing way to much and needs to be split up
@@ -94,55 +98,72 @@ module HTTParty
94
98
  # body => hash of keys/values or a query string (foo=bar&baz=poo)
95
99
  # headers => hash of headers to send request with
96
100
  # basic_auth => :username and :password to use as basic http authentication (overrides @auth class instance variable)
97
- def send_request(method, path, options={})
101
+ # Raises exception Net::XXX (http error code) if an http error occured
102
+ def send_request(method, path, options={}) #:nodoc:
103
+ options = {:limit => 5}.merge(options)
104
+ options[:limit] = 0 if options.delete(:no_follow)
105
+
106
+ raise HTTParty::RedirectionTooDeep, 'HTTP redirects too deep' if options[:limit].to_i <= 0
98
107
  raise ArgumentError, 'only get, post, put and delete methods are supported' unless %w[get post put delete].include?(method.to_s)
99
108
  raise ArgumentError, ':headers must be a hash' if options[:headers] && !options[:headers].is_a?(Hash)
100
109
  raise ArgumentError, ':basic_auth must be a hash' if options[:basic_auth] && !options[:basic_auth].is_a?(Hash)
101
- # we always want path that begins with /
102
- path = path =~ /^(\/|https?:\/\/)/ ? path : "/#{path}"
103
- @format ||= format_from_path(path)
104
- uri = URI.parse("#{base_uri}#{path}")
110
+
111
+ path = URI.parse(path)
112
+ uri = path.relative? ? URI.parse("#{base_uri}#{path}") : path
105
113
  existing_query = uri.query ? "#{uri.query}&" : ''
106
114
  uri.query = if options[:query].blank?
107
- existing_query
115
+ existing_query + default_params.to_query
108
116
  else
109
117
  existing_query + (options[:query].is_a?(Hash) ? default_params.merge(options[:query]).to_query : options[:query])
110
118
  end
119
+
111
120
  klass = Net::HTTP.const_get method.to_s.downcase.capitalize
112
121
  request = klass.new(uri.request_uri)
113
122
  request.body = options[:body].is_a?(Hash) ? options[:body].to_query : options[:body] unless options[:body].blank?
114
123
  basic_auth = options.delete(:basic_auth) || @auth
115
124
  request.initialize_http_header headers.merge(options[:headers] || {})
116
- # note to self: self, do not put basic auth above headers because it removes basic auth
117
125
  request.basic_auth(basic_auth[:username], basic_auth[:password]) if basic_auth
118
126
  response = http(uri).request(request)
119
- parse_response(response.body)
127
+ @format ||= format_from_mimetype(response['content-type'])
128
+
129
+ case response
130
+ when Net::HTTPSuccess
131
+ parse_response(response.body)
132
+ when Net::HTTPRedirection
133
+ options[:limit] -= 1
134
+ send_request(method, response['location'], options)
135
+ else
136
+ response.instance_eval { class << self; attr_accessor :body_parsed; end }
137
+ begin; response.body_parsed = parse_response(response.body); rescue; end
138
+ response.error! # raises exception corresponding to http error Net::XXX
139
+ end
140
+
120
141
  end
121
142
 
122
- def parse_response(body)
143
+ def parse_response(body) #:nodoc:
144
+ return nil if body.nil? or body.empty?
123
145
  case @format
124
- when 'xml'
146
+ when :xml
125
147
  Hash.from_xml(body)
126
- when 'json'
148
+ when :json
127
149
  ActiveSupport::JSON.decode(body)
128
150
  else
129
- # just return the response if no format
130
151
  body
131
152
  end
132
153
  end
133
154
 
134
155
  # Makes it so uri is sure to parse stuff like google.com with the http
135
- def normalize_base_uri(str)
136
- str =~ /^https?:\/\// ? str : "http#{'s' if str.include?(':443')}://#{str}"
156
+ def normalize_base_uri(url) #:nodoc:
157
+ use_ssl = (url =~ /^https/) || url.include?(':443')
158
+ url.chop! if url.ends_with?('/')
159
+ url.gsub!(/^https?:\/\//i, '')
160
+ "http#{'s' if use_ssl}://#{url}"
137
161
  end
138
162
 
139
- # Returns a format that we can handle from the path if possible.
140
- # Just does simple pattern matching on file extention:
141
- # /foobar.xml => 'xml'
142
- # /foobar.json => 'json'
143
- def format_from_path(path)
144
- ext = File.extname(path)[1..-1]
145
- !ext.blank? && AllowedFormats.include?(ext) ? ext : nil
163
+ # Uses the HTTP Content-Type header to determine the format of the response
164
+ # It compares the MIME type returned to the types stored in the AllowedFormats hash
165
+ def format_from_mimetype(mimetype) #:nodoc:
166
+ AllowedFormats.each { |k, v| return k if mimetype.include?(v) }
146
167
  end
147
168
  end
148
169
  end
@@ -13,11 +13,11 @@ end
13
13
  describe HTTParty do
14
14
 
15
15
  describe "base uri" do
16
- it "should be gettable" do
16
+ it "should have reader" do
17
17
  Foo.base_uri.should == 'http://api.foo.com/v1'
18
18
  end
19
19
 
20
- it 'should be setable' do
20
+ it 'should have writer' do
21
21
  Foo.base_uri('http://api.foobar.com')
22
22
  Foo.base_uri.should == 'http://api.foobar.com'
23
23
  end
@@ -28,7 +28,13 @@ describe HTTParty do
28
28
  end
29
29
 
30
30
  it "should add https if not present for ssl requests" do
31
- FooWithHttps.base_uri.should == 'https://api.foo.com/v1:443'
31
+ Foo.base_uri('api.foo.com/v1:443')
32
+ Foo.base_uri.should == 'https://api.foo.com/v1:443'
33
+ end
34
+
35
+ it "should not remove https for ssl requests" do
36
+ Foo.base_uri('https://api.foo.com/v1:443')
37
+ Foo.base_uri.should == 'https://api.foo.com/v1:443'
32
38
  end
33
39
  end
34
40
 
@@ -66,12 +72,12 @@ describe HTTParty do
66
72
  describe "format" do
67
73
  it "should allow xml" do
68
74
  Foo.format :xml
69
- Foo.instance_variable_get("@format").should == 'xml'
75
+ Foo.instance_variable_get("@format").should == :xml
70
76
  end
71
77
 
72
78
  it "should allow json" do
73
79
  Foo.format :json
74
- Foo.instance_variable_get("@format").should == 'json'
80
+ Foo.instance_variable_get("@format").should == :json
75
81
  end
76
82
 
77
83
  it 'should not allow funky format' do
@@ -91,24 +97,6 @@ describe HTTParty do
91
97
  end
92
98
  end
93
99
 
94
- describe "deriving format from path" do
95
- it "should work if there is extension and extension is an allowed format" do
96
- %w[xml json].each do |ext|
97
- Foo.send(:format_from_path, "/foo/bar.#{ext}").should == ext
98
- end
99
- end
100
-
101
- it "should NOT work if there is extension but extention is not allow format" do
102
- Foo.send(:format_from_path, '/foo/bar.php').should == nil
103
- end
104
-
105
- it 'should NOT work if there is no extension' do
106
- ['', '.'].each do |ext|
107
- Foo.send(:format_from_path, "/foo/bar#{ext}").should == nil
108
- end
109
- end
110
- end
111
-
112
100
  describe 'parsing responses' do
113
101
  it 'should handle xml automatically' do
114
102
  xml = %q[<books><book><id>1234</id><name>Foo Bar!</name></book></books>]
@@ -141,5 +129,93 @@ describe HTTParty do
141
129
  Foo.send(:send_request, 'get', '/foo', :basic_auth => 'string')
142
130
  end.should raise_error(ArgumentError)
143
131
  end
132
+
133
+ it "should not attempt to parse empty responses" do
134
+ http = Net::HTTP.new('localhost', 80)
135
+ Foo.stub!(:http).and_return(http)
136
+ response = Net::HTTPNoContent.new("1.1", 204, "No content for you")
137
+ response.stub!(:body).and_return(nil)
138
+ http.stub!(:request).and_return(response)
139
+
140
+ Foo.headers.clear # clear out bogus settings from other specs
141
+ Foo.format :xml
142
+ Foo.send(:send_request, 'get', '/bar').should be_nil
143
+
144
+ response.stub!(:body).and_return("")
145
+ Foo.send(:send_request, 'get', 'bar').should be_nil
146
+ end
147
+
148
+ describe "that respond with redirects" do
149
+ def setup_http
150
+ @http = Net::HTTP.new('localhost', 80)
151
+ Foo.stub!(:http).and_return(@http)
152
+ @redirect = Net::HTTPFound.new("1.1", 302, "")
153
+ @redirect.stub!(:[]).with('location').and_return('/foo')
154
+ @ok = Net::HTTPOK.new("1.1", 200, "Content for you")
155
+ @ok.stub!(:body).and_return({"foo" => "bar"}.to_xml)
156
+ @http.should_receive(:request).and_return(@redirect, @ok)
157
+ Foo.headers.clear
158
+ Foo.format :xml
159
+ end
160
+
161
+ it "should handle redirects for GET transparently" do
162
+ setup_http
163
+ Foo.get('/foo/').should == {"hash" => {"foo" => "bar"}}
164
+ end
165
+
166
+ it "should handle redirects for POST transparently" do
167
+ setup_http
168
+ Foo.post('/foo/', {:foo => :bar}).should == {"hash" => {"foo" => "bar"}}
169
+ end
170
+
171
+ it "should handle redirects for DELETE transparently" do
172
+ setup_http
173
+ Foo.delete('/foo/').should == {"hash" => {"foo" => "bar"}}
174
+ end
175
+
176
+ it "should handle redirects for PUT transparently" do
177
+ setup_http
178
+ Foo.put('/foo/').should == {"hash" => {"foo" => "bar"}}
179
+ end
180
+
181
+ it "should prevent infinite loops" do
182
+ http = Net::HTTP.new('localhost', 80)
183
+ Foo.stub!(:http).and_return(http)
184
+ redirect = Net::HTTPFound.new("1.1", "302", "Look, over there!")
185
+ redirect.stub!(:[]).with('location').and_return('/foo')
186
+ http.stub!(:request).and_return(redirect)
187
+
188
+ lambda do
189
+ Foo.send(:send_request, 'get', '/foo')
190
+ end.should raise_error(HTTParty::RedirectionTooDeep)
191
+ end
192
+
193
+ describe "with explicit override of automatic redirect handling" do
194
+
195
+ it "should fail with redirected GET" do
196
+ lambda do
197
+ Foo.get('/foo', :no_follow => true)
198
+ end.should raise_error(HTTParty::RedirectionTooDeep)
199
+ end
200
+
201
+ it "should fail with redirected POST" do
202
+ lambda do
203
+ Foo.post('/foo', :no_follow => true)
204
+ end.should raise_error(HTTParty::RedirectionTooDeep)
205
+ end
206
+
207
+ it "should fail with redirected DELETE" do
208
+ lambda do
209
+ Foo.delete('/foo', :no_follow => true)
210
+ end
211
+ end
212
+
213
+ it "should fail with redirected PUT" do
214
+ lambda do
215
+ Foo.put('/foo', :no_follow => true)
216
+ end
217
+ end
218
+ end
219
+ end
144
220
  end
145
221
  end
@@ -1,3 +1,12 @@
1
+ desc 'Preps the gem for a new release'
2
+ task :prep_for_release do
3
+ require 'rio'
4
+ Rake::Task['manifest:refresh'].invoke
5
+ gemspec = %x[rake debug_gem]
6
+ lines = gemspec.split("\n")
7
+ rio('httparty.gemspec') < lines[1, lines.length-1].join("\n")
8
+ end
9
+
1
10
  desc 'Release the website and new gem version'
2
11
  task :deploy => [:check_version, :website, :release] do
3
12
  puts "Remember to create SVN tag:"
data/tasks/website.rake CHANGED
@@ -14,4 +14,4 @@ task :website_upload do
14
14
  end
15
15
 
16
16
  desc 'Generate and upload website files'
17
- task :website => [:website_generate, :website_upload, :publish_docs]
17
+ task :website => [:website_upload, :publish_docs]
data/website/index.html CHANGED
@@ -15,6 +15,7 @@
15
15
  <ul id="nav">
16
16
  <li><a href="rdoc/">Docs</a></li>
17
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>
18
19
  <li><a href="http://rubyforge.org/projects/httparty/">Rubyforge</a></li>
19
20
  </ul>
20
21
  </div>
@@ -43,12 +44,13 @@ Twitter.post('/statuses/update.json', :query => {:status => "It's an HTTParty an
43
44
  include HTTParty
44
45
  base_uri 'twitter.com'
45
46
 
46
- def initialize(user, pass)
47
- self.class.basic_auth user, pass
47
+ def initialize(u, p)
48
+ @auth = {:username => u, :password => p}
48
49
  end
49
50
 
50
51
  def post(text)
51
- self.class.post('/statuses/update.json', :query => {:status => text})
52
+ options = { :query => {:status => text}, :basic_auth => @auth }
53
+ self.class.post('/statuses/update.json', options)
52
54
  end
53
55
  end
54
56
 
@@ -66,12 +68,16 @@ Twitter.new('username', 'password').post("It's an HTTParty and everyone is invit
66
68
  <p>Created by <a href="http://addictedtonew.com/about/">John Nunemaker</a></p>
67
69
  </div>
68
70
  </div>
71
+
72
+ <script type="text/javascript">
73
+ var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
74
+ document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
75
+ </script>
76
+ <script type="text/javascript">
77
+ var pageTracker = _gat._getTracker("UA-85301-19");
78
+ pageTracker._initData();
79
+ pageTracker._trackPageview();
80
+ </script>
69
81
 
70
- <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>
71
- <script type="text/javascript">_uacct = "UA-85301-9"; urchinTracker();</script>
72
-
73
- <!-- 103bees.com 'bee' code v1.11 - please do not make any changes! -->
74
- <script type="text/javascript" src="http://103bees.com/bees/?bee=3672&amp;fid=5643"></script>
75
- <!-- 103bees.com 'bee' code -->
76
82
  </body>
77
83
  </html>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jnunemaker-httparty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-31 00:00:00 -07:00
12
+ date: 2008-11-08 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -21,6 +21,15 @@ dependencies:
21
21
  - !ruby/object:Gem::Version
22
22
  version: "2.1"
23
23
  version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: hoe
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 1.8.0
32
+ version:
24
33
  description: Makes http fun! Also, makes consuming restful web services dead easy.
25
34
  email:
26
35
  - nunemaker@gmail.com
@@ -45,12 +54,11 @@ files:
45
54
  - config/requirements.rb
46
55
  - examples/aaws.rb
47
56
  - examples/delicious.rb
57
+ - examples/google.rb
48
58
  - examples/twitter.rb
49
59
  - examples/whoismyrep.rb
50
60
  - httparty.gemspec
51
61
  - lib/httparty.rb
52
- - lib/httparty/core_ext.rb
53
- - lib/httparty/core_ext/hash.rb
54
62
  - lib/httparty/version.rb
55
63
  - script/console
56
64
  - script/destroy
@@ -1,21 +0,0 @@
1
- module HTTParty
2
- module CoreExt
3
- module HashConversions
4
- def to_struct
5
- o = OpenStruct.new
6
- self.each do |k, v|
7
- # if id, we create an accessor so we don't get warning about id deprecation
8
- if k.to_s == 'id'
9
- o.class.class_eval "attr_accessor :id"
10
- o.id = v
11
- else
12
- o.send("#{k}=", v.is_a?(Hash) ? v.to_struct : v)
13
- end
14
- end
15
- o
16
- end
17
- end
18
- end
19
- end
20
-
21
- Hash.send :include, HTTParty::CoreExt::HashConversions
@@ -1,2 +0,0 @@
1
- dir = File.expand_path(File.join(File.dirname(__FILE__), 'core_ext'))
2
- require File.join(dir, 'hash')
data/spec/hash_spec.rb DELETED
@@ -1,11 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
2
-
3
- describe HTTParty::CoreExt::HashConversions do
4
- it "should convert hash to struct" do
5
- {'foo' => 'bar'}.to_struct.should == OpenStruct.new(:foo => 'bar')
6
- end
7
-
8
- it 'should convert nested hash to struct' do
9
- {'foo' => {'bar' => 'baz'}}.to_struct.should == OpenStruct.new(:foo => OpenStruct.new(:bar => 'baz'))
10
- end
11
- end