adobe_connect 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/adobe_connect.gemspec +1 -1
  3. data/lib/adobe_connect.rb +5 -0
  4. data/lib/adobe_connect/acl_field.rb +60 -0
  5. data/lib/adobe_connect/base.rb +128 -0
  6. data/lib/adobe_connect/group.rb +91 -0
  7. data/lib/adobe_connect/meeting.rb +99 -0
  8. data/lib/adobe_connect/meeting_folder.rb +12 -0
  9. data/lib/adobe_connect/param_formatter.rb +6 -0
  10. data/lib/adobe_connect/response.rb +5 -19
  11. data/lib/adobe_connect/service.rb +1 -1
  12. data/lib/adobe_connect/telephony_profile.rb +87 -0
  13. data/lib/adobe_connect/user.rb +21 -55
  14. data/lib/adobe_connect/version.rb +1 -1
  15. data/test/fixtures/acl_field_save_error.xml +6 -0
  16. data/test/fixtures/acl_field_save_success.xml +7 -0
  17. data/test/fixtures/acl_field_update_success.xml +7 -0
  18. data/test/fixtures/{log_in_success.xml → generic_success.xml} +0 -0
  19. data/test/fixtures/group_is_member.xml +13 -0
  20. data/test/fixtures/group_is_not_member.xml +5 -0
  21. data/test/fixtures/group_save_error.xml +6 -0
  22. data/test/fixtures/group_save_success.xml +9 -0
  23. data/test/fixtures/group_update_success.xml +9 -0
  24. data/test/fixtures/meeting_find_by_id_error.xml +4 -0
  25. data/test/fixtures/meeting_find_by_id_success.xml +16 -0
  26. data/test/fixtures/meeting_save_error.xml +6 -0
  27. data/test/fixtures/meeting_save_success.xml +11 -0
  28. data/test/fixtures/meeting_update_success.xml +11 -0
  29. data/test/fixtures/telephony_profile_info_success.xml +13 -0
  30. data/test/fixtures/telephony_profile_list_success.xml +16 -0
  31. data/test/fixtures/telephony_profile_save_error.xml +6 -0
  32. data/test/fixtures/telephony_profile_save_success.xml +7 -0
  33. data/test/fixtures/telephony_profile_update_success.xml +7 -0
  34. data/test/fixtures/user_update_success.xml +4 -0
  35. data/test/lib/adobe_connect/acl_field_test.rb +39 -0
  36. data/test/lib/adobe_connect/adobe_connect_base_tests.rb +121 -0
  37. data/test/lib/adobe_connect/config_test.rb +1 -1
  38. data/test/lib/adobe_connect/group_test.rb +77 -0
  39. data/test/lib/adobe_connect/meeting_folder_test.rb +3 -7
  40. data/test/lib/adobe_connect/meeting_test.rb +117 -0
  41. data/test/lib/adobe_connect/param_formatter_test.rb +1 -1
  42. data/test/lib/adobe_connect/response_test.rb +1 -1
  43. data/test/lib/adobe_connect/service_test.rb +5 -8
  44. data/test/lib/adobe_connect/telephony_profile_test.rb +41 -0
  45. data/test/lib/adobe_connect/user_test.rb +29 -84
  46. data/test/test_helper.rb +16 -0
  47. metadata +87 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc223a736c0e1ffd1752dabb467d5bac287c6bff
4
- data.tar.gz: d97e1dc9f21b30ff133c97f50ea8afecb13d9e81
3
+ metadata.gz: ae95eaae6a338ddf57dc714ddffe464d202deab6
4
+ data.tar.gz: 19d53983d307144139b25ae5e803f05949499f47
5
5
  SHA512:
6
- metadata.gz: b4c3da73e805853355f007365e74336080d4ed46122d8c6884b3563222cbf8e21550c46aabd1d644d04a1ab2f8475eb561825aafe45272957f511e7f885118b8
7
- data.tar.gz: d476b8460774e4ac7546dce81cec16fea8c5c19776af0c433962d60ac9e1d4c123369e0abedd03d88e41fe0b5805fea86e0b72f63caa84fa024245fcc17a0363
6
+ metadata.gz: 3c89efd518cec436b43bc20ad90237ba562c6534fe5be57452adb8be03b056f75b5007aaad47e5b7ae625080ddb5081a66604f85609a1fd387fdf586c9ea9182
7
+ data.tar.gz: 1eef97ab37e4c0edddcfce8b2f65aad63b6bb9be3434be798e1acdb558545489acd80b26494f744ceca1b81fea854e0be16223741a9020d5806f148468485df9
@@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
19
19
  gem.require_paths = ['lib']
20
20
 
21
21
  gem.add_dependency 'activesupport', '>= 2.3.17'
22
- gem.add_dependency 'nokogiri', '~> 1.5.5'
22
+ gem.add_dependency 'nokogiri', '>= 1.5.5', '< 1.7'
23
23
  gem.add_dependency 'rake', '>= 0.9.2'
24
24
 
25
25
  gem.add_development_dependency 'minitest', '~> 4.6.0'
data/lib/adobe_connect.rb CHANGED
@@ -7,7 +7,12 @@ require 'adobe_connect/config'
7
7
  require 'adobe_connect/response'
8
8
  require 'adobe_connect/service'
9
9
  require 'adobe_connect/param_formatter'
10
+ require 'adobe_connect/base'
11
+ require 'adobe_connect/acl_field'
12
+ require 'adobe_connect/group'
13
+ require 'adobe_connect/meeting'
10
14
  require 'adobe_connect/meeting_folder'
15
+ require 'adobe_connect/telephony_profile'
11
16
  require 'adobe_connect/user'
12
17
 
13
18
  # Public: Namespace for AdobeConnect classes/modules.
@@ -0,0 +1,60 @@
1
+ module AdobeConnect
2
+
3
+ # Public: Represents a Custom Field object inside of Connect.
4
+ class AclField < Base
5
+ attr_accessor :name, :obj_type, :id, :service
6
+
7
+ #
8
+ # id - The Field-ID of the custom field object.
9
+ # name - The name of the Field.
10
+ # obj_type- The type of Connect Object this applies to. Allowed values
11
+ # are: principal, meeting, sco, event, read-only
12
+ #
13
+ def attrs
14
+ atrs = {
15
+ :object_type => "object-type-#{obj_type}", :permission_id => 'manage',
16
+ :name => name, :field_type => 'text', :is_required => false,
17
+ :is_primary => true
18
+ }
19
+
20
+ if !id.nil?
21
+ atrs.merge!(:field_id => id)
22
+ end
23
+
24
+ atrs
25
+ end
26
+
27
+ def self.config
28
+ super.merge({ :ac_obj_type => 'field', :ac_method_prefix => 'custom_field' })
29
+ end
30
+
31
+ # Public: Find a folder on the current Connect instance.
32
+ #
33
+ # name, obj_type, service - see #attrs for description
34
+ #
35
+ # Returns a new AdobeConnect::AclField object.
36
+ def self.find_or_create(name, obj_type, service = AdobeConnect::Service.new)
37
+ response = service.custom_fields(:filter_name => name)
38
+ c_flds = response.at_xpath('//custom-fields').children
39
+
40
+ if c_flds.count.zero?
41
+ #Create
42
+ fld = self.new({ :name => name, :obj_type => obj_type }, service)
43
+ fld.save
44
+ else
45
+ fld = load_from_xml(c_flds[0])
46
+ end
47
+
48
+ fld
49
+ end
50
+
51
+ private
52
+ def self.load_from_xml(ac_field, service)
53
+ self.new({
54
+ :id => ac_field.attr('field-id'),
55
+ :name => ac_field.at_xpath('//name').text,
56
+ :obj_type => ac_field.attr('obj_type')
57
+ }, service)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,128 @@
1
+ module AdobeConnect
2
+
3
+ # Provides base interaction with Adobe Connect for a variety of AC Objects
4
+ class Base
5
+ # Public: SCO-ID from the Adobe Connect instance.
6
+ attr_reader :id
7
+
8
+ attr_reader :service, :errors
9
+
10
+ def initialize(obj_options, service = Service.new)
11
+ set_attrs(obj_options)
12
+ @service = service
13
+ @errors = []
14
+ end
15
+
16
+ def attrs
17
+ {}
18
+ end
19
+
20
+ # Public: Delete this object form Adobe Connect.
21
+ #
22
+ # Returns a boolean.
23
+ def delete
24
+ response = service.send(:"#{delete_method_prefix}_delete", {:"#{ac_obj_type}_id" => self.id})
25
+ response.at_xpath('//status').attr('code') == 'ok'
26
+ end
27
+
28
+ # Public: Save this object to the Adobe Connect instance.
29
+ #
30
+ # Returns a boolean.
31
+ def save
32
+ response = service.send(:"#{method_prefix}_update", self.attrs)
33
+
34
+ if response.at_xpath('//status').attr('code') == 'ok'
35
+ # Load the ID if this was a creation
36
+ self.id = response.at_xpath("//#{ac_obj_node_name}").attr("#{ac_obj_type}-id") if self.id.nil?
37
+ true
38
+ else
39
+ save_errors(response)
40
+ false
41
+ end
42
+ end
43
+
44
+ # Public: Update attributes of the loaded object and save.
45
+ #
46
+ # atrs - Generic options (see #initialize for required
47
+ # attributes).
48
+ #
49
+ # Returns a boolean.
50
+ def update_attributes(atrs)
51
+ set_attrs(atrs)
52
+ self.save
53
+ end
54
+
55
+ # Public: Update permissions on the loaded object for the given principal_id.
56
+ #
57
+ # principal_id - id of user
58
+ # permission_id - AdobeConnect permission value
59
+ #
60
+ # Returns a boolean.
61
+ def permissions_update(principal_id, permission_id)
62
+ response = service.permissions_update(
63
+ acl_id: self.id,
64
+ principal_id: principal_id,
65
+ permission_id: permission_id
66
+ )
67
+
68
+ response.at_xpath('//status').attr('code') == 'ok'
69
+ end
70
+
71
+ # Public: Create a Connect obj from the given app obj.
72
+ #
73
+ # obj_options - Generic options (see #initialize for required
74
+ # attributes).
75
+ #
76
+ # Returns an instance of this class, with an attempted save.
77
+ def self.create(obj_options)
78
+ obj = self.new(obj_options)
79
+ obj.save
80
+
81
+ obj
82
+ end
83
+
84
+ def self.config
85
+ { :ac_obj_type => 'principal', :delete_method_is_plural => true }
86
+ end
87
+
88
+ private
89
+ attr_writer :id
90
+
91
+ def ac_obj_node_name
92
+ self.class.config[:ac_obj_node_name] || ac_obj_type
93
+ end
94
+
95
+ def ac_obj_type
96
+ self.class.config[:ac_obj_type]
97
+ end
98
+
99
+ def delete_method_prefix
100
+ prefix = method_prefix
101
+ prefix = prefix.pluralize if self.class.config[:delete_method_is_plural]
102
+ prefix
103
+ end
104
+
105
+ def method_prefix
106
+ self.class.config[:ac_method_prefix] || ac_obj_type
107
+ end
108
+
109
+ # Internal: Store request errors in @errors.
110
+ #
111
+ # response - An AdobeConnect::Response.
112
+ #
113
+ # Returns nothing.
114
+ def save_errors(response)
115
+ @errors = response.xpath('//invalid').map(&:attributes)
116
+ end
117
+
118
+ # Internal: Update attributes from an attribute hash
119
+ #
120
+ # atrs - A hash of keys that match attributes of this object and
121
+ # corresponding values for those attributes.
122
+ #
123
+ # Returns nothing.
124
+ def set_attrs(atrs)
125
+ atrs.each { |key, value| send(:"#{key}=", value) }
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,91 @@
1
+ module AdobeConnect
2
+
3
+ # Public: Represents a Group in a Connect environment.
4
+ class Group < Base
5
+ attr_accessor :description, :name, :id
6
+
7
+ #
8
+ # group_options - A hash with the following keys:
9
+ # name - The group’s name.
10
+ # description - The group's description
11
+ #
12
+
13
+ def attrs
14
+ atrs = { :has_children => 1, :name => name, :description => description }
15
+
16
+ if !self.id.nil?
17
+ atrs.merge!(:principal_id => self.id)
18
+ else
19
+ atrs.merge!(
20
+ :type => 'group'
21
+ )
22
+ end
23
+ atrs
24
+ end
25
+
26
+ # Public: Add a User as a member of this group.
27
+ #
28
+ # user - AdobeConnect::User instance
29
+ #
30
+ # Returns a boolean of success.
31
+ def add_member(user)
32
+ update_membership(user, true)
33
+ end
34
+
35
+ # Public: Find the member of this group.
36
+ #
37
+ # email - User's email address
38
+ #
39
+ # Returns a boolean.
40
+ def is_member?(email)
41
+ return false if self.id.nil?
42
+
43
+ response = service.principal_list(:group_id => self.id,
44
+ :filter_email => email,
45
+ :filter_is_member => true)
46
+
47
+ !response.at_xpath('//principal').nil?
48
+ end
49
+
50
+ # Public: Remove a User from this group.
51
+ #
52
+ # user - AdobeConnect::User instance
53
+ #
54
+ # Returns a boolean of success.
55
+ def remove_member(user)
56
+ update_membership(user, false)
57
+ end
58
+
59
+ # Public: Find the given group on the Connect server.
60
+ #
61
+ # name - Group's name on Connect server
62
+ #
63
+ # Returns an AdobeConnect::Group or nil.
64
+ def self.find_by_name(name, service = AdobeConnect::Service.new)
65
+ response = service.principal_list(:filter_name => name)
66
+
67
+ if principal = response.at_xpath('//principal')
68
+ self.load_from_xml(principal)
69
+ end
70
+ end
71
+
72
+ private
73
+ def update_membership(user, status)
74
+ response = service.group_membership_update({
75
+ :group_id => self.id,
76
+ :principal_id => user.id,
77
+ :is_member => status
78
+ })
79
+
80
+ response.at_xpath('//status').attr('code') == 'ok'
81
+ end
82
+
83
+ def self.load_from_xml(g)
84
+ self.new({
85
+ :name => g.at_xpath('//name').children.text,
86
+ :description => g.at_xpath('//description').try(:children).try(:text),
87
+ :id => g.attr('principal-id')
88
+ })
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,99 @@
1
+ module AdobeConnect
2
+
3
+ # Public: Represents a meeting in a Connect environment.
4
+ class Meeting < Base
5
+ attr_accessor :date_begin, :date_end, :description, :folder_id, :name, :url_path
6
+
7
+ #
8
+ # meeting_options - A hash with the following keys:
9
+ # date_begin - (optional) Datetime that meeting begins.
10
+ # date_end - (optional) Datetime that meeting ends.
11
+ # description - A description of the meeting to be displayed to users.
12
+ # folder_id - (Required for creating) ID of the meeting folder
13
+ # name - Name of the meeting
14
+ # url_path - (optional) Custom url for meeting. One will be generated
15
+ # by AC if not provided
16
+ #
17
+ def attrs
18
+ atrs = {:type => 'meeting'}
19
+
20
+ [ :date_end, :date_begin, :description, :name, :url_path ].each do |atr|
21
+ atrs[atr] = send(atr)
22
+ end
23
+
24
+ if !self.id.nil?
25
+ atrs.merge!(:sco_id => self.id)
26
+ else
27
+ atrs.merge!(:folder_id => folder_id)
28
+ end
29
+
30
+ atrs
31
+ end
32
+
33
+ def add_host(principal_id)
34
+ permissions_update(principal_id, 'host')
35
+ end
36
+
37
+ def add_presenter(principal_id)
38
+ permissions_update(principal_id, 'mini-host')
39
+ end
40
+
41
+ def add_participant(principal_id)
42
+ permissions_update(principal_id, 'view')
43
+ end
44
+
45
+ def remove_user(principal_id)
46
+ permissions_update(principal_id, 'remove')
47
+ end
48
+
49
+ def self.config
50
+ super.merge({ :ac_obj_type => 'sco', :delete_method_is_plural => false })
51
+ end
52
+
53
+ def self.find_by_id(sco_id, service = AdobeConnect::Service.new)
54
+ response = service.sco_info(sco_id: sco_id)
55
+ sco_info = response.at_xpath('//sco')
56
+
57
+ if !sco_info.nil?
58
+ load_from_xml(sco_info, service)
59
+ else
60
+ nil
61
+ end
62
+ end
63
+
64
+ def self.find_by_url_path(url_path, service = AdobeConnect::Service.new)
65
+ response = service.sco_by_url(:url_path => url_path)
66
+
67
+ ac_meeting = response.at_xpath('//sco')
68
+
69
+ if !ac_meeting.nil?
70
+ load_from_xml(ac_meeting, service)
71
+ else
72
+ nil
73
+ end
74
+ end
75
+
76
+ def self.find_within_folder(folder_id, params = {}, service = AdobeConnect::Service.new)
77
+ response = service.sco_contents( params.merge(:sco_id => folder_id, :type => 'meeting') )
78
+ ac_meetings = response.at_xpath('//scos')
79
+ meetings = ac_meetings.children.map{|m| load_from_xml(m, service) }
80
+ end
81
+
82
+ private
83
+ def self.load_from_xml(ac_meeting, service)
84
+ meeting = self.new({}, service)
85
+
86
+ meeting.attrs.each do |atr,v|
87
+ chld = ac_meeting.children.select{|c| c.name == atr.to_s.dasherize}[0]
88
+ if !chld.nil?
89
+ meeting.send(:"#{atr}=", chld.text)
90
+ end
91
+ end
92
+
93
+ meeting.folder_id = ac_meeting.attr('folder-id')
94
+ meeting.instance_variable_set(:@id, ac_meeting.attr('sco-id'))
95
+
96
+ meeting
97
+ end
98
+ end
99
+ end
@@ -41,5 +41,17 @@ module AdobeConnect
41
41
  response.at_xpath('//url-path').text,
42
42
  service)
43
43
  end
44
+
45
+ # Public: Find the "My Meetings" folder ID of the currently logged in User
46
+ #
47
+ # service - An AdobeConnect::Service object (default: Service.new).
48
+ #
49
+ # Returns a string of the sco ID of the folder
50
+ def self.my_meetings_folder_id(service = AdobeConnect::Service.new)
51
+ response = service.sco_shortcuts({})
52
+ response.at_xpath('//shortcuts').children.select{|s|
53
+ s.attr('type') == 'my-meetings'
54
+ }[0].attr('sco-id')
55
+ end
44
56
  end
45
57
  end
@@ -17,9 +17,15 @@ module AdobeConnect
17
17
  # Returns a query string.
18
18
  def format
19
19
  params.sort_by { |k, v| k.to_s }.inject(['']) do |array, param|
20
+ param[1] = format_datetime(param[1]) if param[1].respond_to?(:strftime)
20
21
  key, value = param.map { |p| ERB::Util.url_encode(p) }
21
22
  array << "#{key.dasherize}=#{value}"
22
23
  end.join('&')
23
24
  end
25
+
26
+ private
27
+ def format_datetime(dt)
28
+ dt.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
29
+ end
24
30
  end
25
31
  end