groupdocs 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/groupdocs/document.rb +35 -2
- data/lib/groupdocs/job.rb +2 -2
- data/lib/groupdocs/version.rb +1 -1
- data/spec/groupdocs/document_spec.rb +39 -6
- data/spec/groupdocs/job_spec.rb +6 -2
- data/spec/support/json/job_documents.json +1 -1
- data/spec/support/json/jobs_get.json +38 -32
- metadata +20 -20
data/lib/groupdocs/document.rb
CHANGED
@@ -54,8 +54,32 @@ module GroupDocs
|
|
54
54
|
attr_accessor :file
|
55
55
|
# @attr [Time] process_date
|
56
56
|
attr_accessor :process_date
|
57
|
-
# @attr [Array] outputs
|
57
|
+
# @attr [Array<GroupDocs::Storage::File>] outputs
|
58
58
|
attr_accessor :outputs
|
59
|
+
# @attr [Array<Symbol>] output_formats
|
60
|
+
attr_accessor :output_formats
|
61
|
+
|
62
|
+
#
|
63
|
+
# Coverts passed array of attributes hash to array of GroupDocs::Storage::File.
|
64
|
+
#
|
65
|
+
# @param [Array<Hash>] outputs Array of file attributes hashes
|
66
|
+
#
|
67
|
+
def outputs=(outputs)
|
68
|
+
if outputs
|
69
|
+
@outputs = outputs.map do |output|
|
70
|
+
GroupDocs::Storage::File.new(output)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
#
|
76
|
+
# Returns output formats in human-readable format.
|
77
|
+
#
|
78
|
+
# @return [Array<Symbol>]
|
79
|
+
#
|
80
|
+
def output_formats
|
81
|
+
@output_formats.split(?;).map(&:to_sym)
|
82
|
+
end
|
59
83
|
|
60
84
|
#
|
61
85
|
# Converts timestamp which is return by API server to Time object.
|
@@ -260,6 +284,14 @@ module GroupDocs
|
|
260
284
|
#
|
261
285
|
# Converts document to given format.
|
262
286
|
#
|
287
|
+
# @example
|
288
|
+
# document = GroupDocs::Document.find!(:name, 'CV.doc')
|
289
|
+
# job = document.convert!(:docx)
|
290
|
+
# sleep(5) # wait for server to finish converting
|
291
|
+
# original_document = job.documents!.first
|
292
|
+
# converted_file = original_file.outputs.first
|
293
|
+
# converted_file.download!(File.dirname(__FILE__))
|
294
|
+
#
|
263
295
|
# @param [Symbol] format
|
264
296
|
# @param [Hash] options
|
265
297
|
# @option options [Boolean] :email_results Set to true if converted document should be emailed
|
@@ -274,7 +306,7 @@ module GroupDocs
|
|
274
306
|
api = Api::Request.new do |request|
|
275
307
|
request[:access] = access
|
276
308
|
request[:method] = :POST
|
277
|
-
request[:path] = "/{{client_id}}/files/#{file.guid}"
|
309
|
+
request[:path] = "/async/{{client_id}}/files/#{file.guid}"
|
278
310
|
end
|
279
311
|
api.add_params(options)
|
280
312
|
json = api.execute!
|
@@ -474,6 +506,7 @@ module GroupDocs
|
|
474
506
|
# document_one = GroupDocs::Document.find!(:name, 'CV.doc')
|
475
507
|
# document_two = GroupDocs::Document.find!(:name, 'Resume.doc')
|
476
508
|
# job = document_one.compare!(document_two)
|
509
|
+
# sleep(5) # wait for server to finish comparing
|
477
510
|
# result = job.documents!.first
|
478
511
|
# result.changes!
|
479
512
|
#
|
data/lib/groupdocs/job.rb
CHANGED
@@ -81,7 +81,7 @@ module GroupDocs
|
|
81
81
|
#
|
82
82
|
def documents=(documents)
|
83
83
|
if documents
|
84
|
-
@documents = documents.map do |document|
|
84
|
+
@documents = documents[:inputs].map do |document|
|
85
85
|
document.merge!(file: GroupDocs::Storage::File.new(document))
|
86
86
|
Document.new(document)
|
87
87
|
end
|
@@ -121,7 +121,7 @@ module GroupDocs
|
|
121
121
|
request[:path] = "/async/{{client_id}}/jobs/#{id}/documents"
|
122
122
|
end.execute!
|
123
123
|
|
124
|
-
json[:
|
124
|
+
json[:inputs].map do |document|
|
125
125
|
document.merge!(file: GroupDocs::Storage::File.new(document))
|
126
126
|
Document.new(document)
|
127
127
|
end
|
data/lib/groupdocs/version.rb
CHANGED
@@ -53,18 +53,51 @@ describe GroupDocs::Document do
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
it { should respond_to(:file)
|
57
|
-
it { should respond_to(:file=)
|
58
|
-
it { should respond_to(:process_date)
|
59
|
-
it { should respond_to(:process_date=)
|
60
|
-
it { should respond_to(:outputs)
|
61
|
-
it { should respond_to(:outputs=)
|
56
|
+
it { should respond_to(:file) }
|
57
|
+
it { should respond_to(:file=) }
|
58
|
+
it { should respond_to(:process_date) }
|
59
|
+
it { should respond_to(:process_date=) }
|
60
|
+
it { should respond_to(:outputs) }
|
61
|
+
it { should respond_to(:outputs=) }
|
62
|
+
it { should respond_to(:output_formats) }
|
63
|
+
it { should respond_to(:output_formats=) }
|
62
64
|
|
63
65
|
it 'is compatible with response JSON' do
|
64
66
|
subject.should respond_to(:proc_date=)
|
65
67
|
subject.method(:proc_date=).should == subject.method(:process_date=)
|
66
68
|
end
|
67
69
|
|
70
|
+
describe '#outputs=' do
|
71
|
+
let(:response) do
|
72
|
+
[
|
73
|
+
{ ftype: 1, guid: 'fhy9yh94u238dgf' },
|
74
|
+
{ ftype: 2, guid: 'ofh9rhy9rfohf9s' }
|
75
|
+
]
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'saves outputs as array of GroupDocs::Storage::File objects' do
|
79
|
+
subject.outputs = response
|
80
|
+
outputs = subject.outputs
|
81
|
+
outputs.should be_an(Array)
|
82
|
+
outputs.each do |output|
|
83
|
+
output.should be_a(GroupDocs::Storage::File)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'does nothing if nil is passed' do
|
88
|
+
lambda do
|
89
|
+
subject.outputs = nil
|
90
|
+
end.should_not change(subject, :outputs)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '#output_formats' do
|
95
|
+
it 'returns parsed array of output formats' do
|
96
|
+
subject.output_formats = "pdf;tiff;doc"
|
97
|
+
subject.output_formats.should == [:pdf, :tiff, :doc]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
68
101
|
describe '#process_date' do
|
69
102
|
it 'returns converted to Time object Unix timestamp' do
|
70
103
|
subject.process_date = 1330450135000
|
data/spec/groupdocs/job_spec.rb
CHANGED
@@ -81,8 +81,12 @@ describe GroupDocs::Job do
|
|
81
81
|
|
82
82
|
describe '#documents=' do
|
83
83
|
let(:response) do
|
84
|
-
|
85
|
-
|
84
|
+
{
|
85
|
+
inputs: [
|
86
|
+
{ id: 1, guid: 'fhy9yh94u238dgf', status: 0, outputs: [] },
|
87
|
+
{ id: 2, guid: 'ofh9rhy9rfohf9s', status: 2, outputs: [] }
|
88
|
+
]
|
89
|
+
}
|
86
90
|
end
|
87
91
|
|
88
92
|
it 'saves documents as array of GroupDocs::Document objects' do
|
@@ -7,43 +7,49 @@
|
|
7
7
|
"id": 1,
|
8
8
|
"status": 5,
|
9
9
|
"documents":
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
10
|
+
{
|
11
|
+
"inputs":
|
12
|
+
[
|
13
|
+
{
|
14
|
+
"status": 2,
|
15
|
+
"output_formats": "pdf",
|
16
|
+
"outputs":
|
17
|
+
[
|
18
|
+
{
|
19
|
+
"ftype": 19,
|
20
|
+
"error": null,
|
21
|
+
"url": "http://groupdocs.com",
|
22
|
+
"name": "Test.pdf"
|
23
|
+
}
|
24
|
+
],
|
25
|
+
"id": 123
|
26
|
+
}
|
27
|
+
]
|
28
|
+
}
|
26
29
|
},
|
27
30
|
{
|
28
31
|
"id": 2,
|
29
32
|
"status": 3,
|
30
33
|
"documents":
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
34
|
+
{
|
35
|
+
"inputs":
|
36
|
+
[
|
37
|
+
{
|
38
|
+
"status": 1,
|
39
|
+
"output_formats": "tiff",
|
40
|
+
"outputs":
|
41
|
+
[
|
42
|
+
{
|
43
|
+
"ftype": 15,
|
44
|
+
"error": null,
|
45
|
+
"url": "http://groupdocs.com",
|
46
|
+
"name": "CV.doc"
|
47
|
+
}
|
48
|
+
],
|
49
|
+
"id": 345
|
50
|
+
}
|
51
|
+
]
|
52
|
+
}
|
47
53
|
}
|
48
54
|
]
|
49
55
|
},
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: groupdocs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
16
|
-
requirement: &
|
16
|
+
requirement: &9630200 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '1.6'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *9630200
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: json
|
27
|
-
requirement: &
|
27
|
+
requirement: &9645180 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '1.7'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *9645180
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: ruby-hmac
|
38
|
-
requirement: &
|
38
|
+
requirement: &9643420 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0.4'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *9643420
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &9641900 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '2.9'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *9641900
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rake
|
60
|
-
requirement: &
|
60
|
+
requirement: &9640720 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0.9'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *9640720
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: simplecov
|
71
|
-
requirement: &
|
71
|
+
requirement: &9639740 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0.6'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *9639740
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: yard
|
82
|
-
requirement: &
|
82
|
+
requirement: &9638260 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0.8'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *9638260
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: webmock
|
93
|
-
requirement: &
|
93
|
+
requirement: &9650900 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
version: '1.8'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *9650900
|
102
102
|
description: Ruby SDK for GroupDocs REST API
|
103
103
|
email: p0deje@gmail.com
|
104
104
|
executables: []
|
@@ -253,7 +253,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
253
253
|
version: '0'
|
254
254
|
segments:
|
255
255
|
- 0
|
256
|
-
hash: -
|
256
|
+
hash: -785849018155975745
|
257
257
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
258
258
|
none: false
|
259
259
|
requirements:
|
@@ -262,7 +262,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
262
262
|
version: '0'
|
263
263
|
segments:
|
264
264
|
- 0
|
265
|
-
hash: -
|
265
|
+
hash: -785849018155975745
|
266
266
|
requirements: []
|
267
267
|
rubyforge_project:
|
268
268
|
rubygems_version: 1.8.10
|