Class: MoxiworksPlatform::Group

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

Overview

Moxi Works Platform Group

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

#contactsArray

the contacts in the group

Returns:

  • (Array)

    of MoxiworksPlatform::Contact objects



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

def contacts
  @contacts
end

#moxi_works_agent_idString

moxi_works_agent_id is the Moxi Works Platform ID of the agent which the group is associated with.

this must be set for any Moxi Works Platform transaction

Returns:

  • (String)

    the Moxi Works Platform ID of the agent



11
12
13
# File 'lib/moxiworks_platform/group.rb', line 11

def moxi_works_agent_id
  @moxi_works_agent_id
end

#moxi_works_group_idString

your system’s group ID for the group

Returns:

  • (String)

    representing the name of the group on the Moxi Works Platform



17
# File 'lib/moxiworks_platform/group.rb', line 17

attr_accessor :moxi_works_group_name

#moxi_works_group_nameString

your system’s group ID for the group

Returns:

  • (String)

    representing the name of the group on the Moxi Works Platform



17
18
19
# File 'lib/moxiworks_platform/group.rb', line 17

def moxi_works_group_name
  @moxi_works_group_name
end

Class Method Details

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

Find a Group your system has previously created in Moxi Works Platform

Examples:

results = MoxiworksPlatform::Group.find(
moxi_works_agent_id: '123abc',
moxi_works_group_name: 'foobar'
  )

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 group is associated

  • :moxi_works_group_id (Integer)

    REQUIRED The Moxi Works Group ID for this group.

Returns:

Raises:

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

  • ::MoxiworksPlatform::Exception::ArgumentError if moxi_works_group_id is not an Integer or an integer as a String



44
45
46
47
# File 'lib/moxiworks_platform/group.rb', line 44

def self.find(opts={})
  url = "#{MoxiworksPlatform::Config.url}/api/groups/#{opts[:moxi_works_group_name]}"
  self.send_request(:get, opts, url)
end

.search(opts = {}) ⇒ Array

Search an Agent’s Groups in Moxi Works Platform

Examples:

results = MoxiworksPlatform::Group.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 group is associated

  • :name (String)

    optional name to search for. If no name is provided, all of the Agent’s Groups will be returned

Returns:

  • (Array)

    containing MoxiworksPlatform::Group objects formatted as follows:

Raises:

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



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/moxiworks_platform/group.rb', line 64

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/groups"
  required_opts = [:moxi_works_agent_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)
    json.each do |r|
      results << MoxiworksPlatform::Group.new(r) unless r.nil? or r.empty?
    end
  end
  results
end