示例#1
0
        private static VKParams parseGetParam(
            Int64 userId,
            Boolean extended,
            IEnumerable<Filter> filter,
            IEnumerable<Fields> fields,
            Int32? offset,
            Int32? count
            )
        {
            VKParams param = new VKParams();

            param.Add("user_id", userId);
            param.Add("extended", extended ? "1" : "0");
            if (filter != null)
            {
                param.Add("filter", String.Join(",", filter));
            }
            if (fields != null)
            {
                param.Add("fields", String.Join(",", fields));
            }
            if (offset.HasValue) param.Add("offset", offset.Value.ToString());
            if (count.HasValue) param.Add("count", count.Value.ToString());

            return param;
        }
示例#2
0
        private VKParams GetForGetParams(
            Int64? ownerId,
            Int64? albumId,
            IEnumerable<Int64> audioIds,
            Boolean? needUser,
            Int32 offset,
            Int32? count)
        {
            VKParams param = new VKParams();

            if (ownerId.HasValue)
            {
                param.Add("owner_id", ownerId.Value);
            }
            if (albumId.HasValue)
            {
                param.Add("album_id", albumId.Value);
            }
            if (audioIds != null)
            {
                param.Add("audio_ids", String.Join(",", audioIds));
            }
            if (needUser.HasValue)
            {
                param.Add("need_user", (needUser.Value ? "1" : "0"));
            }
            param.Add("offset", offset);
            if (count.HasValue)
            {
                param.Add("count", count.Value);
            }

            return param;
        }
示例#3
0
        /// <summary>
        ///     Возвращает количество аудиозаписей пользователя или сообщества.
        ///     <remarks>Идентификатор сообщества в параметре <paramref name="ownerId" /> необходимо указывать со знаком "-"</remarks>
        /// </summary>
        /// <param name="ownerId">Идентификатор владельца аудиозаписей (пользователь или сообщество)</param>
        /// <param name="token">Токен для отмены выполнения запроса</param>
        /// <returns>Количество аудиозаписей</returns>
        public async Task<Int32> GetCountAsync(Int64 ownerId, CancellationToken? token = null)
        {
            VKParams param = new VKParams();
            param.Add("owner_id", ownerId);

            return await base.ExecuteAsync<Int32>(GetCountMethod, param, token);
        }
        private VKParams GetRecommendationsParams(
            Int64 targetAudioId,
            Int64 targetAudioOwnerId,
            Int64? userId,
            Int64? offset,
            Int64? count,
            Boolean? shuffle
            )
        {
            VKParams param = new VKParams();

            param.Add("target_audio", String.Format("{0}_{1}", targetAudioOwnerId, targetAudioId));
            if (userId.HasValue)
            {
                param.Add("user_id", userId.Value);
            }
            if (offset.HasValue)
            {
                param.Add("offset", offset.Value);
            }
            if (count.HasValue)
            {
                param.Add("count", count.Value);
            }
            if (shuffle.HasValue)
            {
                param.Add("shuffle", shuffle.Value.ToVKValue());
            }

            return param;
        }
示例#5
0
        /// <summary>
        ///     Возвращает количество аудиозаписей пользователя или сообщества.
        ///     <remarks>Идентификатор сообщества в параметре <paramref name="ownerId" /> необходимо указывать со знаком "-"</remarks>
        /// </summary>
        /// <param name="ownerId">Идентификатор владельца аудиозаписей (пользователь или сообщество).</param>
        /// <returns>Количество аудиозаписей</returns>
        public Int32 GetCount(Int64 ownerId)
        {
            VKParams param = new VKParams();
            param.Add("owner_id", ownerId);

            return base.Execute<Int32>(GetCountMethod, param);
        }
示例#6
0
        private VKParams GetRestoreParams(Int64 audioId, Int64? ownerId)
        {
            VKParams param = new VKParams();
            param.Add("audio_id", audioId);
            if (ownerId.HasValue) param.Add("owner_id", ownerId.Value);

            return param;
        }
示例#7
0
        private VKParams GetDeleteParams(Int64 audioId, Int64 ownerId)
        {
            VKParams param = new VKParams();
            param.Add("audio_id", audioId);
            param.Add("owner_id", ownerId);

            return param;
        }
示例#8
0
        private VKParams GetAddParams(Int64 audioId, Int64 ownerId, Int64? groupId)
        {
            VKParams param = new VKParams();
            param.Add("audio_id", audioId);
            param.Add("owner_id", ownerId);
            if (groupId.HasValue) param.Add("group_id", groupId.Value);

            return param;
        }
        private VKParams GetBroadcastParams(VKBroadcastFilterEnum filter, Boolean getOnlyActive)
        {
            VKParams param = new VKParams();

            param.Add("active", getOnlyActive.ToVKValue());
            param.Add("filter", EnumString.GetStringValue(filter));

            return param;
        }
示例#10
0
        private VKParams GetForGetAlbumsParams(Int64? ownerId, Int32? offset, Int32? count)
        {
            VKParams param = new VKParams();
            if (ownerId.HasValue) param.Add("owner_id", ownerId.Value);
            if (offset.HasValue) param.Add("offset", offset.Value);
            if (count.HasValue) param.Add("count", count.Value);

            return param;
        }
示例#11
0
        /// <summary>
        ///     Возвращает информацию об аудиозаписях.
        /// </summary>
        /// <param name="ownerId">Идентификатор владельца аудиозаписи</param>
        /// <param name="audios">Идентификаторы аудиозаписей</param>
        /// <returns>Список объектов VKAudio</returns>
        public VKList<VKAudio> GetById(Int64 ownerId, IEnumerable<Int64> audios)
        {
            VKParams param = new VKParams
            {
                {"audios", String.Join(",", audios.Select(x => ownerId + "_" + x.ToString()))}
            };

            var list = base.Execute<IEnumerable<VKAudio>>(GetByIdMethod, param);
            return new VKList<VKAudio>(list);
        }
示例#12
0
        /// <summary>
        ///     Возвращает информацию об аудиозаписях.
        /// </summary>
        /// <param name="ownerId">Идентификатор владельца аудиозаписи</param>
        /// <param name="audios">Идентификаторы аудиозаписей</param>
        /// <param name="token">Токен для отмены выполнения запроса</param>
        /// <returns>Список объектов VKAudio</returns>
        public async Task<VKList<VKAudio>> GetByIdAsync(Int64 ownerId, IEnumerable<Int64> audios,
            CancellationToken? token = null)
        {
            VKParams param = new VKParams
            {
                {"audios", String.Join(",", audios.Select(x => ownerId + "_" + x.ToString()))}
            };

            var list = await base.ExecuteAsync<IEnumerable<VKAudio>>(GetByIdMethod, param, token);
            return new VKList<VKAudio>(list);
        }
示例#13
0
        protected TReturn Execute <TReturn>(String method, VKParams param)
        {
            string response = VKSession.Instance.DoRequest(String.Format("{0}.{1}", GroupName, method), param);

            JObject obj = JObject.Parse(response);

            if (obj["response"] == null)
            {
                return(default(TReturn));
            }
            var objArr = JsonConvert.DeserializeObject <TReturn>(obj["response"].ToString());

            return(objArr);
        }
示例#14
0
        internal async Task<String> DoRequestAsync(String method, VKParams param)
        {
            String requestUri = BuildRequest(method, param);

            WebRequest request = WebRequest.Create(requestUri);
            WebResponse response = await request.GetResponseAsync();
            Stream dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream);
            String res = await reader.ReadToEndAsync();

            reader.Close();
            response.Close();

            return res;
        }
        private VKParams GetSetBroadcastParams(
            Int32? ownerId,
            Int32? audioId,
            IEnumerable<Int32> ids)
        {
            VKParams param = new VKParams();

            if (ownerId.HasValue && audioId.HasValue)
            {
                param.Add("audio", String.Format("{0}_{1}", ownerId.Value, audioId.Value));
            }
            if (ids != null) param.Add("target_ids", String.Join(",", ids));

            return param;
        }
示例#16
0
        private VKParams GetPopularParams(
            VKGenreEnum genre,
            Boolean? onlyEng,
            Int32? offset,
            Int32? count)
        {
            VKParams param = new VKParams();

            param.Add("genre_id", (Int32)genre);
            if (onlyEng.HasValue) param.Add("only_eng", onlyEng.Value.ToVKValue());
            if (offset.HasValue) param.Add("offset", offset.Value);
            if (count.HasValue) param.Add("count", count.Value);

            return param;
        }
示例#17
0
        private string BuildRequest(string method, VKParams param)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(UrlAPI).Append(method).Append("?");

            foreach (var item in param)
            {
                builder.AppendFormat("{0}={1}&", item.Key, item.Value);
            }

            builder.AppendFormat("{0}={1}&", "access_token", AccessToken);
            builder.AppendFormat("{0}={1}", "v", VKSettings.APIVer);

            return builder.ToString();
        }
示例#18
0
        internal String DoRequest(String method, VKParams param)
        {
            String requestUri = BuildRequest(method, param);

            WebRequest request =
                WebRequest.Create(requestUri);

            WebResponse response = request.GetResponse();
            Stream dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream);

            String responseFromServer = reader.ReadToEnd();

            reader.Close();
            response.Close();

            return responseFromServer;
        }
示例#19
0
        protected async Task <TReturn> ExecuteAsync <TReturn>(String method, VKParams param, CancellationToken?token)
        {
            string response = await VKSession.Instance.DoRequestAsync(String.Format("{0}.{1}", GroupName, method), param);

            JObject obj = JObject.Parse(response);

            if (obj["response"] == null)
            {
                return(default(TReturn));
            }
            var objArr = await JsonConvert.DeserializeObjectAsync <TReturn>(obj["response"].ToString());

            if (token.HasValue)
            {
                token.Value.ThrowIfCancellationRequested();
            }

            return(objArr);
        }
示例#20
0
        private static VKParams parseParamsForGet(
            IEnumerable<FieldsEnum> fields,
            Int64? userId,
            OrderEnum? order,
            Int64? listId,
            Int32? count,
            Int32? offset,
            NameCaseEnum? nameCase
            )
        {
            VKParams param = new VKParams();

            if (fields != null)
            {
                param.Add("fields", String.Join(",", fields));
            }
            if (userId.HasValue)
            {
                param.Add("user_id", userId.Value);
            }
            if (order.HasValue)
            {
                param.Add("order", order.Value);
            }
            if (listId.HasValue)
            {
                param.Add("list_id", listId.Value);
            }
            if (count.HasValue)
            {
                param.Add("count", count.Value);
            }
            if (offset.HasValue)
            {
                param.Add("offset", offset.Value);
            }
            if (nameCase.HasValue)
            {
                param.Add("name_case", nameCase.Value);
            }

            return param;
        }
示例#21
0
        private static VKParams parseGetParam(
            Int64? ownerId,
            String domain,
            Int32? offset,
            Int32? count,
            FilterEnum? filter,
            Boolean extended
            )
        {
            VKParams param = new VKParams();

            if (ownerId.HasValue) param.Add("owner_id", ownerId.Value);
            if (!String.IsNullOrWhiteSpace(domain)) param.Add("domain", domain);
            if (offset.HasValue) param.Add("offset", offset.Value);
            if (count.HasValue) param.Add("count", count.Value);
            if (filter.HasValue) param.Add("filter", filter.Value);
            param.Add("extended", extended ? "1" : "0");

            return param;
        }
示例#22
0
        private VKParams GetReorderParams(
            Int64 audioId,
            Int64? ownerId,
            Int64? before,
            Int64? after)
        {
            VKParams param = new VKParams();

            param.Add("audio_id", audioId);
            if (ownerId.HasValue)
            {
                param.Add("owner_id", ownerId.Value);
            }
            if (before.HasValue)
            {
                param.Add("before", before.Value);
            }
            if (after.HasValue)
            {
                param.Add("after", after.Value);
            }

            return param;
        }