Class: GroupDocs::Job

Inherits:
Api::Entity show all
Extended by:
Api::Helpers::ByteFlag
Includes:
Api::Helpers::Status
Defined in:
lib/groupdocs/job.rb

Constant Summary collapse

ACTIONS =
{
  :none               =>   0,
  :convert            =>   1,
  :combine            =>   2,
  :compress_zip       =>   4,
  :compress_rar       =>   8,
  :trace              =>  16,
  :convert_body       =>  32,
  :bind_data          =>  64,
  :print              => 128,
  :compare            => 256,
  :import_annotations => 512,
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Api::Helpers::ByteFlag

array_from_byte, byte_from_array

Methods inherited from Api::Entity

#initialize, #inspect, #to_hash

Methods included from Api::Helpers::Accessor

#alias_accessor

Constructor Details

This class inherits a constructor from GroupDocs::Api::Entity

Instance Attribute Details

#actionsArray<Symbol>

Returns job actions in human-readable format.

Returns:

  • (Array<Symbol>)


152
153
154
# File 'lib/groupdocs/job.rb', line 152

def actions
  @actions
end

#documentsObject



158
159
160
# File 'lib/groupdocs/job.rb', line 158

def documents
  @documents
end

#email_resultsObject



154
155
156
# File 'lib/groupdocs/job.rb', line 154

def email_results
  @email_results
end

#guidObject



146
147
148
# File 'lib/groupdocs/job.rb', line 146

def guid
  @guid
end

#idObject



144
145
146
# File 'lib/groupdocs/job.rb', line 144

def id
  @id
end

#nameObject



148
149
150
# File 'lib/groupdocs/job.rb', line 148

def name
  @name
end

#priorityObject



150
151
152
# File 'lib/groupdocs/job.rb', line 150

def priority
  @priority
end

#requested_timeTime

Converts timestamp which is return by API server to Time object.

Returns:

  • (Time)


160
161
162
# File 'lib/groupdocs/job.rb', line 160

def requested_time
  @requested_time
end

#statusSymbol

Converts status to human-readable format.

Returns:

  • (Symbol)


162
163
164
# File 'lib/groupdocs/job.rb', line 162

def status
  @status
end

#url_onlyObject



156
157
158
# File 'lib/groupdocs/job.rb', line 156

def url_only
  @url_only
end

Class Method Details

.all!(options = {}, access = {}) ⇒ Array<GroupDocs::Job>

Returns array of jobs.

Parameters:

  • options (Hash) (defaults to: {})

    Hash of options

  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (options):

  • :page (Integer)

    Page to start with

  • :count (Integer)

    How many items to list

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/groupdocs/job.rb', line 32

def self.all!(options = {}, access = {})
  api = Api::Request.new do |request|
    request[:access] = access
    request[:method] = :GET
    request[:path] = '/async/{{client_id}}/jobs'
  end
  api.add_params(options)
  json = api.execute!

  json[:jobs].map do |job|
    Job.new(job)
  end
end

.create!(options, access = {}) ⇒ GroupDocs::Job

Creates new draft job.

Parameters:

  • options (Hash)
  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (options):

  • :actions (Integer)

    Array of actions to be performed. Required

  • :email_results (Boolean)
  • :out_formats (Array)
  • :url_only (Boolean)

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/groupdocs/job.rb', line 127

def self.create!(options, access = {})
  options[:actions] or raise ArgumentError, 'options[:actions] is required.'
  options[:actions] = convert_actions_to_byte(options[:actions])
  #options[:out_formats] = options[:out_formats].join(?;) if options[:out_formats]

  api = Api::Request.new do |request|
    request[:access] = access
    request[:method] = :POST
    request[:path] = '/async/{{client_id}}/jobs'
    request[:request_body] = options
  end
  json = api.execute!

  Job.new(:id => json[:job_id], :guid => json[:job_guid])
end

.get!(id, access = {}) ⇒ GroupDocs::Job

Returns job by its identifier.

Parameters:

  • id (Integer)
  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/groupdocs/job.rb', line 55

def self.get!(id, access = {})
  api = Api::Request.new do |request|
    request[:access] = access
    request[:method] = :GET
    request[:path] = "/async/{{client_id}}/jobs/#{id}"
  end
  api.add_params(:format => 'json')
  json = api.execute!

  Job.new(json)
end

.get_resources!(options = {}, access = {}) ⇒ GroupDocs::Job

Returns job by its identifier.

Parameters:

  • options (Hash) (defaults to: {})
  • access (Hash) (defaults to: {})

    Access credentials

  • statusIds (Hash)

    a customizable set of options

  • actions (Hash)

    a customizable set of options

  • excluded_actions (Hash)

    a customizable set of options

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:



101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/groupdocs/job.rb', line 101

def self.get_resources!(options = {} , access = {})
  options[:actions] = convert_actions_to_byte(options[:actions])
  api = Api::Request.new do |request|
    request[:access] = access
    request[:method] = :GET
    request[:path] = "/async/{{client_id}}/jobs/resources"
  end
  api.add_params(options)
  json = api.execute!

  json[:dates]
end

.get_xml!(id, access = {}) ⇒ GroupDocs::Job

Returns job by its identifier.

Parameters:

  • id (Integer)
  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/groupdocs/job.rb', line 76

def self.get_xml!(id, access = {})
  api = Api::Request.new do |request|
    request[:access] = access
    request[:method] = :GET
    request[:path] = "/async/{{client_id}}/jobs/#{id}"
  end
  api.add_params(:format => 'xml')
  json = api.execute!

  Job.new(json)
end

.jobs_documents!(options = {}, access = {}) ⇒ Hash

Returns an array of input and output documents associated to jobs.

Parameters:

  • options (Hash) (defaults to: {})
  • access (Hash) (defaults to: {})

    Access credentials

  • page (Hash)

    a customizable set of options

  • count (Hash)

    a customizable set of options

  • actions (Hash)

    a customizable set of options

  • excluded_actions (Hash)

    a customizable set of options

  • order_by (Hash)

    a customizable set of options

  • order_asc (Hash)

    a customizable set of options

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:

  • (Hash)


269
270
271
272
273
274
275
276
277
278
# File 'lib/groupdocs/job.rb', line 269

def self.jobs_documents!(options = {}, access = {})
  api = Api::Request.new do |request|
    request[:access] = access
    request[:method] = :GET
    request[:path] = "/async/{{client_id}}/jobs/documents"
  end
  api.add_params(options)
  api.execute!

end

Instance Method Details

#add_datasource!(document, datasource, access = {}) ⇒ Object

Adds datasource to job document.

Parameters:

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Raises:

  • (ArgumentError)

    If document is not a GroupDocs::Document object

  • (ArgumentError)

    If datasource is not a GroupDocs::DataSource object



336
337
338
339
340
341
342
343
344
345
346
347
# File 'lib/groupdocs/job.rb', line 336

def add_datasource!(document, datasource, access = {})
  document.is_a?(GroupDocs::Document) or raise ArgumentError,
    "Document should be GroupDocs::Document object. Received: #{document.inspect}"
  datasource.is_a?(GroupDocs::DataSource) or raise ArgumentError,
    "Datasource should be GroupDocs::DataSource object. Received: #{datasource.inspect}"

  Api::Request.new do |request|
    request[:access] = access
    request[:method] = :PUT
    request[:path] = "/async/{{client_id}}/jobs/#{id}/files/#{document.file.id}/datasources/#{datasource.id}"
  end.execute!
end

#add_document!(document, options = {}, access = {}) ⇒ Integer

Adds document to job.

Parameters:

  • document (GroupDocs::Document)
  • options (Hash) (defaults to: {})
  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (options):

  • :output_formats (Array)

    Array of output formats to override

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:

  • (Integer)

    Document ID

Raises:

  • (ArgumentError)

    If document is not a GroupDocs::Document object



293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/groupdocs/job.rb', line 293

def add_document!(document, options = {}, access = {})
  document.is_a?(GroupDocs::Document) or raise ArgumentError,
    "Document should be GroupDocs::Document object. Received: #{document.inspect}"

  api = Api::Request.new do |request|
    request[:access] = access
    request[:method] = :PUT
    request[:path] = "/async/{{client_id}}/jobs/#{id}/files/#{document.file.guid}"
  end
  api.add_params(options)
  json = api.execute!

  json[:document_id]
end

#add_url!(url, options = {}, access = {}) ⇒ Integer

Adds URL of web page or document to be converted.

Parameters:

  • url (String)

    Absolute URL

  • options (Hash) (defaults to: {})
  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (options):

  • :output_formats (Array)

    Array of output formats to override

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:

  • (Integer)

    Document ID



360
361
362
363
364
365
366
367
368
369
370
371
372
# File 'lib/groupdocs/job.rb', line 360

def add_url!(url, options = {}, access = {})
  options.merge!(:absolute_url => url)

  api = Api::Request.new do |request|
    request[:access] = access
    request[:method] = :PUT
    request[:path] = "/async/{{client_id}}/jobs/#{id}/urls"
  end
  api.add_params(options)
  json = api.execute!

  json[:document_id]
end

#delete!(access = {}) ⇒ Object

Deletes draft job.

Parameters:

  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)


402
403
404
405
406
407
408
# File 'lib/groupdocs/job.rb', line 402

def delete!(access = {})
  Api::Request.new do |request|
    request[:access] = access
    request[:method] = :DELETE
    request[:path] = "/async/{{client_id}}/jobs/#{id}"
  end.execute!
end

#delete_document!(guid, access = {}) ⇒ Object

Deletes document with guid from job.

Parameters:

  • guid (String)
  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)


316
317
318
319
320
321
322
# File 'lib/groupdocs/job.rb', line 316

def delete_document!(guid, access = {})
  Api::Request.new do |request|
    request[:access] = access
    request[:method] = :DELETE
    request[:path] = "/async/{{client_id}}/jobs/#{id}/documents/#{guid}"
  end.execute!
end

#documents!(access = {}) ⇒ Hash

Returns an hash of input and output documents associated to job.

Parameters:

  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:

  • (Hash)


213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/groupdocs/job.rb', line 213

def documents!(access = {})
  json = Api::Request.new do |request|
    request[:access] = access
    request[:method] = :GET
    request[:path] = "/async/{{client_id}}/jobs/#{id}/documents"
  end.execute!

  self.status = json[:job_status]
  documents = {
    :inputs =>  [],
    :outputs => [],
  }

  # add input documents
  if json[:inputs]
    json[:inputs].each do |document|
      document.merge!(:file => GroupDocs::Storage::File.new(document))
      documents[:inputs] << Document.new(document)
    end
  end

  # add output documents
  if json[:outputs]
    json[:outputs].each do |document|
      document.merge!(:file => GroupDocs::Storage::File.new(document))
      documents[:outputs] << Document.new(document)
    end
  end

  documents
end

#update!(options, access = {}) ⇒ Object

Updates job settings and/or status.

Parameters:

  • options (Hash)
  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (options):

  • :email_results (Boolean)
  • :status (Symbol)

Options Hash (access):

  • :client_id (String)
  • :private_key (String)


384
385
386
387
388
389
390
391
392
393
# File 'lib/groupdocs/job.rb', line 384

def update!(options, access = {})
  options[:status] = parse_status(options[:status]) if options[:status]

  Api::Request.new do |request|
    request[:access] = access
    request[:method] = :PUT
    request[:path] = "/async/{{client_id}}/jobs/#{id}"
    request[:request_body] = options
  end.execute!
end