instapush/libs/gcm.py
def send_json(self, ids=None):
        """
        Sends a json GCM message
        """

        items = ids or self._registration_id
        values = {"registration_ids": items}

        if self._data is not None:
            values["data"] = self._data

        for key, val in self._kwargs.items():
            if val:
                values[key] = val

        data = json.dumps(values, separators=(",", ":"), sort_keys=True).encode(
                self.encoding)

        result = json.loads(self._send(data, "application/json"))

        if ("failure" in result) and (result["failure"]):
            unregistered = []
            throw_error = False

            for index, error in enumerate(result.get("results", [])):
                error = error.get("error", "")
                if error in ("NotRegistered", "InvalidRegistration"):
                    unregistered.append(items[index])
                elif error != "":
                    throw_error = True

            self.deactivate_unregistered_devices(unregistered)
            if throw_error:
                raise GCMPushError(result)

        return result
def send_json(self, ids=None):
        """
        Sends a json GCM message
        """

        items = ids or self._registration_id
        values = {"registration_ids": items}

        if self._data is not None:
            values["data"] = self._data

        for key, val in self._kwargs.items():
            if val:
                values[key] = val

        data = json.dumps(values, separators=(",", ":"), sort_keys=True).encode(
                self.encoding)

        result = json.loads(self._send(data, "application/json"))

        if ("failure" in result) and (result["failure"]):
            unregistered = []
            throw_error = False

            for index, error in enumerate(result.get("results", [])):
                error = error.get("error", "")
                if error in ("NotRegistered", "InvalidRegistration"):
                    unregistered.append(items[index])
                elif error != "":
                    throw_error = True

            self.deactivate_unregistered_devices(unregistered)
            if throw_error:
                raise GCMPushError(result)

        return result
Sends a json GCM message