Class: MoxiworksPlatform::Task

Inherits:
Resource
  • Object
show all
Defined in:
lib/moxiworks_platform/task.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

accept_header, attr_accessor, attributes, #attributes, auth_header, check_for_error_in_response, content_type_header, #float_attrs, headers, #initialize, #method_missing, #numeric_attrs, #numeric_value_for, #to_hash

Constructor Details

This class inherits a constructor from MoxiworksPlatform::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class MoxiworksPlatform::Resource

Instance Attribute Details

#completed_atInteger|nil

the Unix timestamp representing the Date/Time this task was completed.

When the task is not in a ‘completed’ state, this attribute will be nil.

When updating the completed_at attribute, the status attribute must be set to ‘completed’

Returns:

  • (Integer|nil)

    – Default nil



82
# File 'lib/moxiworks_platform/task.rb', line 82

attr_writer :completed_at

#created_atObject

the Unix timestamp representing the Date/Time this Task was created



71
# File 'lib/moxiworks_platform/task.rb', line 71

attr_writer :created_at

#descriptionString

a detailed description to be displayed to the agent for this Task

Returns:

  • (String)


35
36
37
# File 'lib/moxiworks_platform/task.rb', line 35

def description
  @description
end

#due_atInteger

the Unix timestamp representing the due date of this Task

Returns:

  • (Integer)


41
# File 'lib/moxiworks_platform/task.rb', line 41

attr_writer :due_at

#durationInteger

the length (in minutes) estimated to complete this Task

Returns:

  • (Integer)


47
# File 'lib/moxiworks_platform/task.rb', line 47

attr_writer :duration

#moxi_works_agent_idString

moxi_works_agent_id is the Moxi Works Platform ID of the agent which a Task is or is to be associated with.

this must be set for any Moxi Works Platform transaction

Returns:

  • (String)

    the Moxi Works Platform ID of the agent



10
11
12
# File 'lib/moxiworks_platform/task.rb', line 10

def moxi_works_agent_id
  @moxi_works_agent_id
end

#nameString

the title to be displayed to the agent for this Task

Returns:

  • (String)


29
30
31
# File 'lib/moxiworks_platform/task.rb', line 29

def name
  @name
end

#partner_contact_idString

*your system’s* unique ID for the Contact

this must be set for any Moxi Works Platform transaction

Returns:

  • (String)

    your system’s unique ID for the contact



18
19
20
# File 'lib/moxiworks_platform/task.rb', line 18

def partner_contact_id
  @partner_contact_id
end

#partner_task_idString

Returns your system’s unique identifier for the Task.

Returns:

  • (String)

    your system’s unique identifier for the Task



23
24
25
# File 'lib/moxiworks_platform/task.rb', line 23

def partner_task_id
  @partner_task_id
end

#statusString, enumerated

an enumerated string representing the state of this Task

allowed values:

active
completed
[nil]

When creating a new task, the assumed state is ‘active;’ this attribute does not need to be populated when creating or updating a Task unless the status is ‘completed.’

Returns:

  • (String, enumerated)

    – Default: ‘active’



63
64
65
# File 'lib/moxiworks_platform/task.rb', line 63

def status
  @status
end

Class Method Details

.create(opts = {}) ⇒ MoxiworksPlatform::Task

Creates a new Task in Moxi Works Platform

Examples:

MoxiworksPlatform::Task.create(
      moxi_works_agent_id: '123abc',
      partner_contact_id: '1234',
      partner_task_id: 'mySystemsUniqueTaskID',
      name: 'pick up client keys',
      description: 'pick up client keys from1234 there ave',
      due_at: Time.now.to_i + 86400,
      duration: 30
  )

Parameters:

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

    named parameter Hash

Options Hash (opts):

  • :moxi_works_agent_id (String)

    REQUIRED The Moxi Works Agent ID for the agent to which this task is to be associated

  • :partner_task_id (String)

    REQUIRED Your system’s unique ID for this task.

  • :partner_contact_id (String)

    REQUIRED Your system’s unique ID for the Contact for whom this Task is to be associated.

    optional Task parameters

  • :name (String)

    short description of the task

  • :description (String)

    longer description of the task

  • :due_at (Integer)

    Unix timestamp representing the due date

  • :duration (Integer)

    Length of time in minutes that the task should take

Returns:

Raises:

  • ::MoxiworksPlatform::Exception::ArgumentError if required named parameters aren’t included



113
114
115
116
117
118
119
120
# File 'lib/moxiworks_platform/task.rb', line 113

def self.create(opts={})
 required_opts = [:moxi_works_agent_id, :partner_task_id, :partner_contact_id]
 required_opts.each do |opt|
   raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
       opts[opt].nil? or opts[opt].to_s.empty?
 end
 self.send_request(:post, opts)
end

.find(opts = {}) ⇒ MoxiworksPlatform::Task

Find an Task your system has previously created in Moxi Works Platform

Parameters:

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

    named parameter Hash

Options Hash (opts):

  • :moxi_works_agent_id (String)

    REQUIRED The Moxi Works Agent ID for the agent to which this task is associated

  • :partner_task_id (String)

    REQUIRED Your system’s unique ID for this task.

Returns:

Raises:

  • ::MoxiworksPlatform::Exception::ArgumentError if required named parameters aren’t included



132
133
134
135
136
137
138
139
140
# File 'lib/moxiworks_platform/task.rb', line 132

def self.find(opts={})
  required_opts = [:moxi_works_agent_id, :partner_task_id]
  required_opts.each do |opt|
    raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
        opts[opt].nil? or opts[opt].to_s.empty?
  end
  url = "#{MoxiworksPlatform::Config.url}/api/tasks/#{opts[:partner_task_id]}"
  self.send_request(:get, opts, url)
end

.search(opts = {}) ⇒ Hash

Search Agent’s Tasks in Moxi Works Platform

Examples:

results = MoxiworksPlatform::Contact.search(
moxi_works_agent_id: '123abc',
due_date_start:  Time.now.to_i - 1296000,
due_date_end: Time.now.to_i,
page_number: 2
)

Parameters:

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

    named parameter Hash

Options Hash (opts):

  • :moxi_works_agent_id (String)

    REQUIRED The Moxi Works Agent ID for the agent to which this contact is associated

  • :due_date_start (Integer)

    REQUIRED Tasks due after specified date

  • :partner_contact_id (String)

    The partner’s ID for the contact whose tasks they are looking for

  • :page_number (Integer)

    the page of results to return

Returns:

  • (Hash)

    with the format:

    page_number: [Integer],
    total_pages: [Integer],
    tasks:  [Array] containing MoxiworkPlatform::Task objects
    

Raises:

  • ::MoxiworksPlatform::Exception::ArgumentError if required named parameters aren’t included



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/moxiworks_platform/task.rb', line 174

def self.search(opts={})
  url ||= "#{MoxiworksPlatform::Config.url}/api/tasks"
  required_opts = [:moxi_works_agent_id, :due_date_start, :due_date_end]
  required_opts.each do |opt|
    raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
        opts[opt].nil? or opts[opt].to_s.empty?
  end
  results = []
  json = { 'page_number': 1, 'total_pages': 0, 'tasks':[]}
  RestClient::Request.execute(method: :get,
                              url: url,
                              payload: opts, headers: self.headers) do |response|
    puts response if MoxiworksPlatform::Config.debug
    self.check_for_error_in_response(response)
    json = JSON.parse(response)
    json['tasks'].each do |r|
      results << MoxiworksPlatform::Task.new(r) unless r.nil? or r.empty?
    end
    json['tasks'] = results
  end
  json
end

.send_request(method, opts = {}, url = nil) ⇒ MoxiworksPlatform::Task

Send our remote request to the Moxi Works Platform

Parameters:

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

    named parameter Hash

Options Hash (opts):

  • :moxi_works_agent_id (String)

    REQUIRED The Moxi Works Agent ID for the agent to which this task is to be associated

  • :partner_task_id (String)

    REQUIRED Your system’s unique ID for this task.

  • :partner_contact_id (String)

    REQUIRED Your system’s unique ID for the Contact for whom this Task is to be associated.

    optional Task parameters

  • :name (String)

    short description of the task

  • :description (String)

    longer description of the task

  • :due_at (Integer)

    Unix timestamp representing the due date

  • :duration (Integer)

    Length of time in minutes that the task should take

  • :completed_at (Integer)

    Unix timestamp representing the date the task was completed

  • :status (String)

    enumerated string representing task status

Returns:

Raises:

  • ::MoxiworksPlatform::Exception::ArgumentError if required named parameters aren’t included



262
263
264
265
266
267
268
269
270
# File 'lib/moxiworks_platform/task.rb', line 262

def self.send_request(method, opts={}, url=nil)
  url ||= "#{MoxiworksPlatform::Config.url}/api/tasks"
  required_opts = [:moxi_works_agent_id, :partner_task_id]
  required_opts.each do |opt|
    raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
        opts[opt].nil? or opts[opt].to_s.empty?
  end
  super(method, opts, url)
end

.update(opts = {}) ⇒ MoxiworksPlatform::Task

Updates an existing Task in Moxi Works Platform

Examples:

MoxiworksPlatform::Task.create(
      moxi_works_agent_id: '123abc',
      partner_contact_id: '1234',
      partner_task_id: 'mySystemsUniqueTaskID',
      name: 'pick up client keys',
      description: 'pick up client keys from1234 there ave',
      due_at: Time.now.to_i + 86400,
      duration: 30,
      status: 'completed',
      completed_at: Time.now.to_i,
  )

Parameters:

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

    named parameter Hash

Options Hash (opts):

  • :moxi_works_agent_id (String)

    REQUIRED The Moxi Works Agent ID for the agent to which this task is to be associated

  • :partner_task_id (String)

    REQUIRED Your system’s unique ID for this task.

  • :partner_contact_id (String)

    REQUIRED Your system’s unique ID for the Contact for whom this Task is to be associated.

    optional Task parameters

  • :name (String)

    short description of the task

  • :description (String)

    longer description of the task

  • :due_at (Integer)

    Unix timestamp representing the due date

  • :duration (Integer)

    Length of time in minutes that the task should take

  • :completed_at (Integer)

    Unix timestamp representing the date the task was completed

  • :status (String)

    enumerated string representing task status

Returns:

Raises:

  • ::MoxiworksPlatform::Exception::ArgumentError if required named parameters aren’t included



230
231
232
233
234
235
236
237
238
# File 'lib/moxiworks_platform/task.rb', line 230

def self.update(opts={})
  required_opts = [:moxi_works_agent_id, :partner_task_id, :partner_contact_id]
  required_opts.each do |opt|
    raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
        opts[opt].nil? or opts[opt].to_s.empty?
  end
   url = "#{MoxiworksPlatform::Config.url}/api/tasks/#{opts[:partner_task_id]}"
   self.send_request(:put, opts, url)
end

Instance Method Details

#saveMoxiWorksPlatform:Task

Save an instance of MoxiWorksPlatform::Task to Moxi Works Platform

Examples:

task = MoxiWorksPlatform::Task.new()
task.moxi_works_agent_id = '123abcd'
task.partner_task_id = 'myUniqueTaskdentifier'
task.status = 'completed'
task.completed_at =  Time.now.to_i
task.save

Returns:

  • (MoxiWorksPlatform:Task)


283
284
285
# File 'lib/moxiworks_platform/task.rb', line 283

def save
  MoxiworksPlatform::Task.update(self.to_hash)
end