Exemple #1
0
  def _get(self, path, parse="message", post=False, single=False, **args):
    url = "/".join((API_PREFIX, path))

    request = oauth.OAuthRequest.from_consumer_and_token(self.consumer, self.token,
        http_method=post and "POST" or "GET", http_url=url, parameters=util.compact(args))
    request.sign_request(self.sigmethod, self.consumer, self.token)

    if post:
      headers = request.to_header()
      data = network.Download(url, util.compact(args), post, header=headers).get_json()
    else:
      data = network.Download(request.to_url(), None, post).get_json()
    resources.dump(self.account["service"], self.account["id"], data)

    if isinstance(data, dict) and data.get("errors", 0):
      if "authenticate" in data["errors"][0]["message"]:
        logstr = """%s: %s - %s""" % (PROTOCOL_INFO["name"], _("Authentication failed"), data["errors"][0]["message"])
        logger.error("%s", logstr)
        return [{"error": {"type": "auth", "account": self.account, "message": data["errors"][0]["message"]}}]
      else:
        for error in data["errors"]:
          logstr = """%s: %s - %s""" % (PROTOCOL_INFO["name"], _("Unknown failure"), error["message"])
          return [{"error": {"type": "unknown", "account": self.account, "message": error["message"]}}]
    elif isinstance(data, dict) and data.get("error", 0):
      if "Incorrect signature" in data["error"]:
        logstr = """%s: %s - %s""" % (PROTOCOL_INFO["name"], _("Request failed"), data["error"])
        logger.error("%s", logstr)
        return [{"error": {"type": "auth", "account": self.account, "message": data["error"]}}]
    elif isinstance(data, str):
      logstr = """%s: %s - %s""" % (PROTOCOL_INFO["name"], _("Request failed"), data)
      logger.error("%s", logstr)
      return [{"error": {"type": "request", "account": self.account, "message": data}}]

    if parse == "follow" or parse == "unfollow":
      if isinstance(data, dict) and data.get("error", 0):
        logstr = """%s: %s - %s""" % (PROTOCOL_INFO["name"], _("%s failed" % parse), data["error"])
        logger.error("%s", logstr)
        return [{"error": {"type": "auth", "account": self.account, "message": data["error"]}}]
      else:
        return [["friendships", {"type": parse, "account": self.account["id"], "service": self.account["service"],"user_id": data["id"], "nick": data["screen_name"]}]]
    
    if parse == "profile" and isinstance(data, dict):
      return self._profile(data)

    if parse == "list":
      return [self._list(l) for l in data["lists"]]

    if single: return [getattr(self, "_%s" % parse)(data)]
    if parse: return [getattr(self, "_%s" % parse)(m) for m in data]
    else: return []
Exemple #2
0
    def _search(self, **args):
        data = network.Download(
            "%s/api/search.json" % self.account["url_prefix"],
            util.compact(args))
        data = data.get_json()

        return [self._result(m) for m in data["results"]]
Exemple #3
0
    def _get(self,
             path,
             post=False,
             parse="message",
             kind="entries",
             single=False,
             **args):
        url = "/".join((URL_PREFIX, path))
        data = network.Download(url, util.compact(args), post,
                                self.account["username"],
                                self.account["secret_key"]).get_json()

        resources.dump(self.account["service"], self.account["id"], data)

        if isinstance(data, dict) and data.get("errorCode", 0):
            if "unauthorized" in data["errorCode"]:
                raise exceptions.GwibberServiceError("auth",
                                                     self.account["service"],
                                                     self.account["username"],
                                                     data["errorCode"])

        if single: return [getattr(self, "_%s" % parse)(data)]
        if parse:
            return [getattr(self, "_%s" % parse)(m) for m in data["entries"]]
        else:
            return []

        if parse:
            data = data[kind][0] if single else data[kind]
            return [getattr(self, "_%s" % parse)(m) for m in data]
Exemple #4
0
  def _search(self, **args):
    data = network.Download("http://search.twitter.com/search.json", util.compact(args))
    data = data.get_json()["results"]

    if type(data) != list:
      logger.error("Cannot parse search data: %s", str(data))
      return []

    return [self._result(m) for m in data]
Exemple #5
0
  def _search(self, **args):
    data = network.Download("%s/api/search.json" % self.url_prefix, util.compact(args))
    data = data.get_json()

    if type(data) != dict:
      logger.error("Cannot parse search data: %s", str(data))
      return []

    return [self._result(m) for m in data["results"]]
  def send(self, message):
    args = {
        "post_method": "microblog",
        "user_app_key": self.account["secret_key"],
        "api_key": API_KEY,
        "body": message
    }

    data = network.Download("http://api.ping.fm/v1/user.post", util.compact(args), post=True)
    return []
  def _get(self, path, parse="message", post=False, single=False, **args):
    url = "/".join((URL_PREFIX, "api", path))
    url += ("&" if "?" in url else "?") + "apikey=%s" % self.account["password"]
    data = network.Download(url, util.compact(args) or None, post).get_json()

    resources.dump(self.account["service"], self.account["id"], data)

    if single: return [getattr(self, "_%s" % parse)(data)]
    if parse: return [getattr(self, "_%s" % parse)(m) for m in data]
    else: return []
Exemple #8
0
    def _get(self, path, parse="message", post=False, single=False, **args):
        url = "/".join((URL_PREFIX, "api", path))
        url += ("&" if "?" in url else
                "?") + "apikey=%s" % self.account["password"]
        data = network.Download(url,
                                util.compact(args) or None, post).get_json()

        resources.dump(self.account["service"], self.account["id"], data)

        if single: return [getattr(self, "_%s" % parse)(data)]
        if parse: return [getattr(self, "_%s" % parse)(m) for m in data]
        else: return []
Exemple #9
0
    def send(self, message):
        args = {
            "post_method": "microblog",
            "user_app_key": self.account["secret_key"],
            "api_key": API_KEY,
            "body": message
        }

        data = network.Download("http://api.ping.fm/v1/user.post",
                                util.compact(args),
                                post=True)
        return []
  def _get(self, path, parse="message", post=False, single=False, **args):
    url = "/".join((API_PREFIX, path))

    args['clientip'] = '127.0.0.1'
    args['format'] = 'json'
    request = oauth.OAuthRequest.from_consumer_and_token(self.consumer, self.token,
        http_method=post and "POST" or "GET", http_url=url, parameters=util.compact(args))
    request.sign_request(self.sigmethod, self.consumer, self.token)

    if post:
      data = network.Download(request.to_url(), util.compact(args), post).get_json()
    else:
      data = network.Download(request.to_url(), None, post).get_json()

    resources.dump(self.account["service"], self.account["id"], data)

    if isinstance(data, dict) and data.get("errors", 0):
      if "authenticate" in data["errors"][0]["message"]:
        logstr = """%s: %s - %s""" % (PROTOCOL_INFO["name"], _("Authentication failed"), error["message"])
        log.logger.error("%s", logstr)
        return [{"error": {"type": "auth", "account": self.account, "message": data["errors"][0]["message"]}}]
      else:
        for error in data["errors"]:
          logstr = """%s: %s - %s""" % (PROTOCOL_INFO["name"], _("Unknown failure"), error["message"])
          return [{"error": {"type": "unknown", "account": self.account, "message": error["message"]}}]
    elif isinstance(data, dict) and data.get("error", 0):
      if "Incorrect signature" in data["error"]:
        logstr = """%s: %s - %s""" % (PROTOCOL_INFO["name"], _("Request failed"), data["error"])
        log.logger.error("%s", logstr)
        return [{"error": {"type": "auth", "account": self.account, "message": data["error"]}}]
    elif isinstance(data, str):
      logstr = """%s: %s - %s""" % (PROTOCOL_INFO["name"], _("Request failed"), data)
      log.logger.error("%s", logstr)
      return [{"error": {"type": "request", "account": self.account, "message": data}}]
    if parse == "list":
      return [self._list(l) for l in data["data"]['info']]
    if single: return [getattr(self, "_%s" % parse)(data['data'])]
    if parse: return [getattr(self, "_%s" % parse)(m) for m in data['data']['info']]
    else: return []
Exemple #11
0
  def _get(self, path, parse="story", post=False, single=False, **args):
    url = "/".join((URL_PREFIX, path)) + "?appkey=http://gwibber.com&type=json"
    
    data = network.Download(url, util.compact(args) or None, post).get_json()

    if not data: return []

    if "stories" in data:
        if single: return [getattr(self, "_%s" % parse)(data["stories"])]
        if parse: return [getattr(self, "_%s" % parse)(m) for m in data["stories"]]
        else: return []
    else:
        if ("status" in data) and ("message" in data):
            print "Digg: got message with status %s and message %s" % (data["status"], data["message"])
        return []
Exemple #12
0
  def _get(self, path, parse="message", post=False, single=False, **args):
    if not self.account.has_key("access_token") and not self.account.has_key("secret_token"):
      logger.error("%s unexpected result - %s", PROTOCOL_INFO["name"], _("Account needs to be re-authorized"))
      return [{"error": {"type": "auth", "account": self.account, "message": _("Account needs to be re-authorized")}}]

    self.sigmethod = oauth.OAuthSignatureMethod_HMAC_SHA1()
    self.consumer = oauth.OAuthConsumer("anonymous", "anonymous")
    self.token = oauth.OAuthToken(self.account["access_token"], self.account["secret_token"])

    url = "/".join((self.url_prefix, "api", path))
    parameters = util.compact(args)
    request = oauth.OAuthRequest.from_consumer_and_token(self.consumer, self.token,
        http_method=post and "POST" or "GET", http_url=url, parameters=parameters)
    request.sign_request(self.sigmethod, self.consumer, self.token)

    if post:
      data = network.Download(request.to_url(), parameters, post).get_json()
    else:
      data = network.Download(request.to_url(), None, post).get_json()

    resources.dump(self.account["service"], self.account["id"], data)

    if isinstance(data, dict) and data.get("error", 0):
      logger.error("%s failure - %s", PROTOCOL_INFO["name"], data["error"])
      if "authenticate" in data["error"]:
        return [{"error": {"type": "auth", "account": self.account, "message": data["error"]}}]
      else:
        return [{"error": {"type": "unknown", "account": self.account, "message": data["error"]}}]
    elif isinstance(data, str):
      logger.error("%s unexpected result - %s", PROTOCOL_INFO["name"], data)
      return [{"error": {"type": "unknown", "account": self.account, "message": data}}]

    if parse == "follow" or parse == "unfollow":
      if isinstance(data, dict) and data.get("error", 0):
        logstr = """%s: %s - %s""" % (PROTOCOL_INFO["name"], _("%s failed" % parse), data["error"])
        logger.error("%s", logstr)
        return [{"error": {"type": "auth", "account": self.account, "message": data["error"]}}]
      else:
        return [["friendships", {"type": parse, "account": self.account["id"], "service": self.account["service"],"user_id": data["id"], "nick": data["screen_name"]}]]

    if parse == "profile" and isinstance(data, dict):
      return self._profile(data)

    if single: return [getattr(self, "_%s" % parse)(data)]
    if parse: return [getattr(self, "_%s" % parse)(m) for m in data]
    else: return []

    return [self._result(m) for m in data]
Exemple #13
0
  def _get(self, path, collection="items", parse="message", post=False, single=False, body=None, **args):
    url = "/".join((URL_PREFIX, path))
    args.update({"alt": "json"})
    
    request = oauth.OAuthRequest.from_consumer_and_token(self.consumer, self.token,
        http_method=post and "POST" or "GET", http_url=url, parameters=util.compact(args))
    request.sign_request(self.sigmethod, self.consumer, self.token)

    data = network.Download(request.to_url(), None, post,
        header=["Content-Type: application/json"] if body else None, body=body)
    
    data = data.get_json()

    if single: return [getattr(self, "_%s" % parse)(data["data"])]
    if parse: return [getattr(self, "_%s" % parse)(m) for m in data["data"][collection]]
    else: return []
Exemple #14
0
  def _get(self, path, collection="items", parse="message", post=False, single=False, body=None, **args):
    url = "/".join((URL_PREFIX, path))
    args.update({"alt": "json"})
    
    request = oauth.OAuthRequest.from_consumer_and_token(self.consumer, self.token,
        http_method=post and "POST" or "GET", http_url=url, parameters=util.compact(args))
    request.sign_request(self.sigmethod, self.consumer, self.token)

    data = network.Download(request.to_url(), None, post,
        header=["Content-Type: application/json"] if body else None, body=body)
    
    data = data.get_json()

    if single: return [getattr(self, "_%s" % parse)(data["data"])]
    if parse: return [getattr(self, "_%s" % parse)(m) for m in data["data"][collection]]
    else: return []
Exemple #15
0
    def _get(self, path, parse="message", post=False, single=False, **args):
        url = "/".join((URL_PREFIX, path))

        data = network.Download(url,
                                util.compact(args) or None, post,
                                self.account["username"],
                                self.account["password"]).get_json()

        resources.dump(self.account["service"], self.account["id"], data)

        if not self._check_error(data):
            return []

        checkins = data["checkins"]
        if single: return [getattr(self, "_%s" % parse)(checkins)]
        if parse: return [getattr(self, "_%s" % parse)(m) for m in checkins]
        else: return []
  def _get(self, path, post=False, parse="message", kind="entries", single=False, **args):
    url = "/".join((URL_PREFIX, path))
    data = network.Download(url, util.compact(args), post,
        self.account["username"], self.account["secret_key"]).get_json()

    resources.dump(self.account["service"], self.account["id"], data)

    if isinstance(data, dict) and data.get("errorCode", 0):
      if "unauthorized" in data["errorCode"]:
        raise exceptions.GwibberServiceError("auth", self.account["service"], self.account["username"], data["errorCode"])
   
    if single: return [getattr(self, "_%s" % parse)(data)]
    if parse: return [getattr(self, "_%s" % parse)(m) for m in data["entries"]]
    else: return []

    if parse:
      data = data[kind][0] if single else data[kind]
      return [getattr(self, "_%s" % parse)(m) for m in data]
Exemple #17
0
    def _get(self, path, parse="story", post=False, single=False, **args):
        url = "/".join((URL_PREFIX, path)) + "?appkey=http://gwibber.com&type=json"

        data = network.Download(url, util.compact(args) or None, post).get_json()

        if not data:
            return []

        if "stories" in data:
            if single:
                return [getattr(self, "_%s" % parse)(data["stories"])]
            if parse:
                return [getattr(self, "_%s" % parse)(m) for m in data["stories"]]
            else:
                return []
        else:
            if ("status" in data) and ("message" in data):
                print "Digg: got message with status %s and message %s" % (data["status"], data["message"])
            return []
Exemple #18
0
  def _get(self, path, parse="message", post=False, single=False, **args):
    if not self.account.has_key("access_token") and not self.account.has_key("secret_token"):
      log.logger.error("%s unexpected result - %s", PROTOCOL_INFO["name"], _("Account needs to be re-authorized"))
      return [{"error": {"type": "auth", "account": self.account, "message": _("Account needs to be re-authorized")}}]

    self.sigmethod = oauth.OAuthSignatureMethod_HMAC_SHA1()
    self.consumer = oauth.OAuthConsumer("anonymous", "anonymous")
    self.token = oauth.OAuthToken(self.account["access_token"], self.account["secret_token"])

    url = "/".join((self.url_prefix, "api", path))
    parameters = util.compact(args)
    request = oauth.OAuthRequest.from_consumer_and_token(self.consumer, self.token,
        http_method=post and "POST" or "GET", http_url=url, parameters=parameters)
    request.sign_request(self.sigmethod, self.consumer, self.token)

    if post:
      data = network.Download(request.to_url(), parameters, post).get_json()
    else:
      data = network.Download(request.to_url(), None, post).get_json()

    resources.dump(self.account["service"], self.account["id"], data)

    if isinstance(data, dict) and data.get("error", 0):
      log.logger.error("%s failure - %s", PROTOCOL_INFO["name"], data["error"])
      if "authenticate" in data["error"]:
        return [{"error": {"type": "auth", "account": self.account, "message": data["error"]}}]
      else:
        return [{"error": {"type": "unknown", "account": self.account, "message": data["error"]}}]
    elif isinstance(data, str):
      log.logger.error("%s unexpected result - %s", PROTOCOL_INFO["name"], data)
      return [{"error": {"type": "unknown", "account": self.account, "message": data}}]

    if single: return [getattr(self, "_%s" % parse)(data)]
    if parse: return [getattr(self, "_%s" % parse)(m) for m in data]
    else: return []

    return [self._result(m) for m in data]
  def _search(self, **args):
    data = network.Download("%s/api/search.json" % self.url_prefix, util.compact(args))
    data = data.get_json()

    return [self._result(m) for m in data["results"]]
  def _search(self, **args):
    data = network.Download("http://search.twitter.com/search.json", util.compact(args))
    data = data.get_json()["results"]

    return [self._result(m) for m in data]
Exemple #21
0
    def _get(self, path, parse="message", post=False, single=False, **args):
        url = "/".join((API_PREFIX, path))

        request = oauth.OAuthRequest.from_consumer_and_token(
            self.consumer,
            self.token,
            http_method=post and "POST" or "GET",
            http_url=url,
            parameters=util.compact(args))
        request.sign_request(self.sigmethod, self.consumer, self.token)

        if post:
            data = network.Download(request.to_url(), util.compact(args),
                                    post).get_json()
        else:
            data = network.Download(request.to_url(), None, post).get_json()

        resources.dump(self.account["service"], self.account["id"], data)

        if isinstance(data, dict) and data.get("errors", 0):
            if "authenticate" in data["errors"][0]["message"]:
                logstr = """%s: %s - %s""" % (PROTOCOL_INFO["name"],
                                              _("Authentication failed"),
                                              error["message"])
                log.logger.error("%s", logstr)
                return [{
                    "error": {
                        "type": "auth",
                        "account": self.account,
                        "message": data["errors"][0]["message"]
                    }
                }]
            else:
                for error in data["errors"]:
                    logstr = """%s: %s - %s""" % (PROTOCOL_INFO["name"],
                                                  _("Unknown failure"),
                                                  error["message"])
                    return [{
                        "error": {
                            "type": "unknown",
                            "account": self.account,
                            "message": error["message"]
                        }
                    }]
        elif isinstance(data, dict) and data.get("error", 0):
            if "Incorrect signature" in data["error"]:
                logstr = """%s: %s - %s""" % (
                    PROTOCOL_INFO["name"], _("Request failed"), data["error"])
                log.logger.error("%s", logstr)
                return [{
                    "error": {
                        "type": "auth",
                        "account": self.account,
                        "message": data["error"]
                    }
                }]
        elif isinstance(data, str):
            logstr = """%s: %s - %s""" % (PROTOCOL_INFO["name"],
                                          _("Request failed"), data)
            log.logger.error("%s", logstr)
            return [{
                "error": {
                    "type": "request",
                    "account": self.account,
                    "message": data
                }
            }]

        if parse == "list":
            return [self._list(l) for l in data["lists"]]
        if single: return [getattr(self, "_%s" % parse)(data)]
        if parse: return [getattr(self, "_%s" % parse)(m) for m in data]
        else: return []
Exemple #22
0
    def _search(self, **args):
        data = network.Download("http://search.twitter.com/search.json",
                                util.compact(args))
        data = data.get_json()["results"]

        return [self._result(m) for m in data]