Skip to content

Commit

Permalink
Added a method to allow to get content for not implemented functions,…
Browse files Browse the repository at this point in the history
… like the icon for an IssueType.

[release]
  • Loading branch information
Lakritzator committed Aug 18, 2016
1 parent f279bee commit 30bea89
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions Dapplo.Jira.Shared/JiraApi.cs
Expand Up @@ -111,6 +111,27 @@ public void SetBasicAuthentication(string user, string password)
_password = password;
}

/// <summary>
/// Returns the content, specified by the Urim from the JIRA server.
/// This is used internally, but can also be used to get e.g. the icon for an issue type.
/// </summary>
/// <typeparam name="TResponse"></typeparam>
/// <param name="contentUri">Uri</param>
/// <param name="cancellationToken">CancellationToken</param>
/// <returns>TResponse</returns>
public async Task<TResponse> GetUriContentAsync<TResponse>(Uri contentUri, CancellationToken cancellationToken = default(CancellationToken))
where TResponse : class
{
_behaviour.MakeCurrent();

var response = await contentUri.GetAsAsync<HttpResponse<TResponse, string>>(cancellationToken).ConfigureAwait(false);
if (response.HasError)
{
throw new Exception($"Status: {response.StatusCode} Message: {response.ErrorResponse}");
}
return response.Response;
}

/// <summary>
/// Retrieve the Avatar for the supplied avatarUrls object
/// </summary>
Expand All @@ -126,12 +147,7 @@ public void SetBasicAuthentication(string user, string password)
_behaviour.MakeCurrent();
Uri avatarUri = avatarUrls.GetUri(avatarSize);

var response = await avatarUri.GetAsAsync<HttpResponse<TResponse, string>>(cancellationToken).ConfigureAwait(false);
if (response.HasError)
{
throw new Exception($"Status: {response.StatusCode} Message: {response.ErrorResponse}");
}
return response.Response;
return await GetUriContentAsync<TResponse>(avatarUri, cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -370,9 +386,7 @@ public async Task<TResponse> GetAttachmentContentAsAsync<TResponse>(Attachment a
{
throw new ArgumentNullException(nameof(attachment));
}

_behaviour.MakeCurrent();
return await attachment.ContentUri.GetAsAsync<TResponse>(cancellationToken).ConfigureAwait(false);
return await GetUriContentAsync<TResponse>(attachment.ContentUri, cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -393,8 +407,8 @@ public async Task<TResponse> GetAttachmentThumbnailAsAsync<TResponse>(Attachment
{
return null;
}
_behaviour.MakeCurrent();
return await attachment.ThumbnailUri.GetAsAsync<TResponse>(cancellationToken).ConfigureAwait(false);

return await GetUriContentAsync<TResponse>(attachment.ThumbnailUri, cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand Down

0 comments on commit 30bea89

Please sign in to comment.