def post(self): url_to_submit = self.request.get("url") video_title = self.request.get("videoTitle") url = "https://api.flattr.com/rest/v2/flattr" user = get_current_youtify_user_model() headers = {"Authorization": "Bearer %s" % user.flattr_access_token, "Content-Type": "application/json"} data = simplejson.dumps({"url": url_to_submit}) response = urlfetch.fetch( url=url, payload=data, method=urlfetch.POST, headers=headers, validate_certificate=VALIDATE_CERTIFICATE ) json = simplejson.loads(response.content) if json.get("message") == "ok" and "thing" in json: thing_id = str(json["thing"].get("id")) create_flattr_activity(user, thing_id, video_title) user.nr_of_flattrs += 1 user.save() elif json.get("error") == "flattr_once": pass else: logging.error("Error creating flattr click. Response: %s" % response.content) self.response.headers["Content-Type"] = "application/json" self.response.out.write(response.content)
def post(self): url_to_submit = self.request.get('url') video_title = self.request.get('videoTitle') url = 'https://api.flattr.com/rest/v2/flattr' user = get_current_youtify_user_model() headers = { 'Authorization': 'Bearer %s' % user.flattr_access_token, 'Content-Type': 'application/json', } data = simplejson.dumps({ 'url': url_to_submit, }) response = urlfetch.fetch(url=url, payload=data, method=urlfetch.POST, headers=headers, validate_certificate=VALIDATE_CERTIFICATE) json = simplejson.loads(response.content) if json.get('message') == 'ok' and 'thing' in json: thing_id = str(json['thing'].get('id')) create_flattr_activity(user, thing_id, video_title) user.nr_of_flattrs += 1 user.save() else: logging.error('Error creating flattr click. Response: %s' % response.content) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(response.content)
def post(self): thing_id = self.request.get('thing_id') url = 'https://api.flattr.com/rest/v2/things/' + thing_id + '/flattr' user = get_current_youtify_user_model() headers = { 'Authorization': 'Bearer %s' % user.flattr_access_token } response = urlfetch.fetch(url=url, method=urlfetch.POST, headers=headers, validate_certificate=VALIDATE_CERTIFICATE) json = simplejson.loads(response.content) if json.get('message') == 'ok' and 'thing' in json: thing_id = str(json['thing'].get('id')) thing_title = json['thing'].get('title') create_flattr_activity(user, thing_id, thing_title) else: logging.error('Error creating flattr click. Response: %s' % response.content) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(response.content)