cmis-ruby 0.3.8 → 0.3.9
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.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/Gemfile +4 -2
- data/Rakefile +1 -1
- data/cmis-ruby.gemspec +17 -15
- data/lib/cmis/children.rb +1 -1
- data/lib/cmis/connection.rb +5 -6
- data/lib/cmis/document.rb +7 -4
- data/lib/cmis/folder.rb +14 -18
- data/lib/cmis/helpers.rb +8 -5
- data/lib/cmis/repository.rb +3 -3
- data/lib/cmis/server.rb +1 -2
- data/lib/cmis/version.rb +1 -1
- data/readme.md +9 -6
- data/spec/cmis-ruby/document_spec.rb +58 -0
- data/spec/cmis-ruby/folder_spec.rb +66 -0
- data/spec/cmis-ruby/object_spec.rb +75 -0
- data/spec/cmis-ruby/relationship_spec.rb +7 -0
- data/spec/cmis-ruby/repository_spec.rb +143 -0
- data/spec/cmis-ruby/server_spec.rb +39 -0
- data/spec/config.yml +17 -0
- data/spec/rspec.opts +2 -0
- data/spec/spec_helper.rb +35 -0
- metadata +22 -19
- data/spec/document_spec.rb +0 -47
- data/spec/folder_spec.rb +0 -77
- data/spec/helper.rb +0 -26
- data/spec/object_spec.rb +0 -100
- data/spec/relationship_spec.rb +0 -19
- data/spec/repository_spec.rb +0 -150
- data/spec/server_spec.rb +0 -22
- data/spec/type_spec.rb +0 -69
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb2a6ae007e4f3159fd4f301e20f41566a88e0c7
|
4
|
+
data.tar.gz: 847b9a6c163696833c89fdedcb63248658fa7557
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8dbd5f1d1dfd272697240739e7fd8dd9af6f111be7f4afe4946e286920186580b07dcd4f3d71097fad75310c908e1d90d0faf3b82c1f21eb34a995975933d84
|
7
|
+
data.tar.gz: a16cdbc5e5acfb6a5fff6d0b0de835729e644d596e574381cfc718a6fe1eb97316ccd953dddf1d6fb640791373e91023dbda49c3ef1dba91fb3acd857769129f
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/cmis-ruby.gemspec
CHANGED
@@ -2,23 +2,25 @@ $LOAD_PATH.unshift 'lib'
|
|
2
2
|
require 'cmis/version'
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
|
-
s.name
|
6
|
-
s.version
|
7
|
-
s.date
|
8
|
-
s.authors
|
9
|
-
s.email
|
10
|
-
s.homepage
|
11
|
-
s.summary
|
12
|
-
s.license
|
13
|
-
s.has_rdoc
|
5
|
+
s.name = 'cmis-ruby'
|
6
|
+
s.version = CMIS::VERSION
|
7
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
8
|
+
s.authors = ['Kenneth Geerts', 'Michael Brackx']
|
9
|
+
s.email = ['kenneth@up-nxt.com']
|
10
|
+
s.homepage = 'https://github.com/UP-nxt'
|
11
|
+
s.summary = 'Ruby client for CMIS'
|
12
|
+
s.license = 'Apache-2.0'
|
13
|
+
s.has_rdoc = false
|
14
14
|
|
15
|
-
s.files
|
16
|
-
s.executables
|
17
|
-
s.test_files
|
18
|
-
s.require_paths
|
15
|
+
s.files = `git ls-files`.split($/)
|
16
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
18
|
+
s.require_paths = %w( lib )
|
19
19
|
|
20
|
-
s.
|
21
|
-
|
20
|
+
s.required_ruby_version = '>= 1.9.3'
|
21
|
+
|
22
|
+
s.add_dependency 'faraday', '~> 0.9'
|
23
|
+
s.add_dependency 'activesupport', '>= 3.2', '< 5.0'
|
22
24
|
|
23
25
|
s.description = <<-DESCRIPTION
|
24
26
|
CMIS browser binding client library in ruby.
|
data/lib/cmis/children.rb
CHANGED
@@ -88,7 +88,7 @@ module CMIS
|
|
88
88
|
skipCount: @skip_count,
|
89
89
|
orderBy: @order_by,
|
90
90
|
includeRelationships: @include_relationships,
|
91
|
-
filter: @filter}, @opts)
|
91
|
+
filter: @filter }, @opts)
|
92
92
|
|
93
93
|
results = result['objects'].map { |o| build_object_with_relationships(o) }
|
94
94
|
QueryResult.new(results, result['numItems'], result['hasMoreItems'])
|
data/lib/cmis/connection.rb
CHANGED
@@ -3,8 +3,8 @@ module CMIS
|
|
3
3
|
def initialize(options)
|
4
4
|
options.symbolize_keys!
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
message = "option `service_url` must be set"
|
7
|
+
@service_url = options[:service_url] or raise message
|
8
8
|
|
9
9
|
adapter = (options[:adapter] || :net_http).to_sym
|
10
10
|
|
@@ -18,9 +18,8 @@ module CMIS
|
|
18
18
|
builder.request :multipart
|
19
19
|
builder.request :url_encoded
|
20
20
|
|
21
|
-
if
|
22
|
-
|
23
|
-
builder.basic_auth(username, password)
|
21
|
+
if options[:username]
|
22
|
+
builder.basic_auth(options[:username], options[:password])
|
24
23
|
end
|
25
24
|
|
26
25
|
builder.adapter adapter
|
@@ -35,7 +34,7 @@ module CMIS
|
|
35
34
|
options.symbolize_keys!
|
36
35
|
|
37
36
|
query = options[:query] || {}
|
38
|
-
headers = options[:headers]|| {}
|
37
|
+
headers = options[:headers] || {}
|
39
38
|
url = url(params.delete(:repositoryId), params[:objectId])
|
40
39
|
|
41
40
|
response = if params[:cmisaction]
|
data/lib/cmis/document.rb
CHANGED
@@ -37,12 +37,15 @@ module CMIS
|
|
37
37
|
repositoryId: repository.id,
|
38
38
|
objectId: cmis_object_id }, opts)
|
39
39
|
|
40
|
-
rescue Exceptions::Constraint
|
41
|
-
|
42
|
-
|
40
|
+
rescue Exceptions::Constraint => e
|
41
|
+
if e.message =~ /no content stream/
|
42
|
+
nil
|
43
|
+
else
|
44
|
+
raise e
|
45
|
+
end
|
43
46
|
end
|
44
47
|
|
45
|
-
def
|
48
|
+
def content=(opts = {})
|
46
49
|
opts.stringify_keys!
|
47
50
|
content = { stream: opts.delete('stream'),
|
48
51
|
mime_type: opts.delete('mime_type'),
|
data/lib/cmis/folder.rb
CHANGED
@@ -21,29 +21,16 @@ module CMIS
|
|
21
21
|
|
22
22
|
def create(object, opts = {})
|
23
23
|
case object
|
24
|
-
when Relationship
|
25
|
-
raise "'cmis:relationship' is not fileable. Use Repository#create_relationship"
|
26
|
-
|
27
24
|
when Document
|
28
25
|
return object.create_in_folder(self, opts)
|
29
|
-
|
30
26
|
when Folder
|
31
|
-
o =
|
32
|
-
repositoryId: repository.id,
|
33
|
-
properties: object.properties,
|
34
|
-
objectId: cmis_object_id }, opts)
|
35
|
-
|
27
|
+
o = create_in_self(object, 'createFolder', opts)
|
36
28
|
when Policy
|
37
|
-
o =
|
38
|
-
repositoryId: repository.id,
|
39
|
-
properties: object.properties,
|
40
|
-
objectId: cmis_object_id }, opts)
|
29
|
+
o = create_in_self(object, 'createPolicy', opts)
|
41
30
|
when Item
|
42
|
-
o =
|
43
|
-
|
44
|
-
|
45
|
-
objectId: cmis_object_id }, opts)
|
46
|
-
|
31
|
+
o = create_in_self(object, 'createItem', opts)
|
32
|
+
when Relationship
|
33
|
+
raise "`cmis:relationship` is not fileable. Use Repository#create_relationship."
|
47
34
|
else
|
48
35
|
raise "Unexpected base_type_id: #{object.base_type_id}"
|
49
36
|
end
|
@@ -70,5 +57,14 @@ module CMIS
|
|
70
57
|
objectId: object.cmis_object_id,
|
71
58
|
folderId: cmis_object_id }, opts)
|
72
59
|
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def create_in_self(object, cmis_action, opts)
|
64
|
+
server.execute!({ cmisaction: cmis_action,
|
65
|
+
repositoryId: repository.id,
|
66
|
+
properties: object.properties,
|
67
|
+
objectId: cmis_object_id }, opts)
|
68
|
+
end
|
73
69
|
end
|
74
70
|
end
|
data/lib/cmis/helpers.rb
CHANGED
@@ -68,14 +68,17 @@ module CMIS
|
|
68
68
|
def sanitize(prop)
|
69
69
|
value = prop['value']
|
70
70
|
|
71
|
-
# Sometimes (when?) single values come in an array
|
72
|
-
|
73
|
-
|
74
|
-
end
|
71
|
+
# Sometimes (when?) single values come in an array.
|
72
|
+
# For now, we do nothing to hide this and leave it up to the user.
|
73
|
+
# # value = value.first if value.is_a?(Array)
|
75
74
|
|
76
75
|
if !!value && prop['type'] == 'datetime'
|
77
76
|
# CMIS sends millis since epoch
|
78
|
-
value
|
77
|
+
if value.is_a? Array
|
78
|
+
value.map! { |v| Time.at(v / 1000.0) }
|
79
|
+
else
|
80
|
+
value = Time.at(value / 1000.0)
|
81
|
+
end
|
79
82
|
end
|
80
83
|
|
81
84
|
value
|
data/lib/cmis/repository.rb
CHANGED
@@ -68,7 +68,7 @@ module CMIS
|
|
68
68
|
Type.new(result, self)
|
69
69
|
end
|
70
70
|
|
71
|
-
def
|
71
|
+
def type?(type_id)
|
72
72
|
type(type_id)
|
73
73
|
true
|
74
74
|
rescue Exceptions::ObjectNotFound
|
@@ -120,7 +120,7 @@ module CMIS
|
|
120
120
|
value = value.strftime('%Y-%m-%dT%H:%M:%S.%L')
|
121
121
|
"TIMESTAMP '#{value}'"
|
122
122
|
else
|
123
|
-
# TODO Correct escaping for find_object
|
123
|
+
# TODO: Correct escaping for find_object
|
124
124
|
# value = value.gsub(BACKSLASH, BACKSLASH * 4).gsub(QUOTE, "#{BACKSLASH * 2}#{QUOTE}")
|
125
125
|
"'#{value}'"
|
126
126
|
end
|
@@ -130,7 +130,7 @@ module CMIS
|
|
130
130
|
types = []
|
131
131
|
a.each do |t|
|
132
132
|
types << Type.new(t['type'], self)
|
133
|
-
types << construct_types(t['children']) if t.
|
133
|
+
types << construct_types(t['children']) if t.key?('children')
|
134
134
|
end
|
135
135
|
types.flatten
|
136
136
|
end
|
data/lib/cmis/server.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module CMIS
|
2
2
|
class Server < Connection
|
3
|
-
|
4
3
|
def initialize(options = {})
|
5
4
|
super
|
6
5
|
end
|
@@ -20,7 +19,7 @@ module CMIS
|
|
20
19
|
Repository.new(result[repository_id], self)
|
21
20
|
end
|
22
21
|
|
23
|
-
def
|
22
|
+
def repository?(repository_id)
|
24
23
|
repository(repository_id)
|
25
24
|
true
|
26
25
|
rescue Exceptions::ObjectNotFound
|
data/lib/cmis/version.rb
CHANGED
data/readme.md
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
-
#
|
1
|
+
# CMIS ruby
|
2
2
|
|
3
|
-
|
3
|
+
[](http://badge.fury.io/rb/cmis-ruby)
|
4
|
+
[](https://codeclimate.com/github/UP-nxt/cmis-ruby)
|
5
|
+
[](https://travis-ci.org/UP-nxt/cmis-ruby)
|
6
|
+
[](https://gemnasium.com/UP-nxt/cmis-ruby)
|
4
7
|
|
5
|
-
|
8
|
+
**CMIS ruby** is a [CMIS](http://chemistry.apache.org/project/cmis.html) client library, using the the CMIS browser binding ([CMIS 1.1](http://docs.oasis-open.org/cmis/CMIS/v1.1/CMIS-v1.1.html)) for Ruby.
|
6
9
|
|
7
|
-
Running
|
10
|
+
## Running specs
|
8
11
|
|
9
|
-
|
12
|
+
Running the tests requires a separate CMIS server. The default rake task runs the specs.
|
10
13
|
|
11
14
|
## TODO
|
12
15
|
|
@@ -15,4 +18,4 @@ Running the tests requires a running CMIS server.
|
|
15
18
|
|
16
19
|
## Contributing
|
17
20
|
|
18
|
-
Write some code. Run
|
21
|
+
Write some code. Run the specs. Open a pull request.
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module CMIS
|
4
|
+
describe Document do
|
5
|
+
context 'when creating a document with content' do
|
6
|
+
it 'has properties and content' do
|
7
|
+
document = repository.new_document
|
8
|
+
document.name = 'apple_document'
|
9
|
+
document.object_type_id = 'cmis:document'
|
10
|
+
document.content = { stream: StringIO.new('apple is a fruit'),
|
11
|
+
mime_type: 'text/apple',
|
12
|
+
filename: 'apple.txt' }
|
13
|
+
document = document.create_in_folder(repository.root)
|
14
|
+
|
15
|
+
expect(document.content_stream_mime_type).to eq('text/apple')
|
16
|
+
expect(document.content_stream_file_name).to eq('apple.txt')
|
17
|
+
expect(document.content).to eq('apple is a fruit')
|
18
|
+
|
19
|
+
document.delete
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when creating a document without content' do
|
24
|
+
it 'has properties and no content' do
|
25
|
+
document = repository.new_document
|
26
|
+
document.name = 'apple_document'
|
27
|
+
document.object_type_id = 'cmis:document'
|
28
|
+
document = document.create_in_folder(repository.root)
|
29
|
+
|
30
|
+
expect(document.content_stream_mime_type).to be_nil
|
31
|
+
expect(document.content_stream_file_name).to be_nil
|
32
|
+
expect(document.content).to be_nil
|
33
|
+
|
34
|
+
document.delete
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when creating a document and then setting the content' do
|
39
|
+
it 'has properties and content' do
|
40
|
+
document = repository.new_document
|
41
|
+
document.name = 'apple_document'
|
42
|
+
document.object_type_id = 'cmis:document'
|
43
|
+
document = document.create_in_folder(repository.root)
|
44
|
+
|
45
|
+
document.content = { stream: StringIO.new('apple is a fruit'),
|
46
|
+
mime_type: 'text/apple',
|
47
|
+
filename: 'apple.txt' }
|
48
|
+
|
49
|
+
# Why doesn't this work?
|
50
|
+
# expect(document.content_stream_mime_type).to eq('text/apple')
|
51
|
+
# expect(document.content_stream_file_name).to eq('apple.txt')
|
52
|
+
expect(document.content).to eq('apple is a fruit')
|
53
|
+
|
54
|
+
document.delete
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module CMIS
|
4
|
+
describe Folder do
|
5
|
+
describe '#parent' do
|
6
|
+
before do
|
7
|
+
@folder = create_folder
|
8
|
+
end
|
9
|
+
|
10
|
+
after do
|
11
|
+
@folder.delete
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'is nil for the root folder' do
|
15
|
+
expect(repository.root.parent).to be_nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'is the root folder for its child' do
|
19
|
+
expect(@folder.parent.cmis_object_id).to eq(repository.root_folder_id)
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_folder
|
23
|
+
folder = repository.new_folder
|
24
|
+
folder.name = 'test_folder'
|
25
|
+
folder.object_type_id = 'cmis:folder'
|
26
|
+
repository.root.create(folder)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#create' do
|
31
|
+
context 'when creating a relationship in a folder' do
|
32
|
+
it 'raises an exception' do
|
33
|
+
relationship = repository.new_relationship
|
34
|
+
relationship.name = 'test_relationship'
|
35
|
+
relationship.object_type_id = 'cmis:relationship'
|
36
|
+
expect {
|
37
|
+
repository.root.create(new_object)
|
38
|
+
}.to raise_exception
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when creating an item in a folder' do
|
43
|
+
it 'raises an exception' do
|
44
|
+
item = repository.new_item
|
45
|
+
item.name = 'test_item'
|
46
|
+
item.object_type_id = 'cmis:item'
|
47
|
+
item = repository.root.create(item)
|
48
|
+
expect(item).to be_a CMIS::Item
|
49
|
+
expect(item.name).to eq('test_item')
|
50
|
+
item.delete
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'when creating a plain object in a folder' do
|
55
|
+
it 'raises an exception' do
|
56
|
+
new_object = CMIS::Object.new({}, repository)
|
57
|
+
new_object.name = 'object1'
|
58
|
+
new_object.object_type_id = 'cmis:folder'
|
59
|
+
expect {
|
60
|
+
repository.root.create(new_object)
|
61
|
+
}.to raise_exception
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module CMIS
|
4
|
+
describe Object do
|
5
|
+
before do
|
6
|
+
@document = create_document
|
7
|
+
end
|
8
|
+
|
9
|
+
after do
|
10
|
+
@document.delete
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#properties' do
|
14
|
+
# Property accessor behavior...
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#object_type' do
|
18
|
+
it 'returns the type' do
|
19
|
+
expect(@document.object_type).to be_a CMIS::Type
|
20
|
+
expect(@document.object_type.id).to eq('cmis:document')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#parents' do
|
25
|
+
it 'has the root as only parent' do
|
26
|
+
expect(@document.parents.size).to eq(1)
|
27
|
+
expect(@document.parents.first.cmis_object_id).to eq(repository.root_folder_id)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#allowable_actions' do
|
32
|
+
it 'returns the allowable actions' do
|
33
|
+
actions = @document.allowable_actions
|
34
|
+
expect(actions).to_not be_nil
|
35
|
+
expect(actions).to_not be_empty
|
36
|
+
actions.values.each do |v|
|
37
|
+
expect([true, false]).to include(v)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#relationships' do
|
43
|
+
it 'returns all relationships' do
|
44
|
+
relationships = @document.relationships
|
45
|
+
expect(relationships).to be_a_kind_of(Relationships)
|
46
|
+
relationships.each_relationship do |r|
|
47
|
+
expect(r).to be_a(Relationship)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#unfile' do
|
53
|
+
it 'unfiles it from the parent folder' do
|
54
|
+
@document.unfile
|
55
|
+
expect(@document.parents).to be_empty
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#acls' do
|
60
|
+
it 'returns acls' do
|
61
|
+
acls = @document.acls
|
62
|
+
expect(acls).to have_key(:aces)
|
63
|
+
expect(acls).to have_key(:isExact)
|
64
|
+
expect([true, false]).to include(acls[:isExact])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def create_document
|
69
|
+
document = repository.new_document
|
70
|
+
document.name = 'test_document'
|
71
|
+
document.object_type_id = 'cmis:document'
|
72
|
+
repository.root.create(document)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|