cmis-ruby 0.5 → 0.5.1

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: 02dde86712abce2614a30d613e2d555758370a12
4
- data.tar.gz: eae9b485ebb9ab22bccdf90dd12bfa2160e1f9cb
3
+ metadata.gz: 18071f7ae45271f5534f5407231a3164a5c2e7a9
4
+ data.tar.gz: 36039b23cda23f53c81246d3574a797a115b8fcb
5
5
  SHA512:
6
- metadata.gz: e388fa58601821918c3729047795559e8866070d76d570aec71bf5f0dae4758b71a21542941e6b0a845fe17941769eaa7b16ee61fd9a8ce97ee8b822c5d49eab
7
- data.tar.gz: 189cadb79c4b5fdf45b50eebd65782234d4d7f2ca3fe46d0c376c2deeca50174ec02842d1267e86aaefa5b01500dbf5157ba6a083eaffb42b7b53f9d1a551ce8
6
+ metadata.gz: d1db5aeace1879fffc2f3645753c3c246994813b7cdba12c649eae7ddd44790cc42136cabf5eefed1c6cb3813af331f1d75c918e2e35662ae107ead686527e4a
7
+ data.tar.gz: 8cc86fe428199a44801f2e7f5fa6da7f1767fe92ec1d0f60aaa9e32b3e264393eac4366678e9d0b9454415b63b4288ffeb4cf8901a120d26841ef01e7548d83f
data/cmis-ruby.gemspec CHANGED
@@ -19,7 +19,8 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.required_ruby_version = '>= 1.9.3'
21
21
 
22
- s.add_dependency 'faraday', '~> 0.9'
22
+ s.add_dependency 'faraday', '~> 0.9'
23
+ s.add_dependency 'faraday_middleware', '~> 0.9'
23
24
 
24
25
  s.description = <<-DESCRIPTION
25
26
  CMIS browser binding client library in ruby.
@@ -1,8 +1,8 @@
1
- require 'cmis/connection/follow_redirects'
2
1
  require 'cmis/connection/request_modifier'
3
2
  require 'cmis/connection/response_parser'
4
3
  require 'cmis/version'
5
4
  require 'faraday'
5
+ require 'faraday_middleware'
6
6
 
7
7
  module CMIS
8
8
  class Connection
@@ -21,7 +21,7 @@ module CMIS
21
21
  end
22
22
 
23
23
  builder.adapter (options[:adapter] || :net_http).to_sym
24
- builder.use FollowRedirects
24
+ builder.response :follow_redirects, standards_compliant: true
25
25
  builder.response :logger if options[:log_requests]
26
26
  builder.use ResponseParser
27
27
  end
@@ -31,8 +31,9 @@ module CMIS
31
31
  def check_for_cmis_exception!(body)
32
32
  return unless body.is_a?(Hash)
33
33
 
34
- if exception = body['exception']
35
- raise exception_class(exception), "#{exception}: #{body['message']}"
34
+ if body.key?('exception')
35
+ e, m, s = body.values_at('exception', 'message', 'stacktrace')
36
+ raise exception_class(e), "[#{e}] #{m}\n#{s}"
36
37
  end
37
38
  end
38
39
 
@@ -1,20 +1,20 @@
1
1
  module CMIS
2
2
  module Exceptions
3
- class InvalidArgument < Exception; end
4
- class NotSupported < Exception; end
5
- class ObjectNotFound < Exception; end
6
- class PermissionDenied < Exception; end
7
- class Runtime < Exception; end
8
- class Constraint < Exception; end
9
- class ContentAlreadyExists < Exception; end
10
- class FilterNotValid < Exception; end
11
- class NameConstraintViolation < Exception; end
12
- class Storage < Exception; end
13
- class StreamNotSupported < Exception; end
14
- class UpdateConflict < Exception; end
15
- class Versioning < Exception; end
3
+ InvalidArgument = Class.new(Exception)
4
+ NotSupported = Class.new(Exception)
5
+ ObjectNotFound = Class.new(Exception)
6
+ PermissionDenied = Class.new(Exception)
7
+ Runtime = Class.new(Exception)
8
+ Constraint = Class.new(Exception)
9
+ ContentAlreadyExists = Class.new(Exception)
10
+ FilterNotValid = Class.new(Exception)
11
+ NameConstraintViolation = Class.new(Exception)
12
+ Storage = Class.new(Exception)
13
+ StreamNotSupported = Class.new(Exception)
14
+ UpdateConflict = Class.new(Exception)
15
+ Versioning = Class.new(Exception)
16
16
 
17
17
  # Non-CMIS
18
- class Unauthorized < Exception; end
18
+ Unauthorized = Class.new(Exception)
19
19
  end
20
20
  end
data/lib/cmis/object.rb CHANGED
@@ -112,6 +112,10 @@ module CMIS
112
112
  cmis_object_id.nil?
113
113
  end
114
114
 
115
+ def refresh(opts = {})
116
+ detached? ? self : repository.object(cmis_object_id, opts)
117
+ end
118
+
115
119
  private
116
120
 
117
121
  def server
data/lib/cmis/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CMIS
2
- VERSION = '0.5'
2
+ VERSION = '0.5.1'
3
3
  end
data/readme.md CHANGED
@@ -24,7 +24,7 @@ document = repository.find_object('cmis:document',
24
24
  'cmis:name' => 'some_unique_name')
25
25
 
26
26
  # set document content
27
- document.content = { stream: StringIO.new('Apple is a fruit'),
27
+ document.content = { stream: 'Apple is a fruit',
28
28
  mime_type: 'text/plain',
29
29
  filename: 'apple.txt' }
30
30
 
@@ -46,9 +46,9 @@ module CMIS
46
46
  mime_type: 'text/apple',
47
47
  filename: 'apple.txt' }
48
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')
49
+ document = document.refresh
50
+ expect(document.content_stream_mime_type).to eq('text/apple')
51
+ expect(document.content_stream_file_name).to eq('apple.txt')
52
52
  expect(document.content).to eq('apple is a fruit')
53
53
 
54
54
  document.delete
@@ -38,6 +38,18 @@ module CMIS
38
38
  end
39
39
  end
40
40
 
41
+ context 'when creating an item in a folder' do
42
+ it 'has the item available' do
43
+ item = repository.new_item
44
+ item.name = 'test_item'
45
+ item.object_type_id = 'cmis:item'
46
+ item = repository.root.create(item)
47
+ expect(item).to be_a CMIS::Item
48
+ expect(item.name).to eq('test_item')
49
+ item.delete
50
+ end
51
+ end
52
+
41
53
  describe '#create' do
42
54
  context 'when creating a relationship in a folder' do
43
55
  it 'raises an exception' do
@@ -50,18 +62,6 @@ module CMIS
50
62
  end
51
63
  end
52
64
 
53
- context 'when creating an item in a folder' do
54
- it 'raises an exception' do
55
- item = repository.new_item
56
- item.name = 'test_item'
57
- item.object_type_id = 'cmis:item'
58
- item = repository.root.create(item)
59
- expect(item).to be_a CMIS::Item
60
- expect(item.name).to eq('test_item')
61
- item.delete
62
- end
63
- end
64
-
65
65
  context 'when creating a plain object in a folder' do
66
66
  it 'raises an exception' do
67
67
  new_object = CMIS::Object.new({}, repository)
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.5'
4
+ version: 0.5.1
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-04-23 00:00:00.000000000 Z
12
+ date: 2014-04-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -25,6 +25,20 @@ dependencies:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0.9'
28
+ - !ruby/object:Gem::Dependency
29
+ name: faraday_middleware
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '0.9'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '0.9'
28
42
  description: |
29
43
  CMIS browser binding client library in ruby.
30
44
  email:
@@ -42,7 +56,6 @@ files:
42
56
  - lib/cmis-ruby.rb
43
57
  - lib/cmis/children.rb
44
58
  - lib/cmis/connection.rb
45
- - lib/cmis/connection/follow_redirects.rb
46
59
  - lib/cmis/connection/request_modifier.rb
47
60
  - lib/cmis/connection/response_parser.rb
48
61
  - lib/cmis/document.rb
@@ -110,3 +123,4 @@ test_files:
110
123
  - spec/config.yml
111
124
  - spec/rspec.opts
112
125
  - spec/spec_helper.rb
126
+ has_rdoc: false
@@ -1,137 +0,0 @@
1
- require 'faraday'
2
- require 'set'
3
-
4
- module CMIS
5
- class Connection
6
- # Based on https://github.com/lostisland/faraday_middleware/blob/master/lib/faraday_middleware/response/follow_redirects.rb
7
- # Modified ALLOWED_METHODS to only include :get
8
-
9
- # Public: Exception thrown when the maximum amount of requests is exceeded.
10
- class RedirectLimitReached < Faraday::Error::ClientError
11
- attr_reader :response
12
-
13
- def initialize(response)
14
- super "too many redirects; last one to: #{response['location']}"
15
- @response = response
16
- end
17
- end
18
-
19
- # Public: Follow HTTP 301, 302, 303, and 307 redirects.
20
- #
21
- # For HTTP 301, 302, and 303, the original GET, POST, PUT, DELETE, or PATCH
22
- # request gets converted into a GET. With `:standards_compliant => true`,
23
- # however, the HTTP method after 301/302 remains unchanged. This allows you
24
- # to opt into HTTP/1.1 compliance and act unlike the major web browsers.
25
- #
26
- # This middleware currently only works with synchronous requests; i.e. it
27
- # doesn't support parallelism.
28
- class FollowRedirects < Faraday::Middleware
29
- # HTTP methods for which 30x redirects can be followed
30
- ALLOWED_METHODS = Set.new [:get]
31
-
32
- # HTTP redirect status codes that this middleware implements
33
- REDIRECT_CODES = Set.new [301, 302, 303, 307]
34
-
35
- # Keys in env hash which will get cleared between requests
36
- ENV_TO_CLEAR = Set.new [:status, :response, :response_headers]
37
-
38
- # Default value for max redirects followed
39
- FOLLOW_LIMIT = 3
40
-
41
- # Public: Initialize the middleware.
42
- #
43
- # options - An options Hash (default: {}):
44
- # :limit - A Numeric redirect limit (default: 3)
45
- # :standards_compliant - A Boolean indicating whether to respect
46
- # the HTTP spec when following 301/302
47
- # (default: false)
48
- # :cookies - An Array of Strings (e.g.
49
- # ['cookie1', 'cookie2']) to choose
50
- # cookies to be kept, or :all to keep
51
- # all cookies (default: []).
52
- def initialize(app, options = {})
53
- super(app)
54
- @options = options
55
-
56
- @convert_to_get = Set.new [303]
57
- @convert_to_get << 301 << 302 unless standards_compliant?
58
- end
59
-
60
- def call(env)
61
- perform_with_redirection(env, follow_limit)
62
- end
63
-
64
- private
65
-
66
- def convert_to_get?(response)
67
- ![:head, :options].include?(response.env[:method]) &&
68
- @convert_to_get.include?(response.status)
69
- end
70
-
71
- def perform_with_redirection(env, follows)
72
- request_body = env[:body]
73
- response = @app.call(env)
74
-
75
- response.on_complete do |env|
76
- if follow_redirect?(env, response)
77
- raise RedirectLimitReached, response if follows.zero?
78
- env = update_env(env, request_body, response)
79
- response = perform_with_redirection(env, follows - 1)
80
- end
81
- end
82
- response
83
- end
84
-
85
- def update_env(env, request_body, response)
86
- env[:url] += response['location']
87
- if @options[:cookies]
88
- cookies = keep_cookies(env)
89
- env[:request_headers][:cookies] = cookies unless cookies.nil?
90
- end
91
-
92
- if convert_to_get?(response)
93
- env[:method] = :get
94
- env[:body] = nil
95
- else
96
- env[:body] = request_body
97
- end
98
-
99
- ENV_TO_CLEAR.each {|key| env.delete key }
100
-
101
- env
102
- end
103
-
104
- def follow_redirect?(env, response)
105
- ALLOWED_METHODS.include? env[:method] and
106
- REDIRECT_CODES.include? response.status
107
- end
108
-
109
- def follow_limit
110
- @options.fetch(:limit, FOLLOW_LIMIT)
111
- end
112
-
113
- def keep_cookies(env)
114
- cookies = @options.fetch(:cookies, [])
115
- response_cookies = env[:response_headers][:cookies]
116
- cookies == :all ? response_cookies : selected_request_cookies(response_cookies)
117
- end
118
-
119
- def selected_request_cookies(cookies)
120
- selected_cookies(cookies)[0...-1]
121
- end
122
-
123
- def selected_cookies(cookies)
124
- "".tap do |cookie_string|
125
- @options[:cookies].each do |cookie|
126
- string = /#{cookie}=?[^;]*/.match(cookies)[0] + ';'
127
- cookie_string << string
128
- end
129
- end
130
- end
131
-
132
- def standards_compliant?
133
- @options.fetch(:standards_compliant, false)
134
- end
135
- end
136
- end
137
- end