Skip to content

Commit

Permalink
This should hopefully make the build work.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakritzator committed Mar 11, 2016
1 parent 17063da commit 48def67
Show file tree
Hide file tree
Showing 15 changed files with 219 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Dapplo.Confluence.PCL/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
98 changes: 88 additions & 10 deletions Dapplo.Confluence.Shared/ConfluenceApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,17 @@ public void SetBasicAuthentication(string user, string password)
/// <param name="contentId">Id of the content to attach to</param>
/// <param name="content">the content can be anything what Dapplo.HttpExtensions supports</param>
/// <param name="cancellationToken">CancellationToken</param>
/// <returns>Attachment</returns>
/// <returns>Result with Attachment items</returns>
public async Task<Result<Attachment>> AttachAsync(string contentId, object content, CancellationToken cancellationToken = default(CancellationToken))
{
_behaviour.MakeCurrent();
var attachUri = ConfluenceBaseUri.AppendSegments("content", contentId, "child", "attachments");
return await attachUri.PostAsync<Result<Attachment>>(content, cancellationToken).ConfigureAwait(false);
var response = await attachUri.PostAsync<HttpResponse<Result<Attachment>, Error>>(cancellationToken).ConfigureAwait(false);
if (response.HasError)
{
throw new Exception(response.ErrorResponse.Message);
}
return response.Response;
}
#endregion

Expand All @@ -125,7 +130,12 @@ public async Task<TResponse> PictureAsync<TResponse>(Attachment attachment, Canc
{
Path = attachment.Links.Download
};
return await attachmentUriBuilder.Uri.GetAsAsync<TResponse>(cancellationToken).ConfigureAwait(false);
var response = await attachmentUriBuilder.Uri.GetAsAsync<HttpResponse<TResponse, string>>(cancellationToken).ConfigureAwait(false);
if (response.HasError)
{
throw new Exception(response.ErrorResponse);
}
return response.Response;
}

/// <summary>
Expand All @@ -143,7 +153,12 @@ public async Task<TResponse> PictureAsync<TResponse>(Picture picture, Cancellati
{
Path = picture.Path
};
return await pictureUriBuilder.Uri.GetAsAsync<TResponse>(cancellationToken).ConfigureAwait(false);
var response = await pictureUriBuilder.Uri.GetAsAsync<HttpResponse<TResponse, string>>(cancellationToken).ConfigureAwait(false);
if (response.HasError)
{
throw new Exception(response.ErrorResponse);
}
return response.Response;
}

/// <summary>
Expand All @@ -156,17 +171,59 @@ public async Task<Space> SpaceAsync(string spaceKey, CancellationToken cancellat
{
var spaceUri = ConfluenceBaseUri.AppendSegments("space", spaceKey);
_behaviour.MakeCurrent();
return await spaceUri.GetAsAsync<Space>(cancellationToken).ConfigureAwait(false);
var response = await spaceUri.GetAsAsync<HttpResponse<Space, Error>>(cancellationToken).ConfigureAwait(false);
if (response.HasError)
{
throw new Exception(response.ErrorResponse.Message);
}
return response.Response;
}

/// <summary>
/// Get Content information see <a href="https://docs.atlassian.com/confluence/REST/latest/#d3e164">here</a>
/// </summary>
/// <param name="contentId">content id</param>
/// <param name="cancellationToken">CancellationToken</param>
/// <returns>Content</returns>
public async Task<Content> ContentAsync(string contentId, CancellationToken cancellationToken = default(CancellationToken))
{
var contentUri = ConfluenceBaseUri.AppendSegments("content", contentId);
_behaviour.MakeCurrent();
var response = await contentUri.GetAsAsync<HttpResponse<Content, Error>>(cancellationToken).ConfigureAwait(false);
if (response.HasError)
{
throw new Exception(response.ErrorResponse.Message);
}
return response.Response;
}

/// <summary>
/// Get Content information see <a href="https://docs.atlassian.com/confluence/REST/latest/#d3e164">here</a>
/// </summary>
/// <param name="contentId">content id</param>
/// <param name="cancellationToken">CancellationToken</param>
/// <returns>List with Content</returns>
public async Task<IList<Content>> ChildrenAsync(string contentId, CancellationToken cancellationToken = default(CancellationToken))
{
var contentUri = ConfluenceBaseUri.AppendSegments("content", contentId, "child").ExtendQuery("expand", "page");
_behaviour.MakeCurrent();
var response = await contentUri.GetAsAsync<HttpResponse<Child, Error>>(cancellationToken).ConfigureAwait(false);
if (response.HasError)
{
throw new Exception(response.ErrorResponse.Message);
}
return response.Response.Result.Results;
}

/// <summary>
/// Possible since 5.7
/// Search for issues, with a CQL (e.g. from a filter) see <a href="https://docs.atlassian.com/confluence/REST/latest/#d2e4539">here</a>
/// </summary>
/// <param name="cql">Confluence Query Language, like SQL, for the search</param>
/// <param name="cqlContext">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.</param>
/// <param name="limit">Maximum number of results returned, default is 20</param>
/// <param name="cancellationToken">CancellationToken</param>
/// <returns>result with content</returns>
/// <returns>Result with content items</returns>
public async Task<Result<Content>> SearchAsync(string cql, string cqlContext = null, int limit = 20, CancellationToken cancellationToken = default(CancellationToken))
{
_behaviour.MakeCurrent();
Expand All @@ -176,7 +233,13 @@ public async Task<Result<Content>> SearchAsync(string cql, string cqlContext = n
{
searchUri = searchUri.ExtendQuery("cqlcontext", cqlContext);
}
return await searchUri.GetAsAsync<Result<Content>>(cancellationToken).ConfigureAwait(false);

var response = await searchUri.GetAsAsync<HttpResponse<Result<Content>, Error>>(cancellationToken).ConfigureAwait(false);
if (response.HasError)
{
throw new Exception(response.ErrorResponse.Message);
}
return response.Response;
}

/// <summary>
Expand Down Expand Up @@ -210,7 +273,12 @@ public async Task<Result<Content>> ContentByTitleAsync(string spaceKey, string t
"title", title
},
});
return await searchUri.GetAsAsync<Result<Content>>(cancellationToken).ConfigureAwait(false);
var response = await searchUri.GetAsAsync<HttpResponse<Result<Content>, Error>>(cancellationToken).ConfigureAwait(false);
if (response.HasError)
{
throw new Exception(response.ErrorResponse.Message);
}
return response.Response;
}


Expand All @@ -224,7 +292,12 @@ public async Task<User> MyselfAsync(CancellationToken cancellationToken = defaul
{
var myselfUri = ConfluenceBaseUri.AppendSegments("user","current");
_behaviour.MakeCurrent();
return await myselfUri.GetAsAsync<User>(cancellationToken).ConfigureAwait(false);
var response = await myselfUri.GetAsAsync<HttpResponse<User, Error>>(cancellationToken).ConfigureAwait(false);
if (response.HasError)
{
throw new Exception(response.ErrorResponse.Message);
}
return response.Response;
}

/// <summary>
Expand All @@ -238,7 +311,12 @@ public async Task<User> UserAsync(string username, CancellationToken cancellatio
{
var userUri = ConfluenceBaseUri.AppendSegments("user").ExtendQuery("username", username);
_behaviour.MakeCurrent();
return await userUri.GetAsAsync<User>(cancellationToken).ConfigureAwait(false);
var response = await userUri.GetAsAsync<HttpResponse<User, Error>>(cancellationToken).ConfigureAwait(false);
if (response.HasError)
{
throw new Exception(response.ErrorResponse.Message);
}
return response.Response;
}

#endregion
Expand Down
2 changes: 2 additions & 0 deletions Dapplo.Confluence.Shared/Dapplo.Confluence.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)ConfluenceApi.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Entities\Child.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Entities\Error.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Entities\Results.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Entities\Metadata.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Entities\Attachment.cs" />
Expand Down
48 changes: 48 additions & 0 deletions Dapplo.Confluence.Shared/Entities/Child.cs
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/lgpl.txt>.

#region using

using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

#endregion

namespace Dapplo.Confluence.Entities
{
/// <summary>
/// Child information
/// See: https://docs.atlassian.com/confluence/REST/latest
/// </summary>
[DataContract]
public class Child
{
[DataMember(Name = "page")]
public Result<Content> Result { get; set; }

[DataMember(Name = "_expandable")]
public IDictionary<string, string> Expandables { get; set; }

[DataMember(Name = "_links")]
public Links Links { get; set; }
}
}
44 changes: 44 additions & 0 deletions Dapplo.Confluence.Shared/Entities/Error.cs
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/lgpl.txt>.

#region using

using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

#endregion

namespace Dapplo.Confluence.Entities
{
/// <summary>
/// Error information
/// </summary>
[DataContract]
public class Error
{
[DataMember(Name = "statusCode")]
public int StatusCode { get; set; }

[DataMember(Name = "message")]
public string Message { get; set; }
}
}
7 changes: 3 additions & 4 deletions Dapplo.Confluence.Tests/ConfluenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,21 @@ 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;

public ConfluenceTests(ITestOutputHelper testOutputHelper)
{
XUnitLogger.RegisterLogger(testOutputHelper, LogLevel.Verbose);
_confluenceApi = new ConfluenceApi(TestConfluenceUri);
_confluenceApi.SetBasicAuthentication("<username>", "<password>");
//_confluenceApi.SetBasicAuthentication("<username>", "<password>");
}

[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);

Expand Down
7 changes: 5 additions & 2 deletions Dapplo.Confluence.Tests/Dapplo.Confluence.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Dapplo.HttpExtensions, Version=0.4.22.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapplo.HttpExtensions.0.4.22.0\lib\net46\Dapplo.HttpExtensions.dll</HintPath>
<Reference Include="Dapplo.HttpExtensions, Version=0.4.25.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapplo.HttpExtensions.0.4.25.0\lib\net46\Dapplo.HttpExtensions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Dapplo.LogFacade, Version=0.2.13.0, Culture=neutral, processorArchitecture=MSIL">
Expand Down Expand Up @@ -74,6 +74,9 @@
<Compile Include="XUnitLogger.cs" />
</ItemGroup>
<ItemGroup>
<None Include="JsonTestFiles\error.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="JsonTestFiles\attachments.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
2 changes: 1 addition & 1 deletion Dapplo.Confluence.Tests/JsonParseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Content>(json);
Expand Down
4 changes: 4 additions & 0 deletions Dapplo.Confluence.Tests/JsonTestFiles/error.json
Original file line number Diff line number Diff line change
@@ -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"
}
2 changes: 1 addition & 1 deletion Dapplo.Confluence.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Dapplo.HttpExtensions" version="0.4.22.0" targetFramework="net46" />
<package id="Dapplo.HttpExtensions" version="0.4.25.0" targetFramework="net46" />
<package id="Dapplo.LogFacade" version="0.2.13.0" targetFramework="net46" />
<package id="System.ComponentModel" version="4.0.0" targetFramework="net46" />
<package id="System.Runtime.Serialization.Primitives" version="4.0.10" targetFramework="net46" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Dapplo.HttpExtensions, Version=0.4.22.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapplo.HttpExtensions.0.4.22.0\lib\net46\Dapplo.HttpExtensions.dll</HintPath>
<Reference Include="Dapplo.HttpExtensions, Version=0.4.25.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapplo.HttpExtensions.0.4.25.0\lib\net46\Dapplo.HttpExtensions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Dapplo.LogFacade, Version=0.2.13.0, Culture=neutral, processorArchitecture=MSIL">
Expand Down
2 changes: 1 addition & 1 deletion Dapplo.Confluence.WpfExample/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Dapplo.HttpExtensions" version="0.4.22.0" targetFramework="net46" />
<package id="Dapplo.HttpExtensions" version="0.4.25.0" targetFramework="net46" />
<package id="Dapplo.LogFacade" version="0.2.13.0" targetFramework="net46" />
<package id="System.ComponentModel" version="4.0.0" targetFramework="net46" />
<package id="System.Runtime.Serialization.Primitives" version="4.0.10" targetFramework="net46" />
Expand Down

0 comments on commit 48def67

Please sign in to comment.