// ------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
// ------------------------------------------------------------------------------
namespace Microsoft.Graph
{
using System;
using System.Net.Http;
using Microsoft.Graph.Core.Requests;
///
/// A default implementation.
///
public class BaseClient : IBaseClient
{
private string baseUrl;
///
/// Constructs a new .
///
/// The base service URL. For example, "https://graph.microsoft.com/v1.0."
/// The for authenticating request messages.
/// The for sending requests.
public BaseClient(
string baseUrl,
IAuthenticationProvider authenticationProvider,
IHttpProvider httpProvider = null)
{
this.BaseUrl = baseUrl;
this.AuthenticationProvider = authenticationProvider;
this.HttpProvider = httpProvider ?? new HttpProvider(new Serializer());
}
///
/// Constructs a new .
///
/// The base service URL. For example, "https://graph.microsoft.com/v1.0."
/// The custom to be used for making requests
public BaseClient(
string baseUrl,
HttpClient httpClient)
{
this.BaseUrl = baseUrl;
this.HttpProvider = new SimpleHttpProvider(httpClient);
}
///
/// Gets the for authenticating requests.
///
public IAuthenticationProvider AuthenticationProvider { get; set; }
///
/// Gets or sets the base URL for requests of the client.
///
public string BaseUrl
{
get { return this.baseUrl; }
set
{
if (string.IsNullOrEmpty(value))
{
throw new ServiceException(
new Error
{
Code = ErrorConstants.Codes.InvalidRequest,
Message = ErrorConstants.Messages.BaseUrlMissing,
});
}
this.baseUrl = value.TrimEnd('/');
}
}
///
/// Gets the for sending HTTP requests.
///
public IHttpProvider HttpProvider { get; private set; }
///
/// Gets or Sets the for authenticating a single HTTP requests.
///
public Func PerRequestAuthProvider { get; set; }
///
/// Gets the for building batch Requests
///
public IBatchRequestBuilder Batch
{
get
{
return new BatchRequestBuilder(this.BaseUrl + "/$batch", this);
}
}
}
}