Class: MoxiworksPlatform::ActionLog

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

Instance Attribute Summary collapse

Attributes inherited from Resource

#headers

Class 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, #init_attrs_from_hash, #initialize, #int_attrs, #method_missing, #numeric_attrs, #numeric_value_for, #to_hash, underscore, underscore_array, underscore_attribute_names, underscore_hash, user_agent_header

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

#actionsArray

Returns array containing any ActionLog entries found by search request

moxi_works_action_log_id: [String] unique identifier for the Moxi Works Platform ActionLog entry,
type: [String] the type of ActionLog entry this is. The string should be formatted in lowercase with an underscore between each word,
timestamp: [Integer] Unix timestamp for the creation time of the ActionLog entry,
log_data: [Dictionary] the payload data of the ActionLog entry. The structure returned is dependent on the kind of ActionLog entry this is

Returns:

  • (Array)

    array containing any ActionLog entries found by search request

    moxi_works_action_log_id: [String] unique identifier for the Moxi Works Platform ActionLog entry,
    type: [String] the type of ActionLog entry this is. The string should be formatted in lowercase with an underscore between each word,
    timestamp: [Integer] Unix timestamp for the creation time of the ActionLog entry,
    log_data: [Dictionary] the payload data of the ActionLog entry. The structure returned is dependent on the kind of ActionLog entry this is
    



59
60
61
# File 'lib/moxiworks_platform/action_log.rb', line 59

def actions
  @actions
end

#agent_uuidString

agent_uuid is the Moxi Works Platform ID of the agent which an ActionLog entry is or is to be associated with. This will be an RFC 4122 compliant UUID.

this or moxi_works_agent_id 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/action_log.rb', line 10

def agent_uuid
  @agent_uuid
end

#bodyString

the body of the log entry to be displayed for this ActionLog Entry

Returns:

  • (String)


48
49
50
# File 'lib/moxiworks_platform/action_log.rb', line 48

def body
  @body
end

#moxi_works_agent_idString

moxi_works_agent_id is the Moxi Works Platform ID of the agent which an ActionLog entry is or is to be associated with.

this or agent_uuid must be set for any Moxi Works Platform transaction

Returns:

  • (String)

    the Moxi Works Platform ID of the agent



19
20
21
# File 'lib/moxiworks_platform/action_log.rb', line 19

def moxi_works_agent_id
  @moxi_works_agent_id
end

#moxi_works_contact_idString

This is the Moxi Works Platform ID of this Contact that this ActionLog entry is about. This will be an RFC 4122 compliant UUID

this or partner_contact_id must be set for any Moxi Works Platform transaction

Returns:

  • (String)

    your system's unique ID for the contact



28
29
30
# File 'lib/moxiworks_platform/action_log.rb', line 28

def moxi_works_contact_id
  @moxi_works_contact_id
end

#partner_contact_idString

*your system's* unique ID for the Contact

this or moxi_works_contact_id must be set for any Moxi Works Platform transaction

Returns:

  • (String)

    your system's unique ID for the contact



36
37
38
# File 'lib/moxiworks_platform/action_log.rb', line 36

def partner_contact_id
  @partner_contact_id
end

#titleString

the title to be displayed for this ActionLog Entry

Returns:

  • (String)


42
43
44
# File 'lib/moxiworks_platform/action_log.rb', line 42

def title
  @title
end

Class Method Details

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

Creates a new ActionLog entry in Moxi Works Platform

Examples:

MoxiworksPlatform::ActionLog.create(
      moxi_works_agent_id: 'abc123',
      partner_contact_id: 'mySystemsUniqueContactID',
      title: 'New home keys were delivered to Firstname Lastname',
      body: 'Firstname Lastname were delivered their keys to1234 there ave',
  )

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 ActionLog entry is to be associated

  • :partner_contact_id (String)

    REQUIRED Your system's unique ID for the contact for whom the ActionLog entry is being created.

  • :title (String)

    REQUIRED A brief title for this ActionLog entry (85 characters or less)

  • :body (String)

    REQUIRED The body of this ActionLog entry (255 characters or less)

Returns:

Raises:

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



81
82
83
# File 'lib/moxiworks_platform/action_log.rb', line 81

def self.create(opts={})
   self.send_request(:post, opts)
end

.search(opts = {}) ⇒ Array

Search an Agent's ActionLog entries in Moxi Works Platform

Examples:

results = MoxiworksPlatform::ActionLog.search(
moxi_works_agent_id: '123abc',
   )

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 ActionLog is associated – moxi_works_agent_id or agent_uuid must be passed

  • :agent_uuid (String)

    REQUIRED The Agent UUID for the agent to which this ActionLog is associated – moxi_works_agent_id or agent_uuid must be passed

  • :partner_contact_id (String)

    REQUIRED Your system's unique ID for the contact for whom the ActionLog entry is being created. – partner_contact_id or moxi_works_contact_id must be passed

  • :moxi_works_contact_id (String)

    REQUIRED MoxiWorks' unique ID for the contact for whom the ActionLog entry is being created. – partner_contact_id or moxi_works_contact_id must be passed

Returns:

  • (Array)

    containing MoxiworksPlatform::ActionLog objects

Raises:

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



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/moxiworks_platform/action_log.rb', line 102

def self.search(opts={})
  raise ::MoxiworksPlatform::Exception::ArgumentError,
        'arguments must be passed as named parameters' unless opts.is_a? Hash
  url ||= "#{MoxiworksPlatform::Config.url}/api/action_logs"
  required_opts = [:moxi_works_agent_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
  results = MoxiResponseArray.new()
  RestClient::Request.execute(method: :get,
                              url: url,
                              payload: opts, headers: self.headers) do |response|
    puts response if MoxiworksPlatform::Config.debug
    results.headers = response.headers
    self.check_for_error_in_response(response)
    json = JSON.parse(response)

    results.page_number = 1
    results.total_pages = 1

    json['actions'].each do |r|
      results << MoxiworksPlatform::ActionLog.new(r) unless r.nil? or r.empty?
    end
  end
  results
end

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

Send our remote request to the Moxi Works Platform

Parameters:

  • method (String)

    The HTTP method to be used when connecting; ex: :put, :post, :get

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

Options Hash (opts):

  • :moxi_works_agent_id (String)

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

  • :partner_contact_id (String)

    REQUIRED Your system's unique ID for the contact for whom the ActionLog entry is being created.

  • :title (String)

    REQUIRED A brief title for this ActionLog entry (85 characters or less)

  • :body (String)

    REQUIRED The body of this ActionLog entry (255 characters or less)

Returns:

Raises:

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



145
146
147
148
149
150
151
152
153
154
155
# File 'lib/moxiworks_platform/action_log.rb', line 145

def self.send_request(method, opts={}, url=nil)
  raise ::MoxiworksPlatform::Exception::ArgumentError,
        'arguments must be passed as named parameters' unless opts.is_a? Hash
  url ||= "#{MoxiworksPlatform::Config.url}/api/action_logs"
  required_opts = [:moxi_works_agent_id, :partner_contact_id, :title, :body]
  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