Class: Ape::Putter
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Attributes inherited from Invoker
#crumbs, #last_error, #response
Instance Method Summary collapse
-
#initialize(uriString, authent) ⇒ Putter
constructor
A new instance of Putter.
- #put(contentType, body, req = nil) ⇒ Object
- #set_header(name, val) ⇒ Object
Methods inherited from Invoker
#[], #[]=, #header, #need_authentication?, #prepare_http, #restart_authent_checker
Constructor Details
#initialize(uriString, authent) ⇒ Putter
Returns a new instance of Putter.
9 10 11 12 |
# File 'lib/ape/invokers/putter.rb', line 9 def initialize(uriString, authent) super uriString, authent @headers = {} end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
7 8 9 |
# File 'lib/ape/invokers/putter.rb', line 7 def headers @headers end |
Instance Method Details
#put(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 |
# File 'lib/ape/invokers/putter.rb', line 18 def put(contentType, body, req = nil) req = Net::HTTP::Put.new(AtomURI.on_the_wire(@uri)) unless req 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 put(contentType, body, req) if need_authentication?(req) restart_authent_checker unless @response.kind_of? Net::HTTPSuccess @last_error = @response. return false end return true end rescue Exception @last_error = "Can't connect to #{@uri.host} on port #{@uri.port}: #{$!}" return nil end end |
#set_header(name, val) ⇒ Object
14 15 16 |
# File 'lib/ape/invokers/putter.rb', line 14 def set_header(name, val) @headers[name] = val end |