public MilkRawClientTest() { context = new MilkContext("api-key", "secret"); var signatureGeneratorMock = new Mock <IMilkSignatureGenerator>(); signatureGeneratorMock.Setup(g => g.Generate(It.IsAny <IDictionary <string, string> >())) .Returns("signature"); signatureGenerator = signatureGeneratorMock.Object; mock = new Mock <IMilkHttpClient>(); }
public void GenerateAuthUrlTest() { var context = new MilkContext("api123", "sec123"); var signatureGeneratorMock = new Mock <IMilkSignatureGenerator>(); signatureGeneratorMock.Setup(g => g.Generate(It.IsAny <IDictionary <string, string> >())) .Returns("sig123"); var signatureGenerator = signatureGeneratorMock.Object; var auth = new MilkAuth(context, signatureGenerator); var frob = "frob123"; var perms = MilkPerms.Delete; var authUrl = auth.GenerateAuthUrl(perms, frob); Assert.Equal("https://www.rememberthemilk.com/services/auth/?api_key=api123&perms=delete&frob=frob123&api_sig=sig123", authUrl); }
static async Task Main(string[] args) { // rename `appConfig.sample.json` to `appConfig.json` // and modify "api_key" and "api_sig" values. var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appConfig.json"); var configuration = builder.Build(); var context = new MilkContext(configuration["api_key"], configuration["api_sig"]); try { // rtm.test.* method client var test = new MilkTest(context); var param = new Dictionary <string, string> { { "foo", "bar" } }; var rsp = await test.Echo(param); Console.WriteLine(rsp["foo"]); // create client var milkClient = new MilkClient(context); // authorization var frob = await milkClient.Auth.GetFrob(); Console.WriteLine($"frob:{frob}"); var authUrl = milkClient.Auth.GenerateAuthUrl(MilkPerms.Delete, frob); Console.WriteLine($"authUrl: {authUrl}"); OpenUrlOnDefaultWebBrowser(authUrl); Console.WriteLine("Please authenticate with the web page, and push any key."); Console.ReadKey(); var authToken = await milkClient.Auth.GetToken(frob); Console.WriteLine($"token: {authToken.Token}, perms: {authToken.Perms}"); milkClient.Context.AuthToken = authToken; // rtm.lists.* method client milkClient.Lists.GetList() .Subscribe( // OnNext list => Console.WriteLine($"id: {list.Id}, name: {list.Name}"), // OnError (ex) => Console.WriteLine(ex.Message), // OnComplete () => Console.WriteLine("all list have gotten") ); Console.ReadKey(); } catch (MilkHttpException httpEx) { Console.WriteLine($"http status code: {httpEx.StatusCode}"); } catch (MilkFailureException failEx) { Console.WriteLine($"API call is failed | code: {failEx.Code}, msg: {failEx.Msg}"); } }