cmis-ruby 0.3.7 → 0.3.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 97132317b4609f109b961b1069bd5423e6bb1b89
4
- data.tar.gz: a43ebf5d4525804e207d040c0c58feda45e48fd8
3
+ metadata.gz: 5509c0d7a7ebe328fb70713c0d33286634414c3b
4
+ data.tar.gz: 1b083a997de518a72a4d3de31b955321f32184ef
5
5
  SHA512:
6
- metadata.gz: 4ea0dff54def6be22aa39c6ac2738993b6b6dfbb21bc34e0c001bdf2ba6012ac125a5c0cc6382633cefdcc064d53c0a95fd3c8710dcc59b98b971a622b2792b0
7
- data.tar.gz: 29ee254a5eda2bca3b4220d64b219ed97b0815a42ed4330aa185ebc77c87cdfa94b32e98e9df20696279193f541a0434df520fee8be0d311ee93f086642e4530
6
+ metadata.gz: 71aeea351aef546a84493d3090c959b62f8b318c9adc0e13ffbb98ed8125cc7ac03bb63c1ae18d82936ce2a0eb80092b1f71074b9b1b94ea0667fb0bc8ec154a
7
+ data.tar.gz: 933826ba179011b28eda09faa060b4fc722ff5ea595f0a243a9ddc9dbbec9581b50d50f40151936e02550b590c287f256cc43f5ff18588de3470f22fd73c7ea2
@@ -3,8 +3,8 @@ module CMIS
3
3
  def initialize(options)
4
4
  options.symbolize_keys!
5
5
 
6
- @service_url = options[:service_url] || ENV['CMIS_BROWSER_URL'] or raise \
7
- "option `:service_url` or ENV['CMIS_BROWSER_URL'] must be set"
6
+ @service_url = options[:service_url] || ENV['CMIS_BROWSER_URL'] or \
7
+ raise "option `:service_url` or ENV['CMIS_BROWSER_URL'] must be set"
8
8
 
9
9
  adapter = (options[:adapter] || :net_http).to_sym
10
10
 
@@ -130,17 +130,27 @@ module CMIS
130
130
  end
131
131
 
132
132
  class ResponseParser < Faraday::Middleware
133
+ JSON_CONTENT_TYPE = /\/(x-)?json(;.+?)?$/
134
+
133
135
  def call(env)
134
136
  @app.call(env).on_complete do |env|
135
- if env[:response_headers][:content_type] =~ /\/(x-)?json(;.+?)?$/
137
+ if env[:response_headers][:content_type] =~ JSON_CONTENT_TYPE
136
138
  env[:body] = JSON.parse(env[:body]).with_indifferent_access
137
- if env[:body].is_a?(Hash) && ex = env[:body][:exception]
138
- ruby_exception = "CMIS::Exceptions::#{ex.camelize}".constantize
139
- message = "#{ex.underscore.humanize}: #{env[:body][:message]}"
140
- raise ruby_exception, message
141
- end
139
+ check_for_exception!(env[:body])
142
140
  end
143
141
  end
144
142
  end
143
+
144
+ private
145
+
146
+ def check_for_exception!(body)
147
+ return unless body.is_a?(Hash)
148
+
149
+ if ex = body[:exception]
150
+ ruby_exception = "CMIS::Exceptions::#{ex.camelize}".constantize
151
+ message = "#{ex.underscore.humanize}: #{body[:message]}"
152
+ raise ruby_exception, message
153
+ end
154
+ end
145
155
  end
146
156
  end
data/lib/cmis/document.rb CHANGED
@@ -55,11 +55,13 @@ module CMIS
55
55
  if detached?
56
56
  @local_content = content
57
57
  else
58
- update_change_token server.execute!({ cmisaction: 'setContent',
59
- repositoryId: repository.id,
60
- objectId: cmis_object_id,
61
- content: content,
62
- changeToken: change_token }, opts)
58
+ with_change_token do
59
+ server.execute!({ cmisaction: 'setContent',
60
+ repositoryId: repository.id,
61
+ objectId: cmis_object_id,
62
+ content: content,
63
+ changeToken: change_token }, opts)
64
+ end
63
65
  end
64
66
  end
65
67
  end
data/lib/cmis/helpers.rb CHANGED
@@ -12,13 +12,14 @@ module CMIS
12
12
  end
13
13
  end
14
14
 
15
- def update_change_token(r)
16
- if r['properties']
17
- @change_token = r['properties']['cmis:changeToken']['value']
18
- elsif r['succinctProperties']
19
- @change_token = r['succinctProperties']['cmis:changeToken']
15
+ def with_change_token(&block)
16
+ json = yield
17
+ if props = json['properties']
18
+ self.change_token = props['cmis:changeToken']['value']
19
+ elsif succinct_props = json['succinctProperties']
20
+ self.change_token = succinct_props['cmis:changeToken']
20
21
  else
21
- raise "Unexpected input: #{r}"
22
+ raise "Unexpected input: #{json}"
22
23
  end
23
24
  end
24
25
 
data/lib/cmis/object.rb CHANGED
@@ -3,7 +3,7 @@ module CMIS
3
3
  include Helpers
4
4
 
5
5
  attr_reader :repository
6
- attr_accessor :properties
6
+ attr_reader :properties
7
7
 
8
8
  def initialize(raw, repository)
9
9
  initialize_properties(raw)
@@ -27,11 +27,13 @@ module CMIS
27
27
  end
28
28
 
29
29
  def update_properties(properties, opts = {})
30
- update_change_token server.execute!({ cmisaction: 'update',
31
- repositoryId: repository.id,
32
- objectId: cmis_object_id,
33
- properties: properties,
34
- changeToken: change_token }, opts)
30
+ with_change_token do
31
+ server.execute!({ cmisaction: 'update',
32
+ repositoryId: repository.id,
33
+ objectId: cmis_object_id,
34
+ properties: properties,
35
+ changeToken: change_token }, opts)
36
+ end
35
37
  end
36
38
 
37
39
  def parents(opts = {})
data/lib/cmis/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CMIS
2
- VERSION = '0.3.7'
2
+ VERSION = '0.3.8'
3
3
  end
@@ -42,8 +42,8 @@ describe CMIS::Repository do
42
42
  end
43
43
 
44
44
  it 'repository' do
45
- r = CMIS::Server.new.repository('generali')
46
- r.name.should eq 'generali'
45
+ r = CMIS::Server.new.repository('meta')
46
+ r.name.should eq 'meta'
47
47
  end
48
48
 
49
49
  it 'root' do
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.7
4
+ version: 0.3.8
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-11 00:00:00.000000000 Z
12
+ date: 2014-03-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday