示例#1
0
        public async Task pin_json_object_with_options()
        {
            this.server.RespondWithJsonTestFile();

            var body = new { hello = "world" };
            var opts = new PinataOptions
            {
                CidVersion = 1,
            };

            opts.CustomPinPolicy.AddOrUpdateRegion("FRA1", 1);

            var meta = new PinataMetadata
            {
                Name      = "hello",
                KeyValues =
                {
                    { "someKey", "someValue" }
                }
            };
            var r = await this.client.Pinning.PinJsonToIpfsAsync(body, meta, opts);

            var expectedBody = @"{""pinataOptions"":{""cidVersion"":1,""customPinPolicy"":{""regions"":[{""id"":""FRA1"",""desiredReplicationCount"":1}]},""wrapWithDirectory"":null,""hostNodes"":null},""pinataMetadata"":{""name"":""hello"",""keyvalues"":{""someKey"":""someValue""}},""pinataContent"":{""hello"":""world""}}";

            this.server.ShouldHaveCalledPath("/pinning/pinJSONToIPFS")
            .WithVerb(Post)
            .WithExactBody(expectedBody);

            await Verify(r);
        }
示例#2
0
        public async Task pinning_PinJsonToIpfs_as_object_with_options()
        {
            var body = new { hello = "world" };

            var opts = new PinataOptions
            {
                CidVersion = 1,
            };

            opts.CustomPinPolicy.AddOrUpdateRegion("FRA1", 1);

            var meta = new PinataMetadata
            {
                Name      = "hello",
                KeyValues =
                {
                    { "someKey", "someValue" }
                }
            };

            var r = await this.client.Pinning.PinJsonToIpfsAsync(body, meta, opts);
        }
示例#3
0
        public async Task pinning_PinFileToIpfs_with_StringContent_with_options()
        {
            var html     = @"
<html>
   <head>
      <title>Hello IPFS!</title>
   </head>
   <body>
      <h1>Hello World</h1>
   </body>
</html>
";
            var metadata = new PinataMetadata // optional
            {
                KeyValues =
                {
                    { "Author", "Brian Chavez" }
                }
            };

            var options = new PinataOptions(); // optional

            options.CustomPinPolicy.AddOrUpdateRegion("NYC1", desiredReplicationCount: 1);

            var response = await this.client.Pinning.PinFileToIpfsAsync(content =>
            {
                var file = new StringContent(html, Encoding.UTF8, MediaTypeNames.Text.Html);

                content.AddPinataFile(file, "index.html");
            },
                                                                        metadata,
                                                                        options);

            if (response.IsSuccess)
            {
                //File uploaded to Pinata Cloud, now on IPFS!
                var hash = response.IpfsHash;
            }
        }