def _BuildOobLink(self, param, mode): """Builds out-of-band URL. Gitkit API GetOobCode() is called and the returning code is combined with Gitkit widget URL to building the out-of-band url. Args: param: dict of request. mode: string, Gitkit widget mode to handle the oob action after user clicks the oob url in the email. Raises: GitkitClientError: if oob code is not returned. Returns: A string of oob url. """ code = self.rpc_helper.GetOobCode(param) if code: parsed = list(urlparse.urlparse(self.widget_url)) query = dict(urlparse.parse_qsl(parsed[4])) query.update({'mode': mode, 'oobCode': code}) parsed[4] = urllib.urlencode(query) return code, urlparse.urlunparse(parsed) raise errors.GitkitClientError('invalid request')
def _CheckGitkitError(self, raw_response): """Raises error if API invocation failed. Args: raw_response: string, the http response. Raises: GitkitClientError: if the error code is 4xx. GitkitServerError: if the response if malformed. Returns: Successful response as dict. """ try: response = simplejson.loads(raw_response) if 'error' not in response: return response else: error = response['error'] if 'code' in error: code = error['code'] if str(code).startswith('4'): raise errors.GitkitClientError(error['message']) else: raise errors.GitkitServerError(error['message']) except simplejson.JSONDecodeError: pass raise errors.GitkitServerError('null error code from Gitkit server')
def FromDictionary(cls, dictionary): """Initializes from user specified dictionary. Args: dictionary: dict of user specified attributes Returns: GitkitUser object """ if 'user_id' in dictionary: raise errors.GitkitClientError('use localId instead') if 'localId' not in dictionary: raise errors.GitkitClientError('must specify localId') if 'email' not in dictionary: raise errors.GitkitClientError('must specify email') return cls(decode=False, **dictionary)