Exemplo n.º 1
0
    def _transmit(self, queue_item, subscriber):
        """
        @see: PublishService._transmit
        """
        item = json.loads(queue_item['formatted_item'])

        destination = queue_item.get('destination', {})
        assets_url = destination.get('config', {}).get('assets_url')
        try:
            self._copy_published_media_files(
                json.loads(queue_item['formatted_item']), assets_url)
        except Exception as e:
            raise PublishHTTPPushError.httpPushError(e, destination)

        if not queue_item.get(PUBLISHED_IN_PACKAGE) or not destination.get(
                'config', {}).get('packaged', False):
            resource_url = destination.get('config', {}).get('resource_url')
            response = requests.post(resource_url,
                                     data=json.dumps(item),
                                     headers=self.headers)
            if response.status_code != requests.codes.created:  # @UndefinedVariable
                message = 'Error pushing item %s: %s' % (response.status_code,
                                                         response.text)
                raise PublishHTTPPushError.httpPushError(
                    Exception(message, destination))
Exemplo n.º 2
0
    def _transmit(self, queue_item, subscriber):
        """
        @see: PublishService._transmit
        """
        item = json.loads(queue_item['formatted_item'])
        item['guid'] = item[config.ID_FIELD]
        del item[config.ID_FIELD]

        assets_url = queue_item.get('destination',
                                    {}).get('config', {}).get('assets_url')
        try:
            self._copy_published_media_files(
                json.loads(queue_item['formatted_item']), assets_url)
        except Exception as e:
            raise PublishHTTPPushError.httpPushError(
                e, queue_item.get('destination', {}))

        resource_url = queue_item.get('destination',
                                      {}).get('config', {}).get('resource_url')
        response = requests.post(resource_url,
                                 data=json.dumps(item),
                                 headers=self.headers)
        if response.status_code != requests.codes.created:  # @UndefinedVariable
            raise PublishHTTPPushError.httpPushError(
                Exception('Error pushing item %s' % response.text),
                queue_item.get('destination', {}))
Exemplo n.º 3
0
 def _raise_publish_error(self, status_code, e, destination=None):
     if status_code >= 400 and status_code < 500:
         raise PublishHTTPPushClientError.httpPushError(e, destination)
     elif status_code >= 500 and status_code < 600:
         raise PublishHTTPPushServerError.httpPushError(e, destination)
     else:
         raise PublishHTTPPushError.httpPushError(e, destination)
Exemplo n.º 4
0
 def _raise_publish_error(self, status_code, e, destination=None):
     if status_code >= 400 and status_code < 500:
         raise PublishHTTPPushClientError.httpPushError(e, destination)
     elif status_code >= 500 and status_code < 600:
         raise PublishHTTPPushServerError.httpPushError(e, destination)
     else:
         raise PublishHTTPPushError.httpPushError(e, destination)
Exemplo n.º 5
0
    def _transmit(self, queue_item, subscriber):
        """
        @see: PublishService._transmit
        """
        item = json.loads(queue_item['formatted_item'])

        destination = queue_item.get('destination', {})
        assets_url = destination.get('config', {}).get('assets_url')
        try:
            self._copy_published_media_files(json.loads(queue_item['formatted_item']), assets_url)
        except Exception as e:
            raise PublishHTTPPushError.httpPushError(e, destination)

        if not queue_item.get(PUBLISHED_IN_PACKAGE) or not destination.get('config', {}).get('packaged', False):
            resource_url = destination.get('config', {}).get('resource_url')
            response = requests.post(resource_url, data=json.dumps(item), headers=self.headers)
            if response.status_code != requests.codes.created:  # @UndefinedVariable
                message = 'Error pushing item %s: %s' % (response.status_code, response.text)
                raise PublishHTTPPushError.httpPushError(Exception(message, destination))
Exemplo n.º 6
0
    def _transmit(self, queue_item, subscriber):
        """
        @see: PublishService._transmit
        """
        item = json.loads(queue_item["formatted_item"])
        item["guid"] = item[config.ID_FIELD]
        del item[config.ID_FIELD]

        assets_url = queue_item.get("destination", {}).get("config", {}).get("assets_url")
        try:
            self._copy_published_media_files(json.loads(queue_item["formatted_item"]), assets_url)
        except Exception as e:
            raise PublishHTTPPushError.httpPushError(e, queue_item.get("destination", {}))

        resource_url = queue_item.get("destination", {}).get("config", {}).get("resource_url")
        response = requests.post(resource_url, data=json.dumps(item), headers=self.headers)
        if response.status_code != requests.codes.created:  # @UndefinedVariable
            raise PublishHTTPPushError.httpPushError(
                Exception("Error pushing item %s" % response.text), queue_item.get("destination", {})
            )
Exemplo n.º 7
0
# For the full copyright and license information, please see the
# AUTHORS and LICENSE files distributed with this source code, or
# at https://www.sourcefabric.org/superdesk/license

import json

from eve.utils import config
import requests

from superdesk import app
from superdesk.errors import PublishHTTPPushError
from superdesk.publish import register_transmitter
from superdesk.publish.publish_service import PublishService


errors = [PublishHTTPPushError.httpPushError().get_error_description()]


class HTTPPushService(PublishService):
    """HTTP Publish Service."""

    headers = {"Content-type": "application/json", "Accept": "application/json"}

    def _transmit(self, queue_item, subscriber):
        """
        @see: PublishService._transmit
        """
        item = json.loads(queue_item["formatted_item"])
        item["guid"] = item[config.ID_FIELD]
        del item[config.ID_FIELD]
Exemplo n.º 8
0
# AUTHORS and LICENSE files distributed with this source code, or
# at https://www.sourcefabric.org/superdesk/license

import json
import hmac
import logging
import requests

from superdesk import app
from superdesk.publish import register_transmitter

from superdesk.errors import PublishHTTPPushError, PublishHTTPPushServerError, PublishHTTPPushClientError
from superdesk.publish.publish_queue import PUBLISHED_IN_PACKAGE
from superdesk.publish.publish_service import PublishService

errors = [PublishHTTPPushError.httpPushError().get_error_description()]
logger = logging.getLogger(__name__)


class HTTPPushService(PublishService):
    """HTTP Publish Service.

    The HTTP push service publishes items to the resource service via ``POST`` request.
    For media items it first publishes the media files to the assets service.

    For text items the publish sequence is like this:

    * ``POST`` to resource service the text item

    For media items the publish sequence is like this: