def update_team(): """Update a team's info.""" db = get_session(current_app) try: team = _get_team() except ApiError, e: return api_error(e.code, str(e))
def destroy_team(): """Removes a team.""" db = get_session(current_app) try: team = _get_team() except ApiError, e: return api_error(e.code, str(e))
def timesince_last_update(): """Get the time since the users last update in seconds""" db = get_session(current_app) try: user = _get_user() except ApiError, e: return api_error(e.code, str(e))
def destroy_team_member(): """Remove a user from the team.""" db = get_session(current_app) try: team = _get_team() user = _get_user() except ApiError, e: return api_error(e.code, str(e))
def create_team_member(): """Add a user to the team.""" db = get_session(current_app) try: team = _get_team() user = _get_user() except ApiError, e: return api_error(e.code, str(e))
def team_timeline(): """Get a collection of the team's recent status updates.""" MAX = current_app.config.get('API2_TIMELINE_MAX_RESULTS', TIMELINE_MAX_RESULTS) try: params = _get_timeline_params() except ApiError, e: return api_error(e.code, str(e))
def user_timeline(): """Get a collection of the user's recent status updates.""" app = current_app db = get_session(app) MAX = app.config.get("API2_TIMELINE_MAX_RESULTS", TIMELINE_MAX_RESULTS) try: params = _get_params(request) except ApiError, e: return api_error(400, str(e))
def create_team(): """Creates a new team.""" db = get_session(current_app) team = Team() team.slug = request.form.get('slug') if not team.slug: return api_error(400, 'No slug provided.') team.name = request.form.get('name', team.slug) db.add(team) try: db.commit() except IntegrityError: return api_error(400, 'Slug is already in use.') return jsonify(team.dictify())
def home_timeline(): """Get a collection of the most recent status updates.""" app = current_app db = get_session(app) MAX = app.config.get("API2_TIMELINE_MAX_RESULTS", TIMELINE_MAX_RESULTS) try: params = _get_params(request) statuses = db.query(Status) statuses = _handle_since(statuses, params) statuses = _handle_max(statuses, params) statuses = _handle_include_replies(statuses, params) statuses = _handle_count(statuses, MAX, params) except ApiError, e: return api_error(400, str(e))
def home_timeline(): """Get a collection of the most recent status updates.""" db = get_session(current_app) MAX = current_app.config.get('API2_TIMELINE_MAX_RESULTS', TIMELINE_MAX_RESULTS) try: params = _get_timeline_params() statuses = db.query(Status) statuses = _handle_weekly(statuses, params) statuses = _handle_since(statuses, params) statuses = _handle_max(statuses, params) statuses = _handle_include_replies(statuses, params) statuses = _handle_count(statuses, MAX, params) except ApiError, e: return api_error(e.code, str(e))
def wrapper(*args, **kwargs): data = request.args if request.method == 'GET' else request.form api_key = data.get('api_key', '') if api_key != current_app.config.get('API_KEY'): return api_error(403, 'Forbidden: Invalid API key.') return view(*args, **kwargs)
def team_members(): """Get a list of members of the team.""" try: team = _get_team() except ApiError, e: return api_error(e.code, str(e))
try: params = _get_params(request) except ApiError, e: return api_error(400, str(e)) user_id = request.args.get("user_id") screen_name = request.args.get("screen_name") try: if user_id: user = db.query(User).filter_by(id=user_id).one() elif screen_name: user = db.query(User).filter_by(username=screen_name).one() else: return api_error(400, "The `user_id` or `screen_name` parameter " "must be provided.") except NoResultFound: return api_error(404, "User not found.") try: statuses = db.query(Status).filter_by(user=user) statuses = _handle_since(statuses, params) statuses = _handle_max(statuses, params) statuses = _handle_include_replies(statuses, params) statuses = _handle_count(statuses, MAX, params) except ApiError, e: return api_error(400, str(e)) data = [] for status in statuses: data.append(status.dictify(trim_user=params["trim_user"], trim_project=params["trim_project"]))
@crossdomain(origin='*') def user_timeline(): """Get a collection of the user's recent status updates.""" db = get_session(current_app) MAX = current_app.config.get('API2_TIMELINE_MAX_RESULTS', TIMELINE_MAX_RESULTS) try: params = _get_timeline_params() except ApiError, e: return api_error(e.code, str(e)) try: user = _get_user() except ApiError, e: return api_error(e.code, str(e)) try: statuses = db.query(Status).filter_by(user=user) statuses = _handle_weekly(statuses, params) statuses = _handle_since(statuses, params) statuses = _handle_max(statuses, params) statuses = _handle_include_replies(statuses, params) statuses = _handle_count(statuses, MAX, params) except ApiError, e: return api_error(e.code, str(e)) data = _get_data(statuses, params) return jsonify(data)
def wrapper(*args, **kwargs): api_key = request.json.get('api_key', '') if api_key != current_app.config.get('API_KEY'): return api_error(403, 'Forbidden: invalid API key.') return view(*args, **kwargs)