Skip to content

Instantly share code, notes, and snippets.

@terrysahaidak
Created November 5, 2015 21:08
Show Gist options
  • Save terrysahaidak/91ceecf22be723713568 to your computer and use it in GitHub Desktop.
Save terrysahaidak/91ceecf22be723713568 to your computer and use it in GitHub Desktop.
// user_id=27830729
// order=hints
// count=3
// fields=photo_100
// name_case=nom
const resFriends = {
response: {
count: 238,
items: [{
id: 53472976,
first_name: 'Bilo',
last_name: 'Chorna',
photo_100: 'https://pp.vk.me/...224/3ZEVBx_G_js.jpg',
online: 0
}, {
id: 55654958,
first_name: 'Дария',
last_name: 'Сова',
photo_100: 'https://pp.vk.me/...c0d/exUuveeC8m4.jpg',
online: 0
}, {
id: 56781941,
first_name: 'Павло',
last_name: 'Бортник',
photo_100: 'https://pp.vk.me/...603/iaOCVuDlTuY.jpg',
online: 0
}]
}
}
// users.get
// id=27830729
// fields=photo_50,photo_200,can_see_audio,counters
// name_case=Nom
const resProfile = {
response: [{
id: 27830729,
first_name: 'Тарас',
last_name: 'Перун',
photo_50: 'https://pp.vk.me/...053/bjKw2NB6doI.jpg',
photo_200: 'https://pp.vk.me/...051/zKAc4kz2A7c.jpg',
can_see_audio: 1,
counters: {
albums: 1,
videos: 566,
audios: 2349,
notes: 0,
photos: 55,
gifts: 19,
friends: 238,
online_friends: 57,
mutual_friends: 18,
user_videos: 23,
followers: 222,
subscriptions: 0,
pages: 56
}
}]
}
//owner_id=27830729
// need_user=0
// count=3
const resAudio= {
response: {
count: 2349,
items: [{
id: 411573648,
owner_id: 27830729,
artist: 'NRM',
title: 'Три черепахи',
duration: 205,
date: 1446287026,
url: 'https://cs7-2v4.v...C89RGMv9kGJWaMxbbYs',
lyrics_id: 8510555,
genre_id: 18
}, {
id: 411570709,
owner_id: 27830729,
artist: 'Даха Браха',
title: 'Specially for you',
duration: 377,
date: 1446286338,
url: 'https://cs7-1v4.v...fwdPKMkKoPq8zqTxPkU',
lyrics_id: 4622993,
genre_id: 1
}, {
id: 404739833,
owner_id: 27830729,
artist: 'широкий лан',
title: 'Без названия',
duration: 214,
date: 1444149334,
url: 'https://psv4.vk.m...0hEC6vchWYuUy5uVUSE',
genre_id: 18
}]
}
}
function normalize(response) {
const result = Object.assign({}, response, {
ids: [],
items: {}
})
response.items.map(item => {
result.ids.push(item.id)
result.items[[item.id]] = item
})
return result
}
const normalized = normalize(resAudio.response)
console.log(normalized)
const result = { count: 2349,
items:
{ '404739833':
{ id: 404739833,
owner_id: 27830729,
artist: 'широкий лан',
title: 'Без названия',
duration: 214,
date: 1444149334,
url: 'https://psv4.vk.m...0hEC6vchWYuUy5uVUSE',
genre_id: 18 },
'411570709':
{ id: 411570709,
owner_id: 27830729,
artist: 'Даха Браха',
title: 'Specially for you',
duration: 377,
date: 1446286338,
url: 'https://cs7-1v4.v...fwdPKMkKoPq8zqTxPkU',
lyrics_id: 4622993,
genre_id: 1 },
'411573648':
{ id: 411573648,
owner_id: 27830729,
artist: 'NRM',
title: 'Три черепахи',
duration: 205,
date: 1446287026,
url: 'https://cs7-2v4.v...C89RGMv9kGJWaMxbbYs',
lyrics_id: 8510555,
genre_id: 18 } },
ids: [ 411573648, 411570709, 404739833 ] }
const auth = {
isLoginedIn: false
}
const viewer = {
id: '',
avatarUrl: ''
}
const users = {
users: {},
fetchingUsers: false
}
const songs = {
songs: {
},
fetchingSongs: false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment