innowhite_api 1.1.3 → 1.1.7.1

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 +12 -4
  2. data/Rakefile +3 -3
  3. data/innowhite.gemspec +2 -3
  4. data/lib/innowhite.rb +83 -58
  5. metadata +54 -74
data/README.rdoc CHANGED
@@ -5,7 +5,8 @@ Install innowhite gem with RubyGems
5
5
 
6
6
  gem install innowhite
7
7
  or add this to your Gemfile if you use Bundler:
8
- gem "innowhite"
8
+
9
+ gem innowhite_api
9
10
 
10
11
  Step 2:
11
12
  Place the innowhite.yml file in the config directory.
@@ -23,13 +24,14 @@ Then we could access the available methods from the instance :
23
24
  Create new session :
24
25
  Create new room and get its room url to access it.
25
26
 
26
- Arguments (as a Hash) :
27
+ Arguments (as a Hash) :
27
28
  a. :user => the name of the moderator (ex. "John")
28
29
  b. :tags => (optional). Example : (math 101, calculus, integration)
29
- c. :desc => (optional) Description of the room. (ex: Definite Integrals by John)
30
+ c. :desc => (optional) Description of the room. (ex: Definite Integrals by John)
31
+ d. :cb => (mandatory) Server name (ex: "innowhite" or "testinnowhite")
30
32
 
31
33
  Request Command :
32
- innowhite.create_room({}). Ex : innowhite.create_room({:user => "bainur", :tags => "testing, room testing", :desc => "This is only testing for the room"})
34
+ innowhite.create_room({:cb => "innowhite", :user => "bainur"}). Ex : innowhite.create_room({:cb => "innowhite", :user => "bainur", :tags => "testing, room testing", :desc => "This is only testing for the room"})
33
35
 
34
36
  Return value :
35
37
  a. Room Id
@@ -183,3 +185,9 @@ Get Meeting Play back Recording URL :
183
185
 
184
186
  Return Value :
185
187
  a. URL
188
+
189
+
190
+
191
+ Returned data
192
+
193
+ All results returns as Hash with indifferent access. :data key contains result and :errors contains errors.
data/Rakefile CHANGED
@@ -4,9 +4,9 @@ require 'echoe'
4
4
 
5
5
  Echoe.new('innowhite', '0.1.0') do |p|
6
6
  p.description = "Innowhite Api"
7
- p.url = "http://github.com/bainur/innowhite"
8
- p.author = "bainur"
9
- p.email = "inoe.bainur@gmail.com"
7
+ p.url = "http://github.com/firemonk9/innowhite"
8
+ p.author = "firemonk"
9
+ p.email = "dhiraj.peechara@gmail.com"
10
10
  p.ignore_pattern = ["tmp/*", "script/*"]
11
11
  p.development_dependencies = []
12
12
  end
data/innowhite.gemspec CHANGED
@@ -1,9 +1,8 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  Gem::Specification.new do |s|
4
- s.name = %q{innowhite_api}
5
- s.version = "1.1.3"
6
-
4
+ s.name = %q{innowhite}
5
+ s.version = "1.1.7.1"
7
6
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
7
  s.authors = [%q{innowhite}]
9
8
  s.date = %q{2011-08-11}
data/lib/innowhite.rb CHANGED
@@ -4,6 +4,16 @@ require 'rest-client'
4
4
 
5
5
  class Innowhite
6
6
 
7
+ @@errors = {
8
+ :user_miss => [1, "user value missed"],
9
+ :fetch_fail => [2, "failed to fetch, maybe you have entered wrong username"],
10
+ :room_miss => [3, "room not set"],
11
+ :description_miss => [4, "description value not set"],
12
+ :start_time => [5, "startTime value missed"],
13
+ :end_time => [6, "endTime value missed"],
14
+ :time_zone => [7, "timeZone value missed"],
15
+ }
16
+
7
17
  attr_accessor :mod_name, :org_name, :sub, :server_address, :private_key
8
18
 
9
19
  def initialize
@@ -11,16 +21,21 @@ class Innowhite
11
21
  end
12
22
 
13
23
  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}
24
+ return err(*@@errors[:user_miss]) if params[:user].blank?
25
+ room_id = get_room_id(params[:user])
26
+ return room_id[:errors] if room_id.has_key?(:errors)
27
+ res = create_room_info(room_id[:data], params[:user], params[:tags], params[:desc], @org_name)
28
+ $stdout << res.inspect
29
+ res[:status] ? data({"room_id" => room_id[:data], "address" => res[:data]}) : res[:errors]
18
30
  end
19
31
 
20
32
  def join_meeting(room_id, user)
33
+ return err(*@@errors[:user_miss]) if user.nil?
34
+ return err(*@@errors[:room_miss]) if room_id.nil?
21
35
  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)
36
+ res = request("post", url)
37
+ return res[:errors] if res.has_key?(:errors)
38
+ res[:data].blank? ? err(-1, "Unknow") : data(join_room_url(@org_name, room_id, user, false))
24
39
  end
25
40
 
26
41
  def get_sessions(params = {})
@@ -28,19 +43,22 @@ class Innowhite
28
43
  checksum = generating_checksum(URI.escape(temp))
29
44
  tmp = "#{temp}&user=#{params[:user]}&tags=#{params[:tags]}"
30
45
  url = URI.escape("#{@api_address}list_sessions?#{tmp}&checksum=#{checksum}")
31
- JSON::parse(RestClient.get(url, :accept => :json))
46
+ request("get", url)
32
47
 
33
- rescue
34
- {"errors" => "Error fetching sessions check the organization and private key .."}
48
+ rescue
49
+ err(*@@errors[:fetch_fail])
35
50
  end
36
51
 
37
52
  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)
53
+ return err(*@@errors[:user_miss]) if !params[:user] || params[:user].blank?
54
+ return err(*@@errors[:description_miss]) if !params[:description] || params[:description].empty?
55
+
56
+ return err(*@@errors[:start_time]) if !params[:startTime] || params[:startTime].blank?
57
+ return err(*@@errors[:end_time]) if !params[:endTime] || params[:endTime].blank?
58
+ return err(*@@errors[:time_zone]) if !params[:timeZone] || params[:timeZone].blank?
59
+
60
+ room_id = get_room_id(params[:user])
61
+ return room_id[:errors] if room_id.has_key?(:errors)
44
62
 
45
63
  create_schedule(
46
64
  room_id,
@@ -48,10 +66,9 @@ class Innowhite
48
66
  params[:tags],
49
67
  params[:description],
50
68
  params[:parentOrg] || @parent_org,
51
- address,
52
69
  params[:startTime],
53
70
  params[:endTime],
54
- params[:timeZone]) == "true"
71
+ params[:timeZone])
55
72
  end
56
73
 
57
74
  def past_sessions(params = {})
@@ -60,24 +77,24 @@ class Innowhite
60
77
 
61
78
  tmp = "#{temp}&user=#{params[:user]}&tags=#{params[:tags]}"
62
79
  url = URI.escape("#{@api_address}past_sessions?#{tmp}&checksum=#{checksum}")
63
- JSON::parse(RestClient.get(url, :accept => :json))
80
+ request("get", url)
64
81
 
65
82
  rescue
66
- { "errors" => "Error fetching sessions check the organization and private key .." }
83
+ err(*@@errors[:fetch_fail])
67
84
  end
68
85
 
69
86
  def get_scheduled_list(params={})
70
87
  checksum = main_cheksum(params[:parentOrg] || @parent_org, params[:orgName] || @org_name)
71
88
  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))
89
+ url = URI.escape("#{@api_address}get_scheduled_sessions?#{par}&checksum=#{checksum}&tags=#{params[:tags]}&user=#{params[:user]}")
90
+ request("get", url)
74
91
  end
75
92
 
76
93
  def cancel_meeting(room_id)
77
94
  checksum = main_cheksum(@parent_org, @org_name)
78
95
  par = url_generator(@parent_org, @org_name)
79
96
  url = URI.escape("#{@api_address}cancel_meeting?roomId=#{room_id}&#{par}&checksum=#{checksum}")
80
- Nokogiri::XML(open(url)).xpath("//success").text == "true"
97
+ data(request("get", url))[:status]
81
98
  end
82
99
 
83
100
  def update_schedule(params = {})
@@ -85,71 +102,84 @@ class Innowhite
85
102
  params[:startTime] = params[:startTime].to_i if !params[:startTime].blank? && (params[:startTime].is_a?(DateTime) || params[:startTime].is_a?(Time))
86
103
  params[:endTime] = params[:endTime].to_i if !params[:endTime].blank? && (params[:endTime].is_a?(DateTime) || params[:endTime].is_a?(Time))
87
104
 
88
- Nokogiri::XML(RestClient.put("#{@api_address}update_schedule",
105
+ request("put", "#{@api_address}update_schedule",
89
106
  {:roomId => params[:room_id], :tags => params[:tags], :description => params[:description],
90
107
  :parentOrg => @parent_org, :orgName => @org_name,
91
108
  :checksum => checksum, :startTime => params[:startTime],
92
109
  :endTime => params[:endTime], :timeZone => params[:timeZone]
93
110
  }
94
- )).xpath("//success").text == "true"
111
+ )[:status]
95
112
  end
96
113
 
97
114
  def getRecordingURL(room_id)
98
- Nokogiri.parse(RestClient.get("#{@server_address}PlayBackServlet?room_id=#{room_id}")).css("webMpath").text.gsub(/.webm$/, "")
115
+ url = "#{@api_address}api_get_recording_urls?#{{:room_id => room_id}.to_param}"
116
+ data(request("get", url))
117
+ end
118
+
119
+ def self.gen_checksum(params)
120
+ key = params.delete(:key)
121
+ temp = params.to_param
122
+ temp + "&checksum=#{Digest::SHA1.hexdigest(URI.escape(temp) + key)}"
123
+ end
124
+
125
+ def get_room_id(user)
126
+ url = "#{@api_address}api_create_room?#{{:parentOrg => @parent_org, :orgName => @org_name, :user => user, :key => @private_key}.to_param}"
127
+ request("get", url)
99
128
  end
100
129
 
101
130
  protected
131
+ def err(code, message)
132
+ {"errors" => {"message" => message, "code" => code}}.with_indifferent_access
133
+ end
134
+
135
+ def data(values)
136
+ {"data" => values}.with_indifferent_access
137
+ end
138
+
102
139
  def load_settings
103
140
  settings = YAML.load_file('config/innowhite.yml')# if RAILS_ENV == "development"
104
- @server_address = settings["innowhite"]["server_address"]
105
141
  @api_address = settings["innowhite"]["api_address"]
106
142
  @private_key = settings["innowhite"]["private_key"]
107
143
  @parent_org = settings["innowhite"]["organization"]
108
144
  @org_name = @parent_org
109
145
  end
110
146
 
111
- def create_schedule(room_id, user, tags, desc, parent_org, address, start_time, end_time, time_zone)
147
+ def create_schedule(room_id, user, tags, desc, parent_org, start_time, end_time, time_zone)
112
148
  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",
149
+ request("post", "#{@api_address}create_schedule_meeting",
115
150
  {:roomId => room_id, :user => user, :tags => tags, :desc => desc, :startTime => start_time,
116
151
  :endTime => end_time, :timeZone => time_zone,
117
- :parentOrg => parent_org, :address => address, :orgName => parent_org,
118
- :checksum => checksum
152
+ :parentOrg => parent_org, :orgName => parent_org,
153
+ :checksum => checksum, :roomLeader => true,
154
+ :key => @private_key
119
155
  }
120
- )
156
+ )[:status]
121
157
  end
122
158
 
123
- def create_room_info(room_id, user, tags, desc, parent_org, address)
159
+ def create_room_info(room_id, user, tags, desc, parent_org)
124
160
  checksum = generating_checksum(URI.escape(url_generator(parent_org, parent_org)))
125
161
 
126
- RestClient.post("#{@api_address}create_room_info",
162
+ request("post", "#{@api_address}create_room_info",
127
163
  {:roomId => room_id, :user => user, :tags => tags, :desc => desc,
128
- :parentOrg => parent_org, :address => address, :orgName => parent_org,
129
- :checksum => checksum
164
+ :parentOrg => parent_org, :orgName => parent_org,
165
+ :checksum => checksum, :key => @private_key
130
166
  }
131
167
  )
132
168
  end
133
169
 
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'
170
+ private
171
+
172
+ def request(method, url, *params)
173
+ url = url + "?" + params.to_param unless params.blank?
174
+ k = if method == "get" || method == "delete"
175
+ RestClient.send(method, url, :accept => :json)
147
176
  else
148
- "Error With the Server #{url}"
177
+ RestClient.send(method, url, {}, :accept => :json)
149
178
  end
179
+ $stdout << k.inspect
180
+ JSON::parse(k).with_indifferent_access
150
181
  end
151
182
 
152
- private
153
183
  def main_cheksum(parent_org, org_name)
154
184
  checksum_tmp = url_generator(parent_org, org_name)
155
185
  generating_checksum(URI.escape(checksum_tmp))
@@ -168,16 +198,11 @@ class Innowhite
168
198
  end
169
199
 
170
200
  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)}"
201
+ url = "#{@api_address}api_join_room?#{{:parentOrg => @parent_org, :orgName => org_name, :user => user, :roomId => room_id, :roomLeader => is_teacher, :key => @private_key}.to_param}"
202
+ request("post", url)[:data]
174
203
  end
175
204
 
176
205
  def information_url(parent_org, org_name, user_name)
177
206
  "parentOrg=#{parent_org}&orgName=#{org_name}&user=#{user_name}#{@private_key}"
178
207
  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
208
  end
metadata CHANGED
@@ -1,124 +1,104 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: innowhite_api
3
- version: !ruby/object:Gem::Version
4
- hash: 21
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.7.1
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 1
9
- - 3
10
- version: 1.1.3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - innowhite
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-08-11 00:00:00 -05:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2011-08-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: nokogiri
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
18
+ requirements:
27
19
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 15
30
- segments:
31
- - 1
32
- - 4
33
- - 4
20
+ - !ruby/object:Gem::Version
34
21
  version: 1.4.4
35
22
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: rest-client
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.4.4
30
+ - !ruby/object:Gem::Dependency
31
+ name: rest-client
32
+ requirement: !ruby/object:Gem::Requirement
41
33
  none: false
42
- requirements:
34
+ requirements:
43
35
  - - ~>
44
- - !ruby/object:Gem::Version
45
- hash: 1
46
- segments:
47
- - 1
48
- - 6
49
- - 7
36
+ - !ruby/object:Gem::Version
50
37
  version: 1.6.7
51
38
  type: :runtime
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: rspec
55
39
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
57
41
  none: false
58
- requirements:
42
+ requirements:
59
43
  - - ~>
60
- - !ruby/object:Gem::Version
61
- hash: 19
62
- segments:
63
- - 1
64
- - 3
65
- - 4
44
+ - !ruby/object:Gem::Version
45
+ version: 1.6.7
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
66
53
  version: 1.3.4
67
54
  type: :development
68
- version_requirements: *id003
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.4
69
62
  description: Innowhite Api
70
63
  email: dhiraj.peechara@innowhite.com
71
64
  executables: []
72
-
73
65
  extensions: []
74
-
75
- extra_rdoc_files:
66
+ extra_rdoc_files:
76
67
  - README.rdoc
77
68
  - lib/innowhite.rb
78
- files:
69
+ files:
79
70
  - README.rdoc
80
71
  - Rakefile
81
72
  - lib/innowhite.rb
82
73
  - innowhite.gemspec
83
- has_rdoc: true
84
74
  homepage: http://github.com/firemonk9/innowhite
85
75
  licenses: []
86
-
87
76
  post_install_message:
88
- rdoc_options:
77
+ rdoc_options:
89
78
  - --line-numbers
90
79
  - --inline-source
91
80
  - --title
92
81
  - Innowhite
93
82
  - --main
94
83
  - README.rdoc
95
- require_paths:
84
+ require_paths:
96
85
  - lib
97
- required_ruby_version: !ruby/object:Gem::Requirement
86
+ required_ruby_version: !ruby/object:Gem::Requirement
98
87
  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
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
93
  none: false
108
- requirements:
109
- - - ">="
110
- - !ruby/object:Gem::Version
111
- hash: 11
112
- segments:
113
- - 1
114
- - 2
115
- version: "1.2"
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '1.2'
116
98
  requirements: []
117
-
118
99
  rubyforge_project: innowhite_api
119
- rubygems_version: 1.6.2
100
+ rubygems_version: 1.8.23
120
101
  signing_key:
121
102
  specification_version: 3
122
103
  summary: Gem for Innowhite Api
123
104
  test_files: []
124
-