Ejemplo n.º 1
0
    def __init__(self,
                 app_id,
                 key,
                 secret,
                 ssl=True,
                 host=None,
                 port=None,
                 timeout=5,
                 cluster=None,
                 json_encoder=None,
                 json_decoder=None,
                 backend=None,
                 **backend_options):
        super(EventflitClient,
              self).__init__(app_id, key, secret, ssl, host, port, timeout,
                             cluster, json_encoder, json_decoder, backend,
                             **backend_options)

        if host:
            self._host = ensure_text(host, "host")

        elif cluster:
            self._host = (six.text_type("api-%s.eventflit.com") %
                          ensure_text(cluster, "cluster"))
        else:
            self._host = six.text_type("service.eventflit.com")
Ejemplo n.º 2
0
    def trigger(self, channels, event_name, data, socket_id=None):
        """Trigger an event on one or more channels, see:

        http://eventflit.com/docs/rest_api#method-post-event
        """
        if isinstance(channels, six.string_types):
            channels = [channels]

        if isinstance(channels, dict) or not isinstance(
                channels, (collections.Sized, collections.Iterable)):
            raise TypeError("Expected a single or a list of channels")

        if len(channels) > 100:
            raise ValueError("Too many channels")

        channels = list(map(validate_channel, channels))

        event_name = ensure_text(event_name, "event_name")

        if len(event_name) > 200:
            raise ValueError("event_name too long")

        data = data_to_string(data, self._json_encoder)

        if len(data) > 10240:
            raise ValueError("Too much data")

        params = {'name': event_name, 'channels': channels, 'data': data}

        if socket_id:
            params['socket_id'] = validate_socket_id(socket_id)

        return Request(self, POST, "/apps/%s/events" % self.app_id, params)
Ejemplo n.º 3
0
    def from_url(cls, url, **options):
        """Alternative constructor that extracts the information from a URL.

        :param url: String containing a URL

        Usage::

          >> from eventflit import Eventflit
          >> p =
            Eventflit.from_url("http://*****:*****@eventflit.com/apps/432")
        """
        m = eventflit_url_re.match(ensure_text(url, "url"))
        if not m:
            raise Exception("Unparsable url: %s" % url)

        ssl = m.group(1) == 'https'

        options_ = {
            'key': m.group(2),
            'secret': m.group(3),
            'host': m.group(4),
            'app_id': m.group(5),
            'ssl': ssl
        }

        options_.update(options)

        return cls(**options_)
Ejemplo n.º 4
0
    def channels_info(self, prefix_filter=None, attributes=[]):
        """Get information on multiple channels, see:

        http://eventflit.com/docs/rest_api#method-get-channels
        """
        params = {}
        if attributes:
            params['info'] = join_attributes(attributes)

        if prefix_filter:
            params['filter_by_prefix'] = ensure_text(prefix_filter,
                                                     "prefix_filter")

        return Request(self, GET,
                       six.text_type("/apps/%s/channels") % self.app_id,
                       params)
Ejemplo n.º 5
0
    def __init__(self,
                 app_id,
                 key,
                 secret,
                 ssl=True,
                 host=None,
                 port=None,
                 timeout=30,
                 cluster=None,
                 json_encoder=None,
                 json_decoder=None,
                 backend=None,
                 **backend_options):
        super(NotificationClient,
              self).__init__(app_id, key, secret, ssl, host, port, timeout,
                             cluster, json_encoder, json_decoder, backend,
                             **backend_options)

        if host:
            self._host = ensure_text(host, "host")

        else:
            self._host = DEFAULT_HOST