| 1 |
<?php |
| 2 |
|
| 3 |
namespace Templately\API; |
| 4 |
|
| 5 |
use WP_REST_Request; |
| 6 |
|
| 7 |
class Profile extends API { |
| 8 |
|
| 9 |
public function register_routes() { |
| 10 |
$this->register_endpoint( 'profile', [ $this, 'get_profile' ] ); |
| 11 |
$this->get( 'profile/download-history', [ $this, 'get_download_history' ] ); |
| 12 |
$this->get( 'profile/my-favourites', [ $this, 'get_my_favourites' ] ); |
| 13 |
} |
| 14 |
|
| 15 |
public function get_profile( WP_REST_Request $request ) { |
| 16 |
|
| 17 |
} |
| 18 |
|
| 19 |
public function get_download_history() { |
| 20 |
$page = $this->get_param( 'page', 1, 'intval' ); |
| 21 |
$per_page = $this->get_param( 'per_page', 10, 'intval' ); |
| 22 |
|
| 23 |
$response = $this->http()->mutation( |
| 24 |
'myDownloadHistory', |
| 25 |
'data{ name, thumbnail, downloaded_at, slug, type }, current_page, total_page', |
| 26 |
[ |
| 27 |
'api_key' => $this->api_key, |
| 28 |
'per_page' => $per_page, |
| 29 |
"page" => $page |
| 30 |
] |
| 31 |
)->post(); |
| 32 |
|
| 33 |
if ( is_wp_error( $response ) ) { |
| 34 |
return $this->error( |
| 35 |
'invalid_download_history_response', |
| 36 |
__( $response->get_error_message(), 'templately' ), |
| 37 |
'profile/download-history', |
| 38 |
$response->get_error_code() |
| 39 |
); |
| 40 |
} |
| 41 |
|
| 42 |
return $response; |
| 43 |
} |
| 44 |
|
| 45 |
public function get_my_favourites() { |
| 46 |
$type = $this->get_param( 'itemType', 'all' ); |
| 47 |
$plan = $this->get_param( 'plan', 'all' ); |
| 48 |
$plan_type = $this->get_plan( $plan ); |
| 49 |
$page = $this->get_param( 'page', 1, 'intval' ); |
| 50 |
$per_page = $this->get_param( 'per_page', 20, 'intval' ); |
| 51 |
|
| 52 |
$funcArgs = [ |
| 53 |
'api_key' => $this->api_key, |
| 54 |
"page" => $page, |
| 55 |
"per_page" => $per_page, |
| 56 |
"plan_type" => $plan_type |
| 57 |
]; |
| 58 |
|
| 59 |
if( $type != 'all' ) { |
| 60 |
$funcArgs['type'] = $type; |
| 61 |
} |
| 62 |
|
| 63 |
$response = $this->http()->mutation( |
| 64 |
'myFavouriteItem', |
| 65 |
'total_page, current_page, data { id, name, rating, type, slug, favourite_count, thumbnail, thumbnail2, thumbnail3, price, author{ display_name, name, joined } }', |
| 66 |
$funcArgs |
| 67 |
)->post(); |
| 68 |
|
| 69 |
if ( is_wp_error( $response ) ) { |
| 70 |
return $this->error( 'invalid_my_favourites_response', __( $response->get_error_message(), 'templately' ), 'profile/my-favourites', $response->get_error_code() ); |
| 71 |
} |
| 72 |
|
| 73 |
return $response; |
| 74 |
} |
| 75 |
} |