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
@@ -0,0 +1,314 @@
|
|
1
|
+
module GroupDocs
|
2
|
+
module Storage
|
3
|
+
class Folder < GroupDocs::Api::Entity
|
4
|
+
|
5
|
+
extend GroupDocs::Api::Sugar::Lookup
|
6
|
+
include GroupDocs::Api::Helpers::Access
|
7
|
+
|
8
|
+
#
|
9
|
+
# Creates folder on server.
|
10
|
+
#
|
11
|
+
# @param [String] path Path of folder to create starting with "/"
|
12
|
+
# @param [Hash] access Access credentials
|
13
|
+
# @option access [String] :client_id
|
14
|
+
# @option access [String] :private_key
|
15
|
+
# @return [GroupDocs::Storage::Folder] Created folder
|
16
|
+
#
|
17
|
+
# @raise [ArgumentError] If path does not start with /
|
18
|
+
#
|
19
|
+
def self.create!(path, access = {})
|
20
|
+
path.chars.first == '/' or raise ArgumentError, "Path should start with /: #{path.inspect}"
|
21
|
+
|
22
|
+
json = GroupDocs::Api::Request.new do |request|
|
23
|
+
request[:access] = access
|
24
|
+
request[:method] = :POST
|
25
|
+
request[:path] = "/storage/{{client_id}}/paths#{path}"
|
26
|
+
end.execute!
|
27
|
+
|
28
|
+
GroupDocs::Storage::Folder.new(json)
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Returns an array of all folders on server starting with given path.
|
33
|
+
#
|
34
|
+
# @param [String] path Starting path to look for folders
|
35
|
+
# @param [Hash] access Access credentials
|
36
|
+
# @option access [String] :client_id
|
37
|
+
# @option access [String] :private_key
|
38
|
+
# @return [Array<GroupDocs::Storage::Folder>]
|
39
|
+
#
|
40
|
+
def self.all!(path = '/', access = {})
|
41
|
+
folders = Array.new
|
42
|
+
folder = GroupDocs::Storage::Folder.new(path: path)
|
43
|
+
folder.list!({}, access).each do |entity|
|
44
|
+
if entity.is_a?(GroupDocs::Storage::Folder)
|
45
|
+
folders << entity
|
46
|
+
folders += all!("#{path}/#{entity.name}".gsub(/[\/]{2}/, '/'), access)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
folders
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# Returns a list of all directories and files in the path.
|
55
|
+
#
|
56
|
+
# @param [String] path Path of directory to list starting from root ('/')
|
57
|
+
# @param [Hash] options Hash of options
|
58
|
+
# @option options [Integer] :page Page to start with
|
59
|
+
# @option options [Integer] :count How many items to list
|
60
|
+
# @option options [String] :order_by Field name to sort by
|
61
|
+
# @option options [Boolean] :order_asc Set to true to return in ascending order
|
62
|
+
# @param [Hash] access Access credentials
|
63
|
+
# @option access [String] :client_id
|
64
|
+
# @option access [String] :private_key
|
65
|
+
# @return [Array<GroupDocs::Storage::Folder, GroupDocs::Storage::File>]
|
66
|
+
#
|
67
|
+
# @raise [ArgumentError] If path does not start with /
|
68
|
+
#
|
69
|
+
def self.list!(path = '/', options = {}, access = {})
|
70
|
+
path.chars.first == '/' or raise ArgumentError, "Path should start with /: #{path.inspect}"
|
71
|
+
new(path: path).list!(options, access)
|
72
|
+
end
|
73
|
+
|
74
|
+
# @attr [Integer] id
|
75
|
+
attr_accessor :id
|
76
|
+
# @attr [Integer] size
|
77
|
+
attr_accessor :size
|
78
|
+
# @attr [Integer] folder_count
|
79
|
+
attr_accessor :folder_count
|
80
|
+
# @attr [Integer] file_count
|
81
|
+
attr_accessor :file_count
|
82
|
+
# @attr [Time] created_on
|
83
|
+
attr_accessor :created_on
|
84
|
+
# @attr [Time] modified_on
|
85
|
+
attr_accessor :modified_on
|
86
|
+
# @attr [String] url
|
87
|
+
attr_accessor :url
|
88
|
+
# @attr [String] name
|
89
|
+
attr_accessor :name
|
90
|
+
# @attr [String] path
|
91
|
+
attr_accessor :path
|
92
|
+
# @attr [Integer] version
|
93
|
+
attr_accessor :version
|
94
|
+
# @attr [Integer] type
|
95
|
+
attr_accessor :type
|
96
|
+
# @attr [Integer] access
|
97
|
+
attr_accessor :access
|
98
|
+
|
99
|
+
#
|
100
|
+
# Converts timestamp which is return by API server to Time object.
|
101
|
+
#
|
102
|
+
# @return [Time]
|
103
|
+
#
|
104
|
+
def created_on
|
105
|
+
Time.at(@created_on)
|
106
|
+
end
|
107
|
+
|
108
|
+
#
|
109
|
+
# Converts timestamp which is return by API server to Time object.
|
110
|
+
#
|
111
|
+
# @return [Time]
|
112
|
+
#
|
113
|
+
def modified_on
|
114
|
+
Time.at(@modified_on)
|
115
|
+
end
|
116
|
+
|
117
|
+
#
|
118
|
+
# Converts access mode to human-readable format.
|
119
|
+
#
|
120
|
+
# @return [Symbol]
|
121
|
+
#
|
122
|
+
def access
|
123
|
+
parse_access_mode(@access)
|
124
|
+
end
|
125
|
+
|
126
|
+
#
|
127
|
+
# Moves folder contents to given path.
|
128
|
+
#
|
129
|
+
# @param [String] path Destination to move contents to
|
130
|
+
# @param [Hash] access Access credentials
|
131
|
+
# @option access [String] :client_id
|
132
|
+
# @option access [String] :private_key
|
133
|
+
# @return [String] Moved to folder path
|
134
|
+
#
|
135
|
+
# @raise [ArgumentError] If path does not start with /
|
136
|
+
#
|
137
|
+
def move!(path, access = {})
|
138
|
+
path.chars.first == '/' or raise ArgumentError, "Path should start with /: #{path.inspect}"
|
139
|
+
|
140
|
+
GroupDocs::Api::Request.new do |request|
|
141
|
+
request[:access] = access
|
142
|
+
request[:method] = :PUT
|
143
|
+
request[:headers] = { :'Groupdocs-Move' => name }
|
144
|
+
request[:path] = "/storage/{{client_id}}/folders#{path}"
|
145
|
+
end.execute!
|
146
|
+
|
147
|
+
path
|
148
|
+
end
|
149
|
+
|
150
|
+
#
|
151
|
+
# Renames folder to new one.
|
152
|
+
#
|
153
|
+
# @param [String] name New name
|
154
|
+
# @param [Hash] access Access credentials
|
155
|
+
# @option access [String] :client_id
|
156
|
+
# @option access [String] :private_key
|
157
|
+
# @return [String] New name
|
158
|
+
#
|
159
|
+
def rename!(name, access = {})
|
160
|
+
move!("/#{name}", access).sub(/^\//, '')
|
161
|
+
end
|
162
|
+
|
163
|
+
#
|
164
|
+
# Copies folder contents to a destination path.
|
165
|
+
#
|
166
|
+
# @param [String] path Path of directory to copy to starting from root ('/')
|
167
|
+
# @param [Hash] access Access credentials
|
168
|
+
# @option access [String] :client_id
|
169
|
+
# @option access [String] :private_key
|
170
|
+
# @return [String] Copied to folder path
|
171
|
+
#
|
172
|
+
# @raise [ArgumentError] If path does not start with /
|
173
|
+
#
|
174
|
+
def copy!(path, access = {})
|
175
|
+
path.chars.first == '/' or raise ArgumentError, "Path should start with /: #{path.inspect}"
|
176
|
+
|
177
|
+
GroupDocs::Api::Request.new do |request|
|
178
|
+
request[:access] = access
|
179
|
+
request[:method] = :PUT
|
180
|
+
request[:headers] = { :'Groupdocs-Copy' => name }
|
181
|
+
request[:path] = "/storage/{{client_id}}/folders#{path}"
|
182
|
+
end.execute!
|
183
|
+
|
184
|
+
path
|
185
|
+
end
|
186
|
+
|
187
|
+
#
|
188
|
+
# Returns an array of files and folders.
|
189
|
+
#
|
190
|
+
# @param [Hash] options Hash of options
|
191
|
+
# @option options [Integer] :page Page to start with
|
192
|
+
# @option options [Integer] :count How many items to list
|
193
|
+
# @option options [String] :order_by Field name to sort by
|
194
|
+
# @option options [Boolean] :order_asc Set to true to return in ascending order
|
195
|
+
# @param [Hash] access Access credentials
|
196
|
+
# @option access [String] :client_id
|
197
|
+
# @option access [String] :private_key
|
198
|
+
# @return [Array<GroupDocs::Storage::Folder, GroupDocs::Storage::File>]
|
199
|
+
#
|
200
|
+
def list!(options = {}, access = {})
|
201
|
+
query_path = "#{path}/#{name}"
|
202
|
+
query_path.gsub!(/[\/]{2}/, '/')
|
203
|
+
|
204
|
+
api = GroupDocs::Api::Request.new do |request|
|
205
|
+
request[:access] = access
|
206
|
+
request[:method] = :GET
|
207
|
+
request[:path] = "/storage/{{client_id}}/folders#{query_path}"
|
208
|
+
end
|
209
|
+
api.add_params(options)
|
210
|
+
json = api.execute!
|
211
|
+
|
212
|
+
json[:entities].map do |entity|
|
213
|
+
entity.merge!(path: path)
|
214
|
+
if entity[:dir]
|
215
|
+
GroupDocs::Storage::Folder.new(entity)
|
216
|
+
else
|
217
|
+
GroupDocs::Storage::File.new(entity)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
#
|
223
|
+
# Creates folder on server.
|
224
|
+
#
|
225
|
+
# @param [Hash] access Access credentials
|
226
|
+
# @option access [String] :client_id
|
227
|
+
# @option access [String] :private_key
|
228
|
+
#
|
229
|
+
def create!(access = {})
|
230
|
+
self.class.create!("/#{name}", access)
|
231
|
+
end
|
232
|
+
|
233
|
+
#
|
234
|
+
# Deletes folder from server.
|
235
|
+
#
|
236
|
+
# @param [Hash] access Access credentials
|
237
|
+
# @option access [String] :client_id
|
238
|
+
# @option access [String] :private_key
|
239
|
+
#
|
240
|
+
def delete!(access = {})
|
241
|
+
GroupDocs::Api::Request.new do |request|
|
242
|
+
request[:access] = access
|
243
|
+
request[:method] = :DELETE
|
244
|
+
request[:path] = "/storage/{{client_id}}/folders/#{name}"
|
245
|
+
end.execute!
|
246
|
+
end
|
247
|
+
|
248
|
+
#
|
249
|
+
# Returns an array of users a folder is shared with.
|
250
|
+
#
|
251
|
+
# @param [Hash] access Access credentials
|
252
|
+
# @option access [String] :client_id
|
253
|
+
# @option access [String] :private_key
|
254
|
+
# @return [Array<GroupDocs::User>]
|
255
|
+
#
|
256
|
+
def sharers!(access = {})
|
257
|
+
json = GroupDocs::Api::Request.new do |request|
|
258
|
+
request[:access] = access
|
259
|
+
request[:method] = :GET
|
260
|
+
request[:path] = "/doc/{{client_id}}/folders/#{id}/sharers"
|
261
|
+
end.execute!
|
262
|
+
|
263
|
+
json[:shared_users].map do |user|
|
264
|
+
GroupDocs::User.new(user)
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
#
|
269
|
+
# Sets folder sharers to given emails.
|
270
|
+
#
|
271
|
+
# If empty array or nil passed, clears sharers.
|
272
|
+
#
|
273
|
+
# @param [Array] emails List of email addresses to share with
|
274
|
+
# @param [Hash] access Access credentials
|
275
|
+
# @option access [String] :client_id
|
276
|
+
# @option access [String] :private_key
|
277
|
+
# @return [Array<GroupDocs::User>]
|
278
|
+
#
|
279
|
+
def sharers_set!(emails, access = {})
|
280
|
+
if emails.nil? || emails.empty?
|
281
|
+
sharers_clear!(access)
|
282
|
+
else
|
283
|
+
json = GroupDocs::Api::Request.new do |request|
|
284
|
+
request[:access] = access
|
285
|
+
request[:method] = :PUT
|
286
|
+
request[:path] = "/doc/{{client_id}}/folders/#{id}/sharers"
|
287
|
+
request[:request_body] = emails
|
288
|
+
end.execute!
|
289
|
+
|
290
|
+
json[:shared_users].map do |user|
|
291
|
+
GroupDocs::User.new(user)
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
#
|
297
|
+
# Clears sharers list.
|
298
|
+
#
|
299
|
+
# @param [Hash] access Access credentials
|
300
|
+
# @option access [String] :client_id
|
301
|
+
# @option access [String] :private_key
|
302
|
+
# @return nil
|
303
|
+
#
|
304
|
+
def sharers_clear!(access = {})
|
305
|
+
GroupDocs::Api::Request.new do |request|
|
306
|
+
request[:access] = access
|
307
|
+
request[:method] = :DELETE
|
308
|
+
request[:path] = "/doc/{{client_id}}/folders/#{id}/sharers"
|
309
|
+
end.execute![:shared_users]
|
310
|
+
end
|
311
|
+
|
312
|
+
end # Folder
|
313
|
+
end # Storage
|
314
|
+
end # GroupDocs
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module GroupDocs
|
2
|
+
module Storage
|
3
|
+
class Package < GroupDocs::Api::Entity
|
4
|
+
|
5
|
+
# @attr [String] name Package name
|
6
|
+
attr_accessor :name
|
7
|
+
# @attr [Array] objects Storage entities to be packed
|
8
|
+
attr_accessor :objects
|
9
|
+
|
10
|
+
#
|
11
|
+
# Appends object to be packed.
|
12
|
+
#
|
13
|
+
# @param [GroupDocs::Storage::File, GroupDocs::Storage::Folder] object
|
14
|
+
#
|
15
|
+
def add(object)
|
16
|
+
@objects ||= Array.new
|
17
|
+
@objects << object
|
18
|
+
end
|
19
|
+
alias_method :<<, :add
|
20
|
+
|
21
|
+
#
|
22
|
+
# Creates package on server.
|
23
|
+
#
|
24
|
+
# @param [Hash] access Access credentials
|
25
|
+
# @option access [String] :client_id
|
26
|
+
# @option access [String] :private_key
|
27
|
+
# @return [String] URL of package for downloading
|
28
|
+
#
|
29
|
+
def create!(access = {})
|
30
|
+
json = GroupDocs::Api::Request.new do |request|
|
31
|
+
request[:access] = access
|
32
|
+
request[:method] = :POST
|
33
|
+
request[:path] = "/storage/{{client_id}}/packages/#{name}.zip"
|
34
|
+
request[:request_body] = @objects.map(&:name)
|
35
|
+
end.execute!
|
36
|
+
|
37
|
+
json[:url]
|
38
|
+
end
|
39
|
+
|
40
|
+
end # Package
|
41
|
+
end # Storage
|
42
|
+
end # GroupDocs
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module GroupDocs
|
2
|
+
class User < GroupDocs::Api::Entity
|
3
|
+
|
4
|
+
# @attr [Integer] id
|
5
|
+
attr_accessor :id
|
6
|
+
# @attr [String] guid
|
7
|
+
attr_accessor :guid
|
8
|
+
# @attr [String] nickname
|
9
|
+
attr_accessor :nickname
|
10
|
+
# @attr [String] first_name
|
11
|
+
attr_accessor :first_name
|
12
|
+
# @attr [String] last_name
|
13
|
+
attr_accessor :last_name
|
14
|
+
# @attr [String] primary_email
|
15
|
+
attr_accessor :primary_email
|
16
|
+
# @attr [String] private_key
|
17
|
+
attr_accessor :private_key
|
18
|
+
# @attr [String] password_salt
|
19
|
+
attr_accessor :password_salt
|
20
|
+
# @attr [Integer] claimed_id
|
21
|
+
attr_accessor :claimed_id
|
22
|
+
# @attr [String] token
|
23
|
+
attr_accessor :token
|
24
|
+
# @attr [String] storage
|
25
|
+
attr_accessor :storage
|
26
|
+
# @attr [String] photo
|
27
|
+
attr_accessor :photo
|
28
|
+
# @attr [Boolean] active
|
29
|
+
attr_accessor :active
|
30
|
+
# @attr [Boolean] news_enabled
|
31
|
+
attr_accessor :news_enabled
|
32
|
+
# @attr [Time] signed_up_on
|
33
|
+
attr_accessor :signed_up_on
|
34
|
+
|
35
|
+
#
|
36
|
+
# Converts timestamp which is return by API server to Time object.
|
37
|
+
#
|
38
|
+
# @return [Time]
|
39
|
+
#
|
40
|
+
def signed_up_on
|
41
|
+
Time.at(@signed_up_on)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Compatibility with response JSON
|
45
|
+
alias_method :pkey=, :private_key=
|
46
|
+
alias_method :pswd_salt=, :password_salt=
|
47
|
+
alias_method :signedupOn=, :signed_up_on=
|
48
|
+
|
49
|
+
end # User
|
50
|
+
end # GroupDocs
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GroupDocs::Api::Entity do
|
4
|
+
before(:each) do
|
5
|
+
# make sure necessary attribute exist
|
6
|
+
described_class.class_eval('attr_accessor :id, :test')
|
7
|
+
subject.id = 1
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#to_hash' do
|
11
|
+
it 'converts object attributes to hash' do
|
12
|
+
subject.test = 'Test'
|
13
|
+
subject.to_hash.should == { id: 1, test: 'Test' }
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'converts attribute to hash if it is object' do
|
17
|
+
object = described_class.new(id: 1)
|
18
|
+
object.should_receive(:to_hash).and_return({ id: 1 })
|
19
|
+
subject.test = object
|
20
|
+
subject.to_hash.should == { id: 1, test: { id: 1 } }
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'converts attribute to hash if it is array' do
|
24
|
+
object1 = described_class.new(id: 1)
|
25
|
+
object2 = described_class.new(id: 2)
|
26
|
+
object1.should_receive(:to_hash).and_return({ id: 1 })
|
27
|
+
object2.should_receive(:to_hash).and_return({ id: 2 })
|
28
|
+
subject.test = [object1, object2]
|
29
|
+
subject.to_hash.should == { id: 1, test: [{ id: 1 }, { id: 2 }] }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#inspect' do
|
34
|
+
it 'uses accessors instead of instance variables' do
|
35
|
+
subject.instance_variable_set(:@test1, 1)
|
36
|
+
subject.instance_variable_set(:@test2, 1)
|
37
|
+
subject.instance_eval('def test1; { fire: 1 }.invert[@test1] end')
|
38
|
+
subject.instance_eval('def test2; { 1 => "fire" }[@test2] end')
|
39
|
+
subject.inspect.should include('@test1=:fire')
|
40
|
+
subject.inspect.should include('@test2="fire"')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'uses only not-nil instance variables' do
|
44
|
+
subject.instance_variable_set(:@test, nil)
|
45
|
+
subject.inspect.should_not include('@test')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#variable_to_accessor' do
|
50
|
+
it 'converts instance variable symbol to accessor method symbol' do
|
51
|
+
subject.send(:variable_to_accessor, :@test).should == :test
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|