Class: Ape::Poster
Instance Attribute Summary collapse
-
#entry ⇒ Object
readonly
Returns the value of attribute entry.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Attributes inherited from Invoker
#crumbs, #last_error, #response
Instance Method Summary collapse
- #authoritative? ⇒ Boolean
-
#initialize(uriString, authent) ⇒ Poster
constructor
A new instance of Poster.
- #post(contentType, body, req = nil) ⇒ Object
Methods inherited from Invoker
#[], #[]=, #header, #need_authentication?, #prepare_http, #restart_authent_checker, #set_header
Constructor Details
#initialize(uriString, authent) ⇒ Poster
Returns a new instance of Poster.
9 10 11 12 |
# File 'lib/ape/invokers/poster.rb', line 9 def initialize(uriString, authent) super uriString, authent @entry = nil end |
Instance Attribute Details
#entry ⇒ Object (readonly)
Returns the value of attribute entry.
7 8 9 |
# File 'lib/ape/invokers/poster.rb', line 7 def entry @entry end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
7 8 9 |
# File 'lib/ape/invokers/poster.rb', line 7 def uri @uri end |
Instance Method Details
#authoritative? ⇒ Boolean
14 15 16 |
# File 'lib/ape/invokers/poster.rb', line 14 def @response['Location'] == @response['Content-Location'] end |
#post(contentType, body, req = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ape/invokers/poster.rb', line 18 def post(contentType, body, req = nil) req = Net::HTTP::Post.new(AtomURI.on_the_wire(@uri)) if req.nil? req.set_content_type contentType @headers.each { |k, v| req[k]= v } begin http = prepare_http http.start do |connection| @response = connection.request(req, body) return post(contentType, body, req) if need_authentication?(req) restart_authent_checker if @response.code != '201' @last_error = @response. return false end # XXX how can this happen? if (!(@response['Content-type'] =~ %r{^application/atom\+xml(;type=entry)?})) return true end begin @entry = Entry.new(:text => @response.body, :uri => @response['Location']) return true rescue ArgumentError @last_error = $!.to_s return false end end rescue Exception @last_error = "Can't connect to #{@uri.host} on port #{@uri.port}: #{$!}" return false end end |