adobe_connect_api 0.0.1.alpha

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in adobe_connect_api.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Christian Rohrer
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # AdobeConnectApi
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'adobe_connect_api'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install adobe_connect_api
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/adobe_connect_api/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Christian Rohrer"]
6
+ gem.email = ["christian.rohrer@switch.ch"]
7
+ gem.description = %q{Wrapper to the Adobe Connect API}
8
+ gem.summary = %q{Wrapper to the Adobe Connect API written in Ruby}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "adobe_connect_api"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = AdobeConnectApi::VERSION
17
+ end
@@ -0,0 +1,128 @@
1
+ # A filter defeinition can be added to some actions to filter the results
2
+ # server-side. Example:
3
+ # filter = AdobeConnectAPI::FilterDefinition.new
4
+ # filter["sco-id"].greater_than 25
5
+ # filter["date-created"] <= Time.now
6
+
7
+ class AdobeConnectApi::FilterDefinition
8
+ attr_accessor :rows
9
+ attr_accessor :start
10
+ attr_accessor :is_member
11
+
12
+ def initialize
13
+ @fields = Hash.new
14
+ end
15
+
16
+ def [](field_name)
17
+ field = @fields[field_name]
18
+ if field == nil
19
+ field = AdobeConnectApi::FilterDefinition::Field.new(field_name)
20
+ @fields[field_name] = field
21
+ end
22
+ return field
23
+ end
24
+
25
+ def query
26
+ string = ""
27
+
28
+ if @rows != nil
29
+ string += "&filter-rows=" + "#{@rows}"
30
+ end
31
+ if @start != nil
32
+ string += "&filter-start=" + "#{@start}"
33
+ end
34
+ if @is_member != nil
35
+ if @is_member
36
+ string += "&filter-is-member=true"
37
+ else
38
+ string += "&filter-is-member=false"
39
+ end
40
+ end
41
+
42
+ @fields.each_pair do |name, f|
43
+ string += f.query
44
+ end
45
+ return string
46
+ end
47
+
48
+ class Field
49
+ def matches (value)
50
+ @matches = value
51
+ end
52
+
53
+ def greater_than (value)
54
+ @greater_than = value
55
+ end
56
+
57
+ def lesser_than (value)
58
+ @lesser_than = value
59
+ end
60
+
61
+ def like (value)
62
+ @like = value
63
+ end
64
+
65
+ def greater_than_or_equals (value)
66
+ @greater_than_or_equals = value
67
+ end
68
+
69
+ def lesser_than_or_equals (value)
70
+ @lesser_than_or_equals = value
71
+ end
72
+
73
+ def excluding (value)
74
+ @excluding = value
75
+ end
76
+
77
+ def == (value)
78
+ @matches = value
79
+ end
80
+
81
+ def > (value)
82
+ @greater_than = value
83
+ end
84
+
85
+ def < (value)
86
+ @lesser_than = value
87
+ end
88
+
89
+ def >= (value)
90
+ @greater_than_or_equals = value
91
+ end
92
+
93
+ def <= (value)
94
+ @lesser_than_or_equals = value
95
+ end
96
+
97
+ def initialize (name)
98
+ @name = name
99
+ end
100
+
101
+ def query
102
+ query = ""
103
+ if @matches != nil
104
+ query += "&filter-" + @name + "=" + CGI.escape("#{@matches}")
105
+ end
106
+ if @greater_than != nil
107
+ query += "&filter-gt-" + @name + "=" + CGI.escape("#{@greater_than}")
108
+ end
109
+ if @lesser_than != nil
110
+ query += "&filter-lt-" + @name + "=" + CGI.escape("#{@lesser_than}")
111
+ end
112
+ if @like != nil
113
+ query += "&filter-like-" + @name + "=" + CGI.escape("#{@like}")
114
+ end
115
+ if @greater_than_or_equals != nil
116
+ query += "&filter-gte-" + @name + "=" + CGI.escape("#{@greater_than_or_equals}")
117
+ end
118
+ if @lesser_than_or_equals != nil
119
+ query += "&filter-lte-" + @name + "=" + CGI.escape("#{@lesser_than_or_equals}")
120
+ end
121
+ if @excluding != nil
122
+ query += "&filter-out-" + @name + "=" + CGI.escape("#{@excluding}")
123
+ end
124
+
125
+ return query
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,29 @@
1
+ #Result objects are returned by some of the convenience methods to make the
2
+ #resulting values more accessible. The status attribute returns the status/@code field
3
+ #and the rows attribute is an array of hashes with the values of the resulting
4
+ #rows (or quotas etc.)
5
+
6
+ class Result
7
+
8
+ attr_reader :status
9
+ attr_reader :rows
10
+
11
+ def initialize (status, rows)
12
+ @status = status
13
+ @rows = []
14
+ if rows != nil
15
+ rows.each do |row|
16
+ hash = {}
17
+ row.each_pair do |name, val|
18
+ if val.is_a?(Array)
19
+ hash[name] = val[0]
20
+ else
21
+ hash[name] = val
22
+ end
23
+ end
24
+ @rows.push hash
25
+ end
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,36 @@
1
+ #A SortDefinition can be used to sort the result server-side. It is not
2
+ #possible to sort according to more than two fields
3
+ #Example:
4
+ #sort = AdobeConnectAPI::SortDefinition.new
5
+ #sort.desc "date-created"
6
+ #sort.asc "sco-id"
7
+
8
+ class AdobeConnectApi::SortDefinition
9
+
10
+ def asc (field)
11
+ if @sort1 != nil
12
+ @sort1 = {"field" => field, "order" => "asc"}
13
+ elsif @sort2 != nil
14
+ @sort2 = {"field" => field, "order" => "asc"}
15
+ end
16
+ end
17
+
18
+ def desc (field)
19
+ if @sort1 != nil
20
+ @sort1 = {"field" => field, "order" => "desc"}
21
+ elsif @sort2 != nil
22
+ @sort2 = {"field" => field, "order" => "desc"}
23
+ end
24
+ end
25
+
26
+ def query
27
+ if (@sort1 != nil && @sort2 == nil)
28
+ return "&sort-#{@sort1[:field]}=#{@sort1[:direction]}"
29
+ elsif (@sort1 != nil && @sort2 != nil)
30
+ return "&sort1-#{@sort1[:field]}=#{@sort1[:direction]}&sort2-#{@sort2[:field]}=#{@sort2[:direction]}}"
31
+ else
32
+ return ""
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,3 @@
1
+ module AdobeConnectApi
2
+ VERSION = "0.0.1.alpha"
3
+ end
@@ -0,0 +1,252 @@
1
+
2
+ # Copyright (c) 2010 SWITCH - Serving Swiss Universities
3
+ # Author: Mischael Schill <me@mschill.ch>
4
+ # Martin Kos <martin@kos.li>
5
+ # Christian Rohrer <christian.rohrer@switch.ch>
6
+ # $Id$
7
+
8
+ require 'rubygems'
9
+ # require "net/http"
10
+ require "net/https"
11
+ require "uri"
12
+ require 'xmlsimple'
13
+ require "cgi"
14
+ #require 'logger'
15
+
16
+ require "adobe_connect_api/version"
17
+ require 'adobe_connect_api/filter_definition'
18
+ require 'adobe_connect_api/sort_definition'
19
+ require 'adobe_connect_api/result'
20
+
21
+
22
+ # This class is a simple utility to acces the adobe connect api. Before
23
+ # making any queries use the login-method
24
+ # There are dedicated methods for some of the actions of the api and a generic
25
+ # "query"-method for all the others.
26
+ # All the actions are defined in the Adobe Connect Pro API documentation
27
+ # some of the actions are accepting filter- and/or sorting-definitions.
28
+
29
+ # module AdobeConnectApi
30
+ class AdobeConnectAPI
31
+
32
+ attr :url
33
+ attr :pointconfig
34
+
35
+ #The URL is the base URL of the Connect-Server, without the trailing slash
36
+ def initialize (url = nil)
37
+ #TODO ChR: Get this from the application config/initializer/abobe_connect_api.rb
38
+ @pointconfig = YAML::load_file("#{Rails.root}/config/config.breeze.yml")[Rails.env]
39
+ if (url == nil)
40
+ @url = pointconfig["url"]
41
+ else
42
+ @url = url
43
+ end
44
+ end
45
+
46
+ #makes the login to the server
47
+ def login (login = nil, password = nil, account_id=nil, external_auth=nil, domain=nil)
48
+ if(login == nil)
49
+ login = pointconfig["username"]
50
+ end
51
+
52
+ if(password == nil)
53
+ password = pointconfig["password"]
54
+ end
55
+
56
+ res = query("login",
57
+ "login" => login,
58
+ "password" => password,
59
+ "account-id" => account_id,
60
+ "external-auth" => external_auth,
61
+ "domain" => domain)
62
+ cookies = res.response["set-cookie"]
63
+ cookies.split(";").each{|s|
64
+ array = s.split("=")
65
+ if array[0] == "BREEZESESSION"
66
+ @sessionid = array[1]
67
+ end
68
+ }
69
+ puts "ACS: Logged in"
70
+ return res.body
71
+ end
72
+
73
+ #makes a logout and removes the cookie
74
+ def logout
75
+ res = query("logout").body
76
+ @sessionid = nil
77
+ puts "ACS: Logged out"
78
+ return res
79
+ end
80
+
81
+ #Returns all defined quotas (untested)
82
+ def report_quotas
83
+ res = query("report-quota")
84
+ data = XmlSimple.xml_in(res.body)
85
+ rows = []
86
+ if data["report-quotas"]
87
+ data["report-quotas"].each do |trans|
88
+ rows = trans["quota"]
89
+ end
90
+ end
91
+ return AdobeConnectAPI::Result.new(data["status"][0]["code"], rows)
92
+ end
93
+
94
+ #returns all the session of a meeting as a result object
95
+ def report_meeting_sessions(meeting_id, filter = nil, sort = nil)
96
+ res = query("report-meeting-sessions", "sco-id" => meeting_id, "filter" => filter, "sort" => sort)
97
+ data = XmlSimple.xml_in(res.body)
98
+ rows = []
99
+ if data["report-meeting-sessions"]
100
+ data["report-meeting-sessions"].each do |trans|
101
+ rows = trans["row"]
102
+ end
103
+ end
104
+ return AdobeConnectAPI::Result.new(data["status"][0]["code"], rows)
105
+ end
106
+
107
+ #returns all groups
108
+ def report_groups(filter = nil, sort = nil)
109
+ puts "ACS: Query: Groups"
110
+ res = query("principal-list", "filter" => filter, "sort" => sort)
111
+ data = XmlSimple.xml_in(res.body)
112
+ groups = []
113
+ if data["principal-list"]
114
+ data["principal-list"].each do |trans|
115
+ groups = trans["principal"]
116
+ end
117
+ end
118
+ return AdobeConnectAPI::Result.new(data["status"][0]["code"], groups)
119
+
120
+ end
121
+
122
+ #returns all groups
123
+ def report_memberships(group_id, filter = nil, sort = nil)
124
+ puts "ACS: Query: Group Memberships"
125
+ res = query("principal-list", "group-id" => group_id, "filter" => filter, "sort" => sort)
126
+ data = XmlSimple.xml_in(res.body)
127
+ members = []
128
+ if data["principal-list"]
129
+ data["principal-list"].each do |trans|
130
+ members = trans["principal"]
131
+ end
132
+ end
133
+ return AdobeConnectAPI::Result.new(data["status"][0]["code"], members)
134
+
135
+ end
136
+
137
+ #returns SCO contents of sco-id
138
+ def sco_contents(sco_id, filter = nil, sort = nil)
139
+ res = query("sco-contents", "sco-id" => sco_id, "filter" => filter, "sort" => sort)
140
+ data = XmlSimple.xml_in(res.body)
141
+ scos = []
142
+ # puts YAML::dump(data)
143
+ if data["scos"]
144
+ data["scos"].each do |trans|
145
+ # puts YAML::dump(trans)
146
+ # puts "-------"
147
+ scos = trans["sco"]
148
+ end
149
+ end
150
+ return AdobeConnectAPI::Result.new(data["status"][0]["code"], scos)
151
+ end
152
+
153
+ #returns SCO information of sco-id
154
+ def sco_info(sco_id)
155
+ res = query("sco-info", "sco-id" => sco_id)
156
+ data = XmlSimple.xml_in(res.body)
157
+ if data["sco"][0]
158
+ return data["sco"][0]
159
+ end
160
+ end
161
+
162
+ #returns permission information of an sco-id
163
+ def permissions_info(sco_id, filter = nil)
164
+ res = query("permissions-info", "acl-id" => sco_id, "filter" => filter)
165
+ data = XmlSimple.xml_in(res.body)
166
+ puts YAML::dump(data)
167
+ # if data["sco"][0]
168
+ # return data["sco"][0]
169
+ # end
170
+ end
171
+
172
+
173
+ #returns all SCOs as a result object
174
+ def report_bulk_objects(filter = nil, sort = nil)
175
+ res = query("report-bulk-objects", "filter" => filter, "sort" => sort)
176
+ data = XmlSimple.xml_in(res.body)
177
+ rows = []
178
+ if data["report-bulk-objects"]
179
+ data["report-bulk-objects"].each do |trans|
180
+ rows = trans["row"]
181
+ end
182
+ end
183
+ return AdobeConnectAPI::Result.new(data["status"][0]["code"], rows)
184
+ end
185
+
186
+ #returns all users as a result object
187
+ def report_bulk_users(custom_fields = false, filter = nil, sort = nil)
188
+ res = query("report-bulk-users", "custom-fields" => custom_fields, "filter" => filter, "sort" => sort)
189
+ data = XmlSimple.xml_in(res.body)
190
+ rows = []
191
+ if data["report-bulk-users"]
192
+ data["report-bulk-users"].each do |trans|
193
+ rows = trans["row"]
194
+ end
195
+ end
196
+ return AdobeConnectAPI::Result.new(data["status"][0]["code"], rows)
197
+ end
198
+
199
+ #returns all transactions as a result object
200
+ def report_bulk_consolidated_transactions(filter = nil, sort = nil)
201
+ res = query("report-bulk-consolidated-transactions", "filter" => filter, "sort" => sort)
202
+ data = XmlSimple.xml_in(res.body)
203
+ rows = []
204
+ if data["report-bulk-consolidated-transactions"]
205
+ data["report-bulk-consolidated-transactions"].each do |trans|
206
+ rows = trans["row"]
207
+ end
208
+ end
209
+ return AdobeConnectAPI::Result.new(data["status"][0]["code"], rows)
210
+ end
211
+
212
+ #sends a query to the server and returns the http response. Parameters,
213
+ #filter- and sort-definitions can be added. The filter as "filter" => ... and
214
+ #the sort as "sort" => ...
215
+ def query(action, hash = {})
216
+ # uri = URI.parse("https://130.59.10.31")
217
+ # http = Net::HTTP.new(uri.host, uri.port)
218
+ # http.use_ssl = true
219
+ # http.verify_mode = OpenSSL::SSL::VERIFY_NONE
220
+ #
221
+ # request = Net::HTTP::Get.new(uri.request_uri)
222
+ #
223
+ # response = http.request(request)
224
+ # response.body
225
+ # response.status
226
+ # response["header-here"] # All headers are lowercase
227
+ uri = URI.parse(@url + "/api/xml?action=#{action}")
228
+ hash.each_pair do |key, val|
229
+ if val
230
+ if key == "filter" or key == "sort"
231
+ uri.query += val.query
232
+ else
233
+ uri.query += "&" + key + "=" + CGI::escape("#{val}")
234
+ end
235
+ end
236
+ end
237
+ http = Net::HTTP.new(uri.host, uri.port)
238
+ if uri.scheme == "https"
239
+ http.use_ssl=true
240
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
241
+ end
242
+ request = Net::HTTP::Get.new(uri.request_uri)
243
+ # logger = Logger.new('log/development.log')
244
+ # logger.info(url.path + "?" + url.query)
245
+ if @sessionid
246
+ request.add_field("Cookie", "BREEZESESSION="+@sessionid)
247
+ end
248
+ response = http.request(request)
249
+ return response
250
+ end
251
+
252
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: adobe_connect_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Christian Rohrer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-03 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Wrapper to the Adobe Connect API
15
+ email:
16
+ - christian.rohrer@switch.ch
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - adobe_connect_api.gemspec
27
+ - lib/adobe_connect_api.rb
28
+ - lib/adobe_connect_api/filter_definition.rb
29
+ - lib/adobe_connect_api/result.rb
30
+ - lib/adobe_connect_api/sort_definition.rb
31
+ - lib/adobe_connect_api/version.rb
32
+ homepage: ''
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ segments:
45
+ - 0
46
+ hash: 2391563684590532941
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>'
51
+ - !ruby/object:Gem::Version
52
+ version: 1.3.1
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 1.8.24
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: Wrapper to the Adobe Connect API written in Ruby
59
+ test_files: []