def atom(gplus_id, page_id=None): """Return an Atom-format feed for the given G+ id, possibly from cache.""" if len(gplus_id) != 21: return 'Invalid G+ user ID (must be exactly 21 digits).', 404 # Not Found if page_id and len(page_id) != 21: return 'Invalid G+ page ID (must be exactly 21 digits).', 404 # Not Found cache_key = ATOM_CACHE_KEY_TEMPLATE % gplus_id if page_id: cache_key = '%s-%s' % (cache_key, page_id) response = Cache.get(cache_key) # A frozen Response object if response is None: try: response = generate_atom(gplus_id, page_id) except oauth2.UnavailableException as e: app.logger.warning("Feed request failed - %r", e) flask.abort(e.status) response.add_etag() response.freeze() Cache.set(cache_key, response, time=Config.getint('cache', 'stream-expire')) return response.make_conditional(flask.request)
def atom(gplus_id, page_id=None): """Return an Atom-format feed for the given G+ id, possibly from cache.""" if len(gplus_id) != 21: return 'Invalid G+ user ID (must be exactly 21 digits).', 404 # Not Found if page_id and len(page_id) != 21: return 'Invalid G+ page ID (must be exactly 21 digits).', 404 # Not Found # Google+ is no longer publicly available for consumers. return 'Google+ was sunset for consumer users in April 2019. This feed is no longer available.', 410 # Gone ##### CODE BELOW FOR HISTORICAL PURPOSES ONLY ##### cache_key = ATOM_CACHE_KEY_TEMPLATE % gplus_id if page_id: cache_key = '%s-%s' % (cache_key, page_id) response = Cache.get(cache_key) # A frozen Response object if response is None: try: response = generate_atom(gplus_id, page_id) except oauth2.UnavailableException as e: app.logger.info("Feed request failed - %r", e) flask.abort(e.status) response.add_etag() response.freeze() Cache.set(cache_key, response, time=Config.getint('cache', 'stream-expire')) return response.make_conditional(flask.request)
def get_person_by_access_token(token): """Fetch details about an individual from the G+ API and return a dict with the response.""" headers = { 'Authorization': 'Bearer %s' % token, } try: response = session.get(GPLUS_API_ME_ENDPOINT, headers=headers, timeout=GOOGLE_API_TIMEOUT) person = response.json() except requests.exceptions.Timeout: raise UnavailableException('Person API request timed out.', 504) except Exception as e: raise UnavailableException('Person API request raised exception "%r" for %s.' % (e, pprint.pformat(response).text), 502) Cache.set(PROFILE_CACHE_KEY_TEMPLATE % person['id'], person, time=Config.getint('cache', 'profile-expire')) return person
def get_person_by_access_token(token): """Fetch details about an individual from the G+ API and return a dict with the response.""" headers = { 'Authorization': 'Bearer %s' % token, } try: response = session.get(GPLUS_API_ME_ENDPOINT, headers=headers, timeout=GOOGLE_API_TIMEOUT) person = response.json() except requests.exceptions.Timeout: raise UnavailableException('Person API request timed out.', 504) except Exception as e: raise UnavailableException( 'Person API request raised exception "%r" for %s.' % (e, pprint.pformat(response).text), 502) Cache.set(PROFILE_CACHE_KEY_TEMPLATE % person['id'], person, time=Config.getint('cache', 'profile-expire')) return person