groupdocs 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +5 -0
- data/Gemfile +3 -0
- data/README.md +141 -0
- data/Rakefile +9 -0
- data/groupdocs.gemspec +28 -0
- data/lib/groupdocs.rb +53 -0
- data/lib/groupdocs/api.rb +3 -0
- data/lib/groupdocs/api/entity.rb +113 -0
- data/lib/groupdocs/api/helpers.rb +5 -0
- data/lib/groupdocs/api/helpers/access_helper.rb +56 -0
- data/lib/groupdocs/api/helpers/actions_helper.rb +48 -0
- data/lib/groupdocs/api/helpers/rest_helper.rb +89 -0
- data/lib/groupdocs/api/helpers/status_helper.rb +48 -0
- data/lib/groupdocs/api/helpers/url_helper.rb +89 -0
- data/lib/groupdocs/api/request.rb +73 -0
- data/lib/groupdocs/api/sugar/lookup.rb +48 -0
- data/lib/groupdocs/datasource.rb +162 -0
- data/lib/groupdocs/datasource/field.rb +44 -0
- data/lib/groupdocs/document.rb +513 -0
- data/lib/groupdocs/document/annotation.rb +215 -0
- data/lib/groupdocs/document/annotation/reply.rb +167 -0
- data/lib/groupdocs/document/change.rb +35 -0
- data/lib/groupdocs/document/field.rb +27 -0
- data/lib/groupdocs/document/metadata.rb +26 -0
- data/lib/groupdocs/document/rectangle.rb +24 -0
- data/lib/groupdocs/document/view.rb +36 -0
- data/lib/groupdocs/errors.rb +10 -0
- data/lib/groupdocs/job.rb +201 -0
- data/lib/groupdocs/questionnaire.rb +221 -0
- data/lib/groupdocs/questionnaire/execution.rb +120 -0
- data/lib/groupdocs/questionnaire/page.rb +43 -0
- data/lib/groupdocs/questionnaire/question.rb +75 -0
- data/lib/groupdocs/questionnaire/question/answer.rb +10 -0
- data/lib/groupdocs/storage.rb +37 -0
- data/lib/groupdocs/storage/file.rb +248 -0
- data/lib/groupdocs/storage/folder.rb +314 -0
- data/lib/groupdocs/storage/package.rb +42 -0
- data/lib/groupdocs/user.rb +50 -0
- data/lib/groupdocs/version.rb +3 -0
- data/spec/groupdocs/api/entity_spec.rb +54 -0
- data/spec/groupdocs/api/helpers/access_helper_spec.rb +89 -0
- data/spec/groupdocs/api/helpers/actions_helper_spec.rb +51 -0
- data/spec/groupdocs/api/helpers/rest_helper_spec.rb +187 -0
- data/spec/groupdocs/api/helpers/status_helper_spec.rb +85 -0
- data/spec/groupdocs/api/helpers/url_helper_spec.rb +93 -0
- data/spec/groupdocs/api/request_spec.rb +85 -0
- data/spec/groupdocs/datasource/field_spec.rb +50 -0
- data/spec/groupdocs/datasource_spec.rb +156 -0
- data/spec/groupdocs/document/annotation/reply_spec.rb +179 -0
- data/spec/groupdocs/document/annotation_spec.rb +226 -0
- data/spec/groupdocs/document/change_spec.rb +35 -0
- data/spec/groupdocs/document/field_spec.rb +31 -0
- data/spec/groupdocs/document/metadata_spec.rb +26 -0
- data/spec/groupdocs/document/rectangle_spec.rb +34 -0
- data/spec/groupdocs/document/view_spec.rb +36 -0
- data/spec/groupdocs/document_spec.rb +509 -0
- data/spec/groupdocs/errors_spec.rb +7 -0
- data/spec/groupdocs/job_spec.rb +196 -0
- data/spec/groupdocs/questionnaire/execution_spec.rb +136 -0
- data/spec/groupdocs/questionnaire/page_spec.rb +50 -0
- data/spec/groupdocs/questionnaire/question/answer_spec.rb +11 -0
- data/spec/groupdocs/questionnaire/question_spec.rb +84 -0
- data/spec/groupdocs/questionnaire_spec.rb +217 -0
- data/spec/groupdocs/storage/file_spec.rb +242 -0
- data/spec/groupdocs/storage/folder_spec.rb +310 -0
- data/spec/groupdocs/storage/package_spec.rb +41 -0
- data/spec/groupdocs/storage_spec.rb +27 -0
- data/spec/groupdocs/user_spec.rb +53 -0
- data/spec/groupdocs_spec.rb +56 -0
- data/spec/spec_helper.rb +46 -0
- data/spec/support/files/resume.pdf +0 -0
- data/spec/support/json/annotation_collaborators_set.json +16 -0
- data/spec/support/json/annotation_create.json +12 -0
- data/spec/support/json/annotation_list.json +32 -0
- data/spec/support/json/annotation_remove.json +9 -0
- data/spec/support/json/annotation_replies_create.json +9 -0
- data/spec/support/json/annotation_replies_get.json +25 -0
- data/spec/support/json/comparison_changes.json +46 -0
- data/spec/support/json/comparison_compare.json +8 -0
- data/spec/support/json/comparison_document.json +10 -0
- data/spec/support/json/datasource_add.json +8 -0
- data/spec/support/json/datasource_get.json +22 -0
- data/spec/support/json/datasource_remove.json +8 -0
- data/spec/support/json/datasource_update.json +8 -0
- data/spec/support/json/document_access_info_get.json +14 -0
- data/spec/support/json/document_convert.json +8 -0
- data/spec/support/json/document_datasource.json +10 -0
- data/spec/support/json/document_fields.json +34 -0
- data/spec/support/json/document_formats.json +8 -0
- data/spec/support/json/document_metadata.json +15 -0
- data/spec/support/json/document_questionnaire_create.json +9 -0
- data/spec/support/json/document_questionnaires.json +23 -0
- data/spec/support/json/document_sharers_remove.json +8 -0
- data/spec/support/json/document_sharers_set.json +16 -0
- data/spec/support/json/document_views.json +32 -0
- data/spec/support/json/file_compress.json +8 -0
- data/spec/support/json/file_copy.json +14 -0
- data/spec/support/json/file_delete.json +5 -0
- data/spec/support/json/file_move.json +14 -0
- data/spec/support/json/file_upload.json +8 -0
- data/spec/support/json/folder_create.json +8 -0
- data/spec/support/json/folder_delete.json +5 -0
- data/spec/support/json/folder_list.json +21 -0
- data/spec/support/json/folder_move.json +8 -0
- data/spec/support/json/folder_sharers_get.json +16 -0
- data/spec/support/json/folder_sharers_remove.json +8 -0
- data/spec/support/json/folder_sharers_set.json +16 -0
- data/spec/support/json/job_add_url.json +8 -0
- data/spec/support/json/job_create.json +8 -0
- data/spec/support/json/job_documents.json +39 -0
- data/spec/support/json/job_file_add.json +8 -0
- data/spec/support/json/job_update.json +7 -0
- data/spec/support/json/jobs_get.json +52 -0
- data/spec/support/json/package_create.json +7 -0
- data/spec/support/json/questionnaire_create.json +8 -0
- data/spec/support/json/questionnaire_datasources.json +26 -0
- data/spec/support/json/questionnaire_execution_create.json +9 -0
- data/spec/support/json/questionnaire_execution_status_set.json +8 -0
- data/spec/support/json/questionnaire_execution_update.json +8 -0
- data/spec/support/json/questionnaire_executions.json +24 -0
- data/spec/support/json/questionnaire_get.json +14 -0
- data/spec/support/json/questionnaire_remove.json +8 -0
- data/spec/support/json/questionnaire_update.json +8 -0
- data/spec/support/json/questionnaires_get.json +22 -0
- data/spec/support/json/storage_info.json +10 -0
- data/spec/support/shared_examples/api/entity.rb +37 -0
- data/spec/support/shared_examples/api/helpers/status_helper.rb +12 -0
- data/spec/support/shared_examples/api/sugar/lookup.rb +57 -0
- metadata +356 -0
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
## GroupDocs [![Build Status](https://secure.travis-ci.org/p0deje/groupdocs-ruby.png)](http://travis-ci.org/p0deje/groupdocs-ruby)
|
2
|
+
|
3
|
+
Ruby SDK for [GroupDocs](http://groupdocs.com) REST API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
GroupDocs requires Ruby 1.9. Ruby 1.8 is not supported!
|
8
|
+
|
9
|
+
Install as usually
|
10
|
+
|
11
|
+
gem install groupdocs
|
12
|
+
|
13
|
+
Installing from source
|
14
|
+
|
15
|
+
gem install bundler # unless it's already installed
|
16
|
+
git clone git@github.com:p0deje/groupdocs-ruby.git
|
17
|
+
cd groupdocs-ruby/
|
18
|
+
git checkout master
|
19
|
+
bundle install --path vendor/bundle
|
20
|
+
bundle exec rake install
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
All "bang" methods (ending with exclamation sign) imply interaction with API server.
|
25
|
+
|
26
|
+
Other methods (with expect to some methods - see documentation) do not operate with API Server
|
27
|
+
|
28
|
+
### Configuration
|
29
|
+
|
30
|
+
First of all you need to configure your access to API server.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
require 'groupdocs'
|
34
|
+
|
35
|
+
GroupDocs.configure do |groupdocs|
|
36
|
+
groupdocs.client_id = 'your_client_id'
|
37
|
+
groupdocs.private_key = 'your_private_key'
|
38
|
+
# optionally specify API server and version
|
39
|
+
groupdocs.api_server = 'https://dev-api.groupdocs.com'
|
40
|
+
groupdocs.api_version = '2.0'
|
41
|
+
end
|
42
|
+
|
43
|
+
GroupDocs::Storage::Folder.create!('/folder')
|
44
|
+
#=> #<GroupDocs::Storage::Folder:0x0000000171f432 @id=1, @name="folder", @url="http://groupdocs.com">
|
45
|
+
```
|
46
|
+
|
47
|
+
You can also pass access credentials to particular requests
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
GroupDocs::Storage::Folder.create!('/folder', client_id: 'your_client_id', private_key: 'your_private_key')
|
51
|
+
#=> #<GroupDocs::Storage::Folder:0x0000000171f432 @id=1, @name="folder", @url="http://groupdocs.com">
|
52
|
+
|
53
|
+
GroupDocs::Document.find!(:name, 'CV.doc', client_id: 'your_client_id', private_key: 'your_private_key')
|
54
|
+
#=> #<GroupDocs::Storage::Folder:0x0000000171f432 @id=1, @name="Folder1", @url="http://groupdocs.com">
|
55
|
+
```
|
56
|
+
|
57
|
+
### Entities
|
58
|
+
|
59
|
+
All entities can be initialized in several ways.
|
60
|
+
|
61
|
+
* Object is created, attributes are set later.
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
folder = GroupDocs::Storage::Folder.new
|
65
|
+
folder.name = 'Folder'
|
66
|
+
folder.inspect
|
67
|
+
#=> #<GroupDocs::Storage::Folder:0x0000000171f432 @name="Folder">
|
68
|
+
```
|
69
|
+
|
70
|
+
* Hash of attributes are passed to object constructor.
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
GroupDocs::Storage::Folder.new(name: 'Folder')
|
74
|
+
#=> #<GroupDocs::Storage::Folder:0x0000000171f432 @name="Folder">
|
75
|
+
```
|
76
|
+
|
77
|
+
* Block is passed to object constructor.
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
GroupDocs::Storage::Folder.new do |folder|
|
81
|
+
folder.name = 'Folder'
|
82
|
+
end
|
83
|
+
#=> #<GroupDocs::Storage::Folder:0x0000000171f432 @name="Folder">
|
84
|
+
```
|
85
|
+
|
86
|
+
### Find entities
|
87
|
+
|
88
|
+
Some entities support `#all!`, `#find!` and `#find_all!` methods. You can pass any attribute that object responds to and its value to find with.
|
89
|
+
|
90
|
+
* List all files
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
GroupDocs::Storage::File.all!
|
94
|
+
#=> [#<GroupDocs::Storage::File:0x0000000171f432 @id=123, @guid="uhfsa9dry29rhfodn", @name="resume.pdf", @url="http://groupdocs.com">, #<GroupDocs::Storage::File:0x0000000171f498 @id=456, @guid="soif97sr9u24bfosd9", @name="CV.doc", @url="http://groupdocs.com">]
|
95
|
+
```
|
96
|
+
|
97
|
+
* Find folder with name `Folder1`
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
GroupDocs::Storage::Folder.find!(:name, 'Folder1')
|
101
|
+
#=> #<GroupDocs::Storage::Folder:0x0000000171f432 @id=1, @name="Folder1", @url="http://groupdocs.com">
|
102
|
+
```
|
103
|
+
|
104
|
+
* Find all folders which name starts with `Folder`
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
GroupDocs::Storage::Folder.find_all!(:name, /^Folder/)
|
108
|
+
#=> [#<GroupDocs::Storage::Folder:0x0000000171f432 @id=1, @name="Folder1", @url="http://groupdocs.com">, #<GroupDocs::Storage::Folder:0x0000000171f467 @id=2, @name="Folder2", @url="http://groupdocs.com">]
|
109
|
+
```
|
110
|
+
|
111
|
+
### Annotation API
|
112
|
+
|
113
|
+
Read more about examples of using Annotation API on [wiki](https://github.com/p0deje/groupdocs-ruby/wiki/Annotation-API).
|
114
|
+
|
115
|
+
### Assembly API
|
116
|
+
|
117
|
+
Read more about examples of using Assembly API on [wiki](https://github.com/p0deje/groupdocs-ruby/wiki/Assembly-API).
|
118
|
+
|
119
|
+
### Comparison API
|
120
|
+
|
121
|
+
Read more about examples of using Comparison API on [wiki](https://github.com/p0deje/groupdocs-ruby/wiki/Comparison-API).
|
122
|
+
|
123
|
+
### Document API
|
124
|
+
|
125
|
+
Read more about examples of using Document API on [wiki](https://github.com/p0deje/groupdocs-ruby/wiki/Document-API).
|
126
|
+
|
127
|
+
### Job API
|
128
|
+
|
129
|
+
Read more about examples of using Job API on [wiki](https://github.com/p0deje/groupdocs-ruby/wiki/Job-API).
|
130
|
+
|
131
|
+
### Signature API
|
132
|
+
|
133
|
+
Not yet implemented.
|
134
|
+
|
135
|
+
### Storage API
|
136
|
+
|
137
|
+
Read more about examples of using Storage API on [wiki](https://github.com/p0deje/groupdocs-ruby/wiki/Storage-API).
|
138
|
+
|
139
|
+
### Copyright
|
140
|
+
|
141
|
+
Copyright (c) 2012 Aspose Inc.
|
data/Rakefile
ADDED
data/groupdocs.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
|
3
|
+
require "groupdocs/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'groupdocs'
|
7
|
+
s.version = GroupDocs::VERSION
|
8
|
+
s.authors = 'Alex Rodionov'
|
9
|
+
s.email = 'p0deje@gmail.com'
|
10
|
+
s.homepage = 'https://github.com/p0deje/groupdocs-ruby'
|
11
|
+
s.summary = 'Ruby SDK for GroupDocs REST API'
|
12
|
+
s.description = 'Ruby SDK for GroupDocs REST API'
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
17
|
+
s.require_path = 'lib'
|
18
|
+
|
19
|
+
s.add_runtime_dependency 'rest-client', '~> 1.6'
|
20
|
+
s.add_runtime_dependency 'json' , '~> 1.6'
|
21
|
+
s.add_runtime_dependency 'ruby-hmac' , '~> 0.4'
|
22
|
+
|
23
|
+
s.add_development_dependency 'rspec' , '~> 2.9'
|
24
|
+
s.add_development_dependency 'rake' , '~> 0.9'
|
25
|
+
s.add_development_dependency 'simplecov', '~> 0.6'
|
26
|
+
s.add_development_dependency 'yard' , '~> 0.7'
|
27
|
+
s.add_development_dependency 'webmock' , '~> 1.8'
|
28
|
+
end
|
data/lib/groupdocs.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'groupdocs/version'
|
2
|
+
require 'groupdocs/errors'
|
3
|
+
require 'groupdocs/api'
|
4
|
+
require 'groupdocs/datasource'
|
5
|
+
require 'groupdocs/document'
|
6
|
+
require 'groupdocs/job'
|
7
|
+
require 'groupdocs/questionnaire'
|
8
|
+
require 'groupdocs/storage'
|
9
|
+
require 'groupdocs/user'
|
10
|
+
|
11
|
+
module GroupDocs
|
12
|
+
class << self
|
13
|
+
|
14
|
+
# @attr [String] client_id Client ID
|
15
|
+
attr_accessor :client_id
|
16
|
+
|
17
|
+
# @attr [String] private_key Private key
|
18
|
+
attr_accessor :private_key
|
19
|
+
|
20
|
+
# @attr [String] api_server API server
|
21
|
+
attr_accessor :api_server
|
22
|
+
|
23
|
+
# @attr [String] api_version Version of API server
|
24
|
+
attr_accessor :api_version
|
25
|
+
|
26
|
+
#
|
27
|
+
# Returns hostname of API server.
|
28
|
+
#
|
29
|
+
# @return [String] API hostname. Default one if it has not been explicitly set
|
30
|
+
#
|
31
|
+
def api_server
|
32
|
+
@api_server || 'https://api.groupdocs.com'
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# Calls block for configuration of GroupDocs.
|
37
|
+
#
|
38
|
+
# @example
|
39
|
+
# GroupDocs.configure do |groupdocs|
|
40
|
+
# groupdocs.client_id = '07aaaf95f8eb33a4'
|
41
|
+
# groupdocs.private_key = '5cb711b3a52ffc5d90ee8a0f79206f5a'
|
42
|
+
# groupdocs.api_server = 'https://api.groupdocs.com'
|
43
|
+
# groupdocs.api_version = '2.0'
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# @yield [GroupDocs]
|
47
|
+
#
|
48
|
+
def configure(&blk)
|
49
|
+
yield self
|
50
|
+
end
|
51
|
+
|
52
|
+
end # << self
|
53
|
+
end # GroupDocs
|
@@ -0,0 +1,113 @@
|
|
1
|
+
module GroupDocs
|
2
|
+
module Api
|
3
|
+
class Entity
|
4
|
+
|
5
|
+
#
|
6
|
+
# Implements flexible API object creation.
|
7
|
+
#
|
8
|
+
# You can pass hash of options to automatically set attributes.
|
9
|
+
#
|
10
|
+
# @example Create folder with options hash
|
11
|
+
# GroupDocs::Storage::Folder.new(id: 1, name 'Test', url: 'http://groupdocs.com/folder/test')
|
12
|
+
# #=> <#GroupDocs::Storage::Folder @id=1 @name="Test" @url="http://groupdocs.com/folder/test">
|
13
|
+
#
|
14
|
+
# You can also pass block to set up attributes.
|
15
|
+
#
|
16
|
+
# @example Create folder with block
|
17
|
+
# GroupDocs::Storage::Folder.new do |folder|
|
18
|
+
# folder.id = 1
|
19
|
+
# folder.name = 'Test'
|
20
|
+
# folder.url = 'http://groupdocs.com/folder/test'
|
21
|
+
# end
|
22
|
+
# #=> <#GroupDocs::Storage::Folder @id=1 @name="Test" @url="http://groupdocs.com/folder/test">
|
23
|
+
#
|
24
|
+
# @param [Hash] options Each option is object attribute
|
25
|
+
# @yield [self] Use block to set up attributes
|
26
|
+
#
|
27
|
+
def initialize(options = {}, &blk)
|
28
|
+
if options.empty?
|
29
|
+
yield self if block_given?
|
30
|
+
else
|
31
|
+
options.each do |attr, value|
|
32
|
+
send(:"#{attr}=", value) if respond_to?(:"#{attr}=")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
#
|
38
|
+
# Recursively converts object and all its attributes to hash.
|
39
|
+
#
|
40
|
+
# @example Convert simple object to hash
|
41
|
+
# object = GroupDocs::Storage::File.new(id: 1, name, 'Test.pdf')
|
42
|
+
# object.to_hash
|
43
|
+
# #=> { id: 1, name: 'Test.pdf' }
|
44
|
+
#
|
45
|
+
# @return [Hash]
|
46
|
+
#
|
47
|
+
def to_hash
|
48
|
+
hash = {}
|
49
|
+
instance_variables.each do |variable|
|
50
|
+
key = variable_to_accessor(variable)
|
51
|
+
value = instance_variable_get(variable)
|
52
|
+
|
53
|
+
hash[key] = case value
|
54
|
+
when GroupDocs::Api::Entity
|
55
|
+
value.to_hash
|
56
|
+
when Array
|
57
|
+
value.map do |i|
|
58
|
+
i.to_hash if i.respond_to?(:to_hash)
|
59
|
+
end
|
60
|
+
else
|
61
|
+
value
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
hash
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# Inspects object using accessors instead of instance variables values.
|
70
|
+
#
|
71
|
+
# @api private
|
72
|
+
#
|
73
|
+
def inspect
|
74
|
+
not_nil_variables = instance_variables.select do |variable|
|
75
|
+
!send(variable_to_accessor(variable)).nil?
|
76
|
+
end
|
77
|
+
|
78
|
+
variables = not_nil_variables.map do |variable|
|
79
|
+
accessor = variable_to_accessor(variable)
|
80
|
+
value = send(accessor)
|
81
|
+
value = case value
|
82
|
+
when Symbol then ":#{value}"
|
83
|
+
when String then "\"#{value}\""
|
84
|
+
else value
|
85
|
+
end
|
86
|
+
"@#{accessor}=#{value}"
|
87
|
+
end
|
88
|
+
|
89
|
+
inspected = self.to_s
|
90
|
+
unless variables.empty?
|
91
|
+
inspected.gsub!(/>$/, '')
|
92
|
+
inspected << " #{variables.join(', ')}"
|
93
|
+
inspected << ?>
|
94
|
+
end
|
95
|
+
|
96
|
+
inspected
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
#
|
102
|
+
# Converts instance variable symbol to accessor method symbol.
|
103
|
+
# @api private
|
104
|
+
#
|
105
|
+
def variable_to_accessor(variable)
|
106
|
+
word = variable.to_s.delete(?@)
|
107
|
+
word.gsub!(/[A-Z]/) { |letter| "_#{letter.downcase}" }
|
108
|
+
word.to_sym
|
109
|
+
end
|
110
|
+
|
111
|
+
end # Entity
|
112
|
+
end # Api
|
113
|
+
end # GroupDocs
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module GroupDocs
|
2
|
+
module Api
|
3
|
+
module Helpers
|
4
|
+
module Access
|
5
|
+
|
6
|
+
MODES = {
|
7
|
+
private: 0,
|
8
|
+
restricted: 1,
|
9
|
+
public: 2
|
10
|
+
}
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
#
|
15
|
+
# Returns client ID from access hash or GroupDocs class variable.
|
16
|
+
#
|
17
|
+
# @return [String]
|
18
|
+
# @raise [NoClientIdError] If Client ID hasn't been set yet, raise exception.
|
19
|
+
# @api private
|
20
|
+
#
|
21
|
+
def client_id
|
22
|
+
client_id = options[:access][:client_id] || GroupDocs.client_id
|
23
|
+
client_id or raise Errors::NoClientIdError, 'Client ID has not been specified.'
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# Returns private key from access hash or GroupDocs class variable.
|
28
|
+
#
|
29
|
+
# @return [String]
|
30
|
+
# @raise [NoPrivateKeyError] If private key hasn't been set yet, raise exception.
|
31
|
+
# @api private
|
32
|
+
#
|
33
|
+
def private_key
|
34
|
+
private_key = options[:access][:private_key] || GroupDocs.private_key
|
35
|
+
private_key or raise Errors::NoPrivateKeyError, 'Private Key has not been specified.'
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Converts access mode from/to human-readable format.
|
40
|
+
#
|
41
|
+
# @param [Integer, Symbol] mode
|
42
|
+
# @return [Symbol, Integer]
|
43
|
+
# @api private
|
44
|
+
#
|
45
|
+
def parse_access_mode(mode)
|
46
|
+
if mode.is_a?(Integer)
|
47
|
+
MODES.invert[mode]
|
48
|
+
else
|
49
|
+
MODES[mode]
|
50
|
+
end or raise ArgumentError, "Unknown access mode: #{mode.inspect}."
|
51
|
+
end
|
52
|
+
|
53
|
+
end # Access
|
54
|
+
end # Helpers
|
55
|
+
end # Api
|
56
|
+
end # GroupDocs
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module GroupDocs
|
2
|
+
module Api
|
3
|
+
module Helpers
|
4
|
+
module Actions
|
5
|
+
|
6
|
+
ACTIONS = {
|
7
|
+
none: 0,
|
8
|
+
convert: 1,
|
9
|
+
combine: 2,
|
10
|
+
compress_zip: 4,
|
11
|
+
compress_rar: 8,
|
12
|
+
trace: 16,
|
13
|
+
convert_body: 32,
|
14
|
+
bind_data: 64,
|
15
|
+
print: 128,
|
16
|
+
import_annotations: 256,
|
17
|
+
}
|
18
|
+
|
19
|
+
#
|
20
|
+
# Converts actions array to byte flag.
|
21
|
+
#
|
22
|
+
# @param [Array<String, Symbol>] actions
|
23
|
+
# @return [Integer]
|
24
|
+
# @raise [ArgumentError] if actions is not an array
|
25
|
+
# @raise [ArgumentError] if action is unknown
|
26
|
+
# @api private
|
27
|
+
#
|
28
|
+
def convert_actions(actions)
|
29
|
+
actions.is_a?(Array) or raise ArgumentError, "Actions should be an array, received: #{actions.inspect}"
|
30
|
+
actions = actions.map(&:to_sym)
|
31
|
+
|
32
|
+
possible_actions = ACTIONS.map { |hash| hash.first }
|
33
|
+
actions.each do |action|
|
34
|
+
possible_actions.include?(action) or raise ArgumentError, "Unknown action: #{action.inspect}"
|
35
|
+
end
|
36
|
+
|
37
|
+
flag = 0
|
38
|
+
actions.each do |action|
|
39
|
+
flag += ACTIONS[action]
|
40
|
+
end
|
41
|
+
|
42
|
+
flag
|
43
|
+
end
|
44
|
+
|
45
|
+
end # Actions
|
46
|
+
end # Helpers
|
47
|
+
end # Api
|
48
|
+
end # GroupDocs
|