Class: AdobeConnect::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/adobe_connect/base.rb

Overview

Provides base interaction with Adobe Connect for a variety of AC Objects

Direct Known Subclasses

AclField, Group, Meeting, TelephonyProfile, User

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj_options, service = Service.new) ⇒ Base

Returns a new instance of Base.



10
11
12
13
14
# File 'lib/adobe_connect/base.rb', line 10

def initialize(obj_options, service = Service.new)
  set_attrs(obj_options)
  @service  = service
  @errors   = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



8
9
10
# File 'lib/adobe_connect/base.rb', line 8

def errors
  @errors
end

#idObject

Public: SCO-ID from the Adobe Connect instance.



6
7
8
# File 'lib/adobe_connect/base.rb', line 6

def id
  @id
end

#serviceObject (readonly)

Returns the value of attribute service.



8
9
10
# File 'lib/adobe_connect/base.rb', line 8

def service
  @service
end

Class Method Details

.configObject



84
85
86
# File 'lib/adobe_connect/base.rb', line 84

def self.config
  { :ac_obj_type => 'principal', :delete_method_is_plural => true }
end

.create(obj_options) ⇒ Object

Public: Create a Connect obj from the given app obj.

obj_options - Generic options (see #initialize for required

attributes).

Returns an instance of this class, with an attempted save.



77
78
79
80
81
82
# File 'lib/adobe_connect/base.rb', line 77

def self.create(obj_options)
  obj = self.new(obj_options)
  obj.save

  obj
end

Instance Method Details

#ac_obj_node_nameObject (private)



91
92
93
# File 'lib/adobe_connect/base.rb', line 91

def ac_obj_node_name
  self.class.config[:ac_obj_node_name] || ac_obj_type
end

#ac_obj_typeObject (private)



95
96
97
# File 'lib/adobe_connect/base.rb', line 95

def ac_obj_type
  self.class.config[:ac_obj_type]
end

#attrsObject



16
17
18
# File 'lib/adobe_connect/base.rb', line 16

def attrs
  {}
end

#deleteObject

Public: Delete this object form Adobe Connect.

Returns a boolean.



23
24
25
26
# File 'lib/adobe_connect/base.rb', line 23

def delete
  response = service.send(:"#{delete_method_prefix}_delete", {:"#{ac_obj_type}_id" => self.id})
  response.at_xpath('//status').attr('code') == 'ok'
end

#delete_method_prefixObject (private)



99
100
101
102
103
# File 'lib/adobe_connect/base.rb', line 99

def delete_method_prefix
  prefix = method_prefix
  prefix = prefix.pluralize if self.class.config[:delete_method_is_plural]
  prefix
end

#method_prefixObject (private)



105
106
107
# File 'lib/adobe_connect/base.rb', line 105

def method_prefix
  self.class.config[:ac_method_prefix] || ac_obj_type
end

#permissions_update(principal_id, permission_id) ⇒ Object

Public: Update permissions on the loaded object for the given principal_id.

principal_id - id of user permission_id - AdobeConnect permission value

Returns a boolean.



61
62
63
64
65
66
67
68
69
# File 'lib/adobe_connect/base.rb', line 61

def permissions_update(principal_id, permission_id)
  response = service.permissions_update(
    acl_id: self.id,
    principal_id: principal_id,
    permission_id: permission_id
  )

  response.at_xpath('//status').attr('code') == 'ok'
end

#saveObject

Public: Save this object to the Adobe Connect instance.

Returns a boolean.



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/adobe_connect/base.rb', line 31

def save
  response = service.send(:"#{method_prefix}_update", self.attrs)

  if response.at_xpath('//status').attr('code') == 'ok'
    # Load the ID if this was a creation
    self.id = response.at_xpath("//#{ac_obj_node_name}").attr("#{ac_obj_type}-id") if self.id.nil?
    true
  else
    save_errors(response)
    false
  end
end

#save_errors(response) ⇒ Object (private)

Internal: Store request errors in @errors.

response - An AdobeConnect::Response.

Returns nothing.



114
115
116
# File 'lib/adobe_connect/base.rb', line 114

def save_errors(response)
  @errors = response.xpath('//invalid').map(&:attributes)
end

#set_attrs(atrs) ⇒ Object (private)

Internal: Update attributes from an attribute hash

atrs - A hash of keys that match attributes of this object and

corresponding values for those attributes.

Returns nothing.



124
125
126
# File 'lib/adobe_connect/base.rb', line 124

def set_attrs(atrs)
  atrs.each { |key, value| send(:"#{key}=", value) }
end

#update_attributes(atrs) ⇒ Object

Public: Update attributes of the loaded object and save.

atrs - Generic options (see #initialize for required

attributes).

Returns a boolean.



50
51
52
53
# File 'lib/adobe_connect/base.rb', line 50

def update_attributes(atrs)
  set_attrs(atrs)
  self.save
end