- Getting Started
- Obtaining OAuth Tokens For Patrons
- Patreon Integration Examples
- Method Documentation
- Library Architecture
This library is designed to be easy to work with and easy to understand if you wish to learn how it works under the hood. Take a look at the src/Patreon directory to see the Entities and Resources that make up the library, and check out tests/Patreon to see examples of how the various methods can be used.
Entities are objects with properties that are populated from Patreon responses.
Each Entity has defined properties which you can depend on existing (with a
null
value). Additionally, Entities expose helper methods that allow your
application not to concern itself with making determinations about Entity
states, e.g: $reward->isAvailableToChoose()
and $pledge->hasMadeAPayment()
.
You can browse the properties of each Entity via their class files:
Resources represent Patreon API endpoints. Each Resource exposes methods for
fetching data from these endpoints. Each Resource can be accessed through the
Patreon
client, e.g: $patreon->resource()->method()
.
campaigns
providesgetMyCampaign
,getMyCampaignWithPledges
,getCampaign
andgetCampaignWithPledges
me
providesget
pledges
providesgetCampaignPledges
andgetPageOfCampaignPledges
Additionally, the webhook
resource provides an accept
method which will
verify the signature of a Webhook received from Patreon and return the Pledge
Entity.
When there is more than one Entity a Collection is given, Collections "[...] provide a fluent, convenient wrapper for working with arrays of data". This makes it very easy to work with groups of Entities and extract, transform or manage their properties. For example:
$patreon = new Patreon('access_token');
$campaign = $patreon->campaigns()->getMyCampaignWithPledges();
// echo a list of each patron's full_name
$campaign->pledges->each(function ($pledge) {
echo "{$pledge->patron->full_name}\n";
});
// extract each patron's email address
$emails = $campaign->pledges->map(function ($pledge) {
return $pledge->patron->email;
});
// get all Pledges of at least $50
$pledges = $campaign->pledges->where('amount_cents', '>=', 5000);
As a general pointer, when working this library you should never need to use
while
or foreach
loops.
- Contribute!
- Get help!