From 48def67cb0faf4140248c7178403425529f25875 Mon Sep 17 00:00:00 2001 From: "Krom, Robertus" Date: Fri, 11 Mar 2016 13:59:48 +0100 Subject: [PATCH] This should hopefully make the build work. --- Dapplo.Confluence.PCL/project.json | 2 +- Dapplo.Confluence.Shared/ConfluenceApi.cs | 98 +++++++++++++++++-- .../Dapplo.Confluence.Shared.projitems | 2 + Dapplo.Confluence.Shared/Entities/Child.cs | 48 +++++++++ Dapplo.Confluence.Shared/Entities/Error.cs | 44 +++++++++ Dapplo.Confluence.Tests/ConfluenceTests.cs | 7 +- .../Dapplo.Confluence.Tests.csproj | 7 +- Dapplo.Confluence.Tests/JsonParseTests.cs | 2 +- .../JsonTestFiles/error.json | 4 + Dapplo.Confluence.Tests/packages.config | 2 +- .../Dapplo.Confluence.WpfExample.csproj | 4 +- Dapplo.Confluence.WpfExample/packages.config | 2 +- Dapplo.Confluence.sln | 32 +++--- Dapplo.Confluence/Dapplo.Confluence.csproj | 4 +- Dapplo.Confluence/packages.config | 2 +- 15 files changed, 219 insertions(+), 41 deletions(-) create mode 100644 Dapplo.Confluence.Shared/Entities/Child.cs create mode 100644 Dapplo.Confluence.Shared/Entities/Error.cs create mode 100644 Dapplo.Confluence.Tests/JsonTestFiles/error.json diff --git a/Dapplo.Confluence.PCL/project.json b/Dapplo.Confluence.PCL/project.json index 890f9ca..b185c43 100644 --- a/Dapplo.Confluence.PCL/project.json +++ b/Dapplo.Confluence.PCL/project.json @@ -5,7 +5,7 @@ "dnxcore50.app": {} }, "dependencies": { - "Dapplo.HttpExtensions": "0.4.22", + "Dapplo.HttpExtensions": "0.4.25", "Microsoft.NETCore": "5.0.0", "Microsoft.NETCore.Portable.Compatibility": "1.0.0", "System.ComponentModel": "4.0.0", diff --git a/Dapplo.Confluence.Shared/ConfluenceApi.cs b/Dapplo.Confluence.Shared/ConfluenceApi.cs index ea0c202..d1e14c4 100644 --- a/Dapplo.Confluence.Shared/ConfluenceApi.cs +++ b/Dapplo.Confluence.Shared/ConfluenceApi.cs @@ -99,12 +99,17 @@ public void SetBasicAuthentication(string user, string password) /// Id of the content to attach to /// the content can be anything what Dapplo.HttpExtensions supports /// CancellationToken - /// Attachment + /// Result with Attachment items public async Task> AttachAsync(string contentId, object content, CancellationToken cancellationToken = default(CancellationToken)) { _behaviour.MakeCurrent(); var attachUri = ConfluenceBaseUri.AppendSegments("content", contentId, "child", "attachments"); - return await attachUri.PostAsync>(content, cancellationToken).ConfigureAwait(false); + var response = await attachUri.PostAsync, Error>>(cancellationToken).ConfigureAwait(false); + if (response.HasError) + { + throw new Exception(response.ErrorResponse.Message); + } + return response.Response; } #endregion @@ -125,7 +130,12 @@ public async Task PictureAsync(Attachment attachment, Canc { Path = attachment.Links.Download }; - return await attachmentUriBuilder.Uri.GetAsAsync(cancellationToken).ConfigureAwait(false); + var response = await attachmentUriBuilder.Uri.GetAsAsync>(cancellationToken).ConfigureAwait(false); + if (response.HasError) + { + throw new Exception(response.ErrorResponse); + } + return response.Response; } /// @@ -143,7 +153,12 @@ public async Task PictureAsync(Picture picture, Cancellati { Path = picture.Path }; - return await pictureUriBuilder.Uri.GetAsAsync(cancellationToken).ConfigureAwait(false); + var response = await pictureUriBuilder.Uri.GetAsAsync>(cancellationToken).ConfigureAwait(false); + if (response.HasError) + { + throw new Exception(response.ErrorResponse); + } + return response.Response; } /// @@ -156,17 +171,59 @@ public async Task SpaceAsync(string spaceKey, CancellationToken cancellat { var spaceUri = ConfluenceBaseUri.AppendSegments("space", spaceKey); _behaviour.MakeCurrent(); - return await spaceUri.GetAsAsync(cancellationToken).ConfigureAwait(false); + var response = await spaceUri.GetAsAsync>(cancellationToken).ConfigureAwait(false); + if (response.HasError) + { + throw new Exception(response.ErrorResponse.Message); + } + return response.Response; + } + + /// + /// Get Content information see here + /// + /// content id + /// CancellationToken + /// Content + public async Task ContentAsync(string contentId, CancellationToken cancellationToken = default(CancellationToken)) + { + var contentUri = ConfluenceBaseUri.AppendSegments("content", contentId); + _behaviour.MakeCurrent(); + var response = await contentUri.GetAsAsync>(cancellationToken).ConfigureAwait(false); + if (response.HasError) + { + throw new Exception(response.ErrorResponse.Message); + } + return response.Response; + } + + /// + /// Get Content information see here + /// + /// content id + /// CancellationToken + /// List with Content + public async Task> ChildrenAsync(string contentId, CancellationToken cancellationToken = default(CancellationToken)) + { + var contentUri = ConfluenceBaseUri.AppendSegments("content", contentId, "child").ExtendQuery("expand", "page"); + _behaviour.MakeCurrent(); + var response = await contentUri.GetAsAsync>(cancellationToken).ConfigureAwait(false); + if (response.HasError) + { + throw new Exception(response.ErrorResponse.Message); + } + return response.Response.Result.Results; } /// + /// Possible since 5.7 /// Search for issues, with a CQL (e.g. from a filter) see here /// /// Confluence Query Language, like SQL, for the search /// the execution context for CQL functions, provides current space key and content id. If this is not provided some CQL functions will not be available. /// Maximum number of results returned, default is 20 /// CancellationToken - /// result with content + /// Result with content items public async Task> SearchAsync(string cql, string cqlContext = null, int limit = 20, CancellationToken cancellationToken = default(CancellationToken)) { _behaviour.MakeCurrent(); @@ -176,7 +233,13 @@ public async Task> SearchAsync(string cql, string cqlContext = n { searchUri = searchUri.ExtendQuery("cqlcontext", cqlContext); } - return await searchUri.GetAsAsync>(cancellationToken).ConfigureAwait(false); + + var response = await searchUri.GetAsAsync, Error>>(cancellationToken).ConfigureAwait(false); + if (response.HasError) + { + throw new Exception(response.ErrorResponse.Message); + } + return response.Response; } /// @@ -210,7 +273,12 @@ public async Task> ContentByTitleAsync(string spaceKey, string t "title", title }, }); - return await searchUri.GetAsAsync>(cancellationToken).ConfigureAwait(false); + var response = await searchUri.GetAsAsync, Error>>(cancellationToken).ConfigureAwait(false); + if (response.HasError) + { + throw new Exception(response.ErrorResponse.Message); + } + return response.Response; } @@ -224,7 +292,12 @@ public async Task MyselfAsync(CancellationToken cancellationToken = defaul { var myselfUri = ConfluenceBaseUri.AppendSegments("user","current"); _behaviour.MakeCurrent(); - return await myselfUri.GetAsAsync(cancellationToken).ConfigureAwait(false); + var response = await myselfUri.GetAsAsync>(cancellationToken).ConfigureAwait(false); + if (response.HasError) + { + throw new Exception(response.ErrorResponse.Message); + } + return response.Response; } /// @@ -238,7 +311,12 @@ public async Task UserAsync(string username, CancellationToken cancellatio { var userUri = ConfluenceBaseUri.AppendSegments("user").ExtendQuery("username", username); _behaviour.MakeCurrent(); - return await userUri.GetAsAsync(cancellationToken).ConfigureAwait(false); + var response = await userUri.GetAsAsync>(cancellationToken).ConfigureAwait(false); + if (response.HasError) + { + throw new Exception(response.ErrorResponse.Message); + } + return response.Response; } #endregion diff --git a/Dapplo.Confluence.Shared/Dapplo.Confluence.Shared.projitems b/Dapplo.Confluence.Shared/Dapplo.Confluence.Shared.projitems index 6b83ba9..d127a7a 100644 --- a/Dapplo.Confluence.Shared/Dapplo.Confluence.Shared.projitems +++ b/Dapplo.Confluence.Shared/Dapplo.Confluence.Shared.projitems @@ -10,6 +10,8 @@ + + diff --git a/Dapplo.Confluence.Shared/Entities/Child.cs b/Dapplo.Confluence.Shared/Entities/Child.cs new file mode 100644 index 0000000..57d5774 --- /dev/null +++ b/Dapplo.Confluence.Shared/Entities/Child.cs @@ -0,0 +1,48 @@ +// Dapplo - building blocks for desktop applications +// Copyright (C) 2015-2016 Dapplo +// +// For more information see: http://dapplo.net/ +// Dapplo repositories are hosted on GitHub: https://github.com/dapplo +// +// This file is part of Dapplo.Confluence +// +// Dapplo.Confluence is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Dapplo.Confluence is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have Config a copy of the GNU Lesser General Public License +// along with Dapplo.Confluence. If not, see . + +#region using + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; + +#endregion + +namespace Dapplo.Confluence.Entities +{ + /// + /// Child information + /// See: https://docs.atlassian.com/confluence/REST/latest + /// + [DataContract] + public class Child + { + [DataMember(Name = "page")] + public Result Result { get; set; } + + [DataMember(Name = "_expandable")] + public IDictionary Expandables { get; set; } + + [DataMember(Name = "_links")] + public Links Links { get; set; } + } +} \ No newline at end of file diff --git a/Dapplo.Confluence.Shared/Entities/Error.cs b/Dapplo.Confluence.Shared/Entities/Error.cs new file mode 100644 index 0000000..8005e24 --- /dev/null +++ b/Dapplo.Confluence.Shared/Entities/Error.cs @@ -0,0 +1,44 @@ +// Dapplo - building blocks for desktop applications +// Copyright (C) 2015-2016 Dapplo +// +// For more information see: http://dapplo.net/ +// Dapplo repositories are hosted on GitHub: https://github.com/dapplo +// +// This file is part of Dapplo.Confluence +// +// Dapplo.Confluence is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Dapplo.Confluence is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have Config a copy of the GNU Lesser General Public License +// along with Dapplo.Confluence. If not, see . + +#region using + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; + +#endregion + +namespace Dapplo.Confluence.Entities +{ + /// + /// Error information + /// + [DataContract] + public class Error + { + [DataMember(Name = "statusCode")] + public int StatusCode { get; set; } + + [DataMember(Name = "message")] + public string Message { get; set; } + } +} \ No newline at end of file diff --git a/Dapplo.Confluence.Tests/ConfluenceTests.cs b/Dapplo.Confluence.Tests/ConfluenceTests.cs index dc8239e..95b3ef2 100644 --- a/Dapplo.Confluence.Tests/ConfluenceTests.cs +++ b/Dapplo.Confluence.Tests/ConfluenceTests.cs @@ -32,7 +32,7 @@ namespace Dapplo.Confluence.Tests public class ConfluenceTests { // Test against a well known Confluence - private static readonly Uri TestConfluenceUri = new Uri("https://greenshot.atlassian.net/wiki"); + private static readonly Uri TestConfluenceUri = new Uri("https://confluence.cip4.org/"); private readonly ConfluenceApi _confluenceApi; @@ -40,14 +40,13 @@ public ConfluenceTests(ITestOutputHelper testOutputHelper) { XUnitLogger.RegisterLogger(testOutputHelper, LogLevel.Verbose); _confluenceApi = new ConfluenceApi(TestConfluenceUri); - _confluenceApi.SetBasicAuthentication("", ""); + //_confluenceApi.SetBasicAuthentication("", ""); } [Fact] public async Task TestSearch() { - var searchResult = await _confluenceApi.SearchAsync("text ~ \"greenshot\""); - + var searchResult = await _confluenceApi.SearchAsync("text ~ \"CIP4\""); Assert.NotNull(searchResult); Assert.True(searchResult.Results.Count > 0); diff --git a/Dapplo.Confluence.Tests/Dapplo.Confluence.Tests.csproj b/Dapplo.Confluence.Tests/Dapplo.Confluence.Tests.csproj index c417d17..428a3ab 100644 --- a/Dapplo.Confluence.Tests/Dapplo.Confluence.Tests.csproj +++ b/Dapplo.Confluence.Tests/Dapplo.Confluence.Tests.csproj @@ -33,8 +33,8 @@ 4 - - ..\packages\Dapplo.HttpExtensions.0.4.22.0\lib\net46\Dapplo.HttpExtensions.dll + + ..\packages\Dapplo.HttpExtensions.0.4.25.0\lib\net46\Dapplo.HttpExtensions.dll True @@ -74,6 +74,9 @@ + + Always + Always diff --git a/Dapplo.Confluence.Tests/JsonParseTests.cs b/Dapplo.Confluence.Tests/JsonParseTests.cs index 8d7bbf7..6113b33 100644 --- a/Dapplo.Confluence.Tests/JsonParseTests.cs +++ b/Dapplo.Confluence.Tests/JsonParseTests.cs @@ -38,7 +38,7 @@ public JsonParseTests(ITestOutputHelper testOutputHelper) } [Fact] - public void TestParseServerInfo() + public void TestParseContent() { var json = File.ReadAllText("JsonTestFiles/content.json"); var content = SimpleJson.DeserializeObject(json); diff --git a/Dapplo.Confluence.Tests/JsonTestFiles/error.json b/Dapplo.Confluence.Tests/JsonTestFiles/error.json new file mode 100644 index 0000000..4c318f3 --- /dev/null +++ b/Dapplo.Confluence.Tests/JsonTestFiles/error.json @@ -0,0 +1,4 @@ +{ + "statusCode": 500, + "message": "com.sun.jersey.api.ParamException$PathParamException: com.atlassian.confluence.api.service.exceptions.BadRequestException: Can't parse as a ContentId: search" +} \ No newline at end of file diff --git a/Dapplo.Confluence.Tests/packages.config b/Dapplo.Confluence.Tests/packages.config index a7afd73..d832303 100644 --- a/Dapplo.Confluence.Tests/packages.config +++ b/Dapplo.Confluence.Tests/packages.config @@ -1,6 +1,6 @@  - + diff --git a/Dapplo.Confluence.WpfExample/Dapplo.Confluence.WpfExample.csproj b/Dapplo.Confluence.WpfExample/Dapplo.Confluence.WpfExample.csproj index 84560e2..a9b2884 100644 --- a/Dapplo.Confluence.WpfExample/Dapplo.Confluence.WpfExample.csproj +++ b/Dapplo.Confluence.WpfExample/Dapplo.Confluence.WpfExample.csproj @@ -36,8 +36,8 @@ 4 - - ..\packages\Dapplo.HttpExtensions.0.4.22.0\lib\net46\Dapplo.HttpExtensions.dll + + ..\packages\Dapplo.HttpExtensions.0.4.25.0\lib\net46\Dapplo.HttpExtensions.dll True diff --git a/Dapplo.Confluence.WpfExample/packages.config b/Dapplo.Confluence.WpfExample/packages.config index d3618a2..479fd0e 100644 --- a/Dapplo.Confluence.WpfExample/packages.config +++ b/Dapplo.Confluence.WpfExample/packages.config @@ -1,6 +1,6 @@  - + diff --git a/Dapplo.Confluence.sln b/Dapplo.Confluence.sln index 85f743a..4afa183 100644 --- a/Dapplo.Confluence.sln +++ b/Dapplo.Confluence.sln @@ -24,22 +24,22 @@ Global Release|AnyCPU = Release|AnyCPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {4AE569B6-987B-4EEF-936C-D60672CE861E}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU - {4AE569B6-987B-4EEF-936C-D60672CE861E}.Debug|AnyCPU.Build.0 = Debug|Any CPU - {4AE569B6-987B-4EEF-936C-D60672CE861E}.Release|AnyCPU.ActiveCfg = Release|Any CPU - {4AE569B6-987B-4EEF-936C-D60672CE861E}.Release|AnyCPU.Build.0 = Release|Any CPU - {21318574-B731-40E3-BA54-0C92429B5317}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU - {21318574-B731-40E3-BA54-0C92429B5317}.Debug|AnyCPU.Build.0 = Debug|Any CPU - {21318574-B731-40E3-BA54-0C92429B5317}.Release|AnyCPU.ActiveCfg = Release|Any CPU - {21318574-B731-40E3-BA54-0C92429B5317}.Release|AnyCPU.Build.0 = Release|Any CPU - {437D6408-B03C-4AE2-B736-D7E9763C2B09}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU - {437D6408-B03C-4AE2-B736-D7E9763C2B09}.Debug|AnyCPU.Build.0 = Debug|Any CPU - {437D6408-B03C-4AE2-B736-D7E9763C2B09}.Release|AnyCPU.ActiveCfg = Release|Any CPU - {437D6408-B03C-4AE2-B736-D7E9763C2B09}.Release|AnyCPU.Build.0 = Release|Any CPU - {2119C12B-5874-4E60-BD36-45CA1D29FDDC}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU - {2119C12B-5874-4E60-BD36-45CA1D29FDDC}.Debug|AnyCPU.Build.0 = Debug|Any CPU - {2119C12B-5874-4E60-BD36-45CA1D29FDDC}.Release|AnyCPU.ActiveCfg = Release|Any CPU - {2119C12B-5874-4E60-BD36-45CA1D29FDDC}.Release|AnyCPU.Build.0 = Release|Any CPU + {4AE569B6-987B-4EEF-936C-D60672CE861E}.Debug|AnyCPU.ActiveCfg = Debug|AnyCPU + {4AE569B6-987B-4EEF-936C-D60672CE861E}.Debug|AnyCPU.Build.0 = Debug|AnyCPU + {4AE569B6-987B-4EEF-936C-D60672CE861E}.Release|AnyCPU.ActiveCfg = Release|AnyCPU + {4AE569B6-987B-4EEF-936C-D60672CE861E}.Release|AnyCPU.Build.0 = Release|AnyCPU + {21318574-B731-40E3-BA54-0C92429B5317}.Debug|AnyCPU.ActiveCfg = Debug|AnyCPU + {21318574-B731-40E3-BA54-0C92429B5317}.Debug|AnyCPU.Build.0 = Debug|AnyCPU + {21318574-B731-40E3-BA54-0C92429B5317}.Release|AnyCPU.ActiveCfg = Release|AnyCPU + {21318574-B731-40E3-BA54-0C92429B5317}.Release|AnyCPU.Build.0 = Release|AnyCPU + {437D6408-B03C-4AE2-B736-D7E9763C2B09}.Debug|AnyCPU.ActiveCfg = Debug|AnyCPU + {437D6408-B03C-4AE2-B736-D7E9763C2B09}.Debug|AnyCPU.Build.0 = Debug|AnyCPU + {437D6408-B03C-4AE2-B736-D7E9763C2B09}.Release|AnyCPU.ActiveCfg = Release|AnyCPU + {437D6408-B03C-4AE2-B736-D7E9763C2B09}.Release|AnyCPU.Build.0 = Release|AnyCPU + {2119C12B-5874-4E60-BD36-45CA1D29FDDC}.Debug|AnyCPU.ActiveCfg = Debug|AnyCPU + {2119C12B-5874-4E60-BD36-45CA1D29FDDC}.Debug|AnyCPU.Build.0 = Debug|AnyCPU + {2119C12B-5874-4E60-BD36-45CA1D29FDDC}.Release|AnyCPU.ActiveCfg = Release|AnyCPU + {2119C12B-5874-4E60-BD36-45CA1D29FDDC}.Release|AnyCPU.Build.0 = Release|AnyCPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Dapplo.Confluence/Dapplo.Confluence.csproj b/Dapplo.Confluence/Dapplo.Confluence.csproj index a62c909..5248bef 100644 --- a/Dapplo.Confluence/Dapplo.Confluence.csproj +++ b/Dapplo.Confluence/Dapplo.Confluence.csproj @@ -31,8 +31,8 @@ 4 - - ..\packages\Dapplo.HttpExtensions.0.4.22.0\lib\net46\Dapplo.HttpExtensions.dll + + ..\packages\Dapplo.HttpExtensions.0.4.25.0\lib\net46\Dapplo.HttpExtensions.dll True diff --git a/Dapplo.Confluence/packages.config b/Dapplo.Confluence/packages.config index d3618a2..479fd0e 100644 --- a/Dapplo.Confluence/packages.config +++ b/Dapplo.Confluence/packages.config @@ -1,6 +1,6 @@  - +