Beispiel #1
0
    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()

        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:
            click = FlattrClick(
                        youtify_user=user,
                        flattr_user_name=user.flattr_user_name,
                        thing_id=str(json['thing'].get('id')),
                        thing_title=json['thing'].get('title')
                    )
            click.put()
        else:
            logging.error('Error logging flattr click. Response: %s' % response.content)

        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(response.content)
Beispiel #2
0
    def post(self):
        url_to_submit = self.request.get('url')
        url = 'https://api.flattr.com/rest/v2/flattr'
        user = get_current_youtify_user()

        headers = {
            'Authorization': 'Bearer %s' % user.flattr_access_token,
            'Content-Type': 'application/json',
        }

        data = {
            #'url': 'http://flattr.com/submit/auto?' + urllib.urlencode({'url': url_to_submit}),
            #'url': urllib.quote(url_to_submit),
            'url': url_to_submit,
        }

        logging.info(url_to_submit)
        logging.info(data['url'])

        #data = urllib.urlencode(data)
        data = simplejson.dumps(data)

        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:
            click = FlattrClick(
                        youtify_user=user,
                        flattr_user_name=user.flattr_user_name,
                        thing_id=str(json['thing'].get('id')),
                        thing_title=json['thing'].get('title')
                    )
            click.put()
        else:
            logging.error('Error logging flattr click. Response: %s' % response.content)

        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(response.content)