Exemplo n.º 1
0
    def send(self, message):
        """Posts new status message.
        So much fun - it always returns empty list, no matter
        how or what.

        """
        try:
            pyyaru.yaPerson('/me/').set_status(message)
        except pyyaru.yaError, e:
            log.logger.info('Ya.ru publish error: %s' % e)
Exemplo n.º 2
0
    def receive(self, count=COUNT, since=None):
        """Fetch friend status posts."""
        messages = []

        me = pyyaru.yaPerson('/me/').get()
        entries = me.friends_entries('status')
        for entry in entries.objects:
            message = self._message(entry)
            messages.append(message)

        return messages
Exemplo n.º 3
0
    def user_messages(self, id=None, count=COUNT, since=None):
        """Gets entries of a certain person.
        id param here is not an id, as someone like me might think,
        it is a nick of a person. Funny it is.

        """
        # TODO Put it into PROTOCOL_INFO['features'] someday when id would be an id, not bloody name.
        messages = []
        person = pyyaru.yaPerson('https://api-yaru.yandex.ru/person/%s' % quote(id.encode('utf-8'))).get()
        entries = person.entries('status')

        for entry in entries.objects:
            message = self._message(entry, self._user(person))
            messages.append(message)

        return messages
Exemplo n.º 4
0
    def on_yaru_auth_title_change(self, web=None, title=None, data=None):

        saved = False

        url = web.get_main_frame().get_uri()

        if url.find('#') > -1:
            data = urlparse.parse_qs(url.split("#", 1)[1])

            if hasattr(self.dialog, "infobar_content_area"):
                for child in self.dialog.infobar_content_area.get_children(): child.destroy()

            self.dialog.infobar_content_area = self.dialog.infobar.get_content_area()
            self.dialog.infobar_content_area.show()
            message_label = gtk.Label(_("Verifying"))
            message_label.set_use_markup(True)
            message_label.set_ellipsize(pango.ELLIPSIZE_END)
            self.dialog.infobar_content_area.add(message_label)

            if 'access_token' in data:
                # token granted

                self.dialog.infobar.show()
                self.dialog.infobar.show_all()
                self.scroll.hide()

                self.ui.get_object("vbox1").show()
                self.ui.get_object("vbox_advanced").show()

                pyyaru.ACCESS_TOKEN = data["access_token"][0]
                my_profile = pyyaru.yaPerson("/me/").get()

                self.account["access_token"] = data["access_token"][0]
                self.account["username"] = my_profile.name
                self.account["user_id"] = my_profile.id

                saved = self.dialog.on_edit_account_save()

                if saved:
                    message_label.set_text(_("Successful"))
                    self.dialog.infobar.set_message_type(gtk.MESSAGE_INFO)

                self.ui.get_object("hbox_yaru_auth").hide()
                self.ui.get_object("yaru_auth_done_label").set_label(_("%s has been authorized by Ya.ru") % str(self.account["username"]))
                self.ui.get_object("hbox_yaru_auth_done").show()

                if self.dialog.ui and self.account.has_key("id") and not saved:
                    self.dialog.ui.get_object("vbox_save").show()
                elif self.dialog.ui and not saved:
                    self.dialog.ui.get_object("vbox_create").show()

            self.window.resize(*self.winsize)

            if 'error' in data:
                # no token

                web.hide()
                self.dialog.infobar.set_message_type(gtk.MESSAGE_ERROR)
                message_label.set_text(_("Authorization failed. Please try again."))
                self.dialog.infobar.show_all()

                self.ui.get_object("vbox1").show()
                self.ui.get_object("vbox_advanced").show()
                self.window.resize(*self.winsize)