def get_idcard_photo(self, regid, size="medium"): """ Returns a jpeg image, for the passed uwregid. Size is configured as: "small" (20w x 25h px), "medium" (120w x 150h px), "large" (240w x 300h px), {height in pixels} (custom height, default aspect ratio) """ if not self.valid_uwregid(regid): raise InvalidRegID(regid) size = str(size) if (not re.match(r"(?:small|medium|large)$", size) and not re.match(r"[1-9]\d{1,3}$", size)): raise InvalidIdCardPhotoSize(size) url = "/idcard/v1/photo/%s-%s.jpg" % (regid.upper(), size) headers = {"Accept": "image/jpeg"} if self.actas is not None: if not self.valid_uwnetid(self.actas): raise InvalidNetID(self.actas) headers["X-UW-Act-as"] = self.actas response = PWS_DAO().getURL(url, headers) if response.status != 200: raise DataFailureException(url, response.status, response.data) return StringIO(response.data)
def put_name_by_netid(self, netid, data): """ Updates display info for a Name object """ if not self.valid_uwnetid(netid): raise InvalidNetID(netid) pd = self.valid_irws_name_from_json(data) dao = IRWS_DAO() url = "/%s/v1/name/uwnetid=%s" % (self._service_name, netid.lower()) response = dao.putURL(url, {"Accept": "application/json"}, json.dumps(pd)) if response.status != 200: raise DataFailureException(url, response.status, response.data) return response.status
def get_name_by_netid(self, netid): """ Returns a restclients.irws.Name object for the given netid. If the netid isn't found, nothing will be returned. If there is an error communicating with the IRWS, a DataFailureException will be thrown. """ if not self.valid_uwnetid(netid): raise InvalidNetID(netid) dao = IRWS_DAO() url = "/%s/v1/name/uwnetid=%s" % (self._service_name, netid.lower()) response = dao.getURL(url, {"Accept": "application/json"}) if response.status != 200: raise DataFailureException(url, response.status, response.data) return self._name_from_json(response.data)
def get_person_by_netid(self, netid): """ Returns a restclients.Person object for the given netid. If the netid isn't found, or if there is an error communicating with the PWS, a DataFailureException will be thrown. """ if not self.valid_uwnetid(netid): raise InvalidNetID(netid) dao = PWS_DAO() url = "%s/%s/full.json" % (PERSON_PREFIX, netid.lower()) response = dao.getURL(url, {"Accept": "application/json"}) if response.status != 200: raise DataFailureException(url, response.status, response.data) return self._person_from_json(response.data)
def post_hr_person_by_netid(self, netid, data): """ Post to the irws person hr resource. We look up the person by netid to get the uri to post to. """ if not self.valid_uwnetid(netid): raise InvalidNetID(netid) hepps_person = self.valid_hr_person_from_json(data) identity = self.get_identity_by_netid(netid) if not {'hepps', 'uwhr'} & set(identity.identifiers.keys()): raise IRWSPersonNotFound( 'netid {} not a hepps/uwhr person'.format(netid)) source = 'uwhr' if 'uwhr' in identity.identifiers.keys() else 'hepps' post_url = '/{}/v1{}'.format(self._service_name, identity.identifiers[source]) response = IRWS_DAO().postURL(post_url, {'Accept': 'application/json'}, json.dumps(hepps_person)) if response.status != 200: raise DataFailureException(post_url, response.status, response.data) return response.status
def _validate_subscriber_id(self, subscriber_id): if subscriber_id is None or subscriber_id == '': raise InvalidNetID(subscriber_id) if not re.match(r'^([a-z]adm_)?[a-z][a-z0-9]{0,7}(@washington.edu)?$', subscriber_id, re.I): raise InvalidNetID(subscriber_id)