-
Notifications
You must be signed in to change notification settings - Fork 0
/
vk_com_api_methods.h
146 lines (121 loc) · 4.76 KB
/
vk_com_api_methods.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#pragma once
namespace vk_com_api
{
class NOVTABLE api_method_base
{
public:
api_method_base () : m_aborted (false) {}
// Does actual call of vk api method
bool call (abort_callback & p_abort = abort_callback_impl ())
{
m_aborted = false;
m_error.reset ();
try { run (p_abort); }
catch (const exception_aborted &) { m_aborted = true; }
catch (const pfc::exception & e) { m_error = e.what (); }
return m_error.is_empty () && !m_aborted;
}
bool aborted () const { return m_aborted; }
const char * get_error () const { return m_error; }
private:
virtual void run (abort_callback & p_abort) = 0;
bool m_aborted; // Call was aborted by user
protected:
pfc::string8 m_error;
};
// helper implementation of some apis
namespace audio
{
namespace albums
{
// Reads a list of user albums (from vk.com profile)
// Represents as list of (album_name, album_id) pairs
class get : public api_method_base,
public pfc::list_t<audio_album_info>
{
void run (abort_callback & p_abort) override;
};
// Creates new album in user profile
class add : public api_method_base
{
void run (abort_callback & p_abort) override;
audio_album_info m_new_album;
public:
explicit add (const pfc::string_base & title) : m_new_album (boost::make_tuple (title.get_ptr (), 0)) {}
operator audio_album_info const & () const { return m_new_album; }
};
// Deletes album and all of it contents (!) from user profile
class del : public api_method_base
{
void run (abort_callback & p_abort) override;
t_vk_album_id m_id_to_delete;
public:
del (t_vk_album_id id) : m_id_to_delete (id) {}
};
// Renames album in user profile
class ren : public api_method_base
{
void run (abort_callback & p_abort) override;
t_vk_album_id m_album_id;
pfc::string8 m_new_title;
public:
ren (t_vk_album_id album_id, const pfc::string_base & p_new_title)
: m_album_id (album_id), m_new_title (p_new_title) {}
};
} // namespace albums
// Moves vk audio track to specified album
class move_to_album : public api_method_base
{
void run (abort_callback & p_abort) override;
t_vk_audio_id m_audio_id;
t_vk_album_id m_album_id;
public:
move_to_album (t_vk_audio_id audio_id, t_vk_album_id album_id)
: m_audio_id (audio_id), m_album_id (album_id) {}
};
// Queries url for posting upload to
class get_upload_server : public api_method_base
{
void run (abort_callback & p_abort) override;
pfc::string8 m_url;
public:
operator const char* () const { return m_url.get_ptr (); }
};
// Saves newly uploaded audio file in users profile
class save : public api_method_base
{
void run (abort_callback & p_abort) override;
response_json_ptr m_result;
t_vk_audio_id m_id; // Id of newly uploaded mp3 file
pfc::string8 m_artist;
pfc::string8 m_title;
public:
// p_answer from vk.com server returned after file was upload
save (const pfc::string_base & p_answer, const metadb_handle_ptr & p_item_to_save);
t_vk_audio_id get_id () const { return m_id; }
};
// Edits artist/title fields of the track m_id
class edit : public api_method_base
{
void run (abort_callback & p_abort) override;
metadb_handle_ptr m_track;
t_vk_audio_id m_aid;
public:
// Answer from vk.com server returned after file was upload
edit (const metadb_handle_ptr & p_track, t_vk_audio_id aid) : m_track (p_track), m_aid (aid) {}
};
} // namespace audio
namespace wall
{
// Makes post on wall this optimal message and audios attached
class post : public api_method_base
{
void run (abort_callback & p_abort) override;
pfc::string8 m_message;
const pfc::list_t<t_vk_audio_id> & m_audio_ids;
public:
post (const pfc::string_base & p_msg, const pfc::list_t<t_vk_audio_id> & p_audio_ids)
: m_message (p_msg), m_audio_ids (p_audio_ids) {}
};
}
}