← 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/86139

Another approach for the auth flow, relying on the webbrowser module.
-- 
https://code.launchpad.net/~eduardo-mucelli/cairo-dock-plug-ins-extras/Twitter/+merge/86139
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/Twitter'
--- Twitter/Twitter	2011-12-17 03:28:23 +0000
+++ Twitter/Twitter	2011-12-17 13:37:24 +0000
@@ -59,10 +59,17 @@
 
 	# Exchange request token for access token
 	def get_access_token_and_secret(self, pin):
+<<<<<<< TREE
 		oauth_request = oauth.OAuthRequest.from_consumer_and_token(self.consumer,
 																															 http_url = self.access_token_url,
 																															 verifier = pin,
 																															 token = self.request_token )
+=======
+		oauth_request = oauth.OAuthRequest.from_consumer_and_token(self.consumer,
+																															 http_url = self.access_token_url,
+																															 verifier = pin,
+																															 token = self.request_token)
+>>>>>>> MERGE-SOURCE
 		oauth_request.sign_request(self.signature_method, self.consumer, self.request_token)
 		url = oauth_request.to_url()
 		response = get(url)
@@ -181,10 +188,18 @@
 		# self.dialog_type = self.responding_screen_name
 
 	def ask_for_authorization(self):
-		message = "Twitter applet needs you to give the authorization. Press Enter and your browser will be open with the URL shown bellow. Copy the PIN number that will be shown in the browser"
-		dialog = {'buttons':'ok'}
-		widget = {'widget-type':'text-entry', 'initial-value':self.twitter_auth.get_authorization_url()}
-		self.show_popup_message(message, dialog, widget)
+		authorization_url = self.twitter_auth.get_authorization_url()
+		logp("Opening the auth URL '%s'" % authorization_url)
+		try:
+			webbrowser.open(authorization_url)
+			message = "Twitter applet needs you to give the authorization. Authorization page was opened on your browser. As soon as you do, copy the PIN number that will be shown, and close this dialog"
+			dialog = {'buttons':'ok'}
+			self.show_popup_message(message, dialog)
+		except webbrowser.Error:		
+			message = "Twitter applet needs you to give the authorization. Copy the address bellow and access it with your browser. Copy the PIN number that will be shown as soon as you authorize"
+			dialog = {'buttons':'ok'}
+			widget = {'widget-type':'text-entry', 'initial-value':authorization_url}
+			self.show_popup_message(message, dialog, widget)
 		self.dialog_type = self.responding_authorization
 
 	def ask_for_pin_number(self):
@@ -230,15 +245,13 @@
 
 	# Callbacks
 	def on_answer_dialog(self, key, content):
-		if (key == 0 or key == -1) and content:																					# ... and pressed Ok or Enter
+		if (key == 0 or key == -1):																											# ... and pressed Ok or Enter
 			if self.dialog_type == self.responding_screen_name:														# user typed screen name ...
 				logp("Receiving screen name '%s'" % content)
 				self.user.screen_name = content
 				self.ask_for_authorization()
 			elif self.dialog_type == self.responding_authorization:
-				logp("Authorizing ...")
-				webbrowser.open(content)
-				logp("Opening the auth URL '%s'" % content)
+				logp("Asking for PIN")
 				self.ask_for_pin_number()																										# ask for the PIN number received when acessed the auth URL
 			elif self.dialog_type == self.responding_pin:																	# user typed the PIN number
 				logp("Receiving PIN: %s" % content)