Skip to content

Commit 26c0ff4

Browse files
committed
Merge pull request #42 from ivkos/v3
Version 3.0.0
2 parents a8f3073 + ac7cbd5 commit 26c0ff4

22 files changed

+1398
-675
lines changed

.gitignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014 Ivaylo Stoyanov
3+
Copyright (c) 2013-2015 Ivaylo Stoyanov <[email protected]> - https://github.com/ivkos
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 198 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
Pushbullet
2-
==========
1+
Pushbullet for PHP
2+
================
33

44
## Description
5-
Using this class, you can send push notifications to mobile and desktop devices running **Pushbullet**. The following types of push notifications can be sent:
6-
* notes
7-
* links
8-
* addresses
9-
* checklists
10-
* files (smaller than 25 MB)
5+
A PHP library for the **[Pushbullet](https://www.pushbullet.com)** API allowing you to send all supported push notification types, manage contacts, send SMS messages, create/delete channels, and manage channel subscriptions.
116

127
For more information, you can refer to these links:
138
* **Official website**: https://www.pushbullet.com
@@ -17,113 +12,222 @@ For more information, you can refer to these links:
1712

1813
## Requirements
1914
* PHP 5.4.0 or newer
15+
* Composer
2016
* cURL library for PHP
21-
* Your Pushbullet API key (get it here: https://www.pushbullet.com/account)
17+
* Your Pushbullet access token: https://www.pushbullet.com/account
2218

2319
## Install
24-
25-
Via Composer:
20+
Create a `composer.json` file in your project root:
2621

2722
```json
2823
{
2924
"require": {
30-
"ivkos/pushbullet": "2.*"
25+
"ivkos/pushbullet": "3.*"
3126
}
3227
}
3328
```
3429

35-
## Examples
30+
## Quick Documentation
3631

37-
For more detailed usage information, consult the PHPDoc of the methods.
32+
Add this line to include Composer packages:
3833

3934
```php
4035
<?php
36+
require 'vendor/autoload.php';
37+
```
4138

42-
require __DIR__ . '/vendor/autoload.php';
43-
44-
// If you don't use Composer, include the class like so:
45-
// require 'src/Pushbullet.php';
46-
47-
try {
48-
#### AUTHENTICATION ####
49-
// Get your API key here: https://www.pushbullet.com/account
50-
$p = new Pushbullet('YOUR_API_KEY');
39+
Initialize Pushbullet with your API key:
40+
```php
41+
// Get your access token here: https://www.pushbullet.com/account
42+
$pb = new Pushbullet\Pushbullet('YOUR_ACCESS_TOKEN');
43+
```
5144

52-
// If you get SSL errors while using the library, you may need to point cURL to a CA certificate bundle
53-
$p->addCurlCallback(function ($curl) {
54-
// Get a CA certificate bundle here:
45+
If you use PHP for Windows it *may* be necessary to point cURL to a CA certificate bundle, or disable SSL certificate verification altogether:
46+
```php
47+
Pushbullet\Connection::setCurlCallback(function ($curl) {
48+
// Get a CA certificate bundle here:
5549
// https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt
56-
5750
curl_setopt($curl, CURLOPT_CAINFO, 'C:/path/to/ca-bundle.crt');
5851

59-
// Alternatively, you can disable SSL certificate verification.
60-
// However, this is a bad idea since it makes communication vulnerable to MITM attacks.
52+
// Not recommended! Makes communication vulnerable to MITM attacks:
6153
// curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
62-
});
63-
64-
65-
#### Get methods
66-
67-
// Print the definitions for your own devices. Useful for getting the 'iden' for using with the push methods.
68-
print_r($p->getDevices());
69-
70-
// Print the definitions for contacts/devices shared with you. Useful for getting 'iden', too.
71-
print_r($p->getContacts());
72-
73-
// Print information about your Pushbullet account
74-
print_r($p->getUserInformation());
75-
76-
// Print a list of sent push notifications, modified after 1400441645 unix time
77-
print_r($p->getPushHistory(1400441645));
78-
79-
80-
81-
#### Push methods
82-
83-
// Push to email [email protected] a note with a title 'Hey!' and a body 'It works!'
84-
$p->pushNote('[email protected]', 'Hey!', 'It works!');
85-
86-
// Push to device s2GBpJqaq9IY5nx a note with a title 'Hey!' and a body 'It works!'
87-
$p->pushNote('s2GBpJqaq9IY5nx', 'Hey!', 'It works!');
88-
89-
// Push to device gXVZDd2hLY6TOB1 a link with a title 'ivkos at GitHub', a URL 'https://github.com/ivkos' and body 'Pretty useful.'
90-
$p->pushLink('gXVZDd2hLY6TOB1', 'ivkos at GitHub', 'https://github.com/ivkos', 'Pretty useful.');
91-
92-
// Push to device a91kkT2jIICD4JH a Google Maps address with a name 'Google HQ' and an address '1600 Amphitheatre Parkway'
93-
$p->pushAddress('a91kkT2jIICD4JH', 'Google HQ', '1600 Amphitheatre Parkway');
94-
95-
// Push to device qVNRhnXxZzJ95zz a to-do list with a title 'Shopping List' and items 'Milk' and 'Butter'
96-
$p->pushList('qVNRhnXxZzJ95zz', 'Shopping List', array('Milk', 'Butter'));
97-
98-
// Push to device 0PpyWzARDK0w6et the file '../pic.jpg' of MIME type image/jpeg
99-
// Method accepts absolute and relative paths.
100-
$p->pushFile('0PpyWzARDK0w6et', '../pic.jpg', 'image/jpeg');
101-
// If the MIME type argument is omitted, an attempt to guess it will be made.
102-
$p->pushFile('0PpyWzARDK0w6et', '../pic.jpg');
103-
104-
105-
#### Pushing to multiple devices
106-
107-
// Push to all of your own devices, if you set the first argument to NULL or an empty string
108-
$p->pushNote(NULL, 'Some title', 'Some text');
109-
$p->pushNote('', 'Some title', 'Some text');
110-
111-
112-
113-
#### Delete methods
114-
115-
// Delete the push notification with the 'iden' specified
116-
$p->deletePush('a91kkT2jIICD4JH');
117-
118-
// Delete the device with the 'iden' specified
119-
$p->deleteDevice('s2GBpJqaq9IY5nx');
120-
121-
// Delete the contact with the 'iden' specified
122-
$p->deleteContact('0PpyWzARDK0w6et');
123-
} catch (PushbulletException $e) {
124-
// Exception handling
125-
die($e->getMessage());
54+
});
55+
```
56+
57+
### Devices
58+
To list all active devices on your account:
59+
```php
60+
$pb->getDevices();
61+
```
62+
Returns an array of `Device` objects.
63+
64+
----------
65+
66+
You can target a particular device by using its `iden` or `nickname`:
67+
```php
68+
$pb->device("Galaxy S4")->getPhonebook();
69+
```
70+
Returns an array of `PhonebookEntry` objects with names and phone numbers.
71+
72+
### Push Notifications
73+
You can use `push*` methods for `Contact`, `Channel` and `Device` objects. Every `push*` method returns a `Push` object. If an object cannot be pushed to, a `NotPushableException` will be thrown.
74+
75+
#### Note
76+
Arguments:
77+
78+
- Title
79+
- Body
80+
81+
```php
82+
$pb->device("Galaxy S4")->pushNote("Hello world!", "Lorem ipsum...");
83+
```
84+
85+
#### Link
86+
Arguments:
87+
88+
- Title
89+
- URL
90+
- Body
91+
92+
```php
93+
$pb->device("Galaxy S4")->pushLink("ivkos on GitHub", "https://github.com/ivkos", "Look at my page!");
94+
```
95+
96+
#### Address
97+
Arguments:
98+
99+
- Name - the place's name.
100+
- Address - the place's address or a map search query.
101+
102+
```php
103+
$pb->device("Galaxy S4")->pushAddress("Google HQ", "1600 Amphitheatre Parkway");
104+
```
105+
106+
#### List
107+
Arguments:
108+
109+
- Title
110+
- Array of items in the list
111+
112+
```php
113+
$pb->device("Galaxy S4")->pushList("Shopping List", [
114+
"Milk",
115+
"Butter",
116+
"Eggs"
117+
]);
118+
```
119+
120+
#### File
121+
Arguments:
122+
123+
- File path
124+
- MIME type (optional) - if `null`, MIME type will be magically guessed
125+
- Title (optional)
126+
- Body (optional)
127+
- Alternative file name (optional) - push the file as if it had this file name
128+
129+
```php
130+
$pb->device("Galaxy S4")->pushFile(
131+
"/home/ivkos/photos/20150314_092653.jpg",
132+
"image/jpeg",
133+
"Look at this photo!",
134+
"I think it's pretty cool",
135+
"coolphoto.jpg"
136+
);
137+
```
138+
139+
### SMS Messaging
140+
You can send SMS messages only from supported devices. If an attempt is made to send an SMS message from a device doesn't support it, a `NoSmsException` will be thrown.
141+
142+
```php
143+
$pb->device("Galaxy S4")->sendSms("+359123", "Hello there!");
144+
```
145+
146+
Send an SMS text to all people in a device's phonebook:
147+
```php
148+
$people = $pb->device("Galaxy S4")->getPhonebook();
149+
150+
foreach ($people as $person) {
151+
$person->sendSms("Happy New Year!");
126152
}
153+
```
154+
155+
### Channel Management
156+
Get a list of channel subscriptions:
157+
```php
158+
$pb->getChannelSubscriptions();
159+
```
160+
Returns an array of `Channel` objects with subscription information.
161+
162+
----------
163+
164+
To subscribe or unsubscribe from channels:
165+
```php
166+
$pb->channel("greatchannel")->subscribe();
167+
$pb->channel("mehchannel")->unsubscribe();
168+
```
169+
Subscribing to a channel will return a `Channel` object with subscription information.
170+
171+
----------
172+
173+
Get a list of channels created by the current user:
174+
```php
175+
$pb->getMyChannels();
176+
```
177+
Returns an array of `Channel` objects.
178+
179+
----------
180+
181+
Create a channel named `mychannel`. If this channel tag is already registered, a `ChannelException` will be thrown.
182+
```php
183+
$pb->channel("mychannel")->create("My Channel", "This channel will only push awesome stuff!");
184+
```
185+
Returns a `Channel` object for the newly created channel.
186+
187+
----------
188+
189+
Delete a channel if you are its creator:
190+
```php
191+
$pb->channel("mychannel")->delete();
192+
```
193+
194+
### Contact Management
195+
Contacts are people you can send push notification to. They are not to be confused with entries in a device's phonebook.
196+
197+
To list contacts on your account:
198+
```php
199+
$pb->getContacts();
200+
```
201+
Returns an array of `Contact` objects.
202+
203+
---
204+
205+
To create a contact:
206+
```php
207+
$pb->createContact("John Doe", "[email protected]");
208+
```
209+
Returns a `Contact` object for the newly created contact.
210+
211+
---
127212

128-
?>
213+
You can target a particular contact by its email or name:
214+
```php
215+
$pb->contact("[email protected]")->pushNote("Hey John!", "Where are you?");
216+
```
217+
218+
To delete a contact:
219+
```php
220+
$pb->contact("Caroline")->delete();
129221
```
222+
223+
To change a contact's name:
224+
```php
225+
$pb->contact("William")->changeName("Bill");
226+
```
227+
Returns a `Contact` object with an updated name.
228+
229+
230+
----------
231+
232+
233+
***For more detailed documentation, please refer to the PHPDoc in the source files.***

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"autoload": {
2828
"psr-4": {
29-
"": "src/"
29+
"Pushbullet\\": "src/Pushbullet"
3030
}
3131
}
32-
}
32+
}

0 commit comments

Comments
 (0)