class BaseAPI(object): def __init__(self, server): self._browser = CurrentTimeBrowser(server) self._parser = CurrentTimeParser() def login(self, username, password): return self._browser.login(username, password) @property def current_date(self): return self._parser.parse_current_month(self._browser.current_page) def report_activity(self, activity): session_id = self._parser.parse_session_id(self._browser.current_page) if not self._is_in_correct_state(activity.day): raise ValueError("Date argument is not withing the currently displayed date.") response = self._browser.post( session_id, activity.project_id, activity.day.day, activity.duration, activity.comment ) return response def valid_session(self): return self._parser.valid_session(self._browser.current_page) def get_activities(self): return self._parser.parse_activities(self._browser.current_page) def goto_next_month(self): response = self._browser.goto_next_month() return self._parser.parse_navigation(response) def goto_prev_month(self): response = self._browser.goto_prev_month() return self._parser.parse_navigation(response) def goto_next_year(self): response = self._browser.goto_next_year() return self._parser.parse_navigation(response) def goto_prev_year(self): response = self._browser.goto_prev_year() return self._parser.parse_navigation(response) def get_projects(self): response = self._browser.get_projects() return self._parser.parse_projects(response) def _is_in_correct_state(self, date): current = self._parser.parse_current_month(self._browser.current_page) return current.year == date.year and current.month == date.month