def unsetBulk(self, *keys): body = {} for key in keys: body[key] = None response = self.apiClient.sendPost("", json.dumps(body)) return {} if not ApiCallUtil.isJson( response.content) else response.json()
def getTasksFromProject(self, projectId, dueOnToday=False): uri = "/tasks" queryString = { "project": projectId, "opt_fields": "due_on", "completed_since": "now" } response = self.apiClient.sendGet(uri, queryString) responseData = {} if not ApiCallUtil.isJson( response.content) else response.json() if 'errors' in responseData: raise Exception(responseData['errors']) if 'data' not in responseData: raise Exception("invalid response structure: {:s}".format( str(response.content))) if not dueOnToday: return responseData['data'] todayDateString = DatetimeUtil.getTodayDateInStringFormat("%Y-%m-%d") return list( filter(lambda task: task['due_on'] == todayDateString, responseData['data']))
def createEvent(self, calendarId, event): uri = "/calendar/v3/calendars/" + calendarId + "/events" response = self.apiClient.sendPost(uri, json.dumps(event.toDictionary())) responseData = {} if not ApiCallUtil.isJson(response.content) else response.json() if 'error' in responseData: raise Exception(responseData['error']) return responseData
def sendBatchRequest(self, actions=[]): if len(actions) < 1: return [] uri = "/batch" body = {"data": {"actions": actions}} response = self.apiClient.sendPost(uri, json.dumps(body)) return {} if not ApiCallUtil.isJson( response.content) else response.json()
def getAll(self, withCompletedTask=False): uri = "/projects/" + constants.instagantt.CONNECTIONS['Overall'][ 'gid'] + "/tasks" queryString = {} if not withCompletedTask: queryString['completed_since'] = '16758797247900' response = self.apiClient.sendGet(uri, queryString) return [] if not ApiCallUtil.isJson( response.content) else response.json()
def updateKeyResultProgress(self, objectiveId, keyResultId, progress): uri = "/objective/" + str(objectiveId) + "/result/" + str(keyResultId) queryString = {'token': self.apiClient.headers['Authorization']} body = {'progress': int(progress)} response = self.apiClient.sendPost(uri, body, queryString) responseData = {} if not ApiCallUtil.isJson( response.content) else response.json() if 'status' in responseData and responseData['status'] == "error": raise Exception(responseData['message']) return responseData
def increaseValue(self, key, amount): body = { 'action': 'increment_by', 'data': { 'key': key, 'amount': amount } } response = self.apiClient.sendPatch("", json.dumps(body)) return {} if not ApiCallUtil.isJson( response.content) else response.json()
def getEventsForDatetimeRange(self, calendarId, startDatetime, endDatetime): uri = "/calendar/v3/calendars/" + calendarId + "/events" queryString = { 'timeMin': startDatetime, 'timeMax': endDatetime } response = self.apiClient.sendGet(uri, queryString) responseData = {} if not ApiCallUtil.isJson(response.content) else response.json() if 'error' in responseData: raise Exception(responseData['error']) return responseData
def getGoalProgress(self, goalId): uri = "/goals/" + goalId queryString = {'kpi': 'perf_d_1'} response = self.apiClient.sendGet(uri, queryString) responseData = {} if not ApiCallUtil.isJson( response.content) else response.json() if ('result' not in responseData) \ or ('goal' not in responseData['result']) \ or ('kpi' not in responseData['result']['goal']) \ or ('perf_d_1' not in responseData['result']['goal']['kpi']): raise Exception("invalid response structure: {:s}".format( str(response.content))) return responseData['result']['goal']['kpi']['perf_d_1']
def __refreshAccessToken(self): uri = "/oauth_token" body = { 'refresh_token': os.getenv('WEEKDONE_REFRESH_TOKEN'), 'grant_type': 'refresh_token', 'client_id': os.getenv('WEEKDONE_CLIENT_ID'), 'client_secret': os.getenv('WEEKDONE_CLIENT_SECRET'), 'redirect_uri': os.getenv('WEEKDONE_CLIENT_SECRET'), } response = self.oauthClient.sendPost(uri, body) responseData = {} if not ApiCallUtil.isJson( response.content) else response.json() if ('status' in responseData and responseData['status'] == "error") or ('access_token' not in responseData): raise Exception(responseData['message']) self.apiClient.headers['Authorization'] = responseData['access_token']
def __refreshAccessToken(self): uri = "/token" queryString = { 'refresh_token': os.getenv("GOOGLE_CALENDAR_REFRESH_TOKEN"), 'grant_type': 'refresh_token', 'client_id': os.getenv("GOOGLE_CLIENT_ID"), 'client_secret': os.getenv("GOOGLE_CLIENT_SECRET"), } response = self.oauthClient.sendPost(uri, {}, queryString) responseData = {} if not ApiCallUtil.isJson(response.content) else response.json() if 'access_token' not in responseData: raise Exception("invalid response structure: {:s}".format(str(response.content))) if 'error' in responseData: raise Exception(responseData['error']) self.apiClient.headers['Authorization'] = "Bearer " + responseData['access_token']
def set(self, key, value): body = {key: value} response = self.apiClient.sendPost("", json.dumps(body)) return {} if not ApiCallUtil.isJson( response.content) else response.json()
def all(self): response = self.apiClient.sendGet("", {}) return {} if not ApiCallUtil.isJson( response.content) else response.json()
def get(self, key): queryString = {"key": key} response = self.apiClient.sendGet("", queryString) responseData = {} if not ApiCallUtil.isJson( response.content) else response.json() return None if key not in responseData else responseData[key]
def getBulk(self, keys): queryString = {"key[]": keys} response = self.apiClient.sendGet("", queryString) return {} if not ApiCallUtil.isJson( response.content) else response.json()
def setBulk(self, data): response = self.apiClient.sendPost("", json.dumps(data)) return {} if not ApiCallUtil.isJson( response.content) else response.json()
def unset(self, key): body = {key: None} result = self.apiClient.sendPost("", json.dumps(body)) return {} if not ApiCallUtil.isJson( response.content) else response.json()