General concepts
The GoMoob Pushwoosh PHP Library is written to be almost identic to the standard Pushwoosh REST API.
Calls to the Pushwoosh REST Web Services are done using a Pushwoosh client class.
All calls are done the same way :
- Create a Request object.
- Call a method on the Pushwoosh client and receive a Response object.
- Check if the call is successful with the
isOk()
method of the received Response object.
Pushoosh clients
The API provides 2 Pushwoosh clients which redeclare the methods described in the official Pushwoosh Remote API guide .
- A standard Pushwoosh client defined by the
Gomoob\Pushwoosh\Client\Pushwoosh
class - A mock Pushwoosh client defined by the
Gomoob\Pushwoosh\Client\PushwooshMock
class
Those two classes implement the Gomoob\Pushwoosh\IPushwoosh
interface where you'll find a copy of the
documentation of each method described in the
Pushwoosh Remote API guide
.
The Pushwoosh
class
The Gomoob\Pushwoosh\Client\Pushwoosh
class represents a concrete Pushwoosh client which calls the
Pushwoosh Remote API Web Services.
Server URL
By default the Pushwoosh
class uses the https://cp.pushwoosh.com/json/1.3
Pushwoosh server
URL.
If you are using a Pushwoosh enterprise plan then you have a dedicated server URL like
https://your-company.pushwoosh.com
. You can indicate to php-pushwoosh
to use this custom
URL with the following code.
CURL options
The Pushwoosh
client class uses CURL to send HTTP requests to the Pushwoosh Web Services. The default
CURL configuration should work without any problem, but in some rare cases you'll want to change specific CURL
options.
Here is a sample to change the CURLOPT_CONNECTTIMEOUT
and CURLOPT_TIMEOUT
on the CURL
client which is used in the library.
Configuration
Before using your Pushwoosh client you first have to configure it, in most cases you configure your client in one place in a project, then you use it where you want.
The configuration properties to configure are the following :
-
application
: The Pushwoosh application ID to be used by default by all the requests performed by the Pushwoosh client. This identifier can be overwritten by request if needed. If theapplicationGroups
parameter is defined then theapplication
parameter must not be defined.
-
applicationsGroup
: The Pushwoosh applications group code to be used to defautl by all the requests performed by the Pushwoosh client. This identifier can be overwritten by requests if needed. If theapplication
parameter is defined then theapplicationsGroups
parameter must not be defined.
-
auth
: The API access token taken from the Pushwoosh control panel (create this token at https://cp.pushwoosh.com/api_access).
Once a Pushwoosh client is configured the application
(or applicationsGroup
) and
auth
parameters will be automatically injected in the JSON payloads sent to the Pushwoosh servers.
This is much more quick and easy than providing your Pushwoosh creadentials each time you make a request (although proving specific credentials for each request is also possible).
Web Service methods
The Pushwoosh clients define one method for each Web Service endpoint of the Pushwoosh Remote API.
You'll find documentation and several samples about each method by following those links.
- /createMessage
- /deleteMessage
- /getNearestZone
- /pushStat
- /registerDevice
- /setBadge
- /setTags
- /unregisterDevice
The PushwooshMock
class
The PushwooshMock
class represents a mock Pushwoosh client, it defines the same methods as the
Pushwoosh
class but it do not call the Pushwoosh Remote API Web Services.
Instead this class works in memory and simulates the Pushwoosh servers. This class is convenient when you want to write unit tests.
Requests
Each request sent to the Pushwoob REST Web Services is represented by a xxxRequest
request object /
class defined in the Gomoob\Pushwoosh\Model\Request namespace
.
Request classes
The request objects are passed to Pushwoosh client methods to request the Pushwoosh Web Services. Their is one request class for each available Pushwoosh Web Service endpoint.
/createMessage
=>CreateMessageRequest
/deleteMessage
=>DeleteMessageRequest
/getNearestZone
=>GetNearestZoneRequest
/pushStat
=>PushStatRequest
/registerDevice
=>RegisterDeviceRequest
/setBadge
=>SetBadgeRequest
/setTags
=>SetTagsRequest
/unregisterDevice
=>UnregisterDeviceRequest
Overwriting credentials using requests
In general you configure the application
, applicationsGroup
and auth
parameters at one place on your Pushwoosh client.
But, in some cases you'll want to use specific credentials at request time, it's possible to overwrite the credentials parameters configured in your Pushwoosh client for only one particular request.
Responses
Each response received from the Pushwoob REST Web Services is represented by a xxxResponse
response
object / class defined in the Gomoob\Pushwoosh\Model\Response namespace
.
Response classes
The available response objects returned from the Pushwoosh client methods are the followings.
/createMessage
=>CreateMessageResponse
/deleteMessage
=>DeleteMessageResponse
/getNearestZone
=>GetNearestZoneResponse
/pushStat
=>PushStatResponse
/registerDevice
=>RegisterDeviceResponse
/setBadge
=>SetBadgeResponse
/setTags
=>SetTagsResponse
/unregisterDevice
=>UnregisterDeviceResponse
API design
Creation methods
All the concrete classes provided by the Data Model layer (Request, Response and Notification classes) can be
instantiated using the new
operator or a static create
method.
For example the 2 following code are equivalent.
Setters
All the setters provided by the Data Model classes (Request, Response and Notification classes) return the instance associated to the object where the call has been done.
For example the 2 following codes are equivalent.