Exemple #1
0
		/// <summary>
		/// Разобрать из json.
		/// </summary>
		/// <param name="response">Ответ сервера.</param>
		/// <returns></returns>
		internal static NewsSuggestions FromJson(VkResponse response)
		{
			var newsSuggestions = new NewsSuggestions
			{
				Users = new List<User>(),
				Groups = new List<Group>()
			};
			VkResponseArray result = response;
			foreach (var item in result)
			{

				switch (item["type"].ToString())
				{
					case "page":
					case "group":
						{
							Group @group = item;
							newsSuggestions.Groups.Add(@group);
						}
						break;
					case "profile":
						{
							User user = item;
							newsSuggestions.Users.Add(user);
						}
						break;
					default:
						{
							throw new System.Exception(string.Format("Типа '{0}' не существует. Пожалуйста заведите задачу на сайте проекта: https://github.com/vknet/vk/issues", item["type"]));
						}
				}
			}
			return newsSuggestions;
		}
Exemple #2
0
        internal static Education FromJson(VkResponse response)
        {
            if (response["university"] == null || response["university"].ToString() == "0")
                return null;

            var education = new Education();

            education.UniversityId = Utilities.GetNullableLongId(response["university"]);
            education.UniversityName = response["university_name"];
            education.FacultyId = Utilities.GetNullableLongId(response["faculty"]);
            education.FacultyName = response["faculty_name"];
            education.Graduation = (int?) Utilities.GetNullableLongId(response["graduation"]);

            if (education.UniversityId.HasValue && education.UniversityId == 0)
                education.UniversityId = null;

            if (education.FacultyId.HasValue && education.FacultyId == 0)
                education.FacultyId = null;

            if (education.Graduation.HasValue && education.Graduation == 0)
                education.Graduation = null;

            education.EducationForm = response["education_form"]; // установлено экcпериментальным путем
            education.EducationStatus = response["education_status"]; // установлено экcпериментальным путем

            return education;
        }
Exemple #3
0
 /// <summary>
 /// Разобрать из json.
 /// </summary>
 /// <param name="response">Ответ сервера.</param>
 /// <returns></returns>
 public static LookupContactsOther FromJson(VkResponse response)
 {
     return new LookupContactsOther
     {
         Contact = response["contact"],
         CommonCount = response["common_count"]
     };
 }
Exemple #4
0
		/// <summary>
		/// Разобрать из json.
		/// </summary>
		/// <param name="response">Ответ сервера.</param>
		/// <returns></returns>
		internal static AuthConfirmResult FromJson(VkResponse response)
		{
			return new AuthConfirmResult
			{
				Success = response["success"],
				UserId = response["uid"]
			};
		}
Exemple #5
0
 /// <summary>
 /// Разобрать из json.
 /// </summary>
 /// <param name="response">Ответ сервера.</param>
 /// <returns></returns>
 public static LookupContactsResult FromJson(VkResponse response)
 {
     return new LookupContactsResult
     {
         FoundList = response["found"].ToReadOnlyCollectionOf<User>(x => x),
         Other = response["other"].ToReadOnlyCollectionOf<LookupContactsOther>(x => x)
     };
 }
Exemple #6
0
        internal static Comments FromJson(VkResponse response)
        {
            var comments = new Comments();

            comments.Count = response["count"];
            comments.CanPost = response["can_post"];

            return comments;
        }
Exemple #7
0
        internal static Street FromJson(VkResponse response)
        {
            var street = new Street();

            street.Id = response["sid"];
            street.Title = response["name"];

            return street;
        }
Exemple #8
0
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns></returns>
        internal static Product FromJson(VkResponse response)
        {
            var product = new Product
            {
                Price = response["price"]
            };

            return product;
        }
Exemple #9
0
        internal static Lyrics FromJson(VkResponse re)
        {
            var lyrics = new Lyrics();

            lyrics.Id = re["lyrics_id"];
            lyrics.Text = re["text"];

            return lyrics;
        }
Exemple #10
0
        internal static Country FromJson(VkResponse response)
        {
            var country = new Country();

            country.Id = response["cid"] ?? response["id"];
            country.Title = response["title"] ?? response["name"];

            return country;
        }
Exemple #11
0
        internal static Faculty FromJson(VkResponse response)
        {
            var faculty = new Faculty();

            faculty.Id = response["id"];
            faculty.Title = response["title"];

            return faculty;
        }
Exemple #12
0
        internal static LastActivity FromJson(VkResponse re)
        {
            var lastActivity = new LastActivity();

            lastActivity.IsOnline = re["online"];
            lastActivity.Time = Utilities.FromUnixTime(re["time"]);

            return lastActivity;
        }
Exemple #13
0
        internal static PostSource FromJson(VkResponse response)
        {
            var postSource = new PostSource();

            postSource.Type = response["type"];
            postSource.Data = response["data"];

            return postSource;
        }
Exemple #14
0
        internal static Reposts FromJson(VkResponse response)
        {
            var reposts = new Reposts();

            reposts.Count = response["count"];
            reposts.UserReposted = response["user_reposted"];

            return reposts;
        }
Exemple #15
0
        internal static FriendList FromJson(VkResponse response)
        {
            var list = new FriendList();

            list.Id = response["lid"];
            list.Name = response["name"];

            return list;
        }
Exemple #16
0
        internal static Status FromJson(VkResponse response)
        {
            var status = new Status();

            status.Text = response["text"];
            status.Audio = response["audio"];

            return status;
        }
Exemple #17
0
		/// <summary>
		/// Разобрать из json.
		/// </summary>
		/// <param name="response">Ответ сервера.</param>
		/// <returns></returns>
		internal static GroupsCatalogInfo FromJson(VkResponse response)
		{
			var result = new GroupsCatalogInfo
			{
				Enabled = response["enabled"],
				Categories = response["categories"].ToReadOnlyCollectionOf<CategoryGroup>(o => o)
			};

			return result;
		}
Exemple #18
0
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns></returns>
        internal static Currency FromJson(VkResponse response)
        {
            var currency = new Currency
            {
                Id = response["id"],
                Сurrency = response["currency"]
            };

            return currency;
        }
Exemple #19
0
		/// <summary>
		/// Разобрать из json.
		/// </summary>
		/// <param name="response">Ответ сервера.</param>
		/// <returns></returns>
		internal static AccountPushSettings FromJson(VkResponse response)
		{
			return new AccountPushSettings
			{
				Disabled = response["disabled"],
				DisabledUntil = response["disabled_until"],
				Conversations = response["conversations"],
				Settings = response["settings"]
			};
		}
Exemple #20
0
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns></returns>
        public static Country FromJson(VkResponse response)
        {
            var country = new Country
            {
                Id = response["comment_id"] ?? response["cid"] ?? response["id"],
                Title = response["title"] ?? response["name"]
            };

            return country;
        }
Exemple #21
0
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns></returns>
        internal static FriendList FromJson(VkResponse response)
        {
            var list = new FriendList
            {
                Id = response["list_id"] ?? response["lid"],
                Name = response["name"]
            };

            return list;
        }
Exemple #22
0
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns></returns>
        public static LastSeen FromJson(VkResponse response)
        {
            var giftItem = new LastSeen
            {
                Time = response["time"],
                Platform = response["platform"]
            };

            return giftItem;
        }
Exemple #23
0
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns></returns>
        public static Button FromJson(VkResponse response)
        {
            var button = new Button
            {
                Title = response["title"],
                Uri = response["url"]
            };

            return button;
        }
Exemple #24
0
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns></returns>
        public static MessagesPushSettings FromJson(VkResponse response)
        {
            var result = new MessagesPushSettings
            {
                no_sound = response["no_sound"],
                no_text = response["no_text"]
            };

            return result;
        }
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns></returns>
        public static AccountChangePasswordResult FromJson(VkResponse response)
        {
            var item = new AccountChangePasswordResult
            {
                Token = response["token"],
                Secret = response["secret"]
            };

            return item;
        }
Exemple #26
0
        internal static Relative FromJson(VkResponse response)
        {
            var relative = new Relative();

            relative.Id = response["id"];
            relative.Type = response["type"];
            relative.Name = response["name"];

            return relative;
        }
Exemple #27
0
		/// <summary>
		/// Разобрать из json.
		/// </summary>
		/// <param name="response">Ответ сервера.</param>
		/// <returns></returns>
		internal static Faculty FromJson(VkResponse response)
		{
			var faculty = new Faculty
			{
				Id = response["id"],
				Title = response["title"]
			};

			return faculty;
		}
Exemple #28
0
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns></returns>
        internal static Rating FromJson(VkResponse response)
        {
            var rating = new Rating
            {
                Stars = response["stars"],
                ReviewsCount = response["reviews_count"]
            };

            return rating;
        }
Exemple #29
0
        internal static LongPollServerResponse FromJson(VkResponse response)
        {
            var longPollServerResponse = new LongPollServerResponse();

            longPollServerResponse.Key = response["key"];
            longPollServerResponse.Server = response["server"];
            longPollServerResponse.Ts = response["ts"];

            return longPollServerResponse;
        }
Exemple #30
0
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns></returns>
        internal static Store FromJson(VkResponse response)
        {
            var store = new Store
            {
                Id = response["id"],
                Name = response["name"]
            };

            return store;
        }
Exemple #31
0
 /// <summary>
 /// Получение идентификатора.
 ///
 /// Применять когда id может быть задано как строкой так и числом в json'e.
 /// </summary>
 /// <param name="response">Ответ от сервера vk.com</param>
 /// <returns>Число типа long или null</returns>
 public static long?GetNullableLongId(VkResponse response)
 {
     return(!string.IsNullOrWhiteSpace(response?.ToString()) ? System.Convert.ToInt64(response.ToString()) : (long?)null);
 }
Exemple #32
0
 /// <summary>
 /// Получение идентификатора.
 ///
 /// Применять когда id может быть задано как строкой так и числом в json'e.
 /// </summary>
 /// <param name="response"></param>
 /// <returns></returns>
 public static long?GetNullableLongId(VkResponse response)
 {
     return(response != null && !string.IsNullOrEmpty(response.ToString()) ? System.Convert.ToInt64(response.ToString()) : (long?)null);
 }
Exemple #33
0
        /// <summary>
        /// Ошибки VK.
        /// </summary>
        /// <param name="json"> JSON. </param>
        /// <exception cref="VkApiException">
        /// Неправильный данные JSON.
        /// </exception>
        public static void IfErrorThrowException(string json)
        {
            JObject obj;

            try
            {
                obj = JObject.Parse(json: json);
            }
            catch (JsonReaderException ex)
            {
                throw new VkApiException(message: "Wrong json data.", innerException: ex);
            }

            var response = obj[propertyName : "error"];

            if (response == null)
            {
                return;
            }

            var error = new VkResponse(token: response)
            {
                RawJson = json
            };

            var code = (int)response[key : "error_code"];

            switch (code)
            {
            case ErrorCode.Unknown:                     // Error 1

            {
                throw new UnknownException(response: error);
            }

            case ErrorCode.AppOff:                     // Error 2

            {
                throw new AppOffException(response: error);
            }

            case ErrorCode.UnknownMethod:                     // Error 3

            {
                throw new UnknownMethodException(response: error);
            }

            case ErrorCode.InvalidSignature:                     // Error 4

            {
                throw new InvalidSignatureException(response: error);
            }

            case ErrorCode.AuthorizationFailed:                     // Error 5

            {
                throw new UserAuthorizationFailException(response: error);
            }

            case ErrorCode.TooManyRequestsPerSecond:                     // Error 6

            {
                throw new TooManyRequestsException(response: error);
            }

            case ErrorCode.PermissionToPerformThisAction:                     // Error 7

            {
                throw new PermissionToPerformThisActionException(response: error);
            }

            case ErrorCode.InvalidRequest:                     // Error 8

            {
                throw new InvalidRequestException(response: error);
            }

            case ErrorCode.TooMuchOfTheSameTypeOfAction:                     // Error 9

            {
                throw new TooMuchOfTheSameTypeOfActionException(response: error);
            }

            case ErrorCode.PublicServerError:                     // Error 10

            {
                throw new PublicServerErrorException(response: error);
            }

            case ErrorCode.OffAppOrLogin:                     // Error 11

            {
                throw new OffAppOrLoginException(response: error);
            }

            case ErrorCode.ImpossibleToCompileCode:                     // Error 12

            {
                throw new ImpossibleToCompileCodeException(response: error);
            }

            case ErrorCode.ErrorExecutingCode:                     // Error 13

            {
                throw new ErrorExecutingCodeException(response: error);
            }

            case ErrorCode.CaptchaNeeded:                     // Error 14

            {
                throw new CaptchaNeededException(response: error);
            }

            case ErrorCode.CannotBlacklistYourself:                     // Error 15

            {
                throw new CannotBlacklistYourselfException(response: error);
            }

            case ErrorCode.NeedHttps:                     // Error 16

            {
                throw new NeedHttpsException(response: error);
            }

            case ErrorCode.NeedValidationOfUser:                     // Error 17

            {
                throw new NeedValidationException(response: error);
            }

            case ErrorCode.UserDeletedOrBanned:                     // Error 18

            {
                throw new UserDeletedOrBannedException(response: error);
            }

            case ErrorCode.ContentDenied:                     // Error 19

            {
                throw new ContentDeniedException(response: error);
            }

            case ErrorCode.NonStandaloneApplications:                     // Error 20

            {
                throw new NonStandaloneApplicationsException(response: error);
            }

            case ErrorCode.OnlySandaloneOrOpenApi:                     // Error 21

            {
                throw new OnlySandaloneOrOpenApiException(response: error);
            }

            case ErrorCode.LoadingError:                     // Error 22

            {
                throw new LoadingErrorException(response: error);
            }

            case ErrorCode.MethodHasBeenSwitchedOff:                     // Error 23

            {
                throw new MethodHasBeenSwitchedOffException(response: error);
            }

            case ErrorCode.ConfirmationUser:                     // Error 24

            {
                throw new ConfirmationUserException(response: error);
            }

            case ErrorCode.GroupKeyInvalid:                     // Error 27

            {
                throw new GroupKeyInvalidException(error: error);
            }

            case ErrorCode.AppKeyInvalid:                     // Error 28

            {
                throw new AppKeyInvalidException(error: error);
            }

            case ErrorCode.RateLimitReached:                     // Error 29

            {
                throw new RateLimitReachedException(response: error);
            }

            case ErrorCode.ParameterMissingOrInvalid:                     // Error 100

            {
                throw new ParameterMissingOrInvalidException(response: error);
            }

            case ErrorCode.InvalidAppId:                     // Error 101

            {
                throw new InvalidAppIdException(response: error);
            }

            case ErrorCode.OutOfLimits:                     // Error 103

            {
                throw new OutOfLimitsException(response: error);
            }

            case ErrorCode.InvalidUserId:                     // Error 113

            {
                throw new InvalidUserIdException(response: error);
            }

            case ErrorCode.InvalidServer:                     // Error 118

            {
                throw new InvalidServerException(response: error);
            }

            case ErrorCode.InvalidParameter:                     // Error 120

            {
                throw new InvalidParameterException(response: error);
            }

            case ErrorCode.InvalidHash:                     // Error 121

            {
                throw new InvalidHashException(response: error);
            }

            case ErrorCode.InvalidGroupId:                     // Error 125

            {
                throw new InvalidGroupIdException(response: error);
            }

            case ErrorCode.AccessToMenuDenied:                     // Error 148

            {
                throw new AccessToMenuDeniedException(response: error);
            }

            case ErrorCode.InvalidTimestamp:                     // Error 150

            {
                throw new InvalidTimestampException(response: error);
            }

            case ErrorCode.UserAccessDenied:                     // Error 170

            {
                throw new UserAccessDeniedException(response: error);
            }

            case ErrorCode.ListIdInvalid:                     // Error 171

            {
                throw new ListIdInvalidException(response: error);
            }

            case ErrorCode.ListAmountMaximum:                     // Error 173

            {
                throw new ListAmountMaximumException(response: error);
            }

            case ErrorCode.CannotAddYourself:                     // Error 174

            {
                throw new CannotAddYourselfException(response: error);
            }

            case ErrorCode.CannotAddYouBlacklisted:                     // Error 175

            {
                throw new CannotAddYouBlacklistedException(response: error);
            }

            case ErrorCode.CannotAddUserBlacklisted:                     // Error 176

            {
                throw new CannotAddUserBlacklistedException(response: error);
            }

            case ErrorCode.CannotAddUserNotFound:                     // Error 177

            {
                throw new CannotAddUserNotFoundException(response: error);
            }

            case ErrorCode.AlbumAccessDenied:                     // Error 200

            {
                throw new AlbumAccessDeniedException(response: error);
            }

            case ErrorCode.AudioAccessDenied:                     // Error 201

            {
                throw new AudioAccessDeniedException(response: error);
            }

            case ErrorCode.GroupAccessDenied:                     // Error 203

            {
                throw new GroupAccessDeniedException(response: error);
            }

            case ErrorCode.VideoAccessDenied:                     // Error 204

            {
                throw new VideoAccessDeniedException(response: error);
            }

            case ErrorCode.PostAccessDenied:                     // Error 210

            {
                throw new PostAccessDeniedException(response: error);
            }

            case ErrorCode.CommentsWallAccessDenied:                     // Error 211

            {
                throw new CommentsWallAccessDeniedException(response: error);
            }

            case ErrorCode.CommentsPostAccessDenied:                     // Error 212

            {
                throw new CommentsPostAccessDeniedException(response: error);
            }

            case ErrorCode.AccessToCommentDenied:                     // Error 213

            {
                throw new AccessToCommentDeniedException(response: error);
            }

            case ErrorCode.AccessToAddingPostDenied:                     // Error 214

            {
                // Access to adding post denied: you can only add 50 posts a day.
                throw new PostLimitException(response: error);
            }

            case ErrorCode.AdsRecentlyPosted:                     // Error 219

            {
                throw new AdsRecentlyPostedException(response: error);
            }

            case ErrorCode.StatusAccessDenied:                     // Error 220

            {
                throw new StatusAccessDeniedException(response: error);
            }

            case ErrorCode.UserDisabledTrackNameBroadcast:                     // Error 221

            {
                throw new UserDisabledTrackNameBroadcastException(response: error);
            }

            case ErrorCode.PostLinksDenied:                     // Error 222

            {
                throw new PostLinksDeniedException(response: error);
            }

            case ErrorCode.CommentsLimitReached:                     // Error 223

            {
                throw new CommentsLimitReachedException(response: error);
            }

            case ErrorCode.ToomanyAdsPosts:                     // Error 224

            {
                throw new TooManyAdsPostsException(response: error);
            }

            case ErrorCode.GroupsListAccessDenied:                     // Error 260

            {
                throw new GroupsListAccessDeniedException(response: error);
            }

            case ErrorCode.AlbumIsFull:                     // Error 300

            {
                throw new AlbumIsFullException(response: error);
            }

            case ErrorCode.VideoAlbumIsFull:                     // Error 302

            {
                throw new VideoAlbumIsFullException(response: error);
            }

            case ErrorCode.PermissionDenied:                     // Error 500

            {
                // Permission denied. You must enable votes processing in application settings.
                throw new AccessDeniedException(response: error);
            }

            case ErrorCode.AdsAccessDenied:                     // Error 600

            {
                throw new AdsAccessDeniedException(response: error);
            }

            case ErrorCode.ErrorWorkWithAds:                     // Error 603

            {
                throw new ErrorWorkWithAdsException(response: error);
            }

            case ErrorCode.VideoAlreadyAdded:                     // Error 800

            {
                throw new VideoAlreadyAddedException(response: error);
            }

            case ErrorCode.VideoCommentsClosed:                     // Error 801

            {
                throw new VideoCommentsClosedException(response: error);
            }

            case ErrorCode.CannotSendBlacklisted:                     // Error 900

            {
                throw new CannotSendBlacklistedException(response: error);
            }

            case ErrorCode.CannotSendToUserFirstly:                     // Error 901

            {
                throw new CannotSendToUserFirstlyException(response: error);
            }

            case ErrorCode.CannotSendDuePrivacy:                     // Error 902

            {
                throw new CannotSendDuePrivacyException(response: error);
            }

            case ErrorCode.TooMuchSentMessages:                     // Error 913

            {
                throw new TooMuchSentMessagesException(response: error);
            }

            case ErrorCode.MessageIsTooLong:                     // Error 914

            {
                throw new MessageIsTooLongException(response: error);
            }

            default:

            {
                throw new VkApiException(response: error);
            }
            }
        }