def getCalendars(auth: str, start: datetime, end: datetime, userId: str): url = "https://api-prod.hypercare.com/graphql/private" hypercareScope = httphelper.encodeBase64( 'eyJvcmdhbml6YXRpb25JZCI6NzEsInN0YXR1cyI6ImFkbWluIn0K') start = str(start).split(" ") start = start[0] + "T" + start[1] + ".000Z" end = str(end).split(" ") end = end[0] + "T" + end[1] + ".001Z" #payload = "{\"query\":\"query FetchDepartment($departmentId: Int!, $startDate: String!, $endDate: String!) {\\n locating {\\n department(id: $departmentId) {\\n ...DepartmentFragment\\n }\\n }\\n}\\n\\nfragment GeneralUserFragment on GeneralUser {\\n id\\n firstname\\n lastname\\n username\\n}\\n\\nfragment DepartmentFragment on Department {\\n id\\n name\\n roles {\\n ...RoleFragment\\n }\\n}\\n\\nfragment RoleFragment on Role {\\n id\\n name\\n startTime\\n duration\\n pagerNumber\\n site {\\n id\\n name\\n }\\n currentShift {\\n ...ShiftFragment\\n }\\n nextShift {\\n ...ShiftFragment\\n }\\n shifts(startDate: $startDate, endDate: $endDate) {\\n ...ShiftFragment\\n }\\n createdAt\\n updatedAt\\n}\\n\\nfragment ShiftFragment on Shift {\\n id\\n startDate\\n endDate\\n user {\\n ...GeneralUserFragment\\n }\\n}\\n\",\"variables\":{\"departmentId\":105,\"endDate\":\""+end+"\",\"startDate\":\""+start+"\"}}" payload = "{\"query\":\"query FetchShiftsInRange($departmentId: Int!, $startDate: String!, $endDate: String!) {\\n locating {\\n department(id: $departmentId) {\\n roles {\\n id\\n shifts(startDate: $startDate, endDate: $endDate) {\\n ...ShiftFragment\\n }\\n }\\n }\\n }\\n}\\n\\nfragment ShiftFragment on Shift {\\n id\\n user {\\n ...GeneralUserFragment\\n }\\n startDate\\n endDate\\n}\\n\\nfragment GeneralUserFragment on GeneralUser {\\n id\\n firstname\\n lastname\\n username\\n}\",\"variables\":{\"departmentId\":105,\"endDate\":\"" + end + "\",\"startDate\":\"" + start + "\"}}" headers = { 'hypercare-scope': hypercareScope, 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + auth } response = httphelper.post(url, headers, payload) #print(response.status_code) #print(response.text.encode('utf8')) file = json.loads(response.text) prog = file["data"]["locating"]["department"]["roles"][2]["shifts"] for shift in prog: if shift["user"]["id"] == userId: return False return True
def removeWebhook(auth) -> str: url = "https://api-prod.hypercare.com/graphql/private" payload = "{\"query\":\"mutation UnregisterWebhook {\\n"+\ " self {\\n"+\ " unregisterWebhook\\n"+\ " }\\n"+\ "}\",\"variables\":{}}" headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + auth } return httphelper.post(url, headers, payload).text.encode('utf8')
def getId(auth: str, orgId: int): url = "https://api-prod.hypercare.com/graphql/private" hypercareScope = httphelper.encodeBase64('{"organizationId":' + str(orgId) + '}') payload = "{\"query\":\"query self {\\n me {\\n ...FullUserFields\\n }\\n}\\n\\nfragment FullUserFields on FullUser {\\n id\\n firstname\\n lastname\\n username\\n role\\n profilePic {\\n url\\n }\\n inviteCode\\n}\",\"variables\":{}}" headers = { 'hypercare-scope': hypercareScope, 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + auth } response = httphelper.post(url, headers, payload).json() return response['data']['me']['id']
def addWebhook(hook: str, auth: str) -> str: url = "https://api-prod.hypercare.com/graphql/private" payload = "{\"query\":\"mutation RegisterWebhook($url: String!) {\\n"+\ " self {\\n"+\ " registerWebhook(url: $url) {\\n"+\ " url\\n"+\ " createdAt\\n"+\ " updatedAt\\n"+\ " }\\n"+\ " }\\n"+\ "}\",\"variables\":{\"url\":\""+hook+"\"}}" headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + auth } return httphelper.post(url, headers, payload).text.encode('utf8')
def getAuthKey(username: str, password: str, clientId: str, clientSecret: str) -> str: url = 'https://api-prod.hypercare.com/oauth/token' authEncoded = httphelper.encodeBase64(clientId + ':' + clientSecret) headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'Basic ' + authEncoded } payload = { 'grant_type': 'password', 'username': username, 'password': password } response = httphelper.post(url, headers, payload).json() return (response['response']['accessToken'], response['response']['accessTokenExpiresAt'])
def sendMessage(auth:str,chatId:str,orgId:int,message:str): if(message==None): return url = "https://api-prod.hypercare.com/graphql/private" hypercareScope=httphelper.encodeBase64('{"organizationId":'+str(orgId)+'}') payload = "{\"query\":\"mutation sendMessage($chatId: ID!, $message: String!, $fileId: Int, $type: MessageType, $priority: Boolean) {\\n"+\ " chat(chatId: $chatId) {\\n"+\ " sendMessage(message: $message, type: $type, fileId: $fileId, priority: $priority) {\\n"+\ " id\\n"+\ " image\\n"+\ " attachment {\\n"+\ " ...AttachmentFragment\\n"+\ " }\\n"+\ " message\\n"+\ " type\\n"+\ " sender {\\n"+\ " id\\n"+\ " username\\n"+\ " }\\n"+\ " }\\n"+\ " }\\n"+\ "}\\n"+\ "\\n"+\ "fragment AttachmentFragment on Attachment {\\n"+\ " id\\n"+\ " url\\n"+\ " mimeType\\n"+\ " fileName\\n"+\ "}\",\"variables\":{\"chatId\":\""+chatId+"\",\"message\":\""+message+"\",\"type\":\"text\",\"priority\":false}}" headers = { 'hypercare-scope': hypercareScope, 'Content-Type': 'application/json', 'Authorization':'Bearer '+auth } response = httphelper.post(url, headers, payload) print(response.status_code) print(response.text.encode('utf8'))