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); }); }
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); }
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)); }