Last active
November 26, 2015 15:16
-
-
Save shibayan/23425f9f68a91937b7ad to your computer and use it in GitHub Desktop.
Simple Fastly C# Client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Fastly | |
{ | |
public Fastly(string fastlyKey) | |
{ | |
_fastlyKey = fastlyKey; | |
} | |
private readonly string _fastlyKey; | |
private const string EntryPoint = "https://api.fastly.com"; | |
public Task Purge(string uri) | |
{ | |
return Purge(new Uri(uri)); | |
} | |
public Task Purge(Uri uri) | |
{ | |
return SendAsync("PURGE", uri); | |
} | |
public Task PurgeKey(string service, string key) | |
{ | |
var uri = $"{EntryPoint}/service/{WebUtility.UrlEncode(service)}/purge/{key}"; | |
return SendAsync("POST", new Uri(uri)); | |
} | |
public Task PurgeAll(string service) | |
{ | |
var uri = $"{EntryPoint}/service/{WebUtility.UrlEncode(service)}/purge_all"; | |
return SendAsync("POST", new Uri(uri)); | |
} | |
private Task SendAsync(string method, Uri requestUri) | |
{ | |
var request = new HttpRequestMessage | |
{ | |
Method = new HttpMethod(method), | |
RequestUri = requestUri | |
}; | |
request.Headers.Add("Accept", "application/json"); | |
request.Headers.Add("Fastly-Key", _fastlyKey); | |
var client = new HttpClient(); | |
return client.SendAsync(request); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment