Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/API.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Patreon;

class API {
class API {

// Holds the access token
private $access_token;
Expand Down Expand Up @@ -73,6 +73,17 @@ public function fetch_page_of_members_from_campaign($campaign_id, $page_size, $c

}

public function fetch_posts($campaign_id, $records) {
//Fetches all of the posts from the given campaign ID. The number of records to retrive must be specified. Does not collect the content of the posts
//Only retrives the paid / public status, publish date, title and url.
return $this->get_data("campaigns/{$campaign_id}/posts?fields%5Bpost%5D=is_paid,is_public,published_at,title,url&page%5Bcount%5D={$records}");
}

public function fetch_single_post($post_id) {
//Fetches a specific post based on $post_id which can be retrieved by using the fetch_posts function
return $this->get_data("posts/{$post_id}?fields%5Bpost%5D=content,embed_data,embed_url,is_paid,is_public,published_at,title,url");
}

public function get_data( $suffix, $args = array() ) {

// Construct request:
Expand All @@ -87,7 +98,7 @@ public function get_data( $suffix, $args = array() ) {
if ( isset( $this->request_cache[$api_request_hash] ) ) {
return $this->request_cache[$api_request_hash];
}
}
}

// Request is new - actually perform the request

Expand Down Expand Up @@ -126,7 +137,7 @@ public function get_data( $suffix, $args = array() ) {
}

private function __create_ch($api_request) {

// This function creates a cURL handler for a given URL. In our case, this includes entire API request, with endpoint and parameters

$ch = curl_init();
Expand Down Expand Up @@ -170,5 +181,5 @@ public function add_to_request_cache( $api_request_hash, $result ) {

}


}
}