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.
-
#options ⇒ Hash
readonly
Options to be used by the HTTP objects.
-
#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, options) ⇒ 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, options) ⇒ Connection
Returns a new instance of Connection.
13 14 15 16 |
# File 'lib/active_cmis/internal/connection.rb', line 13 def initialize(logger, ) @logger = logger || ActiveCMIS.default_logger @options = || {} 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 |
#options ⇒ Hash (readonly)
Returns Options to be used by the HTTP objects.
10 11 12 |
# File 'lib/active_cmis/internal/connection.rb', line 10 def @options 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
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/active_cmis/internal/connection.rb', line 27 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
97 98 99 100 101 102 103 |
# File 'lib/active_cmis/internal/connection.rb', line 97 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
45 46 47 48 49 50 51 52 53 |
# File 'lib/active_cmis/internal/connection.rb', line 45 def get(url) uri = normalize_url(url) logger.debug "Method get only #{uri}" # Ensure the parsed URL is an HTTP one raise HTTPError::ClientError.new("Invalid URL #{url}") unless uri.is_a?(URI::HTTP) req = Net::HTTP::Get.new(uri.request_uri) req['Cookie'] = [:cookies] handle_request(uri, req) end |
#get_atom_entry(url) ⇒ Nokogiri::XML::Node
81 82 83 84 |
# File 'lib/active_cmis/internal/connection.rb', line 81 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)
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/active_cmis/internal/connection.rb', line 58 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
75 76 77 |
# File 'lib/active_cmis/internal/connection.rb', line 75 def get_xml(url) Nokogiri::XML.parse(get(url), nil, nil, Nokogiri::XML::ParseOptions::STRICT) end |
#post(url, body, headers = {}) ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/active_cmis/internal/connection.rb', line 106 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)
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/active_cmis/internal/connection.rb', line 117 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
87 88 89 90 91 92 93 94 |
# File 'lib/active_cmis/internal/connection.rb', line 87 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 |