← Back to team overview

cairo-dock-team team mailing list archive

[Merge] lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Twitter into lp:cairo-dock-plug-ins-extras

 

Eduardo Mucelli Rezende Oliveira has proposed merging lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Twitter into lp:cairo-dock-plug-ins-extras.

Requested reviews:
  Cairo-Dock Team (cairo-dock-team)

For more details, see:
https://code.launchpad.net/~eduardo-mucelli/cairo-dock-plug-ins-extras/Twitter/+merge/87869

Received direct messages
-- 
https://code.launchpad.net/~eduardo-mucelli/cairo-dock-plug-ins-extras/Twitter/+merge/87869
Your team Cairo-Dock Team is requested to review the proposed merge of lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Twitter into lp:cairo-dock-plug-ins-extras.
=== modified file 'Twitter/ChangeLog'
--- Twitter/ChangeLog	2011-12-17 00:14:56 +0000
+++ Twitter/ChangeLog	2012-01-08 02:16:24 +0000
@@ -1,1 +1,2 @@
+0.0.2: (January/8/2012): Possible to see the received direct messages.
 0.0.1: (December/16/2011): Possible to send a tweety, and see the home timeline.

=== modified file 'Twitter/Twitter'
--- Twitter/Twitter	2012-01-07 20:55:28 +0000
+++ Twitter/Twitter	2012-01-08 02:16:24 +0000
@@ -78,6 +78,7 @@
   def __init__(self, access_key, access_secret):
     self.update_url           = 'http://twitter.com/statuses/update.json'
     self.home_timeline_url    = 'http://twitter.com/statuses/home_timeline.json'
+    self.direct_messages_url  = 'https://api.twitter.com/1/direct_messages.json'
 
     self.signature_method = oauth.OAuthSignatureMethod_HMAC_SHA1()
     consumer_key, consumer_secret = read_consumer_key_and_secret()
@@ -161,6 +162,17 @@
     response = get(url) 
     return simplejson.loads(response)
 
+  def direct_messages(self):
+    oauth_request = oauth.OAuthRequest.from_consumer_and_token(self.consumer,
+                                                               token = self.access_token,
+                                                               http_url = self.direct_messages_url,
+                                                               http_method = "GET")
+    oauth_request.sign_request(self.signature_method, self.consumer, self.access_token)
+    url = oauth_request.to_url()
+    response = get(url)
+    print simplejson.loads(response)[0]
+    return simplejson.loads(response)
+
 class User:
   def __init__(self, screen_name="", access_key="", access_secret=""):
     self.screen_name = screen_name
@@ -179,13 +191,21 @@
 
   def show_home_timeline(self):
     self.inform_start_of_waiting_process()
-
     timeline = self.api.home_timeline()
     if len(timeline) > 0:
       message = "".join (["[%s] %s\n" % (status['user']['name'], status['text']) for status in timeline])
     else:
       message = "Oh, dear, your timeline is empty :-("
+    self.inform_end_of_waiting_process()
+    self.show_popup_message(message)
 
+  def show_direct_messages(self):
+    self.inform_start_of_waiting_process()
+    messages = self.api.direct_messages()
+    if len(messages) > 0:
+      message = "".join (["[%s] %s\n" % (status['sender']['name'], status['text']) for status in messages])
+    else:
+      message = "Oh, dear, you do not have direct messages :-("
     self.inform_end_of_waiting_process()
     self.show_popup_message(message)
 
@@ -266,14 +286,28 @@
     widget_attributes.update(widget)
     self.icon.PopupDialog (dialog_attributes, widget_attributes)
 
+  def build_direct_messages_menu(self):
+    direct_messages_menu = []
+    direct_messages_menu.append ({
+        'type'  : CDApplet.MENU_ENTRY,
+        'label' : "Received direct messages",
+        'menu'  : CDApplet.MAIN_MENU_ID,
+        'id'    : self.direct_messages_menu_id,
+        'icon'  : os.path.abspath("./data/received.png")
+    })
+    self.icon.AddMenuItems(direct_messages_menu)
+
   def __init__(self):
     self.user = User()
     self.user_file = '.users'
     self.twitter_auth = TwitterOauth()
     self.api = None
-    self.responding_screen_name, self.responding_authorization, self.responding_pin, self.responding_success, self.responding_tweety, self.responding_initial_informations = range(6)
+    (self.responding_screen_name, self.responding_authorization, self.responding_pin,
+    self.responding_success, self.responding_tweety, self.responding_initial_informations) = range(6)
     self.dialog_type = None
 
+    self.direct_messages_menu_id = 1000
+
     CDApplet.__init__(self)                                                           # call CDApplet interface init
 
   # Inherited methods from CDApplet
@@ -322,5 +356,12 @@
   def on_middle_click(self):
     self.show_home_timeline()
 
+  def on_build_menu(self):
+    self.build_direct_messages_menu()
+
+  def on_menu_select(self, selected_menu):
+    if selected_menu == self.direct_messages_menu_id:
+      self.show_direct_messages()
+
 if __name__ == '__main__':
   Applet().run()

=== modified file 'Twitter/Twitter.conf'
--- Twitter/Twitter.conf	2011-12-17 00:14:56 +0000
+++ Twitter/Twitter.conf	2012-01-08 02:16:24 +0000
@@ -1,4 +1,4 @@
-#!en;0.0.1
+#!en;0.0.2
 
 #[gtk-about]
 [Icon]

=== modified file 'Twitter/auto-load.conf'
--- Twitter/auto-load.conf	2011-12-18 02:15:50 +0000
+++ Twitter/auto-load.conf	2012-01-08 02:16:24 +0000
@@ -4,13 +4,13 @@
 author = Eduardo Mucelli Rezende Oliveira
 
 # A short description of the applet and how to use it.
-description = On the first time, the applet is going to ask your nickname and authorization to connect with Twitter.\nThe applet is going to open your browser with the authorization page\nAs soon as you authorize it, a PIN number will be shown on the page, copy this number\nPaste this number on the next dialog box will be shown.\nThe plugin is going to inform that you are successfully connected.
+description = You can send tweets, see your timeline, and the received directed messages.\nOn the first time, the applet is going to ask your nickname and authorization to connect with Twitter.\nThe applet is going to open your browser with the authorization page\nAs soon as you authorize it, a PIN number will be shown on the page, copy this number\nPaste this number on the next dialog box will be shown.\nThe plugin is going to inform that you are successfully connected.
 
 # Category of the applet : 2 = files, 3 = internet, 4 = Desktop, 5 = accessory, 6 = system, 7 = fun
 category = 3
 
 # Version of the applet; change it everytime you change something in the config file. Don't forget to update the version both in this file and in the config file.
-version = 0.0.1
+version = 0.0.2
 
 # Whether the applet can be instanciated several times or not.
 multi-instance = true

=== added directory 'Twitter/data'
=== added file 'Twitter/data/received.png'
Binary files Twitter/data/received.png	1970-01-01 00:00:00 +0000 and Twitter/data/received.png	2012-01-08 02:16:24 +0000 differ

Follow ups