~khurshid-alam/gwibber/gwibber-hack

« back to all changes in this revision

Viewing changes to gwibber/lib/__init__.py

  • Committer: Khurshid Alam
  • Date: 2012-04-06 14:38:38 UTC
  • Revision ID: khurshid.alam@linuxmail.org-20120406143838-nz7hjg8vtzi2wl7i
initial revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import dbus
 
2
from gwibber.microblog import util
 
3
 
 
4
class GwibberPublic:
 
5
    """
 
6
    GwibberPublic is the public python class which provides convience methods 
 
7
    for using Gwibber.
 
8
    """
 
9
 
 
10
    def __init__(self):
 
11
        self.bus = dbus.SessionBus()
 
12
        self.accounts = self.getbus("Accounts")
 
13
        self.service = self.getbus("Service")
 
14
        self.shortener = self.getbus("URLShorten")
 
15
 
 
16
    def getbus(self, name):
 
17
        obj = self.bus.get_object(
 
18
            "com.Gwibber.%s" % name,
 
19
            "/com/gwibber/%s" % name,
 
20
            follow_name_owner_changes=True)
 
21
        
 
22
        return dbus.Interface(obj, "com.Gwibber.%s" % name)
 
23
        
 
24
    def post(self, message):
 
25
        args = [message]
 
26
        self.microblog.operation({
 
27
          "args": args,
 
28
          "opname": "send",
 
29
          })
 
30
 
 
31
    def GetServices(self):
 
32
        """
 
33
        Returns a list of services available as json string
 
34
        example:
 
35
            import json, gwibber.lib
 
36
            gw = gwibber.lib.GwibberPublic()
 
37
            services = json.loads(gw.GetServices())
 
38
        """
 
39
        return self.service.GetServices()
 
40
 
 
41
    def GetAccounts(self):
 
42
        """
 
43
        Returns a list of services available as json string
 
44
        example:
 
45
            import json, gwibber.lib
 
46
            gw = gwibber.lib.GwibberPublic()
 
47
            accounts = json.loads(gw.GetAccounts())
 
48
        """
 
49
        return self.accounts.List()
 
50
 
 
51
    def SendMessage(self, message):
 
52
        """
 
53
        Posts a message/status update to all accounts with send_enabled = True.  It 
 
54
        takes one argument, which is a message formated as a string.
 
55
        example:
 
56
            import gwibber.lib
 
57
            gw = gwibber.lib.GwibberPublic()
 
58
            gw.SendMessage("This is a message")
 
59
        """
 
60
        return self.service.SendMessage(message)
 
61
 
 
62
    def Refresh(self):
 
63
        """
 
64
        Calls the Gwibber Service to trigger a refresh operation
 
65
        example:
 
66
            import gwibber.lib
 
67
            gw = gwibber.lib.GwibberPublic()
 
68
            gw.Refresh()
 
69
        """
 
70
        return self.service.Refresh()
 
71
 
 
72
    def Shorten(self, url):
 
73
        """
 
74
        Takes a long url in and returns a shortened url as a string, based on your 
 
75
        configured shortening service
 
76
        example:
 
77
            import gwibber.lib
 
78
            gw = gwibber.lib.GwibberPublic()
 
79
            gw.Shorten(url)
 
80
        """
 
81
        return self.shortener.Shorten(url)
 
82
 
 
83
    def MonitorAccountCreated(self, cb):
 
84
        self.accounts.connect_to_signal("AccountCreated", cb)
 
85
 
 
86
    def MonitorAccountChanged(self, cb):
 
87
        self.accounts.connect_to_signal("AccountChanged", cb)
 
88
 
 
89
    def MonitorAccountDeleted(self, cb):
 
90
        self.accounts.connect_to_signal("AccountDeleted", cb)
 
91
 
 
92