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,
  # add in release 1.5.8
  :split => 1024,
  :view => 2048,
  :index => 4096,
  :number_lines => 8192
}

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>)


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

def actions
  @actions
end

#documentsObject



168
169
170
# File 'lib/groupdocs/job.rb', line 168

def documents
  @documents
end

#email_resultsObject



164
165
166
# File 'lib/groupdocs/job.rb', line 164

def email_results
  @email_results
end

#guidObject



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

def guid
  @guid
end

#idObject



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

def id
  @id
end

#nameObject



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

def name
  @name
end

#priorityObject



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

def priority
  @priority
end

#requested_timeTime

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

Returns:

  • (Time)


170
171
172
# File 'lib/groupdocs/job.rb', line 170

def requested_time
  @requested_time
end

#statusSymbol

Converts status to human-readable format.

Returns:

  • (Symbol)


172
173
174
# File 'lib/groupdocs/job.rb', line 172

def status
  @status
end

#url_onlyObject



166
167
168
# File 'lib/groupdocs/job.rb', line 166

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 (String)

    Page Index

  • :date (String)

    Data

  • :count (String)

    How many items to list

  • :statusIds (String)

    Comma separated status identifiers

  • :actions (String)

    Actions

  • :excluded_actions (String)

    Excluded actions

  • :jobName (String)

    Foltred job name

Options Hash (access):

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

Returns:



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/groupdocs/job.rb', line 42

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:



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/groupdocs/job.rb', line 137

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:



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/groupdocs/job.rb', line 65

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:



111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/groupdocs/job.rb', line 111

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:



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/groupdocs/job.rb', line 86

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)


279
280
281
282
283
284
285
286
287
288
# File 'lib/groupdocs/job.rb', line 279

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



346
347
348
349
350
351
352
353
354
355
356
357
# File 'lib/groupdocs/job.rb', line 346

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



303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/groupdocs/job.rb', line 303

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



370
371
372
373
374
375
376
377
378
379
380
381
382
# File 'lib/groupdocs/job.rb', line 370

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)


412
413
414
415
416
417
418
# File 'lib/groupdocs/job.rb', line 412

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)


326
327
328
329
330
331
332
# File 'lib/groupdocs/job.rb', line 326

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)


223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/groupdocs/job.rb', line 223

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)


394
395
396
397
398
399
400
401
402
403
# File 'lib/groupdocs/job.rb', line 394

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