Skip to content

Instantly share code, notes, and snippets.

@choudeshell
Created February 24, 2019 04:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save choudeshell/2df0f57d5ed9b116170f16c070c5949f to your computer and use it in GitHub Desktop.
Save choudeshell/2df0f57d5ed9b116170f16c070c5949f to your computer and use it in GitHub Desktop.
using EnergyCap.Sdk;
using EnergyCap.Sdk.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
namespace SdkDemo
{
class Program
{
static void Main(string[] args)
{
Test().Wait();
}
public class PagingHandler : DelegatingHandler
{
protected async override Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken)
{
if(request.Headers.Contains("i-pageSize"))
{
var uri = new UriBuilder(request.RequestUri);
uri.Query += $"&pageSize={request.Headers.GetValues("i-pageSize").First()}";
request.RequestUri = uri.Uri;
}
var response = await base.SendAsync(request, cancellationToken);
return response;
}
}
static async Task Test()
{
var httpHandler = new DelegatingHandler[] { new PagingHandler() };
var client = new EnergyCapApi(httpHandler);
client.BaseUri = new Uri("https://implement.energycap.com");
var loginResult = await client.LoginAsync(new LoginRequest()
{
DataSource = "ds",
Username = "un",
Password = "ps"
});
client.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", loginResult.Token);
var headers = new Dictionary<string, List<string>>() {
{ "i-pageSize", new List<string>(){ "1" } }
};
var result = await client.GetPlacesWithHttpMessagesAsync(filter: "", customHeaders: headers);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment