cmis-ruby 0.3.9 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb2a6ae007e4f3159fd4f301e20f41566a88e0c7
4
- data.tar.gz: 847b9a6c163696833c89fdedcb63248658fa7557
3
+ metadata.gz: 54d939c76212d26bf61e62941fc9c8befd44bd32
4
+ data.tar.gz: a46f072f12e9309b00334e1c184c9250fd887539
5
5
  SHA512:
6
- metadata.gz: f8dbd5f1d1dfd272697240739e7fd8dd9af6f111be7f4afe4946e286920186580b07dcd4f3d71097fad75310c908e1d90d0faf3b82c1f21eb34a995975933d84
7
- data.tar.gz: a16cdbc5e5acfb6a5fff6d0b0de835729e644d596e574381cfc718a6fe1eb97316ccd953dddf1d6fb640791373e91023dbda49c3ef1dba91fb3acd857769129f
6
+ metadata.gz: c369361121888cbd294e8c897b153b677377dc115fb31924d46e25cd3c4eb9e24ffdba3081c13a95be8ebf4d490504264b3942febaaade37d43eb10e07f4cb21
7
+ data.tar.gz: 5c8d73ce97ec3a0b873825e8cb9c1247c9b3ef3529469d03182da7d96a83627a7424003f901d3dd560d7b92a51171eed936227ad0c26072897888857acfd393e
data/lib/cmis-ruby.rb CHANGED
@@ -1,20 +1,11 @@
1
- require 'bigdecimal'
2
- require 'json'
3
-
4
- require 'faraday'
5
-
6
1
  require 'active_support/core_ext'
7
2
  require 'core_ext'
8
3
 
9
- require 'cmis/connection'
10
4
  require 'cmis/exceptions'
11
- require 'cmis/server'
12
5
  require 'cmis/helpers'
13
6
  require 'cmis/object_factory'
14
- require 'cmis/query_result'
15
- require 'cmis/query'
16
- require 'cmis/children'
17
- require 'cmis/relationships'
7
+ require 'cmis/connection'
8
+ require 'cmis/server'
18
9
  require 'cmis/repository'
19
10
  require 'cmis/object'
20
11
  require 'cmis/document'
@@ -22,6 +13,5 @@ require 'cmis/folder'
22
13
  require 'cmis/item'
23
14
  require 'cmis/policy'
24
15
  require 'cmis/relationship'
25
- require 'cmis/property_definition'
26
16
  require 'cmis/type'
27
- require 'cmis/version'
17
+ require 'cmis/property_definition'
data/lib/cmis/children.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'bigdecimal'
2
+ require 'cmis/query_result'
3
+
1
4
  module CMIS
2
5
  class Children
3
6
  # Options: from, page_size
@@ -1,10 +1,16 @@
1
+ require 'faraday'
2
+ require 'cmis/version'
3
+ require 'cmis/connection/url_resolver'
4
+ require 'cmis/connection/request_modifier'
5
+ require 'cmis/connection/response_parser'
6
+
1
7
  module CMIS
2
8
  class Connection
3
9
  def initialize(options)
4
10
  options.symbolize_keys!
5
11
 
6
12
  message = "option `service_url` must be set"
7
- @service_url = options[:service_url] or raise message
13
+ service_url = options[:service_url] or raise message
8
14
 
9
15
  adapter = (options[:adapter] || :net_http).to_sym
10
16
 
@@ -27,7 +33,7 @@ module CMIS
27
33
  builder.use ResponseParser
28
34
  end
29
35
 
30
- @url_cache = {}
36
+ @url_resolver = URLResolver.new(@http, service_url)
31
37
  end
32
38
 
33
39
  def execute!(params = {}, options = {})
@@ -35,7 +41,7 @@ module CMIS
35
41
 
36
42
  query = options[:query] || {}
37
43
  headers = options[:headers] || {}
38
- url = url(params.delete(:repositoryId), params[:objectId])
44
+ url = @url_resolver.url(params.delete(:repositoryId), params[:objectId])
39
45
 
40
46
  response = if params[:cmisaction]
41
47
  @http.post(url, params, headers)
@@ -45,111 +51,5 @@ module CMIS
45
51
 
46
52
  response.body
47
53
  end
48
-
49
- private
50
-
51
- def url(repository_id, object_id)
52
- if repository_id.nil?
53
- @service_url
54
- else
55
- urls = repository_urls(repository_id)
56
- urls[object_id ? :root_folder_url : :repository_url]
57
- end
58
- end
59
-
60
- def repository_urls(repository_id)
61
- if @url_cache[repository_id].nil?
62
- repository_infos = @http.get(@service_url).body
63
-
64
- unless repository_infos.has_key?(repository_id)
65
- raise Exceptions::ObjectNotFound, "repositoryId: #{repository_id}"
66
- end
67
-
68
- repository_info = repository_infos[repository_id]
69
- @url_cache[repository_id] = {
70
- repository_url: repository_info[:repositoryUrl],
71
- root_folder_url: repository_info[:rootFolderUrl]
72
- }
73
- end
74
- @url_cache[repository_id]
75
- end
76
- end
77
-
78
- class RequestModifier < Faraday::Middleware
79
- def call(env)
80
- if env[:body]
81
- env[:body].compact!
82
- wrap_content(env)
83
- massage_properties(env)
84
- end
85
- @app.call(env)
86
- end
87
-
88
- private
89
-
90
- def wrap_content(env)
91
- if content_hash = env[:body][:content]
92
- env[:body][:content] = Faraday::UploadIO.new(content_hash[:stream],
93
- content_hash[:mime_type],
94
- content_hash[:filename])
95
- end
96
- end
97
-
98
- def massage_properties(env)
99
- if props = env[:body].delete(:properties)
100
- props.each_with_index do |(id, value), index|
101
- if value.is_a?(Array)
102
- env[:body][id_key(index)] = id
103
- value.each_with_index do |sub_value, sub_index|
104
- env[:body][val_key(index, sub_index)] = normalize(sub_value)
105
- end
106
- else
107
- env[:body][id_key(index)] = id
108
- env[:body][val_key(index)] = normalize(value)
109
- end
110
- end
111
- end
112
- end
113
-
114
- def normalize(value)
115
- value = value.to_time if value.is_a?(Date)
116
- value = (value.to_f * 1000).to_i if value.is_a?(Time)
117
- value
118
- end
119
-
120
- def id_key(index)
121
- "propertyId[#{index}]"
122
- end
123
-
124
- def val_key(i1, i2 = nil)
125
- result = "propertyValue[#{i1}]"
126
- result = "#{result}[#{i2}]" if i2
127
- result
128
- end
129
- end
130
-
131
- class ResponseParser < Faraday::Middleware
132
- JSON_CONTENT_TYPE = /\/(x-)?json(;.+?)?$/
133
-
134
- def call(env)
135
- @app.call(env).on_complete do |env|
136
- if env[:response_headers][:content_type] =~ JSON_CONTENT_TYPE
137
- env[:body] = JSON.parse(env[:body]).with_indifferent_access
138
- check_for_exception!(env[:body])
139
- end
140
- end
141
- end
142
-
143
- private
144
-
145
- def check_for_exception!(body)
146
- return unless body.is_a?(Hash)
147
-
148
- if ex = body[:exception]
149
- ruby_exception = "CMIS::Exceptions::#{ex.camelize}".constantize
150
- message = "#{ex.underscore.humanize}: #{body[:message]}"
151
- raise ruby_exception, message
152
- end
153
- end
154
54
  end
155
55
  end
@@ -0,0 +1,58 @@
1
+ require 'faraday'
2
+
3
+ module CMIS
4
+ class Connection
5
+ class RequestModifier < Faraday::Middleware
6
+ def call(env)
7
+ if env[:body]
8
+ env[:body].compact!
9
+ wrap_content(env)
10
+ massage_properties(env)
11
+ end
12
+ @app.call(env)
13
+ end
14
+
15
+ private
16
+
17
+ def wrap_content(env)
18
+ if content_hash = env[:body][:content]
19
+ env[:body][:content] = Faraday::UploadIO.new(content_hash[:stream],
20
+ content_hash[:mime_type],
21
+ content_hash[:filename])
22
+ end
23
+ end
24
+
25
+ def massage_properties(env)
26
+ if props = env[:body].delete(:properties)
27
+ props.each_with_index do |(id, value), index|
28
+ if value.is_a?(Array)
29
+ env[:body][id_key(index)] = id
30
+ value.each_with_index do |sub_value, sub_index|
31
+ env[:body][val_key(index, sub_index)] = normalize(sub_value)
32
+ end
33
+ else
34
+ env[:body][id_key(index)] = id
35
+ env[:body][val_key(index)] = normalize(value)
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ def normalize(value)
42
+ value = value.to_time if value.is_a?(Date)
43
+ value = (value.to_f * 1000).to_i if value.is_a?(Time)
44
+ value
45
+ end
46
+
47
+ def id_key(index)
48
+ "propertyId[#{index}]"
49
+ end
50
+
51
+ def val_key(i1, i2 = nil)
52
+ result = "propertyValue[#{i1}]"
53
+ result = "#{result}[#{i2}]" if i2
54
+ result
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,31 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module CMIS
5
+ class Connection
6
+ class ResponseParser < Faraday::Middleware
7
+ JSON_CONTENT_TYPE = /\/(x-)?json(;.+?)?$/
8
+
9
+ def call(env)
10
+ @app.call(env).on_complete do |env|
11
+ if env[:response_headers][:content_type] =~ JSON_CONTENT_TYPE
12
+ env[:body] = JSON.parse(env[:body]).with_indifferent_access
13
+ check_for_exception!(env[:body])
14
+ end
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def check_for_exception!(body)
21
+ return unless body.is_a?(Hash)
22
+
23
+ if ex = body[:exception]
24
+ ruby_exception = "CMIS::Exceptions::#{ex.camelize}".constantize
25
+ message = "#{ex.underscore.humanize}: #{body[:message]}"
26
+ raise ruby_exception, message
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,38 @@
1
+ module CMIS
2
+ class Connection
3
+ class URLResolver
4
+ def initialize(http, service_url)
5
+ @http = http
6
+ @service_url = service_url
7
+ @cache = {}
8
+ end
9
+
10
+ def url(repository_id, object_id)
11
+ return @service_url if repository_id.nil?
12
+
13
+ urls = repository_urls(repository_id)
14
+ urls[object_id ? :root_folder_url : :repository_url]
15
+ end
16
+
17
+ private
18
+
19
+ def repository_urls(repository_id)
20
+ if @cache[repository_id].nil?
21
+ repository_infos = @http.get(@service_url).body
22
+
23
+ unless repository_infos.has_key?(repository_id)
24
+ raise Exceptions::ObjectNotFound, "repositoryId: #{repository_id}"
25
+ end
26
+
27
+ repository_info = repository_infos[repository_id]
28
+ @cache[repository_id] = {
29
+ repository_url: repository_info[:repositoryUrl],
30
+ root_folder_url: repository_info[:rootFolderUrl]
31
+ }
32
+ end
33
+
34
+ @cache[repository_id]
35
+ end
36
+ end
37
+ end
38
+ end
data/lib/cmis/folder.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'cmis/children'
2
+
1
3
  module CMIS
2
4
  class Folder < Object
3
5
  def initialize(raw, repository)
data/lib/cmis/object.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'cmis/relationships'
2
+
1
3
  module CMIS
2
4
  class Object
3
5
  include Helpers
data/lib/cmis/query.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'bigdecimal'
2
+ require 'cmis/query_result'
3
+
1
4
  module CMIS
2
5
  class Query
3
6
  # Options: from, page_size
@@ -1,3 +1,6 @@
1
+ require 'bigdecimal'
2
+ require 'cmis/query_result'
3
+
1
4
  module CMIS
2
5
  class Relationships
3
6
  # Options: from, page_size
@@ -1,3 +1,6 @@
1
+ require 'json'
2
+ require 'cmis/query'
3
+
1
4
  module CMIS
2
5
  class Repository
3
6
  attr_reader :server
data/lib/cmis/type.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'json'
2
+
1
3
  module CMIS
2
4
  class Type
3
5
  attr_accessor :repository
data/lib/cmis/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CMIS
2
- VERSION = '0.3.9'
2
+ VERSION = '0.4.0'
3
3
  end
data/readme.md CHANGED
@@ -13,7 +13,11 @@ Running the tests requires a separate CMIS server. The default rake task runs th
13
13
 
14
14
  ## TODO
15
15
 
16
- * facilitate copy between servers (make a flow)
16
+ * remove ActiveSupport dependency:
17
+ * stringify_keys! -> to_options!
18
+ * symbolize_keys! -> to_options!
19
+ * compact!
20
+ * with_indifferent_access -> ?
17
21
  * caching
18
22
 
19
23
  ## Contributing
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.9
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenneth Geerts
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-18 00:00:00.000000000 Z
12
+ date: 2014-03-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -62,6 +62,9 @@ files:
62
62
  - lib/cmis-ruby.rb
63
63
  - lib/cmis/children.rb
64
64
  - lib/cmis/connection.rb
65
+ - lib/cmis/connection/request_modifier.rb
66
+ - lib/cmis/connection/response_parser.rb
67
+ - lib/cmis/connection/url_resolver.rb
65
68
  - lib/cmis/document.rb
66
69
  - lib/cmis/exceptions.rb
67
70
  - lib/cmis/folder.rb