Created
February 21, 2018 21:00
-
-
Save nboliver/8b1f803b9bdd5941cb84a4a243881e0c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
class PatreonAPI { | |
private $access_token; | |
public function __construct($access_token) { | |
$this->access_token = $access_token; | |
} | |
public function fetch_user() { | |
return $this->__get_json('current_user'); | |
} | |
public function fetch_campaign_and_patrons() { | |
return $this->__get_json('current_user/campaigns?include=rewards,creator,goals,pledges'); | |
} | |
public function fetch_creator_info() { | |
return $this->__get_json('current_user/campaigns?include=creator'); | |
} | |
public function fetch_campaign() { | |
return $this->__get_json('current_user/campaigns?include=rewards,creator,goals'); | |
} | |
private function __get_json($suffix) { | |
$api_endpoint = 'http://api.patreon.com/oauth2/api/' . $suffix; | |
$headers = array( | |
'Authorization' => 'Bearer ' . $this->access_token, | |
); | |
$api_request = array( | |
'headers' => $headers, | |
'method' => 'GET', | |
); | |
$response = wp_remote_request( $api_endpoint, $api_request ); | |
return json_decode($response['body'], true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment