/// <summary> /// Initializes a new instance of the <see cref="Protocol"/> class. /// </summary> /// <param name="context">The instance of the <see cref="ProtocolContext"/> /// which contains application credentials. /// How to get PureKit's application credentials /// you will find <see href="https://github.com/passw0rd/cli">here</see>.</param> public Protocol(ProtocolContext context) { Validation.NotNull( context, "Context with Application token, Service Public Key and Application Secret Key isn't provided."); this.ctx = context; }
/// <summary> /// Create the context with PureKit's application credentials. /// How to get PureKit's application credentials /// you will find <see href="https://github.com/passw0rd/cli">here</see>. /// </summary> /// <returns>The new instance of the <see cref="ProtocolContext"/> /// which contains application credentials.</returns> /// <param name="appToken">Application token.</param> /// <param name="servicePublicKey">Service public key.</param> /// <param name="appSecretKey">Application Secret Key.</param> /// <param name="updateToken">Update token. /// How to generate Update Token you will find /// <see href="https://github.com/passw0rd/cli#get-an-update-token">here</see>.</param> public static ProtocolContext Create( string appToken, string servicePublicKey, string appSecretKey, string updateToken = null) { Validation.NotNullOrWhiteSpace(appToken, "Application token isn't provided."); Validation.NotNullOrWhiteSpace(servicePublicKey, "Service Public Key isn't provided."); Validation.NotNullOrWhiteSpace(appSecretKey, "Application Secret Key isn't provided."); var serializer = new HttpBodySerializer(); var client = new PheHttpClient(serializer, appToken, ServiceUrl.ProvideByToken(appToken)); var ctx = new ProtocolContext(appToken, client, servicePublicKey, appSecretKey); if (!string.IsNullOrWhiteSpace(updateToken)) { ctx.UpdatePheClients(updateToken); } return(ctx); }