当前位置: 首页>>代码示例>>C#>>正文


C# VkApi类代码示例

本文整理汇总了C#中VkApi的典型用法代码示例。如果您正苦于以下问题:C# VkApi类的具体用法?C# VkApi怎么用?C# VkApi使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


VkApi类属于命名空间,在下文中一共展示了VkApi类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Call_NotMoreThen3CallsPerSecond

        public void Call_NotMoreThen3CallsPerSecond()
        {
            int invocationCount = 0;
            var browser = new Mock<IBrowser>();
            browser.Setup(m => m.GetJson(It.IsAny<string>()))
                   .Returns(@"{ ""response"": 2 }")
                   .Callback(() => invocationCount++);

            var api = new VkApi {Browser = browser.Object};

            var start = DateTimeOffset.Now;
            while (true)
            {
                api.Call("someMethod", VkParameters.Empty, true);

                int total = (int)(DateTimeOffset.Now - start).TotalMilliseconds;
                if (total > 999)
                    break;

            }

            // Не больше 4 раз, т.к. 4-ый раз вызывается через 1002 мс после первого вызова, а total выходит через 1040 мс
            // переписать тест, когда придумаю более подходящий метод проверки
            browser.Verify(m => m.GetJson(It.IsAny<string>()), Times.AtMost(4));
        }
开发者ID:NastasiyaKudricheva,项目名称:MusikLiker,代码行数:25,代码来源:VkApiTest.cs

示例2: GetJson

        /// <summary>
        /// Получение json по url-адресу
        /// </summary>
        /// <param name="url">Адрес получения json</param>
        /// <returns>Строка в формате json</returns>
        public string GetJson(string url, VkApi vkApi)
        {
            var separatorPosition = url.IndexOf('?');
            string methodUrl = separatorPosition < 0 ? url : url.Substring(0, separatorPosition);
            string parameters = separatorPosition < 0 ? string.Empty : url.Substring(separatorPosition + 1);

            return WebCall.PostCall(methodUrl, parameters, vkApi).Response;
        }
开发者ID:SaintCat,项目名称:VkBot,代码行数:13,代码来源:Browser.cs

示例3: WebCall

 private WebCall(string url, Cookies cookies, VkApi vk)
 {
     Request = (HttpWebRequest)WebRequest.Create(url);
     Request.Accept = "text/html";
     Request.UserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)";
     Request.CookieContainer = cookies.Container;
     if (!vk.isDefaultVkApi)
     {
         createProxy(ProxyManager.getInstance().reserveOrGet(vk.email), Request);
     }
     Result = new WebCallResult(url, cookies);
 }
开发者ID:SaintCat,项目名称:VkBot,代码行数:12,代码来源:WebCall.cs

示例4: PostCall

        public static WebCallResult PostCall(string url, string parameters,VkApi vk)
        {
            var call = new WebCall(url, new Cookies(), vk);
            call.Request.Method = "POST";
            call.Request.ContentType = "application/x-www-form-urlencoded";
            
            var data = Encoding.UTF8.GetBytes(parameters);
            call.Request.ContentLength = data.Length;

            using (var requestStream = call.Request.GetRequestStream())
                requestStream.Write(data, 0, data.Length);                

            return call.MakeRequest(vk);
        }
开发者ID:SaintCat,项目名称:VkBot,代码行数:14,代码来源:WebCall.cs

示例5: Post

        public static WebCallResult Post(WebForm form, VkApi vk)
        {
            var call = new WebCall(form.ActionUrl, form.Cookies, vk);

            var request = call.Request;
            
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            var formRequest = form.GetRequest();
            request.ContentLength = formRequest.Length;
            request.Referer = form.OriginalUrl;
            request.GetRequestStream().Write(formRequest, 0, formRequest.Length);
            request.AllowAutoRedirect = false;

            return call.MakeRequest(vk);
        }
开发者ID:SaintCat,项目名称:VkBot,代码行数:16,代码来源:WebCall.cs

示例6: Init

        public void Init()
        {
            var browser = new Mock<IBrowser>();
            browser.Setup(m => m.GetJson(It.Is<string>(s => s == Url)))
                .Callback(Callback)
                .Returns(() =>
                {
                    if (string.IsNullOrWhiteSpace(Json))
                    {
                        throw new ArgumentNullException(nameof(Json), @"Json не может быть равен null. Обновите значение поля Json");
                    }
                    return Json;
                });

            browser.Setup(o => o.Authorize(
                It.IsAny<ulong>(),
                It.IsAny<string>(),
                It.IsAny<string>(),
                It.IsAny<Settings>(),
                It.IsAny<Func<string>>(),
                It.IsAny<long?>(),
                It.IsAny<string>(),
                It.IsAny<string>(),
                It.IsAny<int?>(),
                It.IsAny<string>(),
                It.IsAny<string>()
                )
			)
			.Returns(VkAuthorization.From(new Uri("https://vk.com/auth?__q_hash=qwerty&access_token=token&expires_in=1000&user_id=1")));
            Api = new VkApi
            {
                Browser = browser.Object
            };
            Api.Authorize(new ApiAuthParams
            {
	            ApplicationId = 1,
				Login = "login",
				Password = "pass",
				Settings = Settings.All
            });
	        Api.RequestsPerSecond = 10000; // Чтобы тесты быстрее выполнялись
        }
开发者ID:kadkin,项目名称:vk,代码行数:42,代码来源:BaseTest.cs

示例7: Search_EmptyAccessToken_ThrowAccessTokenInvalidException

 public void Search_EmptyAccessToken_ThrowAccessTokenInvalidException()
 {
     var vk = new VkApi();
     int count;
     This.Action(() => vk.Users.Search(Query, out count)).Throws<AccessTokenInvalidException>();
 }
开发者ID:SaintCat,项目名称:VkBot,代码行数:6,代码来源:UsersCategoryTest.cs

示例8: GiftsCategory

		/// <summary>
		/// Методы для работы с подарками.
		/// </summary>
		/// <param name="vk">API.</param>
		internal GiftsCategory(VkApi vk)
		{
			_vk = vk;
		}
开发者ID:ProESM,项目名称:vk,代码行数:8,代码来源:GiftsCategory.cs

示例9: DocsCategory

 internal DocsCategory(VkApi vk)
 {
     _vk = vk;
     Ex = new DocsCategoryExtended(this, _vk);
 }
开发者ID:andrew-veresov,项目名称:vk,代码行数:5,代码来源:DocsCategory.cs

示例10: AppsCategory

		/// <summary>
		/// Методы для работы с приложениями.
		/// </summary>
		/// <param name="vk">API.</param>
		internal AppsCategory(VkApi vk)
		{
			_vk = vk;
		}
开发者ID:ProESM,项目名称:vk,代码行数:8,代码来源:AppsCategory.cs

示例11: UsersCategory

 internal UsersCategory(VkApi vk)
 {
     _vk = vk;
 }
开发者ID:J2GIS,项目名称:vk,代码行数:4,代码来源:UsersCategory.cs

示例12: AuthorizeByTokenNegative

 public void AuthorizeByTokenNegative()
 {
     Api = new VkApi(); // В базовом классе предопределено свойство AccessToken
     Api.Authorize("", 1);
     Assert.That(Api.UserId, Is.Null);
 }
开发者ID:vknet,项目名称:vk,代码行数:6,代码来源:VkApiTest.cs

示例13: AuthCategory

 /// <summary>
 /// Методы для работы с подарками.
 /// </summary>
 /// <param name="vk">API.</param>
 public AuthCategory(VkApi vk)
 {
     _vk = vk;
 }
开发者ID:vknet,项目名称:vk,代码行数:8,代码来源:AuthCategory.cs

示例14: FaveCategory

 /// <summary>
 /// Методы для работы с закладками.
 /// </summary>
 /// <param name="vk">API.</param>
 internal FaveCategory(VkApi vk)
 {
     _vk = vk;
 }
开发者ID:Olegasdf,项目名称:vk,代码行数:8,代码来源:FaveCategory.cs

示例15: Call_ThrowsCaptchaNeededException

        public void Call_ThrowsCaptchaNeededException()
        {
            const string json =
                @"{
                    'error': {
                      'error_code': 14,
                      'error_msg': 'Captcha needed',
                      'request_params': [
                        {
                          'key': 'oauth',
                          'value': '1'
                        },
                        {
                          'key': 'method',
                          'value': 'messages.send'
                        },
                        {
                          'key': 'uid',
                          'value': '242508553'
                        },
                        {
                          'key': 'message',
                          'value': 'hello10'
                        },
                        {
                          'key': 'type',
                          'value': '0'
                        },
                        {
                          'key': 'access_token',
                          'value': '1fe7889c3395722934b1'
                        }
                      ],
                      'captcha_sid': '548747100691',
                      'captcha_img': 'http://api.vk.com/captcha.php?sid=548747100284&s=1'
                    }
                  }";

            var browser = Mock.Of<IBrowser>(m => m.GetJson(It.IsAny<string>()) == json);
            var api = new VkApi {Browser = browser};

            var ex = This.Action(() => api.Call("messages.send", VkParameters.Empty, true)).Throws<CaptchaNeededException>();

            ex.Sid.ShouldEqual(548747100691);
            ex.Img.ShouldEqual(new Uri("http://api.vk.com/captcha.php?sid=548747100284&s=1"));
        }
开发者ID:NastasiyaKudricheva,项目名称:MusikLiker,代码行数:46,代码来源:VkApiTest.cs


注:本文中的VkApi类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。