Пример #1
0
    def update_subscription(self, subscription):
        """
        Update an existing subscription on a given channel

        :param subscription:
        is the updated subscription that the client wants to update
        """
        #Validate
        if subscription.get_channel() is not None:
            self._validate_uuid(subscription.get_channel().get_channel_id())
        if subscription.get_endpoint() is not None:
            if subscription.get_endpoint().get_endpoint_id() is not None:
                self._validate_uuid(subscription.get_endpoint().get_endpoint_id())
            self._validate_subscriber_id(subscription.get_endpoint().get_user_net_id())

        #Update the subscription
        dao = NWS_DAO()
        url = "/notification/v1/subscription/%s" % (subscription.subscription_id)
        headers = {"Content-Type": "application/json"}
        if self.override_user is not None:
            headers['X_UW_ACT_AS'] = self.override_user

        put_response = dao.putURL(url, headers, Serializer().serialize(subscription))

        #Http response code 204 No Content:
        #The server has fulfilled the request but does not need to return an entity-body
        if put_response.status != 204:
            raise DataFailureException(url, put_response.status, put_response.data)

        return put_response.status
Пример #2
0
    def update_endpoint(self, endpoint):
        """
        Update an existing endpoint

        :param endpoint:
        is the updated endpoint that the client wants to update
        """
        #Validate
        self._validate_uuid(endpoint.endpoint_id)
        self._validate_subscriber_id(endpoint.user)

        #Update the subscription
        dao = NWS_DAO()
        url = "/notification/v1/endpoint/%s" % (endpoint.endpoint_id)
        headers = {"Content-Type": "application/json"}
        if self.override_user is not None:
            headers['X_UW_ACT_AS'] = self.override_user

        put_response = dao.putURL(url, headers, Serializer().serialize(endpoint))

        #Http response code 204 No Content:
        #The server has fulfilled the request but does not need to return an entity-body
        if put_response.status != 204:
            raise DataFailureException(url, put_response.status, put_response.data)

        return put_response.status
Пример #3
0
    def update_channel(self, channel):
        """
        Update an existing channel

        :param channel:
        is the updated channel that the client wants to update
        """
        #Update the channel
        dao = NWS_DAO()
        url = "/notification/v1/channel/%s" % (channel.channel_id)

        put_response = dao.putURL(url, {"Content-Type": "application/json"}, Serializer().serialize(channel))

        #Http response code 204 No Content:
        #The server has fulfilled the request but does not need to return an entity-body
        if put_response.status != 204:
            raise DataFailureException(url, put_response.status, put_response.data)

        return put_response.status
Пример #4
0
    def update_person(self, person):
        """
        Update an existing person

        :param person:
        is the updated person that the client wants to update
        """
        #Validate
        self._validate_regid(person.person_id)
        self._validate_subscriber_id(person.surrogate_id)

        attributes = person.get_attributes()
        person.attributes = None

        for attribute in attributes:
            if attribute.name in MANAGED_ATTRIBUTES:
                continue

            person.add_attribute(attribute.name, attribute.value, None, None)
        #    ATTRIBUTE_TYPE_EMAIL_DISPATCHED_COUNT = 'DispatchedEmailCount'
        #    ATTRIBUTE_TYPE_SMS_DISPATCHED_COUNT = 'DispatchedTextMessageCount'
        #        ATTRIBUTE_TYPE_SMS_SENT_COUNT = 'SentTextMessageCount'
        #            ATTRIBUTE_TYPE_SUBSCRIPTION_COUNT = 'SubscriptionCount'

        dao = NWS_DAO()
        url = "/notification/v1/person/%s" % (person.person_id)
        headers = {"Content-Type": "application/json"}
        if self.override_user is not None:
            headers['X_UW_ACT_AS'] = self.override_user

        put_response = dao.putURL(url, headers, Serializer().serialize(person))

        #Http response code 204 No Content:
        #The server has fulfilled the request but does not need to return an entity-body
        if put_response.status != 204:
            raise DataFailureException(url, put_response.status, put_response.data)

        return put_response.status