Class: ActiveResource::Connection
- Inherits:
-
Object
- Object
- ActiveResource::Connection
- Defined in:
- lib/fedora/connection.rb
Instance Method Summary collapse
- #multipart_request(req, file) ⇒ Object
- #post(path, body = '', headers = {}) ⇒ Object
- #post_without_multipart ⇒ Object
- #put(path, body = '', headers = {}) ⇒ Object
- #put_without_multipart ⇒ Object
- #raw_get(path, headers = {}) ⇒ Object
Instance Method Details
#multipart_request(req, file) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/fedora/connection.rb', line 80 def multipart_request(req, file) logger.info "#{method.to_s.upcase} #{site.scheme}://#{site.host}:#{site.port}#{path}" if logger result = nil time = Benchmark.realtime do http.start do |conn| req.set_multipart_data(:file => file) result = conn.request(req) end end logger.info "--> #{result.code} #{result.message} (#{result.body ? result.body : 0}b %.2fs)" % time if logger handle_response(result) end |
#post(path, body = '', headers = {}) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/fedora/connection.rb', line 72 def post(path, body = '', headers = {}) if body.is_a?(File) multipart_request(Net::HTTP::Post.new(path, build_request_headers(headers)), body) else post_without_multipart(path, body, headers) end end |
#post_without_multipart ⇒ Object
61 |
# File 'lib/fedora/connection.rb', line 61 alias_method :post_without_multipart, :post |
#put(path, body = '', headers = {}) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/fedora/connection.rb', line 64 def put(path, body = '', headers = {}) if body.is_a?(File) multipart_request(Net::HTTP::Put.new(path, build_request_headers(headers)), body) else put_without_multipart(path, body, headers) end end |
#put_without_multipart ⇒ Object
62 |
# File 'lib/fedora/connection.rb', line 62 alias_method :put_without_multipart, :put |
#raw_get(path, headers = {}) ⇒ Object
93 94 95 |
# File 'lib/fedora/connection.rb', line 93 def raw_get(path, headers = {}) request(:get, path, build_request_headers(headers)) end |