From f6d88d439948f08659f9870c36f6374f030a64ba Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Tue, 26 Aug 2008 00:28:39 +1200 Subject: [PATCH] Starting to implement Connection object and RequestConnection, etc. --- twitterpathy.rb | 60 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/twitterpathy.rb b/twitterpathy.rb index a6dbb7b..fc1c83a 100755 --- a/twitterpathy.rb +++ b/twitterpathy.rb @@ -1,8 +1,8 @@ #!/usr/bin/env ruby -#require 'rubygems' -#gem('twitter4r', '>=0.2.1') -#require 'twitter' +require 'rubygems' +gem('twitter4r', '>=0.2.1') +require 'twitter' require 'dbus' CONN_MGR_PARAM_FLAG_REQUIRED = 1 @@ -21,8 +21,9 @@ class Twitterpathy < DBus::Object dbus_interface "org.freedesktop.Telepathy.ConnectionManager" do dbus_method :GetParameters, "in proto:s, out parameters:a(susv)" do |proto| - puts "GetParameters(#{proto})" + puts "GetParameters(#{proto.inspect})" $stderr.puts "Attempt to use unsupported protocol #{proto}" if proto != 'twitter' + parameters = [['account', CONN_MGR_PARAM_FLAG_REQUIRED | CONN_MGR_PARAM_FLAG_REGISTER, 's', ['s', '']], ['password', CONN_MGR_PARAM_FLAG_REQUIRED | CONN_MGR_PARAM_FLAG_REGISTER | CONN_MGR_PARAM_FLAG_SECRET, 's', ['s', '']]] [parameters] end @@ -34,23 +35,62 @@ class Twitterpathy < DBus::Object end dbus_method :RequestConnection, "in proto:s, in parameters:a{sv}, out service:s, out object:o" do |proto, parameters| - puts "RequestConnection(#{proto}, #{parameters})" + puts "RequestConnection(#{proto.inspect}, #{parameters.inspect})" $stderr.puts "Attempt to use unsupported protocol #{proto}" if proto != 'twitter' - service = nil - object = nil + + object = "/org/freedesktop/Telepathy/Connection/Twitterpathy/twitter/#{parameters['account']}" + service = "org.freedesktop.Telepathy.Connection.Twitterpathy.twitter.#{parameters['account']}" + + #Register a new D-BUS service for this connection + connection_service = $bus.request_service(service) + + #Create the connection object, and export it on the new service + connection = TwitterConnection.new(object, parameters['account'], parameters['password']) + connection_service.export(connection) + + puts "#{service}, #{object}" [service, object] end end end -bus = DBus::SessionBus.instance +class TwitterConnection < DBus::Object + def initialize(path, account, password) + puts "initialize TwitterConnection(#{path}, #{account}, ***)" + @account = account + @password = password + super(path) + end + + dbus_interface 'org.freedesktop.Telepathy.Connection' do + dbus_method :Connect, '' do || + puts "Connect, account=#{@account}" + @twitter_client = Twitter::Client.new(:login => $account, :password => $password) + end + + dbus_method :Disconnect, '' do || + end + + dbus_method :GetInterfaces, 'out interfaces:as' do || + interfaces = [] + [interfaces] + end + + dbus_method :GetProtocol, 'out protocol:s' do || + protocol = 'twitter' + [protocol] + end + end +end + +$bus = DBus::SessionBus.instance -service = bus.request_service("org.freedesktop.Telepathy.ConnectionManager.Twitterpathy") +service = $bus.request_service("org.freedesktop.Telepathy.ConnectionManager.Twitterpathy") exported_obj = Twitterpathy.new("/org/freedesktop/Telepathy/ConnectionManager/Twitterpathy") service.export(exported_obj) puts "listening" main = DBus::Main.new -main << bus +main << $bus main.run -- 2.11.4.GIT