Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get the Arango DB version information #417

Closed
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions arangodb-net-standard/ArangoDBClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using ArangoDBNetStandard.Transport.Http;
using ArangoDBNetStandard.UserApi;
using ArangoDBNetStandard.ViewApi;
using ArangoDBNetStandard.VersionApi;

namespace ArangoDBNetStandard
{
Expand Down Expand Up @@ -99,6 +100,11 @@ public class ArangoDBClient : IArangoDBClient
/// </summary>
public AdminApiClient Admin { get; private set; }

/// <summary>
/// Version API
/// </summary>
public VersionApiClient Version { get; private set; }

/// <summary>
/// Create an instance of <see cref="ArangoDBClient"/> from an existing
/// <see cref="HttpClient"/> instance, using the default JSON serialization.
Expand Down Expand Up @@ -166,6 +172,7 @@ private void InitializeApis(
View = new ViewApiClient(transport, serialization);
Analyzer = new AnalyzerApiClient(transport, serialization);
Admin = new AdminApiClient(transport, serialization);
Version = new VersionApiClient(transport, serialization);
}
}
}
13 changes: 13 additions & 0 deletions arangodb-net-standard/VersionApi/IVersionApiClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Threading.Tasks;
using ArangoDBNetStandard.VersionApi.Models;

namespace ArangoDBNetStandard.VersionApi
{
/// <summary>
/// Defines a client to access the ArangoDB Version API.
/// </summary>
public interface IVersionApiClient
{
Task<VersionResponse> Version();
}
}
13 changes: 13 additions & 0 deletions arangodb-net-standard/VersionApi/Models/VersionResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Net;

namespace ArangoDBNetStandard.VersionApi.Models
{
public class VersionResponse
{
public string Server { get; set; }

public string License { get; set; }
public Version Version { get; set; }
}
}
66 changes: 66 additions & 0 deletions arangodb-net-standard/VersionApi/VersionApiClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.Net;
using System.Threading.Tasks;

using ArangoDBNetStandard.Serialization;
using ArangoDBNetStandard.Transport;
using ArangoDBNetStandard.VersionApi.Models;

namespace ArangoDBNetStandard.VersionApi
{
/// <summary>
/// A client for interacting with ArangoDB Version Management endpoints,
/// implementing <see cref="IVersionApiClient"/>.
/// </summary>
public class VersionApiClient : ApiClientBase, IVersionApiClient
{
/// <summary>
/// The transport client used to communicate with the ArangoDB host.
/// </summary>
protected IApiClientTransport _client;

/// <summary>
/// The root path of the API.
/// </summary>
protected readonly string _userApiPath = "_api/version";

/// <summary>
/// Creates an instance of <see cref="VersionApiClient"/>
/// using the provided transport layer and the default JSON serialization.
/// </summary>
/// <param name="client"></param>
public VersionApiClient(IApiClientTransport client)
: base(new JsonNetApiClientSerialization())
{
_client = client;
}

/// <summary>
/// Creates an instance of <see cref="VersionApiClient"/>
/// using the provided transport and serialization layers.
/// </summary>
/// <param name="client"></param>
/// <param name="serializer"></param>
public VersionApiClient(IApiClientTransport client, IApiClientSerialization serializer)
: base(serializer)
{
_client = client;
}

/// <summary>
/// Gets the server version.
/// </summary>
/// <returns>Version information</returns>
public virtual async Task<VersionResponse> Version()
{
using (var response = await _client.GetAsync(_userApiPath))
{
if (response.IsSuccessStatusCode)
{
var stream = await response.Content.ReadAsStreamAsync();
return DeserializeJsonFromStream<VersionResponse>(stream);
}
throw await GetApiErrorException(response);
}
}
}
}