Skip to content

Commit 34543b5

Browse files
committed
Add documentation
1 parent 990fb63 commit 34543b5

File tree

2 files changed

+14
-73
lines changed

2 files changed

+14
-73
lines changed

README.md

Lines changed: 14 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
# PHP Firebase Cloud Messaging
22

3-
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/83a88985-9752-463b-ae62-7abb06aea791/big.png)](https://insight.sensiolabs.com/projects/83a88985-9752-463b-ae62-7abb06aea791)
43
<a href='https://www.paypal.me/ymerajredjan' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://az743702.vo.msecnd.net/cdn/kofi2.png?v=0' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
54

6-
PHP API for Firebase Cloud Messaging from Google.
7-
8-
Currently this app server library only supports sending Messages/Notifications via HTTP.
5+
PHP SDK for Firebase Cloud Messaging from Google, supporting HTTP V1.
96

107
See original Firebase docs: https://firebase.google.com/docs/
118

@@ -19,85 +16,31 @@ Or add this to your composer.json and run "composer update":
1916

2017
```
2118
"require": {
22-
"redjanym/php-firebase-cloud-messaging": "1.*"
19+
"redjanym/php-firebase-cloud-messaging": "2.*"
2320
}
2421
```
2522

26-
# Send message to **one or multiple** Devices
23+
# Send message to a Device
2724
```
2825
use RedjanYm\FCM\Client;
29-
use RedjanYm\FCM\Message;
30-
use RedjanYm\FCM\Recipient\Device;
3126
use RedjanYm\FCM\Notification;
27+
use RedjanYm\FCM\Recipient\Device;
3228
33-
$server_key = '_YOUR_SERVER_KEY_';
34-
$client = new Client();
35-
$client->setApiKey($server_key);
36-
37-
$message = new Message();
38-
$message->setPriority('high');
39-
$message->addRecipient(new Device('_YOUR_DEVICE_TOKEN_'));
40-
$message
41-
->setNotification(new Notification('some title', 'some body'))
42-
->setData(['key' => 'value'])
43-
;
44-
45-
$response = $client->send($message);
46-
var_dump($response->getStatusCode());
47-
var_dump($response->getBody()->getContents());
48-
```
49-
50-
# Send message to Topic
51-
Currently sending to topics only supports a single topic as recipient. Mutliple topic as outlined
52-
in the google docs don't seem to work, yet.
53-
```
54-
use RedjanYm\FCM\Client;
55-
use RedjanYm\FCM\Message;
56-
use RedjanYm\FCM\Recipient\Topic;
57-
use RedjanYm\FCM\Notification;
58-
59-
$server_key = '_YOUR_SERVER_KEY_';
60-
$client = new Client();
61-
$client->setApiKey($server_key);
62-
63-
$message = new Message();
64-
$message->setPriority('high');
65-
$message->addRecipient(new Topic('_YOUR_TOPIC_'));
66-
$message
67-
->setNotification(new Notification('some title', 'some body'))
68-
->setData(['key' => 'value'])
69-
;
70-
71-
$response = $client->send($message);
72-
var_dump($response->getStatusCode());
73-
var_dump($response->getBody()->getContents());
74-
```
75-
76-
# Subscribe user to the topic
77-
```
78-
use RedjanYm\FCM\Client;
79-
80-
$server_key = '_YOUR_SERVER_KEY_';
81-
$client = new Client();
82-
$client->setApiKey($server_key);
29+
$serviceAccountPath = '/path/to/service-account.json';
30+
$testToken = 'this-is-a-token';
8331
84-
$response = $client->addTopicSubscription('_SOME_TOPIC_ID_', ['_FIRST_TOKEN_', '_SECOND_TOKEN_']);
85-
var_dump($response->getStatusCode());
86-
var_dump($response->getBody()->getContents());
87-
```
32+
$client = new Client($serviceAccountPath);
33+
$recipient = new Device($testToken);
34+
$notification = new Notification($recipient, 'Title', 'Body', ['key' => 'value']);
8835
89-
# Remove user subscription to the topic
36+
$client->send($notification);
9037
```
91-
use RedjanYm\FCM\Client;
9238

93-
$server_key = '_YOUR_SERVER_KEY_';
94-
$client = new Client();
95-
$client->setApiKey($server_key);
39+
# Topic Support
40+
The current version does not have support for Topics. We are going to add it on v2.1.
9641

97-
$response = $client->removeTopicSubscription('_SOME_TOPIC_ID_', ['_FIRST_TOKEN_', '_SECOND_TOKEN_']);
98-
var_dump($response->getStatusCode());
99-
var_dump($response->getBody()->getContents());
100-
```
42+
# Migrating from V1.
43+
Unfortunately V2 of this package introduces breaking changes. But the new structure of the SDK is still simple and very similar to the previous one. We are sure the migration is going to be very fast and easy.
10144

10245
# Interpreting responses
10346
Responses given on the HTTP requests are standard according to the FCM documentations. You may find detailed specifications in this links:

examples/messaging.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
$testToken = '123456789';
1111

1212
$client = new Client($serviceAccountPath);
13-
1413
$recipient = new Device($testToken);
15-
1614
$notification = new Notification($recipient, 'Title', 'Body', ['key' => 'value']);
1715

1816
$response = $client->send($notification);

0 commit comments

Comments
 (0)