class GroupDocs::Job

Constants

ACTIONS

Attributes

actions[RW]

@attr [Array<Symbol>] actions

documents[RW]

@attr [Array<GroupDocs::Document] documents

email_results[RW]

@attr [Boolean] email_results

guid[RW]

@attr [String] guid

id[RW]

@attr [Integer] id

name[RW]

@attr [String] name

priority[RW]

@attr [Integer] priority

requested_time[RW]

@attr [Time] requested_time

status[RW]

@attr [Symbol] status

url_only[RW]

@attr [Boolean] url_only

Public Class Methods

all!(options = {}, access = {}) click to toggle source

Returns array of jobs.

@param [Hash] options Hash of options @option options [String] :page Page Index @option options [String] :date Data @option options [String] :count How many items to list @option options [String] :statusIds Comma separated status identifiers @option options [String] :actions Actions @option options [String] :excluded_actions Excluded actions @option options [String] :jobName Foltred job name @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key @return [Array<GroupDocs::Job>]

# 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 = {}) click to toggle source

Creates new draft job.

@param [Hash] options @option options [Integer] :actions Array of actions to be performed. Required @option options [Boolean] :email_results @option options [Array] :out_formats @option options [Boolean] :url_only @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key @return [GroupDocs::Job]

# 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 = {}) click to toggle source

Returns job by its identifier.

@param [Integer] id @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key @return [GroupDocs::Job]

# 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 = {}) click to toggle source

Returns job by its identifier.

@param [Hash] options @option statusIds [String] :statusIds (required) @option actions [Integer] :actions @option excluded_actions [String] :excluded_actions @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key @return [GroupDocs::Job]

# 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 = {}) click to toggle source

Returns job by its identifier.

@param [Integer] id @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key @return [GroupDocs::Job]

# 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 = {}) click to toggle source

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

@param [Hash] options @option page [String] Page Index @option count [String] Page Size @option actions [String] Actions @option excluded_actions [String] Excluded actions @option order_by [String] Order by @option order_asc [String] Order ask @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key @return [Hash]

# 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

Private Class Methods

convert_actions_to_byte(actions) click to toggle source

Converts actions array to byte flag.

@param [Array<String, Symbol>] actions @return [Integer] @raise [ArgumentError] if actions is not an array @raise [ArgumentError] if action is unknown @api private

# File lib/groupdocs/job.rb, line 431
def self.convert_actions_to_byte(actions)
  actions.is_a?(Array) or raise ArgumentError, "Actions should be an array, received: #{actions.inspect}"
  actions = actions.map(&:to_sym)

  possible_actions = ACTIONS.map { |hash| hash.first }
  actions.each do |action|
    possible_actions.include?(action) or raise ArgumentError, "Unknown action: #{action.inspect}"
  end

  byte_from_array(actions, ACTIONS)
end
get_conversions!(access = {}, file_ext) click to toggle source

Get Possible Conversions.

@example

GroupDocs::Job.get_conversions! "pdf"

@param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key @param [String] file_ext File extension to check

# File lib/groupdocs/job.rb, line 457
def self.get_conversions!(access = {}, file_ext)
  api = Api::Request.new do |request|
    request[:access] = access
    request[:method] = :GET
    request[:path] = "/async/{{client_id}}/possibleConversions/#{file_ext}"
  end
  json = api.execute!
  json[:possibleConversions]
end

Public Instance Methods

add_datasource!(document, datasource, access = {}) click to toggle source

Adds datasource to job document.

@param [GroupDocs::Document] document @param [GroupDocs::DataSource] datasource @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key

@raise [ArgumentError] If document is not a GroupDocs::Document object @raise [ArgumentError] If datasource is not a GroupDocs::DataSource object

# 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 = {}) click to toggle source

Adds document to job.

@param [GroupDocs::Document] document @param [Hash] options @option options [Array] :output_formats Array of output formats to override @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key @return [Integer] Document ID

@raise [ArgumentError] If document is not a GroupDocs::Document object

# 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 = {}) click to toggle source

Adds URL of web page or document to be converted.

@param [String] url Absolute URL @param [Hash] options @option options [Array] :output_formats Array of output formats to override @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key @return [Integer] Document ID

# 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 = {}) click to toggle source

Deletes draft job.

@param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key

# 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 = {}) click to toggle source

Deletes document with guid from job.

@param [String] guid @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key

# 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 = {}) click to toggle source

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

@param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key @return [Hash]

# 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
documents=(documents) click to toggle source

Coverts passed array of attributes hash to array of GroupDocs::Document.

@param [Array<Hash>] documents Array of document attributes hashes

# File lib/groupdocs/job.rb, line 179
def documents=(documents)
  if documents
    @documents = documents[:inputs].map do |document|
      document.merge!(:file => GroupDocs::Storage::File.new(document))
      Document.new(document)
    end
  end
end
update!(options, access = {}) click to toggle source

Updates job settings and/or status.

@param [Hash] options @option options [Boolean] :email_results @option options [Symbol] :status @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key

# 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