def __init__(self, configuration): super(TffBackendPlugin, self).__init__(configuration) self.configuration = parse_complex_value( TffConfiguration, configuration, False) # type: TffConfiguration rogerthat_api_plugin = get_plugin('rogerthat_api') assert (isinstance(rogerthat_api_plugin, RogerthatApiPlugin)) rogerthat_api_plugin.subscribe('messaging.flow_member_result', rogerthat_callbacks.flow_member_result) rogerthat_api_plugin.subscribe('messaging.form_update', rogerthat_callbacks.form_update) rogerthat_api_plugin.subscribe('messaging.update', rogerthat_callbacks.messaging_update) rogerthat_api_plugin.subscribe('messaging.poke', rogerthat_callbacks.messaging_poke) rogerthat_api_plugin.subscribe('friend.is_in_roles', rogerthat_callbacks.friend_is_in_roles) rogerthat_api_plugin.subscribe('friend.update', rogerthat_callbacks.friend_update) rogerthat_api_plugin.subscribe('friend.invited', rogerthat_callbacks.friend_invited) rogerthat_api_plugin.subscribe('friend.register', rogerthat_callbacks.friend_register, trigger_only=True) rogerthat_api_plugin.subscribe( 'friend.invite_result', rogerthat_callbacks.friend_invite_result, trigger_only=True) rogerthat_api_plugin.subscribe('system.api_call', rogerthat_callbacks.system_api_call) patch_onfido_lib()
def __init__(self, configuration): super(IntercomSupportPlugin, self).__init__(configuration) rogerthat_api_plugin = get_plugin('rogerthat_api') assert isinstance(rogerthat_api_plugin, RogerthatApiPlugin) rogerthat_api_plugin.subscribe('messaging.poke', rogerthat_callbacks.messaging_poke, trigger_only=True) rogerthat_api_plugin.subscribe('messaging.new_chat_message', rogerthat_callbacks.messaging_new_chat_message, trigger_only=True)
def call_rogerthat(api_key, method, params, json_rpc_id=None): # type: (unicode, unicode, dict, unicode) -> dict azzert(api_key, 'No API_KEY provided') request = { 'id': json_rpc_id or guid(), 'method': method, 'params': params } run_hook('before_api_call', request) headers = { 'Content-Type': 'application/json-rpc; charset=utf-8', 'X-Nuntiuz-API-key': api_key } json_request = json.dumps(request) api_url = '%s/api/1' % get_plugin(NAMESPACE).configuration.rogerthat_server_url result = urlfetch.fetch(api_url, json_request, method=urlfetch.POST, headers=headers, deadline=600) if result.status_code != httplib.OK: raise RogerthatApiStatusCodeException(result.status_code) json_response = str(result.content) response = json.loads(json_response) run_hook('after_api_call', method, response) error = response['error'] if error: if error['code'] != 1000: raise RogerthatApiException(error) else: raise RogerthatApiUnknownException(error) # Unknown error (e.g. datastore timeout / transaction collision) return response['result']
def log_restapi_call_result(function, success, kwargs, result_or_error): offload_plugin = get_plugin('log_offload') if not offload_plugin: return if function.meta['silent']: request_data = None else: kwarg_types = function.meta[u'kwarg_types'] request_data = {} for arg, value in kwargs.iteritems(): if arg == 'accept_missing' or value is MISSING: continue request_data[arg] = serialize_value(value, *get_type_details( kwarg_types[arg], value), skip_missing=True) if function.meta['silent_result']: result = None elif isinstance(result_or_error, Exception): result = unicode(result_or_error) else: result = result_or_error offload_plugin.create_log(get_current_user_id(), LogTypes.WEB, request_data, result, function.meta['uri'], success)
def populate_intercom_user(session_key, user_detail=None): """ Creates or updates an intercom user with information from itsyou.online Args: session_key (ndb.Key): key of the Session for this user user_detail (UserDetailsTO): key of the Session for this user """ intercom_plugin = get_plugin('intercom_support') if intercom_plugin: session = session_key.get() if not session: return assert isinstance(session, Session) assert isinstance(intercom_plugin, IntercomSupportPlugin) data = get_user(session.user_id, session.jwt) intercom_user = upsert_intercom_user(data.username, data) tag_intercom_users(IntercomTags.APP_REGISTER, [data.username]) if user_detail: message = """Welcome to the ThreeFold Foundation app. If you have questions you can get in touch with us through this chat. Our team is at your service during these hours: Sunday: 07:00 - 15:00 GMT +1 Monday - Friday: 09:00 - 17:00 GMT +1 Of course you can always ask your questions outside these hours, we will then get back to you the next business day.""" chat_id = start_or_get_chat(get_config(NAMESPACE).rogerthat.api_key, '+default+', user_detail.email, user_detail.app_id, intercom_user, message) deferred.defer(store_chat_id_in_user_data, chat_id, user_detail)
def get(self, *args, **kwargs): if get_current_session(): render_logged_in_page(self) else: query = self.request.query if self.request.query else '' if not self.request.GET.get('source'): plugin = get_plugin( IYO_AUTH_NAMESPACE) # type: ItsYouOnlineAuthPlugin query += '&scope=user:memberof:%s' % plugin.configuration.root_organization.name parameters = { 'lang': get_user_language(), 'query_params': '?%s' % query } render_page(self.response, 'unauthorized_index.html', template_parameters=parameters)
def __init__(self, configuration): super(ItsYouOnlineAuthPlugin, self).__init__(configuration) self.configuration = parse_complex_value(ItsYouOnlineConfiguration, configuration, False) # type: ItsYouOnlineConfiguration if self.configuration.api_domain is MISSING: self.configuration.api_domain = u'itsyou.online' if self.configuration.iyo_public_key is MISSING: # key from https://itsyou.online by default self.configuration.iyo_public_key = """-----BEGIN PUBLIC KEY----- MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAES5X8XrfKdx9gYayFITc89wad4usrk0n2 7MjiGYvqalizeSWTHEpnd7oea9IQ8T5oJjMVH5cc0H5tFSKilFFeh//wngxIyny6 6+Vq5t5B0V0Ehy01+2ceEon2Y0XDkIKv -----END PUBLIC KEY-----""" if self.configuration.fetch_information is MISSING: self.configuration.fetch_information = False rogerthat_api_plugin = get_plugin('rogerthat_api') assert isinstance(rogerthat_api_plugin, RogerthatApiPlugin) rogerthat_api_plugin.subscribe('friend.register', friend_register) self.base_uri = u'https://%s/' % self.configuration.api_domain self.api_uri = u'%sapi' % self.base_uri self.oauth_base_url = '%sv1/oauth' % self.base_uri HTTPClient._handle_data = _new_handle_data
def get_iyo_plugin(): # type: () -> ItsYouOnlineAuthPlugin return get_plugin(IYO_AUTH_NAMESPACE)
def __init__(self, configuration): super(VeurneTrashPlugin, self).__init__(configuration) rogerthat_api_plugin = get_plugin('rogerthat_api') assert isinstance(rogerthat_api_plugin, RogerthatApiPlugin) rogerthat_api_plugin.subscribe('system.api_call', system_api_call)
def get_rcc_plugin(): # type: () -> RogerthatControlCenterPlugin p = get_plugin(NAMESPACE) return p
def get_intercom_plugin(): intercom_plugin = get_plugin(INTERCOM_NAMESPACE) # type: IntercomSupportPlugin if intercom_plugin: assert isinstance(intercom_plugin, IntercomSupportPlugin) return intercom_plugin