active_cmis 0.2.6 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # ActiveCMIS Release 0.2.5 #
1
+ # ActiveCMIS Release 0.3.0 #
2
2
  **Homepage**: <http://xaop.com/labs/activecmis>
3
3
  **Git**: <http://github.com/xaop/activecmis>
4
4
  **Documentation**: <http://rdoc.info/github/xaop/activecmis/master/frames>
@@ -12,6 +12,9 @@ ActiveCMIS is Ruby library aimed at easing the interaction with various CMIS pro
12
12
  - Write support and the ability to create new objects.
13
13
  - Support for paging
14
14
 
15
+ ## Changes since 0.2.6 ##
16
+ The way authentication works has changed. If you previously used ActiveCMIS.connect then you're fine, otherwise the authentication changes will affect you: the authenticate methods on ActiveCMIS::Server and ActiveCMIS::Repository now return a new object, and don't change the authentication on the object itself. You can also specify optional authentication when connecting to a Server, or when calling the repository method.
17
+
15
18
  ## Installation ##
16
19
  If you haven't installed Nokogiri yet it will be installed automatically, you will need a C compiler and the development files for libxml2.
17
20
 
data/Rakefile CHANGED
@@ -25,6 +25,7 @@ begin
25
25
 
26
26
  gemspec.add_runtime_dependency 'nokogiri', '>= 1.4.1'
27
27
  gemspec.add_runtime_dependency 'ntlm-http', '~> 0.1.1'
28
+ gemspec.add_runtime_dependency 'require_relative', '~> 1.0.2'
28
29
 
29
30
  gemspec.required_ruby_version = '>= 1.8.6'
30
31
  gemspec.files.exclude '.gitignore'
data/active_cmis.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{active_cmis}
8
- s.version = "0.2.6"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Joeri Samson"]
12
- s.date = %q{2011-10-11}
12
+ s.date = %q{2012-02-06}
13
13
  s.description = %q{A CMIS library implementing both reading and updating capabilities through the AtomPub/REST binding to CMIS.}
14
14
  s.email = %q{joeri@xaop.com}
15
15
  s.extra_rdoc_files = [
@@ -62,13 +62,16 @@ Gem::Specification.new do |s|
62
62
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
63
63
  s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.1"])
64
64
  s.add_runtime_dependency(%q<ntlm-http>, ["~> 0.1.1"])
65
+ s.add_runtime_dependency(%q<require_relative>, ["~> 1.0.2"])
65
66
  else
66
67
  s.add_dependency(%q<nokogiri>, [">= 1.4.1"])
67
68
  s.add_dependency(%q<ntlm-http>, ["~> 0.1.1"])
69
+ s.add_dependency(%q<require_relative>, ["~> 1.0.2"])
68
70
  end
69
71
  else
70
72
  s.add_dependency(%q<nokogiri>, [">= 1.4.1"])
71
73
  s.add_dependency(%q<ntlm-http>, ["~> 0.1.1"])
74
+ s.add_dependency(%q<require_relative>, ["~> 1.0.2"])
72
75
  end
73
76
  end
74
77
 
@@ -37,16 +37,16 @@ module ActiveCMIS
37
37
  logger.level = Logger::WARN
38
38
  end
39
39
 
40
- server = Server.new(config["server_url"], logger)
41
40
  if user_name = config["server_login"] and password = config["server_password"]
42
41
  auth_type = config["server_auth"] || :basic
43
- server.authenticate(auth_type, user_name, password)
42
+ authentication_info = [auth_type, user_name, password]
44
43
  end
45
- repository = server.repository(config["repository_id"])
44
+ server = Server.new(config["server_url"], logger, authentication_info)
46
45
  if user_name = config["repository_login"] and password = config["repository_password"]
47
46
  auth_type = config["repository_auth"] || :basic
48
- repository.authenticate(auth_type, user_name, password)
47
+ authentication_info = [auth_type, user_name, password]
49
48
  end
49
+ repository = server.repository(config["repository_id"], authentication_info)
50
50
  return repository
51
51
  else
52
52
  raise "Configuration does not have correct format (#{config.class} is not a hash)"
@@ -188,7 +188,7 @@ module ActiveCMIS
188
188
  @next = xml.xpath("at:feed/at:link[@rel = 'next']/@href", NS::COMBINED).first
189
189
  @next = @next.nil? ? nil : @next.text
190
190
 
191
- new_elements = xml.xpath('at:feed/at:entry', NS::COMBINED).map &@map_entry
191
+ new_elements = xml.xpath('at:feed/at:entry', NS::COMBINED).map(&@map_entry)
192
192
  @elements.concat(new_elements)
193
193
 
194
194
  num_items = xml.xpath("at:feed/cra:numItems", NS::COMBINED).first
@@ -179,7 +179,7 @@ module ActiveCMIS
179
179
  http.request(req) { |resp|
180
180
  status = resp.code.to_i
181
181
  body = resp.body
182
- headers = resp.header
182
+ headers = resp
183
183
  }
184
184
 
185
185
  logger.debug "RECEIVED #{status}"
@@ -9,7 +9,7 @@ module ActiveCMIS
9
9
  delims = "<>#%\""
10
10
  unwise = '{}|\\\\^\[\]`'
11
11
  query = ";/?:@&=+,$"
12
- URI.escape(parameter, /[#{control+space+delims+unwise+query}]/o)
12
+ escape(parameter, /[#{control+space+delims+unwise+query}]/o)
13
13
  end
14
14
 
15
15
  # Given an url (string or URI) returns that url with the given parameters appended
@@ -33,7 +33,16 @@ module ActiveCMIS
33
33
  # FIXME?? percent_encode and escape_url_parameter serve nearly the same purpose, replace one?
34
34
  # @private
35
35
  def self.percent_encode(string)
36
- URI.escape(string, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
36
+ escape(string, /[^#{URI::PATTERN::UNRESERVED}]/o)
37
+ end
38
+
39
+ def self.escape(string, pattern)
40
+ if defined?(URI::Parser)
41
+ parser = URI::Parser.new
42
+ parser.escape(string, pattern)
43
+ else
44
+ URI.escape(string, pattern)
45
+ end
37
46
  end
38
47
 
39
48
  # Returns id if id is already an object, object_by_id if id is a string, nil otherwise
@@ -3,20 +3,36 @@ module ActiveCMIS
3
3
  # @return [Logger] A logger to which debug output and so on is sent
4
4
  attr_reader :logger
5
5
 
6
+ # @return [ActiveCMIS::Server] The server from which the repository was
7
+ # requested
8
+ attr_reader :server
9
+
6
10
  # @private
7
- def initialize(connection, logger, initial_data) #:nodoc:
11
+ def initialize(server, connection, logger, initial_data, authentication_info) #:nodoc:
12
+ @server = server
8
13
  @conn = connection
9
14
  @data = initial_data
10
15
  @logger = logger
16
+ method, *params = authentication_info
17
+ if method
18
+ conn.authenticate(method, *params)
19
+ end
11
20
  end
12
21
 
13
22
  # Use authentication to access the CMIS repository
23
+ # This returns a new Repository object, the existing repository will still
24
+ # use the previous authentication info.
25
+ # If the used authentication info (method, username, password) is the same
26
+ # as for the current Repository object, then self will be returned (unless
27
+ # the server repository cache is cleared first)
14
28
  #
15
- # e.g.: repo.authenticate(:basic, "username", "password")
16
- # @return [void]
17
- def authenticate(method, *params)
18
- conn.authenticate(method, *params)
19
- nil
29
+ # e.g.: authenticated = repo.authenticate(:basic, "username", "password")
30
+ # @param method [:basic, :ntlm]
31
+ # @param username [String]
32
+ # @param password [String]
33
+ # @return [Repository]
34
+ def authenticate(*authentication_info)
35
+ server.repository(key, authentication_info)
20
36
  end
21
37
 
22
38
  # The identifier of the repository
@@ -303,7 +319,7 @@ module ActiveCMIS
303
319
  # e.g. fill_in_template("objectbyid", "id" => "@root@", "includeACL" => true)
304
320
  # -> 'http://example.org/repo/%40root%40?includeRelationships&includeACL=true'
305
321
  def fill_in_template(template, values)
306
- result = template.gsub /\{([^}]+)\}/ do |match|
322
+ result = template.gsub(/\{([^}]+)\}/) do |match|
307
323
  Internal::Utils.percent_encode(values[$1].to_s)
308
324
  end
309
325
  end
@@ -8,17 +8,18 @@ module ActiveCMIS
8
8
  attr_reader :logger
9
9
 
10
10
  # @return [Server] Cached by endpoint and logger
11
- def self.new(endpoint, logger = nil)
11
+ def self.new(endpoint, logger = nil, authentication_info = nil)
12
12
  endpoint = case endpoint
13
13
  when URI; endpoint
14
14
  else URI(endpoint.to_s)
15
15
  end
16
- endpoints[[endpoint, logger]] ||= super(endpoint, logger || ActiveCMIS.default_logger)
16
+ server = super(endpoint, logger || ActiveCMIS.default_logger, authentication_info)
17
+ endpoints[endpoint.to_s][authentication_info][logger] ||= server
17
18
  end
18
19
 
19
20
  # @return [{(URI, Logger) => Server}] The cache of known Servers
20
21
  def self.endpoints
21
- @endpoints ||= {}
22
+ @endpoints ||= Hash.new {|h, k| h[k] = Hash.new {|h2, k2| h2[k2] = {}}}
22
23
  end
23
24
 
24
25
  # @return [String]
@@ -33,35 +34,59 @@ module ActiveCMIS
33
34
  # A connection needs the URL to a CMIS REST endpoint.
34
35
  #
35
36
  # It's used to manage all communication with the CMIS Server
36
- def initialize(endpoint, logger)
37
+ # @param endpoint [URI] The URL where the CMIS AtomPub REST endpoint can be found
38
+ # @param logger [Logger] The logger that will be used to log debug/info messages
39
+ # @param authentication_info [Array?] Optional authentication info to be used when retrieving the data from the AtomPub endpoint
40
+ def initialize(endpoint, logger, authentication_info = nil)
37
41
  @endpoint = endpoint
38
42
  @logger = logger
43
+
44
+ method, *params = authentication_info
45
+ if method
46
+ conn.authenticate(method, *params)
47
+ end
39
48
  end
40
49
 
50
+ # This returns a new Server object using the specified authentication info
51
+ #
41
52
  # @param (see ActiveCMIS::Internal::Connection#authenticate)
42
53
  # @see Internal::Connection#authenticate
43
54
  # @return [void]
44
- def authenticate(method, *params)
45
- conn.authenticate(method, *params)
55
+ def authenticate(*authentication_info)
56
+ new(endpoint, logger, authentication_info)
46
57
  end
47
58
 
48
59
  # Returns the _Repository identified by the ID
60
+ # Authentication will take place with the optional second paramater, if it
61
+ # is absent and there is server authentcation then the server authentication
62
+ # will be used
63
+ #
64
+ # Cached by the repository_id and, authentcation info. The cache can be reset
65
+ # by calling clear_repositories.
49
66
  #
50
- # Cached by the repository_id, no way to reset cache yet
51
67
  # @param [String] repository_id
68
+ # @param [Array] authentication_info
52
69
  # @return [Repository]
53
- def repository(repository_id)
54
- cached_repositories[repository_id] ||= begin
70
+ def repository(repository_id, authentication_info = self.authentcation_info)
71
+ cached_repositories[[repository_id, authentication_info]] ||= begin
55
72
  repository_data = repository_info.
56
73
  xpath("/app:service/app:workspace[cra:repositoryInfo/c:repositoryId[child::text() = '#{repository_id}']]", NS::COMBINED)
57
74
  if repository_data.empty?
58
75
  raise Error::ObjectNotFound.new("The repository #{repository_id} doesn't exist")
59
76
  else
60
- Repository.new(conn.dup, logger.dup, repository_data)
77
+ Repository.new(self, conn.dup, logger.dup, repository_data, authentication_info)
61
78
  end
62
79
  end
63
80
  end
64
81
 
82
+ # Reset cache of Repository objects
83
+ #
84
+ # @return [void]
85
+ def clear_repositories
86
+ @cached_repositories = {}
87
+ end
88
+
89
+
65
90
  # Lists all the available repositories
66
91
  #
67
92
  # @return [<{:id, :name} => String>]
@@ -1,8 +1,8 @@
1
1
  module ActiveCMIS
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 2
5
- PATCH = 6
4
+ MINOR = 3
5
+ PATCH = 0
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
data/lib/active_cmis.rb CHANGED
@@ -4,27 +4,28 @@ require 'net/https'
4
4
  require 'net/ntlm_http'
5
5
  require 'yaml'
6
6
  require 'logger'
7
- require 'active_cmis/version'
8
- require 'active_cmis/internal/caching'
9
- require 'active_cmis/internal/connection'
10
- require 'active_cmis/exceptions'
11
- require 'active_cmis/server'
12
- require 'active_cmis/repository'
13
- require 'active_cmis/object'
14
- require 'active_cmis/document'
15
- require 'active_cmis/folder'
16
- require 'active_cmis/policy'
17
- require 'active_cmis/relationship'
18
- require 'active_cmis/type'
19
- require 'active_cmis/atomic_types'
20
- require 'active_cmis/property_definition'
21
- require 'active_cmis/collection.rb'
22
- require 'active_cmis/rendition.rb'
23
- require 'active_cmis/acl.rb'
24
- require 'active_cmis/acl_entry.rb'
25
- require 'active_cmis/ns'
26
- require 'active_cmis/active_cmis'
27
- require 'active_cmis/internal/utils'
28
- require 'active_cmis/rel'
29
- require 'active_cmis/attribute_prefix'
30
- require 'active_cmis/query_result'
7
+ require 'require_relative'
8
+ require_relative 'active_cmis/version'
9
+ require_relative 'active_cmis/internal/caching'
10
+ require_relative 'active_cmis/internal/connection'
11
+ require_relative 'active_cmis/exceptions'
12
+ require_relative 'active_cmis/server'
13
+ require_relative 'active_cmis/repository'
14
+ require_relative 'active_cmis/object'
15
+ require_relative 'active_cmis/document'
16
+ require_relative 'active_cmis/folder'
17
+ require_relative 'active_cmis/policy'
18
+ require_relative 'active_cmis/relationship'
19
+ require_relative 'active_cmis/type'
20
+ require_relative 'active_cmis/atomic_types'
21
+ require_relative 'active_cmis/property_definition'
22
+ require_relative 'active_cmis/collection.rb'
23
+ require_relative 'active_cmis/rendition.rb'
24
+ require_relative 'active_cmis/acl.rb'
25
+ require_relative 'active_cmis/acl_entry.rb'
26
+ require_relative 'active_cmis/ns'
27
+ require_relative 'active_cmis/active_cmis'
28
+ require_relative 'active_cmis/internal/utils'
29
+ require_relative 'active_cmis/rel'
30
+ require_relative 'active_cmis/attribute_prefix'
31
+ require_relative 'active_cmis/query_result'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_cmis
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 6
10
- version: 0.2.6
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joeri Samson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-11 00:00:00 +02:00
18
+ date: 2012-02-06 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -50,6 +50,22 @@ dependencies:
50
50
  version: 0.1.1
51
51
  type: :runtime
52
52
  version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: require_relative
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 19
62
+ segments:
63
+ - 1
64
+ - 0
65
+ - 2
66
+ version: 1.0.2
67
+ type: :runtime
68
+ version_requirements: *id003
53
69
  description: A CMIS library implementing both reading and updating capabilities through the AtomPub/REST binding to CMIS.
54
70
  email: joeri@xaop.com
55
71
  executables: []