innowhite_api 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.rdoc +185 -0
  2. data/Rakefile +14 -0
  3. data/innowhite.gemspec +32 -0
  4. data/lib/innowhite.rb +183 -0
  5. metadata +124 -0
data/README.rdoc ADDED
@@ -0,0 +1,185 @@
1
+ Getting Started
2
+
3
+ Step 1:
4
+ Install innowhite gem with RubyGems
5
+
6
+ gem install innowhite
7
+ or add this to your Gemfile if you use Bundler:
8
+ gem "innowhite"
9
+
10
+ Step 2:
11
+ Place the innowhite.yml file in the config directory.
12
+ This file will be sent to you by email.
13
+
14
+
15
+ In the code :
16
+ we need to initialize the Innowhite class
17
+ innowhite = Innowhite.new
18
+
19
+
20
+ Available Command Requests
21
+ Then we could access the available methods from the instance :
22
+
23
+ Create new session :
24
+ Create new room and get its room url to access it.
25
+
26
+ Arguments (as a Hash) :
27
+ a. :user => the name of the moderator (ex. "John")
28
+ b. :tags => (optional). Example : (math 101, calculus, integration)
29
+ c. :desc => (optional) Description of the room. (ex: Definite Integrals by John)
30
+
31
+ Request Command :
32
+ innowhite.create_room({}). Ex : innowhite.create_room({:user => "bainur", :tags => "testing, room testing", :desc => "This is only testing for the room"})
33
+
34
+ Return value :
35
+ a. Room Id
36
+ b. URL (this URL will be passed to user so that he needs to be redirected to open in new page.)
37
+
38
+
39
+
40
+
41
+ Join an existing session
42
+ Joining the existing room and get its room url to access it.
43
+
44
+ Arguments :
45
+ a. room_id => (mandatory) The room id which want to join.
46
+ b. username => (mandatory) Username of the user who want to join the room.
47
+
48
+ Request Command :
49
+ innowhite.join_meeting(room_id, username). Ex : innowhite.join_meeting(12345, "bainur")
50
+
51
+ Return value :
52
+ a. URL (this URL will be passed to the user, the user needs to be redirected to open in new page.)
53
+
54
+
55
+
56
+
57
+
58
+ Get the live sessions
59
+ Get the list of existing sessions.
60
+
61
+ Arguments (as a Hash) :
62
+ a. :tags (optional)
63
+ b. :user (optional)
64
+
65
+ Request Command :
66
+ innowhite.get_sessions({})
67
+
68
+ Return value :
69
+ a. RoomId
70
+ b. Room Description
71
+ c. All tags associated with this room.
72
+ d. Room Created by.
73
+ e. Room start time.
74
+
75
+
76
+
77
+
78
+
79
+ Schedule a session :
80
+ Scheduling new session.
81
+
82
+ Arguments (as a Hash) :
83
+ a. :tags (optional)
84
+ b. :startTime (format should be in seconds)
85
+ c. :timeZone (GMT time zone ) (ex : +1, +2)
86
+ d. :endTime (format should be in seconds)
87
+ e. :user
88
+ f. :description
89
+
90
+ Request Command :
91
+ innowhite.schedule_meeting({})
92
+
93
+ Return Value :
94
+ a. True or False
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+ Get the past sessions
103
+ Get the list of past sessions.
104
+
105
+ Arguments (as a Hash) :
106
+ a. :tags (optional)
107
+ b. :user (optional)
108
+
109
+ Request Command :
110
+ innowhite.past_sessions({})
111
+
112
+
113
+ Return Value :
114
+ a. tags (optional)
115
+ b. orgName (optional)
116
+ c. Moderator Name
117
+ d. Room Description
118
+ e. Link to play the video.
119
+
120
+
121
+
122
+
123
+ Get the scheduled sessions
124
+ Get the list of scheduled sessions.
125
+
126
+ Arguments (as a Hash) :
127
+ a. :tags (optional)
128
+ b. :user (optional)
129
+
130
+ Request Command :
131
+ innowhite.get_scheduled_list({})
132
+
133
+ Return Value:
134
+ a. Tags (optional)
135
+ b. orgName (optional)
136
+ c. Start time (format should be in seconds)
137
+ d. Time zone (GMT time zone ) (ex : +1, +2)
138
+ e. End time (format should be in seconds)
139
+ f. Room Description
140
+ g. Moderator name
141
+
142
+
143
+ Cancel scheduled session
144
+ Cancel the scheduled session.
145
+
146
+ Arguments :
147
+ a. room_id (mandatory)
148
+
149
+ Request Command :
150
+ innowhite.cancel_meeting(room_id)
151
+
152
+ Return Value:
153
+ a. True or False
154
+
155
+
156
+
157
+ Update a scheduled session :
158
+ Updating the exist scheduled session.
159
+
160
+ Arguments (as a Hash) :
161
+ a. :room_id (mandatory)
162
+ b. :startTime (format should be in milliseconds) (optional)
163
+ c. :timeZone (optional)
164
+ d. :endTime (format should be in milliseconds) (optional)
165
+ e. :description (optional)
166
+ f. :tags (optional)
167
+
168
+ Request Command :
169
+ innowhite.update_schedule({})
170
+
171
+ Return Value :
172
+ a. True or False
173
+
174
+
175
+
176
+ Get Meeting Play back Recording URL :
177
+ Returns the video playback URL.
178
+
179
+ a. :room_id (mandatory)
180
+
181
+ Request Command :
182
+ innowhite.getRecordingURL({})
183
+
184
+ Return Value :
185
+ a. URL
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('innowhite', '0.1.0') do |p|
6
+ p.description = "Innowhite Api"
7
+ p.url = "http://github.com/bainur/innowhite"
8
+ p.author = "bainur"
9
+ p.email = "inoe.bainur@gmail.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = []
12
+ end
13
+
14
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
data/innowhite.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{innowhite_api}
5
+ s.version = "1.1.3"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = [%q{innowhite}]
9
+ s.date = %q{2011-08-11}
10
+ s.description = %q{Innowhite Api}
11
+ s.email = %q{dhiraj.peechara@innowhite.com}
12
+ s.extra_rdoc_files = [%q{README.rdoc}, %q{lib/innowhite.rb}]
13
+ s.files = [%q{README.rdoc}, %q{Rakefile}, %q{lib/innowhite.rb}, %q{innowhite.gemspec}]
14
+ s.homepage = %q{http://github.com/firemonk9/innowhite}
15
+ s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Innowhite}, %q{--main}, %q{README.rdoc}]
16
+ s.require_paths = [%q{lib}]
17
+ s.rubyforge_project = %q{innowhite_api}
18
+ s.rubygems_version = %q{1.8.6}
19
+ s.summary = %q{Gem for Innowhite Api}
20
+ s.add_dependency 'nokogiri', '~> 1.4.4'
21
+ s.add_dependency 'rest-client', '~> 1.6.7'
22
+ s.add_development_dependency "rspec", "~> 1.3.4"
23
+
24
+ if s.respond_to? :specification_version then
25
+ s.specification_version = 3
26
+
27
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
28
+ else
29
+ end
30
+ else
31
+ end
32
+ end
data/lib/innowhite.rb ADDED
@@ -0,0 +1,183 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+ require 'rest-client'
4
+
5
+ class Innowhite
6
+
7
+ attr_accessor :mod_name, :org_name, :sub, :server_address, :private_key
8
+
9
+ def initialize
10
+ load_settings
11
+ end
12
+
13
+ def create_room(params = {})
14
+ room_id = get_room_id
15
+ address = join_room_url(@org_name, room_id, params[:user], true)
16
+ res = create_room_info(room_id, params[:user], params[:tags], params[:desc], @org_name, address)
17
+ res.include?("Missing") ? {"errors" => "Failed to fetch, maybe you have entered wrong username / organization name .."} : {"room_id" => room_id, "address" => address}
18
+ end
19
+
20
+ def join_meeting(room_id, user)
21
+ url = "#{@api_address}exist_session?roomId=#{room_id}"
22
+ doc = Nokogiri::XML(open(url))
23
+ doc.text.blank? ? nil : join_room_url(@org_name, room_id, user, false)
24
+ end
25
+
26
+ def get_sessions(params = {})
27
+ temp = url_generator(params[:parentOrg] || @parent_org, params[:orgName] || @org_name)
28
+ checksum = generating_checksum(URI.escape(temp))
29
+ tmp = "#{temp}&user=#{params[:user]}&tags=#{params[:tags]}"
30
+ url = URI.escape("#{@api_address}list_sessions?#{tmp}&checksum=#{checksum}")
31
+ JSON::parse(RestClient.get(url, :accept => :json))
32
+
33
+ rescue
34
+ {"errors" => "Error fetching sessions check the organization and private key .."}
35
+ end
36
+
37
+ def schedule_meeting(params = {})
38
+ room_id = get_room_id
39
+ address = join_room_url(
40
+ params[:orgName] || @org_name,
41
+ room_id,
42
+ params[:user],
43
+ true)
44
+
45
+ create_schedule(
46
+ room_id,
47
+ params[:user],
48
+ params[:tags],
49
+ params[:description],
50
+ params[:parentOrg] || @parent_org,
51
+ address,
52
+ params[:startTime],
53
+ params[:endTime],
54
+ params[:timeZone]) == "true"
55
+ end
56
+
57
+ def past_sessions(params = {})
58
+ temp = url_generator(params[:parentOrg] || @parent_org, params[:orgName] || @org_name)
59
+ checksum = generating_checksum(URI.escape(temp))
60
+
61
+ tmp = "#{temp}&user=#{params[:user]}&tags=#{params[:tags]}"
62
+ url = URI.escape("#{@api_address}past_sessions?#{tmp}&checksum=#{checksum}")
63
+ JSON::parse(RestClient.get(url, :accept => :json))
64
+
65
+ rescue
66
+ { "errors" => "Error fetching sessions check the organization and private key .." }
67
+ end
68
+
69
+ def get_scheduled_list(params={})
70
+ checksum = main_cheksum(params[:parentOrg] || @parent_org, params[:orgName] || @org_name)
71
+ par = url_generator(params[:parentOrg] || @parent_org, params[:orgName] || @org_name)
72
+ url = URI.escape("#{@api_address}get_scheduled_sessions?#{par}&checksum=#{checksum}&tags=#{params[:tags]}}")
73
+ JSON::parse(RestClient.get(url, :accept => :json))
74
+ end
75
+
76
+ def cancel_meeting(room_id)
77
+ checksum = main_cheksum(@parent_org, @org_name)
78
+ par = url_generator(@parent_org, @org_name)
79
+ url = URI.escape("#{@api_address}cancel_meeting?roomId=#{room_id}&#{par}&checksum=#{checksum}")
80
+ Nokogiri::XML(open(url)).xpath("//success").text == "true"
81
+ end
82
+
83
+ def update_schedule(params = {})
84
+ checksum = main_cheksum(@parent_org, @org_name)
85
+ params[:startTime] = params[:startTime].to_i if !params[:startTime].blank? && (params[:startTime].is_a?(DateTime) || params[:startTime].is_a?(Time))
86
+ params[:endTime] = params[:endTime].to_i if !params[:endTime].blank? && (params[:endTime].is_a?(DateTime) || params[:endTime].is_a?(Time))
87
+
88
+ Nokogiri::XML(RestClient.put("#{@api_address}update_schedule",
89
+ {:roomId => params[:room_id], :tags => params[:tags], :description => params[:description],
90
+ :parentOrg => @parent_org, :orgName => @org_name,
91
+ :checksum => checksum, :startTime => params[:startTime],
92
+ :endTime => params[:endTime], :timeZone => params[:timeZone]
93
+ }
94
+ )).xpath("//success").text == "true"
95
+ end
96
+
97
+ def getRecordingURL(room_id)
98
+ Nokogiri.parse(RestClient.get("#{@server_address}PlayBackServlet?room_id=#{room_id}")).css("webMpath").text.gsub(/.webm$/, "")
99
+ end
100
+
101
+ protected
102
+ def load_settings
103
+ settings = YAML.load_file('config/innowhite.yml')# if RAILS_ENV == "development"
104
+ @server_address = settings["innowhite"]["server_address"]
105
+ @api_address = settings["innowhite"]["api_address"]
106
+ @private_key = settings["innowhite"]["private_key"]
107
+ @parent_org = settings["innowhite"]["organization"]
108
+ @org_name = @parent_org
109
+ end
110
+
111
+ def create_schedule(room_id, user, tags, desc, parent_org, address, start_time, end_time, time_zone)
112
+ checksum = generating_checksum(URI.escape(url_generator(parent_org, parent_org)))
113
+ address = join_room_url(@org_name, room_id, user, true)
114
+ RestClient.post("#{@api_address}create_schedule_meeting",
115
+ {:roomId => room_id, :user => user, :tags => tags, :desc => desc, :startTime => start_time,
116
+ :endTime => end_time, :timeZone => time_zone,
117
+ :parentOrg => parent_org, :address => address, :orgName => parent_org,
118
+ :checksum => checksum
119
+ }
120
+ )
121
+ end
122
+
123
+ def create_room_info(room_id, user, tags, desc, parent_org, address)
124
+ checksum = generating_checksum(URI.escape(url_generator(parent_org, parent_org)))
125
+
126
+ RestClient.post("#{@api_address}create_room_info",
127
+ {:roomId => room_id, :user => user, :tags => tags, :desc => desc,
128
+ :parentOrg => parent_org, :address => address, :orgName => parent_org,
129
+ :checksum => checksum
130
+ }
131
+ )
132
+ end
133
+
134
+ def get_room_id
135
+ url = create_room_url
136
+ doc = Nokogiri::XML(open(url))
137
+ status = doc.xpath('//returnStatus').text.gsub("\n", "") rescue ""
138
+
139
+ if status.include?('SUCCESS')
140
+ doc.xpath('//roomId').text.gsub("\n", "").to_i
141
+ elsif status.include?('AUTH_FAILED')
142
+ "AUTH_FAILED"
143
+ elsif status.include?('EXPIRED')
144
+ 'EXPIRED'
145
+ elsif status.include?('OUT_OF_SERVICE')
146
+ 'OUT_OF_SERVICE'
147
+ else
148
+ "Error With the Server #{url}"
149
+ end
150
+ end
151
+
152
+ private
153
+ def main_cheksum(parent_org, org_name)
154
+ checksum_tmp = url_generator(parent_org, org_name)
155
+ generating_checksum(URI.escape(checksum_tmp))
156
+ end
157
+
158
+ def generating_checksum(params)
159
+ Digest::SHA1.hexdigest(params + @private_key)
160
+ end
161
+
162
+ def generate_checksum(parent_org, org_name, user_name)
163
+ Digest::SHA1.hexdigest(information_url(parent_org, org_name, user_name))
164
+ end
165
+
166
+ def url_generator(parent_org, org_name)
167
+ "parentOrg=#{parent_org}&orgName=#{org_name}"
168
+ end
169
+
170
+ def join_room_url(org_name, room_id, user, is_teacher)
171
+ action = "#{@server_address}JoinRoom?"
172
+ address = "parentOrg=#{@parent_org}&orgName=#{org_name}&roomId=#{room_id}&user=#{user}&roomLeader=#{is_teacher}"
173
+ "#{action}#{address}&checksum=#{generating_checksum(address)}"
174
+ end
175
+
176
+ def information_url(parent_org, org_name, user_name)
177
+ "parentOrg=#{parent_org}&orgName=#{org_name}&user=#{user_name}#{@private_key}"
178
+ end
179
+
180
+ def create_room_url
181
+ "#{@server_address}CreateRoom?parentOrg=#{@parent_org}&orgName=#{@org_name}&user=#{@mod_name}&checksum=#{generate_checksum(@parent_org, @org_name, @mod_name)}"
182
+ end
183
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: innowhite_api
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 1
9
+ - 3
10
+ version: 1.1.3
11
+ platform: ruby
12
+ authors:
13
+ - innowhite
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-11 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: nokogiri
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 1
32
+ - 4
33
+ - 4
34
+ version: 1.4.4
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rest-client
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 1
46
+ segments:
47
+ - 1
48
+ - 6
49
+ - 7
50
+ version: 1.6.7
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 19
62
+ segments:
63
+ - 1
64
+ - 3
65
+ - 4
66
+ version: 1.3.4
67
+ type: :development
68
+ version_requirements: *id003
69
+ description: Innowhite Api
70
+ email: dhiraj.peechara@innowhite.com
71
+ executables: []
72
+
73
+ extensions: []
74
+
75
+ extra_rdoc_files:
76
+ - README.rdoc
77
+ - lib/innowhite.rb
78
+ files:
79
+ - README.rdoc
80
+ - Rakefile
81
+ - lib/innowhite.rb
82
+ - innowhite.gemspec
83
+ has_rdoc: true
84
+ homepage: http://github.com/firemonk9/innowhite
85
+ licenses: []
86
+
87
+ post_install_message:
88
+ rdoc_options:
89
+ - --line-numbers
90
+ - --inline-source
91
+ - --title
92
+ - Innowhite
93
+ - --main
94
+ - README.rdoc
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ hash: 11
112
+ segments:
113
+ - 1
114
+ - 2
115
+ version: "1.2"
116
+ requirements: []
117
+
118
+ rubyforge_project: innowhite_api
119
+ rubygems_version: 1.6.2
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: Gem for Innowhite Api
123
+ test_files: []
124
+