|
| 1 | +from pubnub import utils |
| 2 | +from pubnub.endpoints.endpoint import Endpoint |
| 3 | +from pubnub.enums import HttpMethod, PNOperationType |
| 4 | +from pubnub.models.consumer.signal import PNSignalResult |
| 5 | + |
| 6 | + |
| 7 | +class Signal(Endpoint): |
| 8 | + SIGNAL_PATH = '/signal/%s/%s/0/%s/0/%s' |
| 9 | + |
| 10 | + def __init__(self, pubnub): |
| 11 | + Endpoint.__init__(self, pubnub) |
| 12 | + self._channel = None |
| 13 | + self._message = None |
| 14 | + |
| 15 | + def channel(self, channel): |
| 16 | + self._channel = str(channel) |
| 17 | + return self |
| 18 | + |
| 19 | + def message(self, message): |
| 20 | + self._message = message |
| 21 | + return self |
| 22 | + |
| 23 | + def build_path(self): |
| 24 | + stringified_message = utils.write_value_as_string(self._message) |
| 25 | + msg = utils.url_encode(stringified_message) |
| 26 | + return Signal.SIGNAL_PATH % ( |
| 27 | + self.pubnub.config.publish_key, self.pubnub.config.subscribe_key, |
| 28 | + utils.url_encode(self._channel), msg |
| 29 | + ) |
| 30 | + |
| 31 | + def custom_params(self): |
| 32 | + return {} |
| 33 | + |
| 34 | + def http_method(self): |
| 35 | + return HttpMethod.GET |
| 36 | + |
| 37 | + def is_auth_required(self): |
| 38 | + return True |
| 39 | + |
| 40 | + def validate_params(self): |
| 41 | + self.validate_subscribe_key() |
| 42 | + self.validate_publish_key() |
| 43 | + self.validate_channel() |
| 44 | + |
| 45 | + def create_response(self, result): # pylint: disable=W0221 |
| 46 | + return PNSignalResult(result) |
| 47 | + |
| 48 | + def request_timeout(self): |
| 49 | + return self.pubnub.config.non_subscribe_request_timeout |
| 50 | + |
| 51 | + def connect_timeout(self): |
| 52 | + return self.pubnub.config.connect_timeout |
| 53 | + |
| 54 | + def operation_type(self): |
| 55 | + return PNOperationType.PNSignalOperation |
| 56 | + |
| 57 | + def name(self): |
| 58 | + return "Signal" |
0 commit comments