Getting click to call working and adding GoogleVoice support to the UI
[gc-dialer] / src / gc_backend.py
index 0df3dec..e1573db 100644 (file)
@@ -51,7 +51,6 @@ class GCDialer(object):
        _inboxRe = re.compile(r"""<td>.*?(voicemail|received|missed|call return).*?</td>\s+<td>\s+<font size="2">\s+(.*?)\s+&nbsp;\|&nbsp;\s+<a href="/mobile/contacts/.*?">(.*?)\s?</a>\s+<br/>\s+(.*?)\s?<a href=""", re.S)
        _contactsRe = re.compile(r"""<a href="/mobile/contacts/detail/(\d+)">(.*?)</a>""", re.S)
        _contactsNextRe = re.compile(r""".*<a href="/mobile/contacts(\?page=\d+)">Next</a>""", re.S)
-       _contactDetailGroupRe = re.compile(r"""Group:\s*(\w*)""", re.S)
        _contactDetailPhoneRe = re.compile(r"""(\w+):[0-9\-\(\) \t]*?<a href="/mobile/calls/click_to_call\?destno=(\d+).*?">call</a>""", re.S)
 
        _validateRe = re.compile("^[0-9]{10,}$")
@@ -93,8 +92,7 @@ class GCDialer(object):
                try:
                        forwardSelectionPage = self._browser.download(GCDialer._forwardselectURL)
                except urllib2.URLError, e:
-                       warnings.warn("%s is not accesible" % GCDialer._forwardselectURL, UserWarning, 2)
-                       return False
+                       raise RuntimeError("%s is not accesible" % GCDialer._forwardselectURL)
 
                self._browser.cookies.save()
                if GCDialer._isLoginPageRe.search(forwardSelectionPage) is None:
@@ -117,8 +115,7 @@ class GCDialer(object):
                try:
                        loginSuccessOrFailurePage = self._browser.download(GCDialer._loginURL, loginPostData)
                except urllib2.URLError, e:
-                       warnings.warn("%s is not accesible" % GCDialer._loginURL, UserWarning, 2)
-                       return False
+                       raise RuntimeError("%s is not accesible" % GCDialer._loginURL)
 
                return self.is_authed()
 
@@ -152,7 +149,6 @@ class GCDialer(object):
                                {'Referer' : 'http://www.grandcentral.com/mobile/messages'}
                        )
                except urllib2.URLError, e:
-                       warnings.warn("%s is not accesible" % GCDialer._clicktocallURL, UserWarning, 2)
                        raise RuntimeError("%s is not accesible" % GCDialer._clicktocallURL)
 
                if GCDialer._gcDialingStrRe.search(callSuccessPage) is None:
@@ -226,8 +222,7 @@ class GCDialer(object):
                try:
                        callbackSetPage = self._browser.download(GCDialer._setforwardURL, callbackPostData)
                except urllib2.URLError, e:
-                       warnings.warn("%s is not accesible" % GCDialer._setforwardURL, UserWarning, 2)
-                       return False
+                       raise RuntimeError("%s is not accesible" % GCDialer._setforwardURL)
 
                self._browser.cookies.save()
                return True
@@ -248,8 +243,7 @@ class GCDialer(object):
                try:
                        recentCallsPage = self._browser.download(GCDialer._inboxallURL)
                except urllib2.URLError, e:
-                       warnings.warn("%s is not accesible" % GCDialer._inboxallURL, UserWarning, 2)
-                       return
+                       raise RuntimeError("%s is not accesible" % GCDialer._inboxallURL)
 
                for match in self._inboxRe.finditer(recentCallsPage):
                        phoneNumber = match.group(4)
@@ -284,7 +278,10 @@ class GCDialer(object):
 
                        contactsPagesUrls = [GCDialer._contactsURL]
                        for contactsPageUrl in contactsPagesUrls:
-                               contactsPage = self._browser.download(contactsPageUrl)
+                               try:
+                                       contactsPage = self._browser.download(contactsPageUrl)
+                               except urllib2.URLError, e:
+                                       raise RuntimeError("%s is not accesible" % contactsPageUrl)
                                for contact_match in self._contactsRe.finditer(contactsPage):
                                        contactId = contact_match.group(1)
                                        contactName = contact_match.group(2)
@@ -304,7 +301,11 @@ class GCDialer(object):
                """
                @returns Iterable of (Phone Type, Phone Number)
                """
-               detailPage = self._browser.download(GCDialer._contactDetailURL + '/' + contactId)
+               try:
+                       detailPage = self._browser.download(GCDialer._contactDetailURL + '/' + contactId)
+               except urllib2.URLError, e:
+                       raise RuntimeError("%s is not accesible" % GCDialer._contactDetailURL)
+
                for detail_match in self._contactDetailPhoneRe.finditer(detailPage):
                        phoneType = detail_match.group(1)
                        phoneNumber = detail_match.group(2)