コード例 #1
0
        public DigitalOceanClient(string token)
        {
            var client = new RestClient(DigitalOceanApiUrl)
            {
                UserAgent = "digitalocean-api-dotnet"
            };

            client.AddDefaultHeader("Authorization", $"Bearer {token}");

            _connection = new Connection(client);

            Actions           = new ActionsClient(_connection);
            DomainRecords     = new DomainRecordsClient(_connection);
            Domains           = new DomainsClient(_connection);
            DropletActions    = new DropletActionsClient(_connection);
            Droplets          = new DropletsClient(_connection);
            FloatingIps       = new FloatingIpsClient(_connection);
            FloatingIpActions = new FloatingIpActionsClient(_connection);
            ImageActions      = new ImageActionsClient(_connection);
            Images            = new ImagesClient(_connection);
            Keys      = new KeysClient(_connection);
            Regions   = new RegionsClient(_connection);
            Sizes     = new SizesClient(_connection);
            Snapshots = new SnapshotsClient(_connection);
            Tags      = new TagsClient(_connection);
            Volumes   = new VolumesClient(_connection);
        }
コード例 #2
0
        public override void ExecuteCmdlet()
        {
            if (!string.IsNullOrWhiteSpace(this.ResourceId))
            {
                if (ShouldProcess(this.ResourceId, Resources.RemoveTagMessage))
                {
                    var res = TagsClient.DeleteTagAtScope(this.ResourceId);
                    if (this.PassThru.IsPresent)
                    {
                        WriteObject(res);
                    }
                }
            }
            else
            {
                PSTag tag = null;

                ConfirmAction(
                    Resources.RemovePredefinedTagMessage,
                    Name,
                    () =>
                {
                    tag = TagsClient.DeleteTag(Name, Value != null ? Value.ToList() : null);
                    if (PassThru)
                    {
                        WriteObject(tag);
                    }
                });
            }
        }
コード例 #3
0
        public override void ExecuteCmdlet()
        {
            List <PSTag> tags = string.IsNullOrEmpty(Name) ? TagsClient.ListTags() : new List <PSTag>()
            {
                TagsClient.GetTag(Name)
            };

            if (tags != null && tags.Count > 0)
            {
                if (Name != null)
                {
                    WriteObject(tags[0]);
                }
                else
                {
                    if (Detailed)
                    {
                        WriteObject(tags, true);
                    }
                    else
                    {
                        List <PSObject> output = new List <PSObject>();
                        tags.ForEach(t => output.Add(base.ConstructPSObject(
                                                         null,
                                                         "Name", t.Name,
                                                         "Count", t.Count)));

                        WriteObject(output, true);
                    }
                }
            }
        }
コード例 #4
0
        public void CorrectRequestForUntag()
        {
            var factory = Substitute.For <IConnection>();
            var client  = new TagsClient(factory);

            var resources = new Models.Requests.TagResources()
            {
                Resources = new List <Models.Requests.TagResource>()
                {
                    new Models.Requests.TagResource()
                    {
                        Id   = "9001",
                        Type = "droplet"
                    },
                    new Models.Requests.TagResource()
                    {
                        Id   = "9002",
                        Type = "droplet"
                    }
                }
            };

            client.Untag("notarealtag", resources);

            var parameters = Arg.Is <List <Parameter> >(list => (string)list[0].Value == "notarealtag");
            var body       = Arg.Is <Models.Requests.TagResources>(tr => tr.Resources.SequenceEqual(resources.Resources));

            factory.Received().ExecuteRaw("tags/{name}/resources", parameters, body, Method.DELETE);
        }
コード例 #5
0
        public TagsClientTest()
        {
            var auth = new Authentication(AppId, AppKey);
            var restClientFactory = new RestClientFactory(auth);

            tagsClient = new TagsClient(restClientFactory);
        }
コード例 #6
0
ファイル: ApiClient.cs プロジェクト: lulzzz/aika
 /// <summary>
 /// Creates a new <see cref="ApiClient"/> object.
 /// </summary>
 /// <param name="loggerFactory">The logger factory for the API client.  Can be <see langword="null"/>.</param>
 private ApiClient(ILoggerFactory loggerFactory)
 {
     _logger          = loggerFactory?.CreateLogger <ApiClient>();
     Info             = new InfoClient(this);
     Tags             = new TagsClient(this);
     Snapshot         = new SnapshotSubscriptionClient(this, loggerFactory);
     TagConfiguration = new TagConfigurationClient(this);
 }
コード例 #7
0
        public void CorrectRequestForCreate()
        {
            var factory = Substitute.For <IConnection>();
            var client  = new TagsClient(factory);

            client.Create("notarealtag");

            factory.Received().ExecuteRequest <Tag>("tags", null, Arg.Is <Models.Requests.Tag>(data => data.Name == "notarealtag"), "tag", Method.POST);
        }
コード例 #8
0
 /// <summary>
 /// Instantiates a new GitHub Git API client.
 /// </summary>
 /// <param name="apiConnection">An API connection</param>
 public GitDatabaseClient(IApiConnection apiConnection)
     : base(apiConnection)
 {
     Blob      = new BlobsClient(apiConnection);
     Tree      = new TreesClient(apiConnection);
     Tag       = new TagsClient(apiConnection);
     Commit    = new CommitsClient(apiConnection);
     Reference = new ReferencesClient(apiConnection);
 }
コード例 #9
0
        public async Task RequestsCorrectUrlWithRepositoryId()
        {
            var connection = Substitute.For <IApiConnection>();
            var client     = new TagsClient(connection);

            await client.Get(1, "reference");

            connection.Received().Get <GitTag>(Arg.Is <Uri>(u => u.ToString() == "repositories/1/git/tags/reference"), null, "application/vnd.github.cryptographer-preview+sha");
        }
コード例 #10
0
        public void RequestsCorrectUrl()
        {
            var connection = Substitute.For <IApiConnection>();
            var client     = new TagsClient(connection);

            client.Get("owner", "repo", "reference");

            connection.Received().Get <GitTag>(Arg.Is <Uri>(u => u.ToString() == "repos/owner/repo/git/tags/reference"), null);
        }
コード例 #11
0
        public void CorrectRequestForGetAll()
        {
            var factory = Substitute.For <IConnection>();
            var client  = new TagsClient(factory);

            client.GetAll();

            factory.Received().GetPaginated <Tag>("tags", null, "tags");
        }
コード例 #12
0
ファイル: TagsClientTests.cs プロジェクト: x5a/octokit.net
        public async Task RequestsCorrectUrlWithRepositoryId()
        {
            var connection = Substitute.For <IApiConnection>();
            var client     = new TagsClient(connection);

            await client.Get(1, "reference");

            connection.Received().Get <GitTag>(Arg.Is <Uri>(u => u.ToString() == "repositories/1/git/tags/reference"));
        }
コード例 #13
0
 public GitDatabaseClient(IApiConnection apiConnection) 
     : base(apiConnection)
 {
     Blob = new BlobsClient(apiConnection);
     Tree = new TreesClient(apiConnection);
     Tag = new TagsClient(apiConnection);
     Commit = new CommitsClient(apiConnection);
     Reference = new ReferencesClient(apiConnection);
 }
コード例 #14
0
        public void CorrectRequestForDelete()
        {
            var factory = Substitute.For <IConnection>();
            var client  = new TagsClient(factory);

            client.Delete("notarealtag");

            var parameters = Arg.Is <List <Parameter> >(list => (string)list[0].Value == "notarealtag");

            factory.Received().ExecuteRaw("tags/{name}", parameters, null, Method.DELETE);
        }
コード例 #15
0
        public void CorrectRequestForUpdate()
        {
            var factory = Substitute.For <IConnection>();
            var client  = new TagsClient(factory);

            client.Update("notarealtag", "notarealtag2");

            var parameters = Arg.Is <List <Parameter> >(list => (string)list[0].Value == "notarealtag");

            factory.Received().ExecuteRequest <Tag>("tags/{name}", parameters, Arg.Is <Models.Requests.Tag>(data => data.Name == "notarealtag2"), "tag", Method.PUT);
        }
コード例 #16
0
        public void PostsToTheCorrectUrl()
        {
            var connection = Substitute.For <IApiConnection>();
            var client     = new TagsClient(connection);

            client.Create("owner", "repo", new NewTag {
                Type = TaggedType.Tree
            });

            connection.Received().Post <GitTag>(Arg.Is <Uri>(u => u.ToString() == "repos/owner/repo/git/tags"),
                                                Arg.Is <NewTag>(nt => nt.Type == TaggedType.Tree));
        }
コード例 #17
0
        public override void ExecuteCmdlet()
        {
            if (!string.IsNullOrWhiteSpace(this.ResourceId))
            {
                if (ShouldProcess(this.ResourceId, string.Format(Resources.UpdateTagMessage, this.Operation)))
                {
                    var tagDict = this.Tag.Cast <DictionaryEntry>().ToDictionary(d => d.Key?.ToString(), d => d.Value?.ToString());
                    var res     = TagsClient.UpdateTagAtScope(this.ResourceId, this.Operation, tagDict);

                    WriteObject(res);
                }
            }
        }
コード例 #18
0
        public async Task EnsuresNonNullArguments()
        {
            var client = new TagsClient(Substitute.For <IApiConnection>());

            await AssertEx.Throws <ArgumentNullException>(async() => await client.Create(null, "name", new NewTag()));

            await AssertEx.Throws <ArgumentNullException>(async() => await client.Create("owner", null, new NewTag()));

            await AssertEx.Throws <ArgumentNullException>(async() => await client.Create("owner", "name", null));

            await AssertEx.Throws <ArgumentException>(async() => await client.Create("", "name", new NewTag()));

            await AssertEx.Throws <ArgumentException>(async() => await client.Create("owner", "", new NewTag()));
        }
コード例 #19
0
        public override void ExecuteCmdlet()
        {
            PSTag tag = null;

            ConfirmAction(
                Force.IsPresent,
                string.Format(Resources.RemovingTag, Name),
                Resources.RemoveTagMessage,
                Name,
                () => tag = TagsClient.DeleteTag(Name, Value != null ? Value.ToList() : null));

            if (PassThru)
            {
                WriteObject(tag);
            }
        }
コード例 #20
0
        public override void ExecuteCmdlet()
        {
            PSTag tag = null;

            ConfirmAction(
                Resources.RemoveTagMessage,
                Name,
                () =>
            {
                tag = TagsClient.DeleteTag(Name, Value != null ? Value.ToList() : null);
                if (PassThru)
                {
                    WriteObject(tag);
                }
            });
        }
コード例 #21
0
        public async Task EnsuresNonNullArguments()
        {
            var client = new TagsClient(Substitute.For <IApiConnection>());

            await Assert.ThrowsAsync <ArgumentNullException>(() => client.Get(null, "name", "reference"));

            await Assert.ThrowsAsync <ArgumentNullException>(() => client.Get("owner", null, "reference"));

            await Assert.ThrowsAsync <ArgumentNullException>(() => client.Get("owner", "name", null));

            await Assert.ThrowsAsync <ArgumentException>(() => client.Get("", "name", "reference"));

            await Assert.ThrowsAsync <ArgumentException>(() => client.Get("owner", "", "reference"));

            await Assert.ThrowsAsync <ArgumentException>(() => client.Get("owner", "name", ""));
        }
コード例 #22
0
        public void CorrectRequestForUntag()
        {
            var factory = Substitute.For <IConnection>();
            var client  = new TagsClient(factory);

            List <KeyValuePair <string, string> > resources = new List <KeyValuePair <string, string> >(new KeyValuePair <string, string>[] {
                new KeyValuePair <string, string>("9001", "droplet"),
                new KeyValuePair <string, string>("9002", "droplet")
            });

            client.Untag("notarealtag", resources);

            var parameters = Arg.Is <List <Parameter> >(list => (string)list[0].Value == "notarealtag");

            factory.Received().ExecuteRaw("tags/{name}/resources", parameters, Arg.Is <Models.Requests.TagResource>(data => data.Resources[1].Id == "9002"), Method.DELETE);
        }
コード例 #23
0
        public void TagsTest()
        {
            var data      = TestHelper.Load(@"Live/Tags/tags.html");
            var ulHtmlDoc = new HtmlDocument();

            ulHtmlDoc.LoadHtml(data);
            var ulHtml = ulHtmlDoc.DocumentNode;

            var ret = TagsClient.ParseTagsData(data);

            Assert.AreEqual(ulHtml.ChildNodes.Any(child => child.GetElementByClassName("edit") != null), ret.IsEditable);

            foreach (var tag in ulHtml.ChildNodes.Where(child => child.GetElementByClassName("nicopedia") != null))
            {
                var tagValue = tag.GetElementByClassName("nicopedia").InnerText;
                var retTag   = ret.Tags.Where(t => t.Value == tagValue).Single();
                Assert.AreEqual(tagValue, retTag.Value);
                Assert.AreEqual(tag.GetElementByClassName("category") != null, retTag.IsCategoryTag);
                Assert.AreEqual(tag.GetElementByClassName("npit").InnerText.Trim(new char[] { '(', ')' }).ToUShort(), retTag.Count);
            }
        }
コード例 #24
0
        public DigitalOceanClient(string token)
        {
            var client = new RestClient(DigitalOceanApiUrl)
            {
                UserAgent = "digitalocean-api-dotnet"
            };

            client.AddDefaultHeader("Authorization", string.Format("Bearer {0}", token));

            _connection = new Connection(client);

            Account           = new AccountClient(_connection);
            Actions           = new ActionsClient(_connection);
            CdnEndpoints      = new CdnEndpointsClient(_connection);
            Certificates      = new CertificatesClient(_connection);
            ContainerRegistry = new ContainerRegistryClient(_connection);
            Databases         = new DatabasesClient(_connection);
            DomainRecords     = new DomainRecordsClient(_connection);
            Domains           = new DomainsClient(_connection);
            DropletActions    = new DropletActionsClient(_connection);
            Droplets          = new DropletsClient(_connection);
            Firewalls         = new FirewallsClient(_connection);
            FloatingIpActions = new FloatingIpActionsClient(_connection);
            FloatingIps       = new FloatingIpsClient(_connection);
            ImageActions      = new ImageActionsClient(_connection);
            Images            = new ImagesClient(_connection);
            LoadBalancers     = new LoadBalancerClient(_connection);
            Projects          = new ProjectsClient(_connection);
            ProjectResources  = new ProjectResourcesClient(_connection);
            Keys          = new KeysClient(_connection);
            Kubernetes    = new KubernetesClient(_connection);
            Regions       = new RegionsClient(_connection);
            Sizes         = new SizesClient(_connection);
            Snapshots     = new SnapshotsClient(_connection);
            Tags          = new TagsClient(_connection);
            Volumes       = new VolumesClient(_connection);
            VolumeActions = new VolumeActionsClient(_connection);
            BalanceClient = new BalanceClient(_connection);
            Vpc           = new VpcClient(_connection);
        }
コード例 #25
0
        public override void ExecuteCmdlet()
        {
            if (!string.IsNullOrWhiteSpace(this.ResourceId))
            {
                if (ShouldProcess(this.ResourceId, Resources.CreateTagMessage))
                {
                    var tagDict = this.Tag.Cast <DictionaryEntry>().ToDictionary(d => d.Key?.ToString(), d => d.Value?.ToString());
                    var res     = TagsClient.CreateOrUpdateTagAtScope(this.ResourceId, tagDict);

                    WriteObject(res);
                }
            }
            else
            {
                if (ShouldProcess(this.Name, string.Format(Resources.CreatePredefinedTagMessage, this.Value)))
                {
                    WriteObject(TagsClient.CreateTag(Name, Value != null ? new List <string> {
                        Value
                    } : null));
                }
            }
        }
コード例 #26
0
        public DigitalOceanClient(string token)
        {
            var client = new RestClient(DigitalOceanApiUrl)
            {
                UserAgent = "digitalocean-api-dotnet"
            };

            client.AddDefaultHeader("Authorization", string.Format("Bearer {0}", token));

            _connection = new Connection(client);

            Actions        = new ActionsClient(_connection);
            DomainRecords  = new DomainRecordsClient(_connection);
            Domains        = new DomainsClient(_connection);
            DropletActions = new DropletActionsClient(_connection);
            Droplets       = new DropletsClient(_connection);
            ImageActions   = new ImageActionsClient(_connection);
            Images         = new ImagesClient(_connection);
            Keys           = new KeysClient(_connection);
            Regions        = new RegionsClient(_connection);
            Sizes          = new SizesClient(_connection);
            Tags           = new TagsClient(_connection);
        }
コード例 #27
0
 public override void ExecuteCmdlet()
 {
     WriteObject(TagsClient.CreateTag(Name, Value != null ? new List <string> {
         Value
     } : null));
 }
コード例 #28
0
 public GitDatabaseClient(IApiConnection apiConnection)
     : base(apiConnection)
 {
     Tag = new TagsClient(apiConnection);
 }
コード例 #29
0
        private async Task <List <int> > GetContentIdsAsync(ContentStatus status, string token, ResourceType type)
        {
            var ids = new List <int>();

            switch (type)
            {
            case ResourceType _ when type == ResourceTypes.Exhibit:
                var exhibitsClient = new ExhibitsClient(_endpointConfig.DataStoreUrl)
                {
                    Authorization = token
                };
                var exhibits = await exhibitsClient.GetAsync(status : status);

                foreach (var exhibit in exhibits.Items)
                {
                    if (UserPermissions.IsAllowedToGetHistory(User.Identity, exhibit.UserId))
                    {
                        ids.Add(exhibit.Id);
                    }
                }
                break;

            case ResourceType _ when type == ResourceTypes.Route:
                var routesClient = new RoutesClient(_endpointConfig.DataStoreUrl)
                {
                    Authorization = token
                };
                var routes = await routesClient.GetAsync(status : status);

                foreach (var route in routes.Items)
                {
                    if (UserPermissions.IsAllowedToGetHistory(User.Identity, route.UserId))
                    {
                        ids.Add(route.Id);
                    }
                }
                break;

            case ResourceType _ when type == ResourceTypes.Tag:
                var tagsClient = new TagsClient(_endpointConfig.DataStoreUrl)
                {
                    Authorization = token
                };
                var tags = await tagsClient.GetAllAsync(status : status);

                foreach (var tag in tags.Items)
                {
                    if (UserPermissions.IsAllowedToGetHistory(User.Identity, tag.UserId))
                    {
                        ids.Add(tag.Id);
                    }
                }
                break;

            case ResourceType _ when type == ResourceTypes.Media:
                var mediaClient = new MediaClient(_endpointConfig.DataStoreUrl)
                {
                    Authorization = token
                };
                var media = await mediaClient.GetAsync(status : status);

                foreach (var medium in media.Items)
                {
                    if (UserPermissions.IsAllowedToGetHistory(User.Identity, medium.UserId))
                    {
                        ids.Add(medium.Id);
                    }
                }
                break;

            case ResourceType _ when type == ResourceTypes.ExhibitPage:
                var exhibitPagesClient = new ExhibitPagesClient(_endpointConfig.DataStoreUrl)
                {
                    Authorization = token
                };
                var exhibitPages = await exhibitPagesClient.GetAllPagesAsync(status : status);

                foreach (var exhibitPage in exhibitPages.Items)
                {
                    if (UserPermissions.IsAllowedToGetHistory(User.Identity, exhibitPage.UserId))
                    {
                        ids.Add(exhibitPage.Id);
                    }
                }
                break;
            }
            return(ids);
        }
コード例 #30
0
 protected override void ProcessRecord()
 {
     WriteObject(TagsClient.CreateTag(Name, Value != null ? new List <string> {
         Value
     } : null));
 }
コード例 #31
0
 public TagsClientTest()
 {
     this.tagsClient = new TagsClient(new Authentication(AppId, AppKey));
 }
コード例 #32
0
 public GitDatabaseClient(IApiConnection apiConnection) 
     : base(apiConnection)
 {
     Tag = new TagsClient(apiConnection);
 }