Created
May 9, 2016 19:34
-
-
Save AndrewLane/543f5802424d65733521849746291a54 to your computer and use it in GitHub Desktop.
Localytics Push Playground
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using RestSharp; | |
using RestSharp.Authenticators; | |
namespace LocalyticsPushPlayground | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
const string apiKey = "..."; | |
const string apiSecret = "..."; | |
const string appId = "..."; | |
const string apiUrlFormat = "https://messaging.localytics.com/v2/push/{0}"; | |
var url = String.Format(apiUrlFormat, appId); | |
var client = new RestClient(url); | |
var request = new RestRequest(Method.POST); | |
client.Authenticator = new HttpBasicAuthenticator(apiKey, apiSecret); | |
const string requestBody = @"{ | |
""request_id"":""1234123412341234"", | |
""campaign_key"":""pizza_delivery"", | |
""target_type"":""customer_id"", | |
""messages"":[ | |
{ | |
""target"":""user123"", | |
""alert"":""Your pizza is ready!"", | |
""ios"":{ | |
""sound"":""default.wav"", | |
""badge"":1 | |
} | |
} | |
] | |
}"; | |
request.AddParameter("application/json", requestBody, ParameterType.RequestBody); | |
IRestResponse response = client.Execute(request); | |
if (response.StatusCode == System.Net.HttpStatusCode.OK) | |
{ | |
Console.WriteLine("Success"); | |
} | |
else | |
{ | |
Console.WriteLine("Failure"); | |
Console.WriteLine("ErrorMessage: {0}", response.ErrorMessage); | |
Console.WriteLine("StatusCode: {0}", (int)response.StatusCode); | |
Console.WriteLine("StatusDescription: {0}", response.StatusDescription); | |
Console.WriteLine("Content: {0}", response.Content); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment