Example #1
0
    def post(self, type, external_user_id):
        """Subscribes to an external user"""
        youtify_user_model = get_current_youtify_user_model()
        if youtify_user_model == None:
            self.error(403)
            return
        
        external_user_model = ExternalUser.all().filter('type =', type).filter('external_user_id =', external_user_id).get()
        if external_user_model is None:
            external_user_model = ExternalUser(type=type, external_user_id=external_user_id) 

            # @XXX should not trust client with this information, fetch from server instead
            external_user_model.username = self.request.get('username')
            external_user_model.avatar_url = self.request.get('avatar_url')
            external_user_model.get_last_updated = True

            external_user_model.save()
        
        if external_user_model.key() in youtify_user_model.external_user_subscriptions:
            self.error(400)
            self.response.out.write('You already subscribe to this external user')
            return
            
        youtify_user_model.external_user_subscriptions.append(external_user_model.key())
        youtify_user_model.save()
        
        external_user_model.subscribers.append(youtify_user_model.key())
        external_user_model.nr_of_subscribers = len(external_user_model.subscribers)
        external_user_model.get_last_updated = True
        external_user_model.save()

        create_external_subscribe_activity(youtify_user_model, external_user_model)
        
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('ok')
Example #2
0
def import_followings(external_user_id):
    url = "http://api.soundcloud.com/users/%s/followings.json?client_id=%s" % (
        external_user_id, '206f38d9623048d6de0ef3a89fea1c4d')
    result = urlfetch.fetch(url)
    result = simplejson.loads(result.content)
    for user in result:
        if ExternalUser.all().filter('type =', 'soundcloud').filter(
                'external_user_id =', str(user['id'])).get() is None:
            external_user_model = ExternalUser(type='soundcloud',
                                               external_user_id=str(
                                                   user['id']))
            external_user_model.username = user['permalink']
            external_user_model.avatar_url = user['avatar_url']
            external_user_model.save()
Example #3
0
def import_followings(external_user_id):
    url = "http://api.soundcloud.com/users/%s/followings.json?client_id=%s" % (
        external_user_id,
        "206f38d9623048d6de0ef3a89fea1c4d",
    )
    result = urlfetch.fetch(url)
    result = simplejson.loads(result.content)
    for user in result:
        if (
            ExternalUser.all().filter("type =", "soundcloud").filter("external_user_id =", str(user["id"])).get()
            is None
        ):
            external_user_model = ExternalUser(type="soundcloud", external_user_id=str(user["id"]))
            external_user_model.username = user["permalink"]
            external_user_model.avatar_url = user["avatar_url"]
            external_user_model.save()
Example #4
0
    def post(self, type, external_user_id):
        """Subscribes to an external user"""
        youtify_user_model = get_current_youtify_user_model()
        if youtify_user_model == None:
            self.error(403)
            return

        external_user_model = ExternalUser.all().filter('type =', type).filter(
            'external_user_id =', external_user_id).get()
        if external_user_model is None:
            external_user_model = ExternalUser(
                type=type, external_user_id=external_user_id)

            # @XXX should not trust client with this information, fetch from server instead
            external_user_model.username = self.request.get('username')
            external_user_model.avatar_url = self.request.get('avatar_url')
            external_user_model.get_last_updated = True

            external_user_model.save()

        if external_user_model.key(
        ) in youtify_user_model.external_user_subscriptions:
            self.error(400)
            self.response.out.write(
                'You already subscribe to this external user')
            return

        youtify_user_model.external_user_subscriptions.append(
            external_user_model.key())
        youtify_user_model.save()

        external_user_model.subscribers.append(youtify_user_model.key())
        external_user_model.nr_of_subscribers = len(
            external_user_model.subscribers)
        external_user_model.get_last_updated = True
        external_user_model.save()

        create_external_subscribe_activity(youtify_user_model,
                                           external_user_model)

        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('ok')