コード例 #1
0
        public void TestRetrieveTokenWithWrong()
        {
            var requester = new DefaultHttpRequester();

            var context = new ApiContext();

            context.AddParam("grant_type", "client_credential")
            .AddParam("appid", "wrong AppId")
            .AddParam("secret", "wrong AppSecret");
            Assert.Throws <ApiInvokeException>(() => {
                var token = requester.Execute <Token>("/cgi-bin/token", context);
            });
        }
コード例 #2
0
        public void TestRetrieveToken()
        {
            var x         = new SecretInformationReader();
            var requester = new DefaultHttpRequester();

            var context = new ApiContext();

            context.AddParam("grant_type", "client_credential")
            .AddParam("appid", x.AppId)
            .AddParam("secret", x.AppSecret);
            var token = requester.Execute <Token>("/cgi-bin/token", context);

            Assert.NotNull(token.access_token);
        }
コード例 #3
0
        public T Request <T>(string resource, Action <ApiContext> action) where T : new()
        {
            Log.Logger.Info("requesting resource: {0}", resource);

            var context = new ApiContext();

            action(context);

            if (context.AutoToken)
            {
                context.AddParam("access_token", Token.TokenValue);
            }

            return(HttpRequester.Execute <T>(resource, context));
        }