cmis-ruby 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cmis-ruby.gemspec +2 -3
- data/lib/cmis-ruby.rb +2 -6
- data/lib/cmis/connection.rb +107 -151
- data/lib/cmis/server.rb +1 -10
- data/lib/cmis/version.rb +1 -1
- data/readme.md +0 -1
- metadata +11 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02a90b75f0be84cc302c4a1009af31ba8c5bda9b
|
4
|
+
data.tar.gz: 4c4fbdf04f4c5dee685f77a1ecfe43af08616431
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d21dacc515544df7721021adc675a1a7492ec56d3067e0a9a7220b205274dbdbb06212cb2028b926867deef899aa8373c3112be0071ab2e1e46973633070aa21
|
7
|
+
data.tar.gz: 5b2ed9b877541bf0fb23f97ca15fa8f7bafa776eb803dab54c2d025fc30984023479f0c0a3b47c2b49c6cf51f452d35b56ed17cc3d3ed0170e4f95c2c86b50f2
|
data/cmis-ruby.gemspec
CHANGED
@@ -16,9 +16,8 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
17
17
|
s.require_paths = ['lib']
|
18
18
|
|
19
|
-
s.add_dependency '
|
20
|
-
s.add_dependency '
|
21
|
-
s.add_dependency 'activesupport', '>= 3.2'
|
19
|
+
s.add_dependency 'faraday', '~> 0.9.0'
|
20
|
+
s.add_dependency 'activesupport', '>= 3.2', '< 5.0'
|
22
21
|
|
23
22
|
s.description = <<-DESC.gsub(/^ /, '')
|
24
23
|
CMIS browser binding client library in ruby.
|
data/lib/cmis-ruby.rb
CHANGED
@@ -1,16 +1,11 @@
|
|
1
|
-
# ruby
|
2
1
|
require 'bigdecimal'
|
3
2
|
require 'json'
|
4
3
|
|
5
|
-
# core extensions
|
6
4
|
require 'active_support/core_ext'
|
7
5
|
require 'core_ext'
|
8
6
|
|
9
|
-
|
10
|
-
require 'typhoeus'
|
11
|
-
require 'net/http/post/multipart'
|
7
|
+
require 'faraday'
|
12
8
|
|
13
|
-
# cmis-ruby
|
14
9
|
require 'cmis/connection'
|
15
10
|
require 'cmis/exceptions'
|
16
11
|
require 'cmis/server'
|
@@ -29,3 +24,4 @@ require 'cmis/policy'
|
|
29
24
|
require 'cmis/relationship'
|
30
25
|
require 'cmis/property_definition'
|
31
26
|
require 'cmis/type'
|
27
|
+
require 'cmis/version'
|
data/lib/cmis/connection.rb
CHANGED
@@ -1,189 +1,145 @@
|
|
1
1
|
module CMIS
|
2
2
|
class Connection
|
3
|
-
def initialize(
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
@
|
3
|
+
def initialize(options)
|
4
|
+
options.symbolize_keys!
|
5
|
+
|
6
|
+
service_url = options[:service_url] || ENV['CMIS_BROWSER_URL']
|
7
|
+
@service_url = service_url or raise "\
|
8
|
+
option `:service_url` or ENV['CMIS_BROWSER_URL'] must be set"
|
9
|
+
|
10
|
+
adapter = (options[:adapter] || :net_http).to_sym
|
11
|
+
|
12
|
+
headers = {
|
13
|
+
user_agent: "cmis-ruby/#{VERSION} [#{adapter}]"
|
14
|
+
}.merge(options[:headers] || {})
|
15
|
+
conn_opts = { headers: headers, ssl: options[:ssl] }.compact
|
16
|
+
|
17
|
+
@http = Faraday.new(conn_opts) do |builder|
|
18
|
+
builder.use RequestModifier
|
19
|
+
builder.request :multipart
|
20
|
+
builder.request :url_encoded
|
21
|
+
|
22
|
+
if username = options[:username] || ENV['CMIS_USER']
|
23
|
+
password = options[:password] || ENV['CMIS_PASSWORD']
|
24
|
+
builder.basic_auth(username, password)
|
25
|
+
end
|
26
|
+
|
27
|
+
builder.adapter adapter
|
28
|
+
builder.response :logger if options[:log_requests]
|
29
|
+
builder.use ResponseParser
|
30
|
+
end
|
8
31
|
|
9
32
|
@url_cache = {}
|
10
33
|
end
|
11
34
|
|
12
35
|
def execute!(params = {}, options = {})
|
13
|
-
query, headers = parse_options(options)
|
14
|
-
|
15
|
-
Request.new(service_url: @service_url,
|
16
|
-
url_cache: @url_cache,
|
17
|
-
params: params,
|
18
|
-
query: query,
|
19
|
-
headers: headers,
|
20
|
-
username: @username,
|
21
|
-
password: @password).run
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def parse_options(options)
|
27
36
|
options.symbolize_keys!
|
28
|
-
query = options[:query] || {}
|
29
|
-
headers = @headers
|
30
|
-
headers.merge!(options[:headers]) if options[:headers]
|
31
|
-
[ query, headers ]
|
32
|
-
end
|
33
37
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
@url_cache = options[:url_cache]
|
38
|
-
@params = massage(options[:params])
|
39
|
-
@repository_id = @params.delete(:repositoryId)
|
40
|
-
@query = options[:query]
|
41
|
-
@headers = options[:headers]
|
42
|
-
@username = options[:username]
|
43
|
-
@password = options[:password]
|
44
|
-
end
|
38
|
+
query = options[:query] || {}
|
39
|
+
headers = options[:headers]|| {}
|
40
|
+
url = url(params.delete(:repositoryId), params[:objectId])
|
45
41
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
when 'post'
|
51
|
-
typhoeus_request
|
52
|
-
when 'multipart_post'
|
53
|
-
multipart_post
|
54
|
-
end
|
42
|
+
response = if params[:cmisaction]
|
43
|
+
@http.post(url, params, headers)
|
44
|
+
else
|
45
|
+
@http.get(url, params.merge(query), headers)
|
55
46
|
end
|
56
47
|
|
57
|
-
|
48
|
+
response.body
|
49
|
+
end
|
58
50
|
|
59
|
-
|
60
|
-
options = {
|
61
|
-
method: method,
|
62
|
-
body: body,
|
63
|
-
params: query,
|
64
|
-
headers: @headers,
|
65
|
-
followlocation: true
|
66
|
-
}
|
67
|
-
options[:userpwd] = "#{@username}:#{@password}" if @username
|
68
|
-
response = Typhoeus::Request.new(url, options).run
|
69
|
-
Response.new(response.headers['Content-Type'], response.body).parse!
|
70
|
-
end
|
51
|
+
private
|
71
52
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
{ use_ssl: true , verify_mode: OpenSSL::SSL::VERIFY_NONE }
|
79
|
-
else
|
80
|
-
{}
|
81
|
-
end
|
82
|
-
Net::HTTP.start(uri.host, uri.port, opts) do |http|
|
83
|
-
response = http.request(req)
|
84
|
-
Response.new(response['Content-Type'], response.body).parse!
|
85
|
-
end
|
53
|
+
def url(repository_id, object_id)
|
54
|
+
if repository_id.nil?
|
55
|
+
@service_url
|
56
|
+
else
|
57
|
+
urls = repository_urls(repository_id)
|
58
|
+
urls[object_id ? :root_folder_url : :repository_url]
|
86
59
|
end
|
60
|
+
end
|
87
61
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
else
|
92
|
-
urls = repository_urls(@repository_id)
|
93
|
-
if @params[:objectId]
|
94
|
-
urls[:root_folder_url]
|
95
|
-
else
|
96
|
-
urls[:repository_url]
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
62
|
+
def repository_urls(repository_id)
|
63
|
+
if @url_cache[repository_id].nil?
|
64
|
+
repository_infos = @http.get(@service_url).body
|
100
65
|
|
101
|
-
|
102
|
-
|
103
|
-
if @params[:content]
|
104
|
-
'multipart_post'
|
105
|
-
else
|
106
|
-
'post'
|
107
|
-
end
|
108
|
-
else
|
109
|
-
'get'
|
66
|
+
unless repository_infos.has_key?(repository_id)
|
67
|
+
raise Exceptions::ObjectNotFound, "repositoryId: #{repository_id}"
|
110
68
|
end
|
111
|
-
end
|
112
69
|
|
113
|
-
|
114
|
-
@
|
70
|
+
repository_info = repository_infos[repository_id]
|
71
|
+
@url_cache[repository_id] = {
|
72
|
+
repository_url: repository_info['repositoryUrl'],
|
73
|
+
root_folder_url: repository_info['rootFolderUrl']
|
74
|
+
}
|
115
75
|
end
|
76
|
+
@url_cache[repository_id]
|
77
|
+
end
|
78
|
+
end
|
116
79
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
80
|
+
class RequestModifier < Faraday::Middleware
|
81
|
+
def call(env)
|
82
|
+
if env[:body]
|
83
|
+
env[:body].compact!
|
84
|
+
wrap_content(env)
|
85
|
+
massage_properties(env)
|
123
86
|
end
|
87
|
+
@app.call(env)
|
88
|
+
end
|
124
89
|
|
125
|
-
|
126
|
-
def massage(hash)
|
127
|
-
hash.compact
|
90
|
+
private
|
128
91
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
92
|
+
def wrap_content(env)
|
93
|
+
if content_hash = env[:body][:content]
|
94
|
+
env[:body][:content] = Faraday::UploadIO.new(content_hash[:stream],
|
95
|
+
content_hash[:mime_type],
|
96
|
+
content_hash[:filename])
|
97
|
+
end
|
98
|
+
end
|
134
99
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
hash.merge!("propertyValue[#{index}][#{idx}]" => value[idx])
|
143
|
-
end
|
144
|
-
else
|
145
|
-
hash.merge!("propertyId[#{index}]" => id,
|
146
|
-
"propertyValue[#{index}]" => value)
|
100
|
+
def massage_properties(env)
|
101
|
+
if props = env[:body].delete(:properties)
|
102
|
+
props.each_with_index do |(id, value), index|
|
103
|
+
if value.is_a?(Array)
|
104
|
+
env[:body][id_key(index)] = id
|
105
|
+
value.each_with_index do |sub_value, sub_index|
|
106
|
+
env[:body][val_key(index, sub_index)] = normalize(sub_value)
|
147
107
|
end
|
108
|
+
else
|
109
|
+
env[:body][id_key(index)] = id
|
110
|
+
env[:body][val_key(index)] = normalize(value)
|
148
111
|
end
|
149
112
|
end
|
150
|
-
hash
|
151
113
|
end
|
114
|
+
end
|
152
115
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
options[:userpwd] = "#{@username}:#{@password}" if @username
|
158
|
-
response = Typhoeus::Request.new(@service_url, options).run
|
159
|
-
repository_infos = JSON.parse(response.body)
|
160
|
-
|
161
|
-
unless repository_infos.has_key?(repository_id)
|
162
|
-
raise Exceptions::ObjectNotFound, "repositoryId: #{repository_id}"
|
163
|
-
end
|
164
|
-
|
165
|
-
repository_info = repository_infos[repository_id]
|
166
|
-
@url_cache[repository_id] = { repository_url: repository_info['repositoryUrl'],
|
167
|
-
root_folder_url: repository_info['rootFolderUrl'] }
|
168
|
-
end
|
169
|
-
@url_cache[repository_id]
|
170
|
-
end
|
116
|
+
def normalize(value)
|
117
|
+
value = value.to_time if value.is_a?(Date)
|
118
|
+
value = (value.to_f * 1000).to_i if value.is_a?(Time)
|
119
|
+
value
|
171
120
|
end
|
172
121
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
@body = body
|
177
|
-
end
|
122
|
+
def id_key(index)
|
123
|
+
"propertyId[#{index}]"
|
124
|
+
end
|
178
125
|
|
179
|
-
|
180
|
-
|
126
|
+
def val_key(i1, i2 = nil)
|
127
|
+
result = "propertyValue[#{i1}]"
|
128
|
+
result = "#{result}[#{i2}]" if i2
|
129
|
+
result
|
130
|
+
end
|
131
|
+
end
|
181
132
|
|
182
|
-
|
183
|
-
|
184
|
-
|
133
|
+
class ResponseParser < Faraday::Middleware
|
134
|
+
def call(env)
|
135
|
+
@app.call(env).on_complete do |env|
|
136
|
+
if env[:response_headers][:content_type] =~ /\/(x-)?json(;.+?)?$/
|
137
|
+
env[:body] = JSON.parse(env[:body]).with_indifferent_access
|
138
|
+
if env[:body].is_a?(Hash) && ex = env[:body][:exception]
|
139
|
+
ruby_exception = "CMIS::Exceptions::#{ex.camelize}".constantize
|
140
|
+
raise ruby_exception, env[:body]['message']
|
141
|
+
end
|
185
142
|
end
|
186
|
-
result.with_indifferent_access
|
187
143
|
end
|
188
144
|
end
|
189
145
|
end
|
data/lib/cmis/server.rb
CHANGED
@@ -3,16 +3,7 @@ module CMIS
|
|
3
3
|
attr_reader :connection
|
4
4
|
|
5
5
|
def initialize(options = {})
|
6
|
-
options
|
7
|
-
|
8
|
-
service_url = options['service_url'] || ENV['CMIS_BROWSER_URL']
|
9
|
-
username = options['username'] || ENV['CMIS_USER']
|
10
|
-
password = options['password'] || ENV['CMIS_PASSWORD']
|
11
|
-
headers = options['headers'] || {}
|
12
|
-
|
13
|
-
raise "`service_url` must be set" unless service_url
|
14
|
-
|
15
|
-
@connection = Connection.new(service_url, username, password, headers)
|
6
|
+
@connection = Connection.new(options)
|
16
7
|
end
|
17
8
|
|
18
9
|
def repositories(opts = {})
|
data/lib/cmis/version.rb
CHANGED
data/readme.md
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cmis-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenneth Geerts
|
@@ -9,36 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-03-
|
12
|
+
date: 2014-03-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: faraday
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 0.9.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
28
|
-
- !ruby/object:Gem::Dependency
|
29
|
-
name: multipart-post
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
32
|
-
- - "~>"
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '1.1'
|
35
|
-
type: :runtime
|
36
|
-
prerelease: false
|
37
|
-
version_requirements: !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - "~>"
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: '1.1'
|
27
|
+
version: 0.9.0
|
42
28
|
- !ruby/object:Gem::Dependency
|
43
29
|
name: activesupport
|
44
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -46,6 +32,9 @@ dependencies:
|
|
46
32
|
- - ">="
|
47
33
|
- !ruby/object:Gem::Version
|
48
34
|
version: '3.2'
|
35
|
+
- - "<"
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '5.0'
|
49
38
|
type: :runtime
|
50
39
|
prerelease: false
|
51
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -53,6 +42,9 @@ dependencies:
|
|
53
42
|
- - ">="
|
54
43
|
- !ruby/object:Gem::Version
|
55
44
|
version: '3.2'
|
45
|
+
- - "<"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
56
48
|
description: |
|
57
49
|
CMIS browser binding client library in ruby.
|
58
50
|
email:
|