Last active
April 21, 2016 19:04
-
-
Save guitarrapc/39ddc7900c7f9846e9a294ce75a2c737 to your computer and use it in GitHub Desktop.
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 AzureFunctionTrigger | |
{ | |
public HttpStatusCode StatusCode { get; private set; } | |
public string ResponseMessage { get; private set;} | |
public static async Task<AzureFunctionTrigger> PostAsync(string functionUrl) | |
{ | |
var payload = new | |
{ | |
first = "Azure", | |
last = "Functions", | |
name = "Azure" | |
}; | |
var jsonString = JsonConvert.SerializeObject(payload); | |
using (var client = new HttpClient()) | |
{ | |
var res = await client.PostAsync(functionUrl, new StringContent(jsonString, Encoding.UTF8, "application/json")); | |
if (!res.IsSuccessStatusCode) | |
{ | |
return new AzureFunctionTrigger | |
{ | |
StatusCode = res.StatusCode, | |
ResponseMessage = res.ReasonPhrase | |
}; | |
} | |
var json = await res.Content.ReadAsStringAsync(); | |
return new AzureFunctionTrigger | |
{ | |
StatusCode = res.StatusCode, | |
ResponseMessage = json | |
}; | |
} | |
} | |
public static async Task<AzureFunctionTrigger> PostAsync(string functionUrl, string key) | |
{ | |
var payload = new | |
{ | |
first = "Azure", | |
last = "Functions", | |
name = "Azure" | |
}; | |
var jsonString = JsonConvert.SerializeObject(payload); | |
using (var client = new HttpClient()) | |
{ | |
client.DefaultRequestHeaders.Add("x-functions-key", key); | |
var res = await client.PostAsync(functionUrl, new StringContent(jsonString, Encoding.UTF8, "application/json")); | |
if (!res.IsSuccessStatusCode) | |
{ | |
return new AzureFunctionTrigger | |
{ | |
StatusCode = res.StatusCode, | |
ResponseMessage = res.ReasonPhrase | |
}; | |
} | |
var json = await res.Content.ReadAsStringAsync(); | |
return new AzureFunctionTrigger | |
{ | |
StatusCode = res.StatusCode, | |
ResponseMessage = json | |
}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment