Author: raido
Date: Thu May 6 10:17:18 2010
New Revision: 941641
URL: http://svn.apache.org/viewvc?rev=941641&view=rev
Log:
Initial Ruby connector framework. See TestWookieService.rb for example.
Added:
incubator/wookie/trunk/connector/ruby/
incubator/wookie/trunk/connector/ruby/README.txt (with props)
incubator/wookie/trunk/connector/ruby/TestWookieService.rb (with props)
incubator/wookie/trunk/connector/ruby/wookie/
incubator/wookie/trunk/connector/ruby/wookie/WookieConnectorService.rb
(with props)
incubator/wookie/trunk/connector/ruby/wookie/WookieServerConnection.rb
(with props)
incubator/wookie/trunk/connector/ruby/wookie/widget/
incubator/wookie/trunk/connector/ruby/wookie/widget/User.rb (with props)
incubator/wookie/trunk/connector/ruby/wookie/widget/Widget.rb (with props)
incubator/wookie/trunk/connector/ruby/wookie/widget/WidgetInstance.rb
(with props)
Added: incubator/wookie/trunk/connector/ruby/README.txt
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/ruby/README.txt?rev=941641&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/ruby/README.txt (added)
+++ incubator/wookie/trunk/connector/ruby/README.txt Thu May 6 10:17:18 2010
@@ -0,0 +1,8 @@
+This is a Ruby implementation of the Wookie Connector Framework.
+
+INSTALLATION
+============
+
+Simply copy directory "wookie" into a convenient place in your plugin and use
the WookieConnectorService
+to communicate with the Wookie Server.
+
Propchange: incubator/wookie/trunk/connector/ruby/README.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/wookie/trunk/connector/ruby/README.txt
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/wookie/trunk/connector/ruby/TestWookieService.rb
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/ruby/TestWookieService.rb?rev=941641&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/ruby/TestWookieService.rb (added)
+++ incubator/wookie/trunk/connector/ruby/TestWookieService.rb Thu May 6
10:17:18 2010
@@ -0,0 +1,33 @@
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'wookie/WookieConnectorService.rb'
+
+service = WookieConnectorService.new("http://localhost:8081/wookie/", "TEST",
"ruby_localhost", "demo_ruby_user")
+
+print service.getCurrentUser().screenName
+
+alive = service.getConnection().Test()
+if alive:
+ puts service.getConnection().host
+ service.getAvailableWidgets().each do |widget|
+ widgetInstance = service.getOrCreateWidgetInstance(widget.guid)
+ puts widgetInstance.url
+ puts widgetInstance.width
+ puts widgetInstance.height
+ break
+ end
+else
+ print "Connection failed!"
+end
Propchange: incubator/wookie/trunk/connector/ruby/TestWookieService.rb
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wookie/trunk/connector/ruby/wookie/WookieConnectorService.rb
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/ruby/wookie/WookieConnectorService.rb?rev=941641&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/ruby/wookie/WookieConnectorService.rb
(added)
+++ incubator/wookie/trunk/connector/ruby/wookie/WookieConnectorService.rb Thu
May 6 10:17:18 2010
@@ -0,0 +1,79 @@
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'wookie/WookieServerConnection.rb'
+require 'wookie/widget/User.rb'
+require 'wookie/widget/Widget.rb'
+require 'wookie/widget/WidgetInstance.rb'
+
+require 'net/http'
+require 'uri'
+require 'rexml/document'
+
+class WookieConnectorService
+
+ def initialize(host, apiKey, sharedDataKey, userName)
+ @wookieConnection = WookieServerConnection.new(host, apiKey,
sharedDataKey)
+ @currentUser = User.new(userName);
+ end
+
+ def getConnection()
+ return @wookieConnection
+ end
+
+ def getCurrentUser()
+ return @currentUser
+ end
+
+ def getAvailableWidgets()
+ widgets = Array.new
+ xmlData =
Net::HTTP.get_response(URI.parse(@wookieConnection.host+"/widgets?all=true")).body
+ # widgets node, if not found return false
+ begin
+ doc = REXML::Document.new(xmlData)
+ doc.elements.each('widgets/widget') do |widget|
+ height = widget.attributes['height']
+ width = widget.attributes['width']
+ title = widget.elements['title'].text
+ guid = widget.attributes['identifier']
+ newWidget = Widget.new(title, guid, width, height)
+ widgets.push(newWidget)
+ end
+ rescue REXML::ParseException=>e
+ return widgets
+ end
+ return widgets
+ end
+
+ def getOrCreateWidgetInstance(guid)
+ xmlData =
Net::HTTP.post_form(URI.parse(@wookieConnection.host+'/widgetinstances'),
+ {'api_key'=>@wookieConnection.apiKey,
+ 'shareddatakey'=>
@wookieConnection.sharedDataKey,
+ 'userid'=> self.getCurrentUser().loginName,
+ 'widgetid'=> guid }).body
+ begin
+ doc = REXML::Document.new(xmlData)
+ widgetNode = doc.elements['widgetdata']
+ height = widgetNode.elements['height'].text
+ width = widgetNode.elements['width'].text
+ title = widgetNode.elements['title'].text
+ url = widgetNode.elements['url'].text
+ newInstance = WidgetInstance.new(title, url, width, height)
+ return newInstance
+ rescue REXML::ParseException=>e
+ return nil
+ end
+ return nil
+ end
+end
Propchange:
incubator/wookie/trunk/connector/ruby/wookie/WookieConnectorService.rb
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wookie/trunk/connector/ruby/wookie/WookieServerConnection.rb
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/ruby/wookie/WookieServerConnection.rb?rev=941641&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/ruby/wookie/WookieServerConnection.rb
(added)
+++ incubator/wookie/trunk/connector/ruby/wookie/WookieServerConnection.rb Thu
May 6 10:17:18 2010
@@ -0,0 +1,43 @@
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+class WookieServerConnection
+ attr_accessor :host, :apiKey, :sharedDataKey
+
+ def initialize(host, apiKey, sharedDataKey)
+ @host = host
+ @apiKey = apiKey
+ @sharedDataKey = sharedDataKey
+ end
+
+ def Test()
+ require 'net/http'
+ require 'rexml/document'
+ xmlData =
Net::HTTP.get_response(URI.parse(@host+"/widgets?all=true")).body
+ # widgets node, if not found return false
+ begin
+ doc = REXML::Document.new(xmlData)
+ anyWidgetsFound = doc.elements['widgets']
+ if anyWidgetsFound:
+ return true
+ else
+ return false
+ end
+ rescue REXML::ParseException=>e
+ return false
+ end
+
+ end
+end
+
Propchange:
incubator/wookie/trunk/connector/ruby/wookie/WookieServerConnection.rb
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wookie/trunk/connector/ruby/wookie/widget/User.rb
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/ruby/wookie/widget/User.rb?rev=941641&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/ruby/wookie/widget/User.rb (added)
+++ incubator/wookie/trunk/connector/ruby/wookie/widget/User.rb Thu May 6
10:17:18 2010
@@ -0,0 +1,26 @@
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+class User
+ attr_accessor :loginName, :screenName, :thumbnailUrl
+
+ def initialize(userName, screenName = '', thumnailUrl = '')
+ @loginName = userName
+ if screenName == ''
+ screenName = userName
+ end
+ @screenName = screenName
+ @thumbnailUrl = thumbnailUrl
+ end
+end
Propchange: incubator/wookie/trunk/connector/ruby/wookie/widget/User.rb
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wookie/trunk/connector/ruby/wookie/widget/Widget.rb
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/ruby/wookie/widget/Widget.rb?rev=941641&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/ruby/wookie/widget/Widget.rb (added)
+++ incubator/wookie/trunk/connector/ruby/wookie/widget/Widget.rb Thu May 6
10:17:18 2010
@@ -0,0 +1,24 @@
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+class Widget
+ attr_accessor :title, :guid, :width, :height
+
+ def initialize(title, guid, width, height)
+ @title = title
+ @guid = guid
+ @width = width
+ @height = height
+ end
+end
Propchange: incubator/wookie/trunk/connector/ruby/wookie/widget/Widget.rb
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wookie/trunk/connector/ruby/wookie/widget/WidgetInstance.rb
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/ruby/wookie/widget/WidgetInstance.rb?rev=941641&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/ruby/wookie/widget/WidgetInstance.rb
(added)
+++ incubator/wookie/trunk/connector/ruby/wookie/widget/WidgetInstance.rb Thu
May 6 10:17:18 2010
@@ -0,0 +1,24 @@
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+class WidgetInstance
+ attr_accessor :title, :url, :width, :height
+
+ def initialize(title, url, width, height)
+ @title = title
+ @url = url
+ @width = width
+ @height = height
+ end
+end
Propchange:
incubator/wookie/trunk/connector/ruby/wookie/widget/WidgetInstance.rb
------------------------------------------------------------------------------
svn:eol-style = native