Beispiel #1
0
 def test_to_dict_with_data(self):
     data = Data('name', 'value', 'prompt')
     expected = {
         'name': 'name',
         'value': 'value',
         'prompt': 'prompt',
     }
     self.assertEqual(data.to_dict(), expected)
Beispiel #2
0
    def get(self):
        #get users from database
        users = g.con.get_users()

        template = {
            "data": [{
                'name': 'Username',
                'value': '',
                'prompt': ''
            }, {
                'name': 'Realname',
                'value': '',
                'prompt': ''
            }, {
                'name': 'Email',
                'value': '',
                'prompt': ''
            }]
        }

        links = [  #{"href": "www.sangz.com","rel": "home"},
            {
                "href": api.url_for(Songs),
                "rel": "Songs",
                'prompt': 'See the list of all songs'
            }, {
                "href": api.url_for(Playlist),
                "rel": "Playlist",
                "prompt": "See the current playlist"
            }, {
                "href": api.url_for(Chat),
                "rel": "Chat",
                "prompt": "See the conversation"
            }
        ]

        #links = {}
        collection = Collection(api.url_for(Users),
                                template=template,
                                links=links)
        collection.version = "1.0"
        for user in users:
            item = Item(api.url_for(User, userid=user[0]))
            item.data.append(Data("Id", user[0]))
            item.data.append(Data("nickname", user[1]))
            collection.items.append(item)

        string_data = str(collection)
        return Response(string_data,
                        200,
                        mimetype="application/vnd.collection+json" + ";" +
                        APIARY_PROFILES_URL)
Beispiel #3
0
 def test_to_dict_minimal(self):
     data = Data('name')
     expected = {
         'name': 'name'
     }
     self.assertEqual(data.to_dict(), expected)
Beispiel #4
0
    def get(self):
        #connect to the db
        args = request.args
        try:
            user_id = int(args['user_id'])
        except (KeyError, ValueError):
            user_id = None

        # songs_db = g.con.get_songs() old non filtering db call
        songs_db = g.con.get_songs_filtered(user_id=user_id)

        links = [  #{"href": "www.sangz.com", "rel": "home"},
            {
                "href": api.url_for(Users),
                "rel": "Users",
                "prompt": "Get the list of all users"
            }, {
                "href": api.url_for(Playlist),
                "rel": "Playlist",
                "prompt": "See the current playlist"
            }, {
                "href": api.url_for(Chat),
                "rel": "Chat",
                "prompt": "See the conversation"
            }
        ]

        template = {
            "data":
            [{
                "prompt": "",
                "name": "user_id",
                "value": ""
            }, {
                "prompt": "",
                "name": "song_name",
                "value": ""
            }
             #{"prompt": "", "name":"media_location",
             #"value":""},
             #{"prompt": "", "name":"media_type",
             #"value":""},
             #{"prompt": "", "name":"artist_id",
             #"value":""},
             #{"prompt": "", "name":"album_id",
             #"value":""},
             #{"prompt": "", "name":"user_id",
             #"value":""}
             ]
        }
        collection = Collection(api.url_for(Songs),
                                template=template,
                                links=links)
        collection.version = "1.0"
        #create items
        print songs_db
        for song in songs_db:
            print song
            item = Item(api.url_for(Song, songid=song[0]))
            item.data.append(Data("ID", song[0]))
            item.data.append(Data("songname", song[1]))
            item.data.append(
                Data("uploader", api.url_for(User, userid=song[2])))
            #links to artist and album are unavailable because they are not implemented
            collection.items.append(item)

        string_data = str(collection)
        return Response(string_data,
                        200,
                        mimetype="application/vnd.collection+json" + ";" +
                        SANGZ_SONG_PROFILE)