Checking protocol
[twitterpathy.git] / twitterpathy.rb
bloba6dbb7b9f6a984140687f8d8f819379d13b01f65
1 #!/usr/bin/env ruby
3 #require 'rubygems'
4 #gem('twitter4r', '>=0.2.1')
5 #require 'twitter'
6 require 'dbus'
8 CONN_MGR_PARAM_FLAG_REQUIRED = 1
9 CONN_MGR_PARAM_FLAG_REGISTER = 2
10 CONN_MGR_PARAM_FLAG_HAS_DEFAULT = 4
11 CONN_MGR_PARAM_FLAG_SECRET = 8
13 class Twitterpathy < DBus::Object
14         # Create an interface.
15         dbus_interface "org.ruby.SampleInterface" do
16                 # Create a hello method in that interface.
17                 dbus_method :hello, "in name:s, in name2:s" do |name, name2|
18                         puts "hello(#{name}, #{name2})"
19                 end
20         end
21         
22         dbus_interface "org.freedesktop.Telepathy.ConnectionManager" do
23                 dbus_method :GetParameters, "in proto:s, out parameters:a(susv)" do |proto|
24                         puts "GetParameters(#{proto})"
25                         $stderr.puts "Attempt to use unsupported protocol #{proto}" if proto != 'twitter'
26                         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', '']]]
27                         [parameters]
28                 end
29                 
30                 dbus_method :ListProtocols, "out protocols:as" do ||
31                         puts "ListProtocols"
32                         protocols = ['twitter']
33                         [protocols]
34                 end
35                 
36                 dbus_method :RequestConnection, "in proto:s, in parameters:a{sv}, out service:s, out object:o" do |proto, parameters|
37                         puts "RequestConnection(#{proto}, #{parameters})"
38                         $stderr.puts "Attempt to use unsupported protocol #{proto}" if proto != 'twitter'
39                         service = nil
40                         object = nil
41                         [service, object]
42                 end
43         end
44 end
46 bus = DBus::SessionBus.instance
48 service = bus.request_service("org.freedesktop.Telepathy.ConnectionManager.Twitterpathy")
50 exported_obj = Twitterpathy.new("/org/freedesktop/Telepathy/ConnectionManager/Twitterpathy")
51 service.export(exported_obj)
53 puts "listening"
54 main = DBus::Main.new
55 main << bus
56 main.run