Module: Requester
- Defined in:
- lib/ramaze/spec/helper/requester.rb
Overview
Copyright © 2008 Michael Fellinger [email protected] All files in this distribution are subject to the terms of the Ruby license.
Instance Method Summary collapse
- #eget(url = '/', hash = {}) ⇒ Object
- #epost(url = '/', hash = {}) ⇒ Object
- #erequest(method, url, hash = {}) ⇒ Object
- #get(url = '/', hash = {}) ⇒ Object
- #hget(url = '/', hash = {}) ⇒ Object
- #hpost(url = '/', hash = {}) ⇒ Object
- #post(url = '/', hash = {}) ⇒ Object
- #request(method, url, hash = {}) ⇒ Object
- #url2uri(url) ⇒ Object
Instance Method Details
#eget(url = '/', hash = {}) ⇒ Object
28 29 30 |
# File 'lib/ramaze/spec/helper/requester.rb', line 28 def eget url = '/', hash = {} erequest(:get, url, hash) end |
#epost(url = '/', hash = {}) ⇒ Object
24 25 26 |
# File 'lib/ramaze/spec/helper/requester.rb', line 24 def epost url = '/', hash = {} erequest(:post, url, hash) end |
#erequest(method, url, hash = {}) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/ramaze/spec/helper/requester.rb', line 32 def erequest method, url, hash = {} response = request(method, url, hash) eval(response) rescue Object => ex p :response => response ex. end |
#get(url = '/', hash = {}) ⇒ Object
5 6 7 |
# File 'lib/ramaze/spec/helper/requester.rb', line 5 def get url = '/', hash = {} request(:get, url, hash) end |
#hget(url = '/', hash = {}) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/ramaze/spec/helper/requester.rb', line 40 def hget(url = '/', hash = {}) @response = get(url, hash) @body = @response.body @status = @response.status Hpricot(@body) end |
#hpost(url = '/', hash = {}) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/ramaze/spec/helper/requester.rb', line 47 def hpost(url = '/', hash = {}) @response = post(url, hash) @body = @response.body @status = @response.status Hpricot(@body) end |
#post(url = '/', hash = {}) ⇒ Object
9 10 11 |
# File 'lib/ramaze/spec/helper/requester.rb', line 9 def post url = '/', hash = {} request(:post, url, hash) end |
#request(method, url, hash = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ramaze/spec/helper/requester.rb', line 13 def request method, url, hash = {} http = SimpleHttp.new(url2uri(url)) if method == :get and not hash.empty? http.uri.query = hash.map{|k,v| "#{k}=#{v}"}.join('&') hash = {} end puts "#{method.to_s.upcase} => #{http.uri}" http.send(method, hash).strip end |