Class: ActiveCMIS::Internal::Connection
- Inherits:
-
Object
- Object
- ActiveCMIS::Internal::Connection
- Defined in:
- lib/active_cmis/internal/connection.rb
Instance Attribute Summary collapse
-
#logger ⇒ Logger
readonly
A logger used to send debug and info messages.
-
#user ⇒ String?
readonly
The user that is used with the authentication to the server.
Instance Method Summary collapse
-
#authenticate(method, *params) ⇒ void
Use authentication to access the CMIS repository.
- #delete(url) ⇒ Object
-
#get(url) ⇒ String
The return value is the unparsed body, unless an error occured If an error occurred, exceptions are thrown (see _ActiveCMIS::Exception.
- #get_atom_entry(url) ⇒ Nokogiri::XML::Node
-
#get_response(url) ⇒ Net::HTTP::Response
Does not throw errors, returns the full response (includes status code and headers).
-
#get_xml(url) ⇒ Nokogiri::XML::Document
Returns the parsed body of the result.
-
#initialize(logger) ⇒ Connection
constructor
A new instance of Connection.
- #post(url, body, headers = {}) ⇒ Object
-
#post_response(url, body, headers = {}) ⇒ Object
Does not throw errors, returns the full response (includes status code and headers).
- #put(url, body, headers = {}) ⇒ Object
Constructor Details
#initialize(logger) ⇒ Connection
Returns a new instance of Connection.
11 12 13 |
# File 'lib/active_cmis/internal/connection.rb', line 11 def initialize(logger) @logger = logger || ActiveCMIS.default_logger end |
Instance Attribute Details
#logger ⇒ Logger (readonly)
Returns A logger used to send debug and info messages.
8 9 10 |
# File 'lib/active_cmis/internal/connection.rb', line 8 def logger @logger end |
#user ⇒ String? (readonly)
Returns The user that is used with the authentication to the server.
6 7 8 |
# File 'lib/active_cmis/internal/connection.rb', line 6 def user @user end |
Instance Method Details
#authenticate(method, *params) ⇒ void
This method returns an undefined value.
Use authentication to access the CMIS repository
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/active_cmis/internal/connection.rb', line 24 def authenticate(method, *params) case method when :basic, "basic" @authentication = {:method => :basic_auth, :params => params} @user = params.first when :ntlm, "ntlm" require 'net/ntlm_http' @authentication = {:method => :ntlm_auth, :params => params} @user = params.first else raise "Authentication method not supported" end end |
#delete(url) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/active_cmis/internal/connection.rb', line 91 def delete(url, headers = {}) uri = normalize_url(url) req = Net::HTTP::Put.new(uri.request_uri) headers.each {|k,v| req.add_field k, v} handle_request(uri, req) end |
#get(url) ⇒ String
The return value is the unparsed body, unless an error occured If an error occurred, exceptions are thrown (see _ActiveCMIS::Exception
42 43 44 45 46 47 |
# File 'lib/active_cmis/internal/connection.rb', line 42 def get(url) uri = normalize_url(url) req = Net::HTTP::Get.new(uri.request_uri) handle_request(uri, req) end |
#get_atom_entry(url) ⇒ Nokogiri::XML::Node
75 76 77 78 |
# File 'lib/active_cmis/internal/connection.rb', line 75 def get_atom_entry(url) # FIXME: add validation that first child is really an entry get_xml(url).child end |
#get_response(url) ⇒ Net::HTTP::Response
Does not throw errors, returns the full response (includes status code and headers)
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/active_cmis/internal/connection.rb', line 52 def get_response(url) logger.debug "GET (response) #{url}" uri = normalize_url(url) req = Net::HTTP::Get.new(uri.request_uri) http = authenticate_request(uri, req) response = nil http.request(req) do |res| logger.debug "GOT (#{res.code}) #{url}" response = res end response end |
#get_xml(url) ⇒ Nokogiri::XML::Document
Returns the parsed body of the result
69 70 71 |
# File 'lib/active_cmis/internal/connection.rb', line 69 def get_xml(url) Nokogiri::XML.parse(get(url), nil, nil, Nokogiri::XML::ParseOptions::STRICT) end |
#post(url, body, headers = {}) ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'lib/active_cmis/internal/connection.rb', line 100 def post(url, body, headers = {}) uri = normalize_url(url) req = Net::HTTP::Post.new(uri.request_uri) headers.each {|k,v| req.add_field k, v} assign_body(req, body) handle_request(uri, req) end |
#post_response(url, body, headers = {}) ⇒ Object
Does not throw errors, returns the full response (includes status code and headers)
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/active_cmis/internal/connection.rb', line 111 def post_response(url, body, headers = {}) logger.debug "POST (response) #{url}" uri = normalize_url(url) req = Net::HTTP::Post.new(uri.request_uri) headers.each {|k,v| req.add_field k, v} assign_body(req, body) http = authenticate_request(uri, req) response = http.request(req) logger.debug "POSTED (#{response.code}) #{url}" response end |
#put(url, body, headers = {}) ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/active_cmis/internal/connection.rb', line 81 def put(url, body, headers = {}) uri = normalize_url(url) req = Net::HTTP::Put.new(uri.request_uri) headers.each {|k,v| req.add_field k, v} assign_body(req, body) handle_request(uri, req) end |