groupdocs 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. data/.travis.yml +5 -0
  2. data/Gemfile +3 -0
  3. data/README.md +141 -0
  4. data/Rakefile +9 -0
  5. data/groupdocs.gemspec +28 -0
  6. data/lib/groupdocs.rb +53 -0
  7. data/lib/groupdocs/api.rb +3 -0
  8. data/lib/groupdocs/api/entity.rb +113 -0
  9. data/lib/groupdocs/api/helpers.rb +5 -0
  10. data/lib/groupdocs/api/helpers/access_helper.rb +56 -0
  11. data/lib/groupdocs/api/helpers/actions_helper.rb +48 -0
  12. data/lib/groupdocs/api/helpers/rest_helper.rb +89 -0
  13. data/lib/groupdocs/api/helpers/status_helper.rb +48 -0
  14. data/lib/groupdocs/api/helpers/url_helper.rb +89 -0
  15. data/lib/groupdocs/api/request.rb +73 -0
  16. data/lib/groupdocs/api/sugar/lookup.rb +48 -0
  17. data/lib/groupdocs/datasource.rb +162 -0
  18. data/lib/groupdocs/datasource/field.rb +44 -0
  19. data/lib/groupdocs/document.rb +513 -0
  20. data/lib/groupdocs/document/annotation.rb +215 -0
  21. data/lib/groupdocs/document/annotation/reply.rb +167 -0
  22. data/lib/groupdocs/document/change.rb +35 -0
  23. data/lib/groupdocs/document/field.rb +27 -0
  24. data/lib/groupdocs/document/metadata.rb +26 -0
  25. data/lib/groupdocs/document/rectangle.rb +24 -0
  26. data/lib/groupdocs/document/view.rb +36 -0
  27. data/lib/groupdocs/errors.rb +10 -0
  28. data/lib/groupdocs/job.rb +201 -0
  29. data/lib/groupdocs/questionnaire.rb +221 -0
  30. data/lib/groupdocs/questionnaire/execution.rb +120 -0
  31. data/lib/groupdocs/questionnaire/page.rb +43 -0
  32. data/lib/groupdocs/questionnaire/question.rb +75 -0
  33. data/lib/groupdocs/questionnaire/question/answer.rb +10 -0
  34. data/lib/groupdocs/storage.rb +37 -0
  35. data/lib/groupdocs/storage/file.rb +248 -0
  36. data/lib/groupdocs/storage/folder.rb +314 -0
  37. data/lib/groupdocs/storage/package.rb +42 -0
  38. data/lib/groupdocs/user.rb +50 -0
  39. data/lib/groupdocs/version.rb +3 -0
  40. data/spec/groupdocs/api/entity_spec.rb +54 -0
  41. data/spec/groupdocs/api/helpers/access_helper_spec.rb +89 -0
  42. data/spec/groupdocs/api/helpers/actions_helper_spec.rb +51 -0
  43. data/spec/groupdocs/api/helpers/rest_helper_spec.rb +187 -0
  44. data/spec/groupdocs/api/helpers/status_helper_spec.rb +85 -0
  45. data/spec/groupdocs/api/helpers/url_helper_spec.rb +93 -0
  46. data/spec/groupdocs/api/request_spec.rb +85 -0
  47. data/spec/groupdocs/datasource/field_spec.rb +50 -0
  48. data/spec/groupdocs/datasource_spec.rb +156 -0
  49. data/spec/groupdocs/document/annotation/reply_spec.rb +179 -0
  50. data/spec/groupdocs/document/annotation_spec.rb +226 -0
  51. data/spec/groupdocs/document/change_spec.rb +35 -0
  52. data/spec/groupdocs/document/field_spec.rb +31 -0
  53. data/spec/groupdocs/document/metadata_spec.rb +26 -0
  54. data/spec/groupdocs/document/rectangle_spec.rb +34 -0
  55. data/spec/groupdocs/document/view_spec.rb +36 -0
  56. data/spec/groupdocs/document_spec.rb +509 -0
  57. data/spec/groupdocs/errors_spec.rb +7 -0
  58. data/spec/groupdocs/job_spec.rb +196 -0
  59. data/spec/groupdocs/questionnaire/execution_spec.rb +136 -0
  60. data/spec/groupdocs/questionnaire/page_spec.rb +50 -0
  61. data/spec/groupdocs/questionnaire/question/answer_spec.rb +11 -0
  62. data/spec/groupdocs/questionnaire/question_spec.rb +84 -0
  63. data/spec/groupdocs/questionnaire_spec.rb +217 -0
  64. data/spec/groupdocs/storage/file_spec.rb +242 -0
  65. data/spec/groupdocs/storage/folder_spec.rb +310 -0
  66. data/spec/groupdocs/storage/package_spec.rb +41 -0
  67. data/spec/groupdocs/storage_spec.rb +27 -0
  68. data/spec/groupdocs/user_spec.rb +53 -0
  69. data/spec/groupdocs_spec.rb +56 -0
  70. data/spec/spec_helper.rb +46 -0
  71. data/spec/support/files/resume.pdf +0 -0
  72. data/spec/support/json/annotation_collaborators_set.json +16 -0
  73. data/spec/support/json/annotation_create.json +12 -0
  74. data/spec/support/json/annotation_list.json +32 -0
  75. data/spec/support/json/annotation_remove.json +9 -0
  76. data/spec/support/json/annotation_replies_create.json +9 -0
  77. data/spec/support/json/annotation_replies_get.json +25 -0
  78. data/spec/support/json/comparison_changes.json +46 -0
  79. data/spec/support/json/comparison_compare.json +8 -0
  80. data/spec/support/json/comparison_document.json +10 -0
  81. data/spec/support/json/datasource_add.json +8 -0
  82. data/spec/support/json/datasource_get.json +22 -0
  83. data/spec/support/json/datasource_remove.json +8 -0
  84. data/spec/support/json/datasource_update.json +8 -0
  85. data/spec/support/json/document_access_info_get.json +14 -0
  86. data/spec/support/json/document_convert.json +8 -0
  87. data/spec/support/json/document_datasource.json +10 -0
  88. data/spec/support/json/document_fields.json +34 -0
  89. data/spec/support/json/document_formats.json +8 -0
  90. data/spec/support/json/document_metadata.json +15 -0
  91. data/spec/support/json/document_questionnaire_create.json +9 -0
  92. data/spec/support/json/document_questionnaires.json +23 -0
  93. data/spec/support/json/document_sharers_remove.json +8 -0
  94. data/spec/support/json/document_sharers_set.json +16 -0
  95. data/spec/support/json/document_views.json +32 -0
  96. data/spec/support/json/file_compress.json +8 -0
  97. data/spec/support/json/file_copy.json +14 -0
  98. data/spec/support/json/file_delete.json +5 -0
  99. data/spec/support/json/file_move.json +14 -0
  100. data/spec/support/json/file_upload.json +8 -0
  101. data/spec/support/json/folder_create.json +8 -0
  102. data/spec/support/json/folder_delete.json +5 -0
  103. data/spec/support/json/folder_list.json +21 -0
  104. data/spec/support/json/folder_move.json +8 -0
  105. data/spec/support/json/folder_sharers_get.json +16 -0
  106. data/spec/support/json/folder_sharers_remove.json +8 -0
  107. data/spec/support/json/folder_sharers_set.json +16 -0
  108. data/spec/support/json/job_add_url.json +8 -0
  109. data/spec/support/json/job_create.json +8 -0
  110. data/spec/support/json/job_documents.json +39 -0
  111. data/spec/support/json/job_file_add.json +8 -0
  112. data/spec/support/json/job_update.json +7 -0
  113. data/spec/support/json/jobs_get.json +52 -0
  114. data/spec/support/json/package_create.json +7 -0
  115. data/spec/support/json/questionnaire_create.json +8 -0
  116. data/spec/support/json/questionnaire_datasources.json +26 -0
  117. data/spec/support/json/questionnaire_execution_create.json +9 -0
  118. data/spec/support/json/questionnaire_execution_status_set.json +8 -0
  119. data/spec/support/json/questionnaire_execution_update.json +8 -0
  120. data/spec/support/json/questionnaire_executions.json +24 -0
  121. data/spec/support/json/questionnaire_get.json +14 -0
  122. data/spec/support/json/questionnaire_remove.json +8 -0
  123. data/spec/support/json/questionnaire_update.json +8 -0
  124. data/spec/support/json/questionnaires_get.json +22 -0
  125. data/spec/support/json/storage_info.json +10 -0
  126. data/spec/support/shared_examples/api/entity.rb +37 -0
  127. data/spec/support/shared_examples/api/helpers/status_helper.rb +12 -0
  128. data/spec/support/shared_examples/api/sugar/lookup.rb +57 -0
  129. metadata +356 -0
@@ -0,0 +1,120 @@
1
+ module GroupDocs
2
+ class Questionnaire::Execution < GroupDocs::Api::Entity
3
+
4
+ STATUSES = {
5
+ draft: 0,
6
+ submitted: 1,
7
+ executed: 2,
8
+ approved: 3,
9
+ rejected: 4,
10
+ closed: 5,
11
+ }
12
+
13
+ #
14
+ # Returns an array of all executions.
15
+ #
16
+ # @param [Hash] access Access credentials
17
+ # @option access [String] :client_id
18
+ # @option access [String] :private_key
19
+ # @return [Array<GroupDocs::Questionnaire::Execution>]
20
+ #
21
+ def self.all!(access = {})
22
+ GroupDocs::Questionnaire.executions!(access)
23
+ end
24
+
25
+ # @attr [Integer] id
26
+ attr_accessor :id
27
+ # @attr [Integer] ownerId
28
+ attr_accessor :ownerId
29
+ # @attr [Integer] questionnaireId
30
+ attr_accessor :questionnaireId
31
+ # @attr [Integer] executiveId
32
+ attr_accessor :executiveId
33
+ # @attr [Integer] approverId
34
+ attr_accessor :approverId
35
+ # @attr [Integer] datasourceId
36
+ attr_accessor :datasourceId
37
+ # @attr [Integer] documentId
38
+ attr_accessor :documentId
39
+ # @attr [Integer] status
40
+ attr_accessor :status
41
+ # @attr [String] guid
42
+ attr_accessor :guid
43
+
44
+ # Human-readable accessors
45
+ alias_method :owner_id, :ownerId
46
+ alias_method :owner_id=, :ownerId=
47
+ alias_method :questionnaire_id, :questionnaireId
48
+ alias_method :questionnaire_id=, :questionnaireId=
49
+ alias_method :executive_id, :executiveId
50
+ alias_method :executive_id=, :executiveId=
51
+ alias_method :approver_id, :approverId
52
+ alias_method :approver_id=, :approverId=
53
+ alias_method :datasource_id, :datasourceId
54
+ alias_method :datasource_id=, :datasourceId=
55
+ alias_method :document_id, :documentId
56
+ alias_method :document_id=, :documentId=
57
+
58
+ #
59
+ # Updates status with machine-readable format.
60
+ #
61
+ # If you want to update status on server, use #set_status! method.
62
+ #
63
+ # @param [Symbol, Integer] status
64
+ # @raise [ArgumentError] if status is unknown
65
+ #
66
+ def status=(status)
67
+ if status.is_a?(Symbol)
68
+ STATUSES.keys.include?(status) or raise ArgumentError, "Unknown status: #{status.inspect}"
69
+ status = STATUSES[status]
70
+ end
71
+
72
+ @status = status
73
+ end
74
+
75
+ #
76
+ # Returns execution status in human-readable format.
77
+ #
78
+ # @return [Symbol]
79
+ #
80
+ def status
81
+ STATUSES.invert[@status]
82
+ end
83
+
84
+ #
85
+ # Updates status of execution on server.
86
+ #
87
+ # @param [Symbol] status
88
+ # @param [Hash] access Access credentials
89
+ # @option access [String] :client_id
90
+ # @option access [String] :private_key
91
+ #
92
+ def set_status!(status, access = {})
93
+ GroupDocs::Api::Request.new do |request|
94
+ request[:access] = access
95
+ request[:method] = :PUT
96
+ request[:path] = "/merge/{{client_id}}/questionnaires/executions/#{id}/status"
97
+ request[:request_body] = STATUSES[status]
98
+ end.execute!
99
+
100
+ self.status = status
101
+ end
102
+
103
+ #
104
+ # Updates execution on server.
105
+ #
106
+ # @param [Hash] access Access credentials
107
+ # @option access [String] :client_id
108
+ # @option access [String] :private_key
109
+ #
110
+ def update!(access = {})
111
+ GroupDocs::Api::Request.new do |request|
112
+ request[:access] = access
113
+ request[:method] = :PUT
114
+ request[:path] = "/merge/{{client_id}}/questionnaires/executions/#{id}"
115
+ request[:request_body] = to_hash
116
+ end.execute!
117
+ end
118
+
119
+ end # Questionnaire::Execution
120
+ end # GroupDocs
@@ -0,0 +1,43 @@
1
+ module GroupDocs
2
+ class Questionnaire::Page < GroupDocs::Api::Entity
3
+
4
+ # @attr [Integer] number
5
+ attr_accessor :number
6
+ # @attr [String] title
7
+ attr_accessor :title
8
+ # @attr [Array<GroupDocs::Questionnaire::Question>] questions
9
+ attr_accessor :questions
10
+
11
+ #
12
+ # Converts each question to GroupDocs::Questionnaire::Question object.
13
+ #
14
+ # @param [Array<GroupDocs::Questionnaire::Question, Hash>] questions
15
+ #
16
+ def questions=(questions)
17
+ if questions
18
+ @questions = questions.map do |question|
19
+ if question.is_a?(GroupDocs::Questionnaire::Question)
20
+ question
21
+ else
22
+ GroupDocs::Questionnaire::Question.new(question)
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ #
29
+ # Adds question to page.
30
+ #
31
+ # @param [GroupDocs::Questionnaire::Question] question
32
+ # @raise [ArgumentError] if question is not GroupDocs::Questionnaire::Question object
33
+ #
34
+ def add_question(question)
35
+ question.is_a?(GroupDocs::Questionnaire::Question) or raise ArgumentError,
36
+ "Question should be GroupDocs::Questionnaire::Question object, received: #{question.inspect}"
37
+
38
+ @questions ||= Array.new
39
+ @questions << question
40
+ end
41
+
42
+ end # Questionnaire::Page
43
+ end # GroupDocs
@@ -0,0 +1,75 @@
1
+ module GroupDocs
2
+ class Questionnaire::Question < GroupDocs::Api::Entity
3
+
4
+ require 'groupdocs/questionnaire/question/answer'
5
+
6
+ TYPES = {
7
+ simple: 0,
8
+ multiple_choice: 1,
9
+ }
10
+
11
+ # @attr [String] field
12
+ attr_accessor :field
13
+ # @attr [String] text
14
+ attr_accessor :text
15
+ # @attr [String] def_answer
16
+ attr_accessor :def_answer
17
+ # @attr [Boolean] required
18
+ attr_accessor :required
19
+ # @attr [Symbol] type
20
+ attr_accessor :type
21
+ # @attr [Array<Hash>] answers
22
+ attr_accessor :answers
23
+
24
+ #
25
+ # Converts each answer to GroupDocs::Questionnaire::Question::Answer object.
26
+ #
27
+ # @param [Array<Hash>] answers
28
+ #
29
+ def answers=(answers)
30
+ if answers
31
+ @answers = answers.map do |answer|
32
+ if answer.is_a?(GroupDocs::Questionnaire::Question::Answer)
33
+ answer
34
+ else
35
+ GroupDocs::Questionnaire::Question::Answer.new(answer)
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ #
42
+ # Adds answer to the question.
43
+ #
44
+ # @param [GroupDocs::Questionnaire::Question::Answer] answer
45
+ # @raise [ArgumentError] if answer is not GroupDocs::Questionnaire::Question::Answer object
46
+ #
47
+ def add_answer(answer)
48
+ answer.is_a?(GroupDocs::Questionnaire::Question::Answer) or raise ArgumentError,
49
+ "Answer should be GroupDocs::Questionnaire::Question::Answer object, received: #{answer.inspect}"
50
+
51
+ @answers ||= Array.new
52
+ @answers << answer
53
+ end
54
+
55
+ #
56
+ # Updates type with machine-readable format.
57
+ #
58
+ # @param [Symbol] type
59
+ #
60
+ def type=(type)
61
+ type = TYPES[type] if type.is_a?(Symbol)
62
+ @type = type
63
+ end
64
+
65
+ #
66
+ # Returns field type in human-readable format.
67
+ #
68
+ # @return [Symbol]
69
+ #
70
+ def type
71
+ TYPES.invert[@type]
72
+ end
73
+
74
+ end # Questionnaire::Question
75
+ end # GroupDocs
@@ -0,0 +1,10 @@
1
+ module GroupDocs
2
+ class Questionnaire::Question::Answer < GroupDocs::Api::Entity
3
+
4
+ # @attr [String] text
5
+ attr_accessor :text
6
+ # @attr [String] value
7
+ attr_accessor :value
8
+
9
+ end # Questionnaire::Question::Answer
10
+ end # GroupDocs
@@ -0,0 +1,37 @@
1
+ require 'groupdocs/storage/folder'
2
+ require 'groupdocs/storage/file'
3
+ require 'groupdocs/storage/package'
4
+
5
+
6
+ module GroupDocs
7
+ module Storage
8
+
9
+ #
10
+ # Returns hash of information about user's storage.
11
+ #
12
+ # @example
13
+ # GroupDocs::Storage.info!
14
+ # #=> { total_space: "1024 MB", available_space: "1020 MB", document_credits: 5000, available_credits: 4964 }
15
+ #
16
+ # @param [Hash] access Access credentials
17
+ # @option access [String] :client_id
18
+ # @option access [String] :private_key
19
+ # @return [Hash]
20
+ #
21
+ def self.info!(access = {})
22
+ json = GroupDocs::Api::Request.new do |request|
23
+ request[:access] = access
24
+ request[:method] = :GET
25
+ request[:path] = '/storage/{{client_id}}'
26
+ end.execute!
27
+
28
+ {
29
+ total_space: "#{json[:total_space] / 1048576} MB",
30
+ available_space: "#{json[:avail_space] / 1048576} MB",
31
+ document_credits: json[:doc_credits],
32
+ available_credits: json[:avail_credits]
33
+ }
34
+ end
35
+
36
+ end # Storage
37
+ end # GroupDocs
@@ -0,0 +1,248 @@
1
+ module GroupDocs
2
+ module Storage
3
+ class File < GroupDocs::Api::Entity
4
+
5
+ extend GroupDocs::Api::Sugar::Lookup
6
+
7
+ #
8
+ # Uploads file to API server.
9
+ #
10
+ # @example
11
+ # GroupDocs::Storage::File.upload!('resume.pdf', '/folder/cv.pdf', description: 'My resume')
12
+ #
13
+ # @param [String] filepath Path to file to be uploaded
14
+ # @param [String] upload_path Full path to directory to upload file to starting with "/".
15
+ # You can also add filename and then uploaded file will use it.
16
+ # @param [Hash] options Hash of options
17
+ # @option options [String] :description Optional description for file
18
+ # @param [Hash] access Access credentials
19
+ # @option access [String] :client_id
20
+ # @option access [String] :private_key
21
+ # @return [GroupDocs::Storage::File]
22
+ #
23
+ # @raise [ArgumentError] If path does not start with /
24
+ #
25
+ def self.upload!(filepath, upload_path = '/', options = {}, access = {})
26
+ upload_path.chars.first == '/' or raise ArgumentError, "Path should start with /: #{upload_path.inspect}"
27
+ upload_path << "/#{Object::File.basename(filepath)}" unless upload_path =~ /\.(\w){3,4}$/
28
+
29
+ api = GroupDocs::Api::Request.new do |request|
30
+ request[:access] = access
31
+ request[:method] = :POST
32
+ request[:path] = "/storage/{{client_id}}/folders#{upload_path.gsub(/[\/]{2}/, '/')}"
33
+ request[:request_body] = Object::File.new(filepath, 'rb')
34
+ end
35
+ api.add_params(options)
36
+ json = api.execute!
37
+
38
+ GroupDocs::Storage::File.new(json)
39
+ end
40
+
41
+ #
42
+ # Returns an array of all files on server starting with given path.
43
+ #
44
+ # @param [String] path Starting path to look for files
45
+ # @param [Hash] access Access credentials
46
+ # @option access [String] :client_id
47
+ # @option access [String] :private_key
48
+ # @return [Array<GroupDocs::Storage::File>]
49
+ #
50
+ def self.all!(path = '/', access = {})
51
+ files = Array.new
52
+ folder = GroupDocs::Storage::Folder.new(path: path)
53
+ folder.list!({}, access).each do |entity|
54
+ if entity.is_a?(GroupDocs::Storage::Folder)
55
+ files += all!("#{path}/#{entity.name}".gsub(/[\/]{2}/, '/'), access)
56
+ else
57
+ files << entity
58
+ end
59
+ end
60
+
61
+ files
62
+ end
63
+
64
+ # @attr [Integer] id
65
+ attr_accessor :id
66
+ # @attr [Integer] guid
67
+ attr_accessor :guid
68
+ # @attr [Integer] size
69
+ attr_accessor :size
70
+ # @attr [Boolean] known
71
+ attr_accessor :known
72
+ # @attr [String] thumbnail
73
+ attr_accessor :thumbnail
74
+ # @attr [Time] created_on
75
+ attr_accessor :created_on
76
+ # @attr [Time] modified_on
77
+ attr_accessor :modified_on
78
+ # @attr [String] url
79
+ attr_accessor :url
80
+ # @attr [String] name
81
+ attr_accessor :name
82
+ # @attr [Integer] version
83
+ attr_accessor :version
84
+ # @attr [Integer] type
85
+ attr_accessor :type
86
+ # @attr [Integer] access
87
+ attr_accessor :access
88
+ # @attr [String] path
89
+ attr_accessor :path
90
+
91
+ # Compatibility with response JSON
92
+ alias_method :adj_name=, :name=
93
+
94
+ #
95
+ # Converts timestamp which is return by API server to Time object.
96
+ #
97
+ # @return [Time]
98
+ #
99
+ def created_on
100
+ Time.at(@created_on)
101
+ end
102
+
103
+ #
104
+ # Converts timestamp which is return by API server to Time object.
105
+ #
106
+ # @return [Time]
107
+ #
108
+ def modified_on
109
+ Time.at(@modified_on)
110
+ end
111
+
112
+ #
113
+ # Downloads file to given path.
114
+ #
115
+ # @param [String] path Directory to download file to
116
+ # @param [Hash] access Access credentials
117
+ # @option access [String] :client_id
118
+ # @option access [String] :private_key
119
+ # @return [String] Path to downloaded file
120
+ #
121
+ def download!(path, access = {})
122
+ response = GroupDocs::Api::Request.new do |request|
123
+ request[:access] = access
124
+ request[:method] = :DOWNLOAD
125
+ request[:path] = "/storage/{{client_id}}/files/#{id}"
126
+ end.execute!
127
+
128
+ filepath = "#{path}/#{name}"
129
+ Object::File.open(filepath, 'w') do |file|
130
+ file.write(response)
131
+ end
132
+
133
+ filepath
134
+ end
135
+
136
+ #
137
+ # Moves file to given path.
138
+ #
139
+ # @param [String] path Full path to directory to move file to starting with "/".
140
+ # You can also add filename and then moved file will use it.
141
+ # @param [Hash] access Access credentials
142
+ # @option access [String] :client_id
143
+ # @option access [String] :private_key
144
+ # @return [GroupDocs::Storage::File] Moved to file
145
+ #
146
+ # @raise [ArgumentError] If path does not start with /
147
+ #
148
+ def move!(path, access = {})
149
+ path.chars.first == '/' or raise ArgumentError, "Path should start with /: #{path.inspect}"
150
+ path << "/#{Object::File.basename(name)}" unless path =~ /\.(\w){3,4}$/
151
+
152
+ json = GroupDocs::Api::Request.new do |request|
153
+ request[:access] = access
154
+ request[:method] = :PUT
155
+ request[:headers] = { :'Groupdocs-Move' => id }
156
+ request[:path] = "/storage/{{client_id}}/files#{path}"
157
+ end.execute!
158
+
159
+ GroupDocs::Storage::File.new(json[:dst_file])
160
+ end
161
+
162
+ #
163
+ # Renames file to new one.
164
+ #
165
+ # @param [String] name New file name
166
+ # @param [Hash] access Access credentials
167
+ # @option access [String] :client_id
168
+ # @option access [String] :private_key
169
+ # @return [GroupDocs::Storage::File] Renamed file
170
+ #
171
+ def rename!(name, access = {})
172
+ move!("#{path}#{name}", access)
173
+ end
174
+
175
+ #
176
+ # Moves file to given path.
177
+ #
178
+ # @param [String] path Full path to directory to copy file to starting with "/".
179
+ # You can also add filename and then copied file will use it.
180
+ # @param [Hash] access Access credentials
181
+ # @option access [String] :client_id
182
+ # @option access [String] :private_key
183
+ # @return [GroupDocs::Storage::File] Copied to file
184
+ #
185
+ # @raise [ArgumentError] If path does not start with /
186
+ #
187
+ def copy!(path, access = {})
188
+ path.chars.first == '/' or raise ArgumentError, "Path should start with /: #{path.inspect}"
189
+ path << "/#{Object::File.basename(name)}" unless path =~ /\.(\w){3,4}$/
190
+
191
+ json = GroupDocs::Api::Request.new do |request|
192
+ request[:access] = access
193
+ request[:method] = :PUT
194
+ request[:headers] = { :'Groupdocs-Copy' => id }
195
+ request[:path] = "/storage/{{client_id}}/files#{path}"
196
+ end.execute!
197
+
198
+ GroupDocs::Storage::File.new(json[:dst_file])
199
+ end
200
+
201
+ #
202
+ # Compresses file on server to given archive type.
203
+ #
204
+ # @param [Symbol] type Archive type: :zip, :rar.
205
+ # @param [Hash] access Access credentials
206
+ # @option access [String] :client_id
207
+ # @option access [String] :private_key
208
+ # @return [GroupDocs::Storage::File] Archive file
209
+ #
210
+ def compress!(type = :zip, access = {})
211
+ json = GroupDocs::Api::Request.new do |request|
212
+ request[:access] = access
213
+ request[:method] = :POST
214
+ request[:path] = "/storage/{{client_id}}/files/#{id}/archive/#{type}"
215
+ end.execute!
216
+
217
+ # HACK add filename for further download
218
+ json[:name] = "#{name}.#{type}"
219
+ GroupDocs::Storage::File.new(json)
220
+ end
221
+
222
+ #
223
+ # Deletes file from server.
224
+ #
225
+ # @param [Hash] access Access credentials
226
+ # @option access [String] :client_id
227
+ # @option access [String] :private_key
228
+ #
229
+ def delete!(access = {})
230
+ GroupDocs::Api::Request.new do |request|
231
+ request[:access] = access
232
+ request[:method] = :DELETE
233
+ request[:path] = "/storage/{{client_id}}/files/#{guid}"
234
+ end.execute!
235
+ end
236
+
237
+ #
238
+ # Converts file to GroupDocs::Document.
239
+ #
240
+ # @return [GroupDocs::Document]
241
+ #
242
+ def to_document
243
+ GroupDocs::Document.new(file: self)
244
+ end
245
+
246
+ end # File
247
+ end # Storage
248
+ end # GroupDocs