groupdocs 0.2 → 0.2.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.
Files changed (35) hide show
  1. data/lib/groupdocs.rb +1 -0
  2. data/lib/groupdocs/api.rb +0 -1
  3. data/lib/groupdocs/api/helpers.rb +3 -1
  4. data/lib/groupdocs/api/helpers/access_mode_helper.rb +32 -0
  5. data/lib/groupdocs/api/helpers/{access_helper.rb → credentials_helper.rb} +2 -23
  6. data/lib/groupdocs/api/helpers/path_helper.rb +28 -0
  7. data/lib/groupdocs/api/helpers/rest_helper.rb +1 -1
  8. data/lib/groupdocs/api/helpers/url_helper.rb +1 -1
  9. data/lib/groupdocs/api/request.rb +3 -3
  10. data/lib/groupdocs/datasource.rb +6 -6
  11. data/lib/groupdocs/document.rb +34 -34
  12. data/lib/groupdocs/document/annotation.rb +6 -6
  13. data/lib/groupdocs/document/annotation/reply.rb +5 -5
  14. data/lib/groupdocs/extensions.rb +1 -0
  15. data/lib/groupdocs/extensions/lookup.rb +52 -0
  16. data/lib/groupdocs/job.rb +13 -13
  17. data/lib/groupdocs/questionnaire.rb +14 -14
  18. data/lib/groupdocs/questionnaire/execution.rb +3 -3
  19. data/lib/groupdocs/questionnaire/page.rb +1 -1
  20. data/lib/groupdocs/questionnaire/question.rb +1 -1
  21. data/lib/groupdocs/storage.rb +1 -1
  22. data/lib/groupdocs/storage/file.rb +28 -25
  23. data/lib/groupdocs/storage/folder.rb +19 -27
  24. data/lib/groupdocs/storage/package.rb +1 -1
  25. data/lib/groupdocs/version.rb +1 -1
  26. data/spec/groupdocs/api/helpers/access_mode_helper_spec.rb +49 -0
  27. data/spec/groupdocs/api/helpers/{access_helper_spec.rb → credentials_helpers_spec.rb} +1 -42
  28. data/spec/groupdocs/api/helpers/path_helper_spec.rb +28 -0
  29. data/spec/groupdocs/document_spec.rb +1 -1
  30. data/spec/groupdocs/storage/file_spec.rb +23 -28
  31. data/spec/groupdocs/storage/folder_spec.rb +18 -18
  32. data/spec/support/shared_examples/api/helpers/access_mode_helper.rb +12 -0
  33. data/spec/support/shared_examples/{api/sugar → extensions}/lookup.rb +1 -1
  34. metadata +35 -26
  35. data/lib/groupdocs/api/sugar/lookup.rb +0 -57
@@ -111,7 +111,7 @@ module GroupDocs
111
111
  reply
112
112
  else
113
113
  reply.merge!(annotation: self)
114
- GroupDocs::Document::Annotation::Reply.new(reply)
114
+ Document::Annotation::Reply.new(reply)
115
115
  end
116
116
  end
117
117
  end
@@ -144,7 +144,7 @@ module GroupDocs
144
144
  # @option access [String] :private_key
145
145
  #
146
146
  def create!(access = {})
147
- json = GroupDocs::Api::Request.new do |request|
147
+ json = Api::Request.new do |request|
148
148
  request[:access] = access
149
149
  request[:method] = :POST
150
150
  request[:path] = "/ant/{{client_id}}/files/#{document.file.guid}/annotations"
@@ -166,7 +166,7 @@ module GroupDocs
166
166
  # @return [Array<GroupDocs::User>]
167
167
  #
168
168
  def collaborators_set!(emails, access = {})
169
- json = GroupDocs::Api::Request.new do |request|
169
+ json = Api::Request.new do |request|
170
170
  request[:access] = access
171
171
  request[:method] = :PUT
172
172
  request[:path] = "/ant/{{client_id}}/files/#{document.file.guid}/collaborators"
@@ -174,7 +174,7 @@ module GroupDocs
174
174
  end.execute!
175
175
 
176
176
  json[:collaborators].map do |collaborator|
177
- GroupDocs::User.new(collaborator)
177
+ User.new(collaborator)
178
178
  end
179
179
  end
180
180
  # note that aliased version cannot accept access credentials hash
@@ -188,7 +188,7 @@ module GroupDocs
188
188
  # @option access [String] :private_key
189
189
  #
190
190
  def remove!(access = {})
191
- GroupDocs::Api::Request.new do |request|
191
+ Api::Request.new do |request|
192
192
  request[:access] = access
193
193
  request[:method] = :DELETE
194
194
  request[:path] = "/ant/{{client_id}}/annotations/#{guid}"
@@ -208,7 +208,7 @@ module GroupDocs
208
208
  # @raise [ArgumentError] If :after option is passed but it's not an instance of Time
209
209
  #
210
210
  def replies!(options = {}, access = {})
211
- GroupDocs::Document::Annotation::Reply.get!(self, options, access)
211
+ Document::Annotation::Reply.get!(self, options, access)
212
212
  end
213
213
 
214
214
  end # Document::Annotation
@@ -23,7 +23,7 @@ module GroupDocs
23
23
 
24
24
  options[:after] = (options[:after].to_i * 1000) if options[:after]
25
25
 
26
- api = GroupDocs::Api::Request.new do |request|
26
+ api = Api::Request.new do |request|
27
27
  request[:access] = access
28
28
  request[:method] = :GET
29
29
  request[:path] = "/ant/{{client_id}}/annotations/#{annotation.guid}/replies"
@@ -33,7 +33,7 @@ module GroupDocs
33
33
 
34
34
  json[:replies].map do |reply|
35
35
  reply.merge!(annotation: annotation)
36
- GroupDocs::Document::Annotation::Reply.new(reply)
36
+ Document::Annotation::Reply.new(reply)
37
37
  end
38
38
  end
39
39
 
@@ -101,7 +101,7 @@ module GroupDocs
101
101
  # @raise [NameError] if annotation or annotation_guid are not set
102
102
  #
103
103
  def create!(access = {})
104
- json = GroupDocs::Api::Request.new do |request|
104
+ json = Api::Request.new do |request|
105
105
  request[:access] = access
106
106
  request[:method] = :POST
107
107
  request[:path] = "/ant/{{client_id}}/annotations/#{get_annotation_guid}/replies"
@@ -127,7 +127,7 @@ module GroupDocs
127
127
  # @option access [String] :private_key
128
128
  #
129
129
  def edit!(access = {})
130
- GroupDocs::Api::Request.new do |request|
130
+ Api::Request.new do |request|
131
131
  request[:access] = access
132
132
  request[:method] = :PUT
133
133
  request[:path] = "/ant/{{client_id}}/replies/#{guid}"
@@ -145,7 +145,7 @@ module GroupDocs
145
145
  # @todo currently not implemented in API
146
146
  #
147
147
  def remove!(access = {})
148
- GroupDocs::Api::Request.new do |request|
148
+ Api::Request.new do |request|
149
149
  request[:access] = access
150
150
  request[:method] = :DELETE
151
151
  request[:path] = "/ant/{{client_id}}/replies/#{guid}"
@@ -0,0 +1 @@
1
+ require 'groupdocs/extensions/lookup'
@@ -0,0 +1,52 @@
1
+ module GroupDocs
2
+ module Extensions
3
+ #
4
+ # Extends classes providing them with .find! and .find_all! class methods
5
+ # which is a bit of sugar for working with files, folder and documents,
6
+ #
7
+ # It's not that flexible because requires extending class to implement
8
+ # .all! class method.
9
+ #
10
+ # This module is a subject to modifications.
11
+ #
12
+ module Lookup
13
+
14
+ #
15
+ # Returns first object matching given options.
16
+ #
17
+ # @param [Symbol] attribute
18
+ # @param [Integer, String, Regexp] value
19
+ # @param [Hash] access Access credentials
20
+ # @option access [String] :client_id
21
+ # @option access [String] :private_key
22
+ # @return [GroupDocs::Api::Entity] Matching entity
23
+ #
24
+ def find!(attribute, value, access = {})
25
+ find_all!(attribute, value, access).first
26
+ end
27
+
28
+ #
29
+ # Returns all objects matching given options.
30
+ #
31
+ # Each entity has to implement #all! method for this to work.
32
+ #
33
+ # @param [Symbol] attribute
34
+ # @param [Integer, String, Regexp] value
35
+ # @param [Hash] access Access credentials
36
+ # @option access [String] :client_id
37
+ # @option access [String] :private_key
38
+ # @return [Array] Array of matching entities
39
+ #
40
+ # @raise [NoMethodError] if extending class does not implement .all! class method.
41
+ #
42
+ def find_all!(attribute, value, access = {})
43
+ respond_to?(:all!) or raise NoMethodError, "#{self}.all! is not implemented - aborting."
44
+
45
+ all!('/', access).select do |object|
46
+ value === object.send(attribute)
47
+ end
48
+ end
49
+
50
+ end # Lookup
51
+ end # Extensions
52
+ end # GroupDocs
data/lib/groupdocs/job.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module GroupDocs
2
2
  class Job < GroupDocs::Api::Entity
3
3
 
4
- extend GroupDocs::Api::Helpers::Actions
5
- include GroupDocs::Api::Helpers::Status
4
+ extend Api::Helpers::Actions
5
+ include Api::Helpers::Status
6
6
 
7
7
  #
8
8
  # Returns array of recent jobs.
@@ -16,7 +16,7 @@ module GroupDocs
16
16
  # @return [Array<GroupDocs::Job>]
17
17
  #
18
18
  def self.all!(options = {}, access = {})
19
- api = GroupDocs::Api::Request.new do |request|
19
+ api = Api::Request.new do |request|
20
20
  request[:access] = access
21
21
  request[:method] = :GET
22
22
  request[:path] = '/async/{{client_id}}/jobs'
@@ -25,7 +25,7 @@ module GroupDocs
25
25
  json = api.execute!
26
26
 
27
27
  json[:jobs].map do |job|
28
- GroupDocs::Job.new(job)
28
+ Job.new(job)
29
29
  end
30
30
  end
31
31
 
@@ -47,7 +47,7 @@ module GroupDocs
47
47
  options[:actions] = convert_actions(options[:actions])
48
48
  options[:out_formats] = options[:out_formats].join(?;) if options[:out_formats]
49
49
 
50
- api = GroupDocs::Api::Request.new do |request|
50
+ api = Api::Request.new do |request|
51
51
  request[:access] = access
52
52
  request[:method] = :POST
53
53
  request[:path] = '/async/{{client_id}}/jobs'
@@ -55,7 +55,7 @@ module GroupDocs
55
55
  end
56
56
  json = api.execute!
57
57
 
58
- GroupDocs::Job.new(id: json[:job_id])
58
+ Job.new(id: json[:job_id])
59
59
  end
60
60
 
61
61
  # @attr [Integer] id
@@ -71,7 +71,7 @@ module GroupDocs
71
71
  def documents=(documents)
72
72
  @documents = documents.map do |document|
73
73
  document.merge!(file: GroupDocs::Storage::File.new(document))
74
- GroupDocs::Document.new(document)
74
+ Document.new(document)
75
75
  end
76
76
  end
77
77
 
@@ -84,7 +84,7 @@ module GroupDocs
84
84
  # @return [Array<GroupDocs::Document>]
85
85
  #
86
86
  def documents!(access = {})
87
- json = GroupDocs::Api::Request.new do |request|
87
+ json = Api::Request.new do |request|
88
88
  request[:access] = access
89
89
  request[:method] = :GET
90
90
  request[:path] = "/async/{{client_id}}/jobs/#{id}/documents"
@@ -92,7 +92,7 @@ module GroupDocs
92
92
 
93
93
  json[:documents].map do |document|
94
94
  document.merge!(file: GroupDocs::Storage::File.new(document))
95
- GroupDocs::Document.new(document)
95
+ Document.new(document)
96
96
  end
97
97
  end
98
98
 
@@ -113,7 +113,7 @@ module GroupDocs
113
113
  document.is_a?(GroupDocs::Document) or raise ArgumentError,
114
114
  "Document should be GroupDocs::Document object. Received: #{document.inspect}"
115
115
 
116
- api = GroupDocs::Api::Request.new do |request|
116
+ api = Api::Request.new do |request|
117
117
  request[:access] = access
118
118
  request[:method] = :PUT
119
119
  request[:path] = "/async/{{client_id}}/jobs/#{id}/files/#{document.file.guid}"
@@ -144,7 +144,7 @@ module GroupDocs
144
144
  datasource.is_a?(GroupDocs::DataSource) or raise ArgumentError,
145
145
  "Datasource should be GroupDocs::DataSource object. Received: #{datasource.inspect}"
146
146
 
147
- GroupDocs::Api::Request.new do |request|
147
+ Api::Request.new do |request|
148
148
  request[:access] = access
149
149
  request[:method] = :PUT
150
150
  request[:path] = "/async/{{client_id}}/jobs/#{id}/files/#{document.file.guid}/datasources/#{datasource.id}"
@@ -165,7 +165,7 @@ module GroupDocs
165
165
  def add_url!(url, options = {}, access = {})
166
166
  options.merge!(absolute_url: url)
167
167
 
168
- api = GroupDocs::Api::Request.new do |request|
168
+ api = Api::Request.new do |request|
169
169
  request[:access] = access
170
170
  request[:method] = :PUT
171
171
  request[:path] = "/async/{{client_id}}/jobs/#{id}/urls"
@@ -189,7 +189,7 @@ module GroupDocs
189
189
  def update!(options, access = {})
190
190
  options[:status] = parse_status(options[:status]) if options[:status]
191
191
 
192
- GroupDocs::Api::Request.new do |request|
192
+ Api::Request.new do |request|
193
193
  request[:access] = access
194
194
  request[:method] = :PUT
195
195
  request[:path] = "/async/{{client_id}}/jobs/#{id}"
@@ -5,7 +5,7 @@ module GroupDocs
5
5
  require 'groupdocs/questionnaire/page'
6
6
  require 'groupdocs/questionnaire/question'
7
7
 
8
- include GroupDocs::Api::Helpers::Access
8
+ include Api::Helpers::AccessMode
9
9
 
10
10
  #
11
11
  # Returns an array of all questionnaires.
@@ -16,14 +16,14 @@ module GroupDocs
16
16
  # @return [Array<GroupDocs::Questionnaire>]
17
17
  #
18
18
  def self.all!(access = {})
19
- json = GroupDocs::Api::Request.new do |request|
19
+ json = Api::Request.new do |request|
20
20
  request[:access] = access
21
21
  request[:method] = :GET
22
22
  request[:path] = '/merge/{{client_id}}/questionnaires'
23
23
  end.execute!
24
24
 
25
25
  json[:questionnaires].map do |questionnaire|
26
- GroupDocs::Questionnaire.new(questionnaire)
26
+ Questionnaire.new(questionnaire)
27
27
  end
28
28
  end
29
29
 
@@ -37,13 +37,13 @@ module GroupDocs
37
37
  # @return [GroupDocs::Questionnaire, nil]
38
38
  #
39
39
  def self.get!(id, access = {})
40
- json = GroupDocs::Api::Request.new do |request|
40
+ json = Api::Request.new do |request|
41
41
  request[:access] = access
42
42
  request[:method] = :GET
43
43
  request[:path] = "/merge/{{client_id}}/questionnaires/#{id}"
44
44
  end.execute!
45
45
 
46
- GroupDocs::Questionnaire.new(json[:questionnaire])
46
+ Questionnaire.new(json[:questionnaire])
47
47
  rescue RestClient::BadRequest
48
48
  nil
49
49
  end
@@ -57,14 +57,14 @@ module GroupDocs
57
57
  # @return [Array<GroupDocs::Questionnaire::Execution>]
58
58
  #
59
59
  def self.executions!(access = {})
60
- json = GroupDocs::Api::Request.new do |request|
60
+ json = Api::Request.new do |request|
61
61
  request[:access] = access
62
62
  request[:method] = :GET
63
63
  request[:path] = '/merge/{{client_id}}/questionnaires/executions'
64
64
  end.execute!
65
65
 
66
66
  json[:executions].map do |execution|
67
- GroupDocs::Questionnaire::Execution.new(execution)
67
+ Questionnaire::Execution.new(execution)
68
68
  end
69
69
  end
70
70
 
@@ -92,7 +92,7 @@ module GroupDocs
92
92
  if page.is_a?(GroupDocs::Questionnaire::Page)
93
93
  page
94
94
  else
95
- GroupDocs::Questionnaire::Page.new(page)
95
+ Questionnaire::Page.new(page)
96
96
  end
97
97
  end
98
98
  end
@@ -120,7 +120,7 @@ module GroupDocs
120
120
  # @option access [String] :private_key
121
121
  #
122
122
  def create!(access = {})
123
- json = GroupDocs::Api::Request.new do |request|
123
+ json = Api::Request.new do |request|
124
124
  request[:access] = access
125
125
  request[:method] = :POST
126
126
  request[:path] = '/merge/{{client_id}}/questionnaires'
@@ -138,7 +138,7 @@ module GroupDocs
138
138
  # @option access [String] :private_key
139
139
  #
140
140
  def update!(access = {})
141
- GroupDocs::Api::Request.new do |request|
141
+ Api::Request.new do |request|
142
142
  request[:access] = access
143
143
  request[:method] = :PUT
144
144
  request[:path] = "/merge/{{client_id}}/questionnaires/#{id}"
@@ -154,7 +154,7 @@ module GroupDocs
154
154
  # @option access [String] :private_key
155
155
  #
156
156
  def remove!(access = {})
157
- GroupDocs::Api::Request.new do |request|
157
+ Api::Request.new do |request|
158
158
  request[:access] = access
159
159
  request[:method] = :DELETE
160
160
  request[:path] = "/merge/{{client_id}}/questionnaires/#{id}"
@@ -173,14 +173,14 @@ module GroupDocs
173
173
  # @return [Array<GroupDocs::DataSource>]
174
174
  #
175
175
  def datasources!(access = {})
176
- json = GroupDocs::Api::Request.new do |request|
176
+ json = Api::Request.new do |request|
177
177
  request[:access] = access
178
178
  request[:method] = :GET
179
179
  request[:path] = "/merge/{{client_id}}/questionnaires/#{id}/datasources"
180
180
  end.execute!
181
181
 
182
182
  json[:datasources].map do |datasource|
183
- GroupDocs::DataSource.new(datasource)
183
+ DataSource.new(datasource)
184
184
  end
185
185
  end
186
186
 
@@ -204,7 +204,7 @@ module GroupDocs
204
204
  execution.is_a?(GroupDocs::Questionnaire::Execution) or raise ArgumentError,
205
205
  "Execution should be GroupDocs::Questionnaire::Execution object, received: #{execution.inspect}"
206
206
 
207
- json = GroupDocs::Api::Request.new do |request|
207
+ json = Api::Request.new do |request|
208
208
  request[:access] = access
209
209
  request[:method] = :POST
210
210
  request[:path] = "/merge/{{client_id}}/questionnaires/#{id}/executions"
@@ -19,7 +19,7 @@ module GroupDocs
19
19
  # @return [Array<GroupDocs::Questionnaire::Execution>]
20
20
  #
21
21
  def self.all!(access = {})
22
- GroupDocs::Questionnaire.executions!(access)
22
+ Questionnaire.executions!(access)
23
23
  end
24
24
 
25
25
  # @attr [Integer] id
@@ -90,7 +90,7 @@ module GroupDocs
90
90
  # @option access [String] :private_key
91
91
  #
92
92
  def set_status!(status, access = {})
93
- GroupDocs::Api::Request.new do |request|
93
+ Api::Request.new do |request|
94
94
  request[:access] = access
95
95
  request[:method] = :PUT
96
96
  request[:path] = "/merge/{{client_id}}/questionnaires/executions/#{id}/status"
@@ -108,7 +108,7 @@ module GroupDocs
108
108
  # @option access [String] :private_key
109
109
  #
110
110
  def update!(access = {})
111
- GroupDocs::Api::Request.new do |request|
111
+ Api::Request.new do |request|
112
112
  request[:access] = access
113
113
  request[:method] = :PUT
114
114
  request[:path] = "/merge/{{client_id}}/questionnaires/executions/#{id}"
@@ -19,7 +19,7 @@ module GroupDocs
19
19
  if question.is_a?(GroupDocs::Questionnaire::Question)
20
20
  question
21
21
  else
22
- GroupDocs::Questionnaire::Question.new(question)
22
+ Questionnaire::Question.new(question)
23
23
  end
24
24
  end
25
25
  end
@@ -32,7 +32,7 @@ module GroupDocs
32
32
  if answer.is_a?(GroupDocs::Questionnaire::Question::Answer)
33
33
  answer
34
34
  else
35
- GroupDocs::Questionnaire::Question::Answer.new(answer)
35
+ Questionnaire::Question::Answer.new(answer)
36
36
  end
37
37
  end
38
38
  end
@@ -19,7 +19,7 @@ module GroupDocs
19
19
  # @return [Hash]
20
20
  #
21
21
  def self.info!(access = {})
22
- json = GroupDocs::Api::Request.new do |request|
22
+ json = Api::Request.new do |request|
23
23
  request[:access] = access
24
24
  request[:method] = :GET
25
25
  request[:path] = '/storage/{{client_id}}'
@@ -2,7 +2,8 @@ module GroupDocs
2
2
  module Storage
3
3
  class File < GroupDocs::Api::Entity
4
4
 
5
- extend GroupDocs::Api::Sugar::Lookup
5
+ extend Extensions::Lookup
6
+ include Api::Helpers::AccessMode
6
7
 
7
8
  DOCUMENT_TYPES = {
8
9
  undefined: -1,
@@ -31,17 +32,17 @@ module GroupDocs
31
32
  # @raise [ArgumentError] If path does not start with /
32
33
  #
33
34
  def self.upload!(filepath, upload_path = '/', access = {})
34
- upload_path.chars.first == '/' or raise ArgumentError, "Path should start with /: #{upload_path.inspect}"
35
- upload_path << "/#{Object::File.basename(filepath)}" unless upload_path =~ /\.(\w){3,4}$/
35
+ Api::Helpers::Path.verify_starts_with_root(upload_path)
36
+ Api::Helpers::Path.append_file_name(upload_path, filepath)
36
37
 
37
- json = GroupDocs::Api::Request.new do |request|
38
+ json = Api::Request.new do |request|
38
39
  request[:access] = access
39
40
  request[:method] = :POST
40
41
  request[:path] = "/storage/{{client_id}}/folders#{upload_path}"
41
42
  request[:request_body] = Object::File.new(filepath, 'rb')
42
43
  end.execute!
43
44
 
44
- GroupDocs::Storage::File.new(json)
45
+ Storage::File.new(json)
45
46
  end
46
47
 
47
48
  #
@@ -132,6 +133,15 @@ module GroupDocs
132
133
  Time.at(@created_on)
133
134
  end
134
135
 
136
+ #
137
+ # Converts access mode to human-readable format.
138
+ #
139
+ # @return [Symbol]
140
+ #
141
+ def access
142
+ parse_access_mode(@access)
143
+ end
144
+
135
145
  #
136
146
  # Converts timestamp which is return by API server to Time object.
137
147
  #
@@ -151,7 +161,7 @@ module GroupDocs
151
161
  # @return [String] Path to downloaded file
152
162
  #
153
163
  def download!(path, access = {})
154
- response = GroupDocs::Api::Request.new do |request|
164
+ response = Api::Request.new do |request|
155
165
  request[:access] = access
156
166
  request[:method] = :DOWNLOAD
157
167
  request[:path] = "/storage/{{client_id}}/files/#{id}"
@@ -175,20 +185,18 @@ module GroupDocs
175
185
  # @option access [String] :private_key
176
186
  # @return [GroupDocs::Storage::File] Moved to file
177
187
  #
178
- # @raise [ArgumentError] If path does not start with /
179
- #
180
188
  def move!(path, access = {})
181
- path.chars.first == '/' or raise ArgumentError, "Path should start with /: #{path.inspect}"
182
- path << "/#{Object::File.basename(name)}" unless path =~ /\.(\w){3,4}$/
189
+ Api::Helpers::Path.verify_starts_with_root(path)
190
+ Api::Helpers::Path.append_file_name(path, name)
183
191
 
184
- json = GroupDocs::Api::Request.new do |request|
192
+ json = Api::Request.new do |request|
185
193
  request[:access] = access
186
194
  request[:method] = :PUT
187
195
  request[:headers] = { :'Groupdocs-Move' => id }
188
196
  request[:path] = "/storage/{{client_id}}/files#{path}"
189
197
  end.execute!
190
198
 
191
- GroupDocs::Storage::File.new(json[:dst_file])
199
+ Storage::File.new(json[:dst_file])
192
200
  end
193
201
 
194
202
  #
@@ -214,20 +222,18 @@ module GroupDocs
214
222
  # @option access [String] :private_key
215
223
  # @return [GroupDocs::Storage::File] Copied to file
216
224
  #
217
- # @raise [ArgumentError] If path does not start with /
218
- #
219
225
  def copy!(path, access = {})
220
- path.chars.first == '/' or raise ArgumentError, "Path should start with /: #{path.inspect}"
221
- path << "/#{Object::File.basename(name)}" unless path =~ /\.(\w){3,4}$/
226
+ Api::Helpers::Path.verify_starts_with_root(path)
227
+ Api::Helpers::Path.append_file_name(path, name)
222
228
 
223
- json = GroupDocs::Api::Request.new do |request|
229
+ json = Api::Request.new do |request|
224
230
  request[:access] = access
225
231
  request[:method] = :PUT
226
232
  request[:headers] = { :'Groupdocs-Copy' => id }
227
233
  request[:path] = "/storage/{{client_id}}/files#{path}"
228
234
  end.execute!
229
235
 
230
- GroupDocs::Storage::File.new(json[:dst_file])
236
+ Storage::File.new(json[:dst_file])
231
237
  end
232
238
 
233
239
  #
@@ -239,7 +245,7 @@ module GroupDocs
239
245
  # @return [GroupDocs::Storage::File] Archive file
240
246
  #
241
247
  def compress!(access = {})
242
- json = GroupDocs::Api::Request.new do |request|
248
+ json = Api::Request.new do |request|
243
249
  request[:access] = access
244
250
  request[:method] = :POST
245
251
  request[:path] = "/storage/{{client_id}}/files/#{id}/archive/zip"
@@ -247,7 +253,7 @@ module GroupDocs
247
253
 
248
254
  # HACK add filename for further file operations
249
255
  json[:name] = "#{name}.zip"
250
- GroupDocs::Storage::File.new(json)
256
+ Storage::File.new(json)
251
257
  end
252
258
 
253
259
  #
@@ -258,14 +264,11 @@ module GroupDocs
258
264
  # @option access [String] :private_key
259
265
  #
260
266
  def delete!(access = {})
261
- GroupDocs::Api::Request.new do |request|
267
+ Api::Request.new do |request|
262
268
  request[:access] = access
263
269
  request[:method] = :DELETE
264
270
  request[:path] = "/storage/{{client_id}}/files/#{guid}"
265
271
  end.execute!
266
- # TODO: workaround for http://scotland.groupdocs.com/jira/browse/CORE-423
267
- rescue RestClient::BadRequest
268
- nil
269
272
  end
270
273
 
271
274
  #
@@ -274,7 +277,7 @@ module GroupDocs
274
277
  # @return [GroupDocs::Document]
275
278
  #
276
279
  def to_document
277
- GroupDocs::Document.new(file: self)
280
+ Document.new(file: self)
278
281
  end
279
282
 
280
283
  end # File