Skip to content
This repository has been archived by the owner on Dec 23, 2023. It is now read-only.

Return HTTP response and parsed workspace JSON, instead of printing to the Console #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Structurizr.Client/Api/StructurizrClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ public Workspace GetWorkspace(long workspaceId)
/// </summary>
/// <param name="workspaceId">The workspace ID.</param>
/// <param name="workspace">The workspace to be updated.</param>
public void PutWorkspace(long workspaceId, Workspace workspace)
/// <returns>A tuple containing the HTTP Response and the parsed workspace JSON.</returns>
/// <exception cref="ArgumentException"></exception>
/// <exception cref="StructurizrClientException"></exception>
public (string response, string workspaceAsJson) PutWorkspace(long workspaceId, Workspace workspace)
{
if (workspace == null)
{
Expand Down Expand Up @@ -292,7 +295,6 @@ public void PutWorkspace(long workspaceId, Workspace workspace)
}
stringWriter.Flush();
workspaceAsJson = stringWriter.ToString();
System.Console.WriteLine(workspaceAsJson);
}

AddHeaders(httpClient, httpMethod, new Uri(Url + path).AbsolutePath, workspaceAsJson, "application/json; charset=UTF-8");
Expand All @@ -305,13 +307,14 @@ public void PutWorkspace(long workspaceId, Workspace workspace)

var response = httpClient.PutAsync(this.Url + path, content);
string responseContent = response.Result.Content.ReadAsStringAsync().Result;
System.Console.WriteLine(responseContent);

if (response.Result.StatusCode != HttpStatusCode.OK)
{
ApiResponse apiResponse = ApiResponse.Parse(responseContent);
throw new StructurizrClientException(apiResponse.Message);
}

return (responseContent, workspaceAsJson);
}
catch (Exception e)
{
Expand Down