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 |
# 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" @authentication = {:method => :ntlm_auth, :params => params} @user = params.first else raise "Authentication method not supported" end end |
#delete(url) ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/active_cmis/internal/connection.rb', line 87 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
41 42 43 44 45 46 |
# File 'lib/active_cmis/internal/connection.rb', line 41 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
71 72 73 74 |
# File 'lib/active_cmis/internal/connection.rb', line 71 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)
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/active_cmis/internal/connection.rb', line 51 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 = http.request(req) logger.debug "GOT (#{response.code}) #{url}" response end |
#get_xml(url) ⇒ Nokogiri::XML::Document
Returns the parsed body of the result
65 66 67 |
# File 'lib/active_cmis/internal/connection.rb', line 65 def get_xml(url) Nokogiri::XML.parse(get(url), nil, nil, Nokogiri::XML::ParseOptions::STRICT) end |
#post(url, body, headers = {}) ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/active_cmis/internal/connection.rb', line 96 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)
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/active_cmis/internal/connection.rb', line 107 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
77 78 79 80 81 82 83 84 |
# File 'lib/active_cmis/internal/connection.rb', line 77 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 |