I've now used it on a number of projects, and it works really for fluently accessing REST API's (if I do say so myself). So I thought I'd do a quick post on a real life scenario. For a client of mine I've recently needed to integrate PushWoosh.
I'd like to share some code to show how easy it would be to create a PushWoosh SDK with DalSoft.RestClient.
Start by installing the DalSoft.RestClient NuGet package:
PM> Install-Package DalSoft.RestClient
Then use the code below for any of the PushWoosh methods:
// Method /createMessage https://www.pushwoosh.com/programming-push-notification/pushwoosh-push-notification-remote-api/#PushserviceAPI-Method-messages-create
dynamic pushwoosh = new RestClient("https://cp.pushwoosh.com/json/1.3");
var pushWooshResponse = await pushwoosh.CreateMessage.Post(new
{
request = new
{
application = "APPLICATION_CODE",
auth = "API_ACCESS_TOKEN",
notifications = new[] { new {
send_date = "now", // YYYY-MM-DD HH:mm OR 'now'
ignore_user_timezone = true, // or false
content = "your message",
// Optional. Not more than 1000 tokens in an array. If set, message will only be delivered to the devices in the list. Ignored if the applications group is used. Only lower case for iOS
devices = new[] { "dec301908b9ba8df85e57a58e40f96f523f4c2068674f5fe2ba25cdc250a2a41" } //
}}
}
});
// Method /deleteMessage https://www.pushwoosh.com/programming-push-notification/pushwoosh-push-notification-remote-api/#PushserviceAPI-Method-messages-delete
dynamic pushwoosh = new RestClient("https://cp.pushwoosh.com/json/1.3");
var response = await pushwoosh.DeleteMessage.Post(new
{
request = new
{
auth = "api_access_token",
message = "Message code obtained in createMessage"
}
});
// Method /getNearestZone https://www.pushwoosh.com/programming-push-notification/pushwoosh-push-notification-remote-api/#PushserviceAPI-MethodGetNearestZone
dynamic pushwoosh = new RestClient("https://cp.pushwoosh.com/json/1.3");
var response = await pushwoosh.GetNearestZone.Post(new
{
request = new
{
application = "APPLICATION_CODE",
hwid = "hardware device id",
lat = 10.12345,
lng = 28.12345
}
});
// Method /getTags https://www.pushwoosh.com/programming-push-notification/pushwoosh-push-notification-remote-api/#PushserviceAPI-MethodGetTags
dynamic pushwoosh = new RestClient("https://cp.pushwoosh.com/json/1.3");
var response = await pushwoosh.GetTags.Post(new
{
request = new
{
auth = "api_access_token",
application = "APPLICATION_CODE",
hwid = "hardware device id"
}
});
// Method /pushStat https://www.pushwoosh.com/programming-push-notification/pushwoosh-push-notification-remote-api/#PushserviceAPI-MethodPushStat
dynamic pushwoosh = new RestClient("https://cp.pushwoosh.com/json/1.3");
var response = await pushwoosh.PushStat.Post(new
{
request = new
{
application = "APPLICATION_CODE",
hwid = "hardware device id",
hash = "hash" // received in the push notification in the "p" parameter
}
});
// Method /registerDevice https://www.pushwoosh.com/programming-push-notification/pushwoosh-push-notification-remote-api/#PushserviceAPI-MethodRegister
dynamic pushwoosh = new RestClient("https://cp.pushwoosh.com/json/1.3");
var response = await pushwoosh.RegisterDevice.Post(new
{
request = new
{
application = "APPLICATION_CODE",
push_token = "DEVICE_PUSH_TOKEN",
hwid = "hardware device id",
device_type = 1
}
});
// Method /setBadge https://www.pushwoosh.com/programming-push-notification/pushwoosh-push-notification-remote-api/#PushserviceAPI-MethodSetBadge
dynamic pushwoosh = new RestClient("https://cp.pushwoosh.com/json/1.3");
var response = await pushwoosh.SetBadge.Post(new
{
request = new
{
application = "APPLICATION_CODE",
hwid = "hardware device id",
badge = 5
}
});
// Method /setTags https://www.pushwoosh.com/programming-push-notification/pushwoosh-push-notification-remote-api/#PushserviceAPI-MethodSetTags
dynamic pushwoosh = new RestClient("https://cp.pushwoosh.com/json/1.3");
var response = await pushwoosh.SetTags.Post(new
{
request = new
{
application = "APPLICATION_CODE",
hwid = "hardware device id",
tags = new {
StringTag = "string value",
IntegerTag = 42,
ListTag = new[] { "string1", "string2" }
}}
}
});
//Method /unregisterDevice https://www.pushwoosh.com/programming-push-notification/pushwoosh-push-notification-remote-api/#PushserviceAPI-MethodUnregister
dynamic pushwoosh = new RestClient("https://cp.pushwoosh.com/json/1.3");
var response = await pushwoosh.UnRegisterDevice.Post(new
{
request = new
{
application = "APPLICATION_CODE",
hwid = "hardware device id"
}
});