1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Igorsgm\Ghost\Apis; |
4
|
|
|
|
5
|
|
|
use Igorsgm\Ghost\Models\Resources\Author; |
6
|
|
|
use Igorsgm\Ghost\Models\Resources\Page; |
7
|
|
|
use Igorsgm\Ghost\Models\Resources\Post; |
8
|
|
|
use Igorsgm\Ghost\Models\Resources\Settings; |
9
|
|
|
use Igorsgm\Ghost\Models\Resources\Tag; |
10
|
|
|
use Igorsgm\Ghost\Models\Resources\Tier; |
11
|
|
|
use Igorsgm\Ghost\Responses\ErrorResponse; |
12
|
|
|
use Igorsgm\Ghost\Responses\SuccessResponse; |
13
|
|
|
use Illuminate\Support\Facades\Http; |
14
|
|
|
|
15
|
|
|
class ContentApi extends BaseApi |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @param array $params Here you can provide 'key', 'domain', 'version' to override the default ones. |
19
|
|
|
*/ |
20
|
64 |
|
public function __construct(array $params = []) |
21
|
|
|
{ |
22
|
64 |
|
$this->key = data_get($params, 'key') ?? config('ghost.content_key'); |
23
|
64 |
|
$this->domain = data_get($params, 'domain') ?? config('ghost.admin_domain'); |
24
|
64 |
|
$this->version = data_get($params, 'version') ?? config('ghost.ghost_api_version'); |
25
|
64 |
|
$this->baseUrl = sprintf('%s/ghost/api/v%s/content', rtrim($this->domain, '/'), $this->version); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return SuccessResponse|ErrorResponse |
30
|
|
|
*/ |
31
|
42 |
|
public function get() |
32
|
|
|
{ |
33
|
42 |
|
$response = Http::withoutVerifying()->get($this->makeApiUrl()); |
34
|
|
|
|
35
|
42 |
|
return $this->handleResponse($response); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Posts are the primary resource in a Ghost site. |
40
|
|
|
* Using the posts' endpoint it is possible to get lists of posts filtered by various criteria. |
41
|
|
|
* By default, posts are returned in reverse chronological order by published date when fetching more than one. |
42
|
|
|
* |
43
|
|
|
* @see https://ghost.org/docs/content-api/#posts |
44
|
|
|
*/ |
45
|
23 |
|
public function posts(): ContentApi |
46
|
|
|
{ |
47
|
23 |
|
return $this->setResource(Post::class); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Pages are static resources that are not included in channels or collections on the Ghost front-end. |
52
|
|
|
* The API will only return pages that were created as resources |
53
|
|
|
* and will not contain routes created with dynamic routing. |
54
|
|
|
* |
55
|
|
|
* @see https://ghost.org/docs/content-api/#pages |
56
|
|
|
*/ |
57
|
7 |
|
public function pages(): ContentApi |
58
|
|
|
{ |
59
|
7 |
|
return $this->setResource(Page::class); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Tags are the primary taxonomy within a Ghost site. |
64
|
|
|
* |
65
|
|
|
* @see https://ghost.org/docs/content-api/#tags |
66
|
|
|
*/ |
67
|
7 |
|
public function tags(): ContentApi |
68
|
|
|
{ |
69
|
7 |
|
return $this->setResource(Tag::class); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Authors are a subset of users who have published posts associated with them. |
74
|
|
|
* |
75
|
|
|
* @see https://ghost.org/docs/content-api/#authors |
76
|
|
|
*/ |
77
|
7 |
|
public function authors(): ContentApi |
78
|
|
|
{ |
79
|
7 |
|
return $this->setResource(Author::class); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Settings contain the global settings for a site. |
84
|
|
|
* |
85
|
|
|
* @see https://ghost.org/docs/content-api/#settings |
86
|
|
|
*/ |
87
|
3 |
|
public function settings(): ContentApi |
88
|
|
|
{ |
89
|
3 |
|
return $this->setResource(Settings::class); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Tiers allow publishers to create multiple options for an audience to become paid subscribers. |
94
|
|
|
* Each tier can have its own price points, benefits, and content access levels. |
95
|
|
|
* Ghost connects tiers directly to the publication’s Stripe account. |
96
|
|
|
* |
97
|
|
|
* @see https://ghost.org/docs/content-api/#tiers |
98
|
|
|
*/ |
99
|
4 |
|
public function tiers(): ContentApi |
100
|
|
|
{ |
101
|
4 |
|
return $this->setResource(Tier::class); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|