-
Notifications
You must be signed in to change notification settings - Fork 26
Push Examples
Adam Yeager edited this page Jan 24, 2018
·
10 revisions
For detailed information on the request objects used below, check out the Push Request Objects wiki page.
All of the Push methods returns a PushResponse which is documented on the Response Objects page.
You can push to a single client if you know the device_iden.
PushbulletClient client = new PushbulletClient("--YOURAPIKEY--");
//If you don't know your device_iden, you can always query your devices
var devices = client.CurrentUsersDevices();
var device = devices.Devices.Where(o => o.manufacturer == "Apple").FirstOrDefault();
if (device != null)
{
PushNoteRequest request = new PushNoteRequest
{
DeviceIden = device.iden,
Title = "hello world",
Body = "This is a test from my C# wrapper."
};
PushResponse response = client.PushNote(request);
}Alternatively you can always push to all devices for the account by using an email address instead of a specific device_iden (this is not specific to just pushing notes; it'll work for all push types).
PushbulletClient client = new PushbulletClient("--YOURAPIKEY--");
var currentUserInformation = client.CurrentUsersInformation();
if (currentUserInformation != null)
{
PushNoteRequest request = new PushNoteRequest
{
Email = currentUserInformation.Email,
Title = "hello world",
Body = "This is a test from my C# wrapper."
};
PushResponse response = client.PushNote(request);
}PushbulletClient client = new PushbulletClient("--YOURAPIKEY--");
//If you don't know your device_iden, you can always query your devices
var devices = client.CurrentUsersActiveDevices();
var device = devices.Devices.Where(o => o.manufacturer == "Apple").FirstOrDefault();
if (device != null)
{
PushLinkRequest request = new PushLinkRequest
{
device_iden = device.iden,
title = "Google",
url = "http://google.com/",
body = "Search the internet."
};
PushResponse response = client.PushLink(request);
}PushbulletClient client = new PushbulletClient("--YOURAPIKEY--");
//If you don't know your device_iden, you can always query your devices
var devices = Client.CurrentUsersDevices();
var device = devices.Devices.Where(o => o.manufacturer == "Apple").FirstOrDefault();
using(var fileStream = new FileStream(@"c:\daftpunk.png", FileMode.Open, FileAccess.Read, FileShare.Read))
{
PushFileRequest request = new PushFileRequest
{
device_iden = device.iden,
file_name = "daftpunk.png",
file_type = "image/png",
file_stream = fileStream,
body = "Work It Harder\r\nMake It Better\r\nDo It Faster"
};
var response = client.PushFile(request);
}