1 | <?php |
||
10 | class Writing_On_GitHub_Base_Client { |
||
11 | |||
12 | const HOST_OPTION_KEY = 'wogh_host'; |
||
13 | const TOKEN_OPTION_KEY = 'wogh_oauth_token'; |
||
14 | const REPO_OPTION_KEY = 'wogh_repository'; |
||
15 | const BRANCH_OPTION_KEY = 'wogh_branch'; |
||
16 | |||
17 | /** |
||
18 | * Application container. |
||
19 | * |
||
20 | * @var Writing_On_GitHub |
||
21 | */ |
||
22 | protected $app; |
||
23 | |||
24 | /** |
||
25 | * Instantiates a new Api object. |
||
26 | * |
||
27 | * @param Writing_On_GitHub $app Application container. |
||
28 | */ |
||
29 | 8 | public function __construct( Writing_On_GitHub $app ) { |
|
32 | |||
33 | /** |
||
34 | * Generic GitHub API interface and response handler |
||
35 | * |
||
36 | * @param string $method HTTP method. |
||
37 | * @param string $endpoint API endpoint. |
||
38 | * @param array $body Request body. |
||
39 | * |
||
40 | * @return stdClass|WP_Error |
||
41 | */ |
||
42 | 8 | protected function call( $method, $endpoint, $body = array() ) { |
|
80 | |||
81 | /** |
||
82 | * Validates whether the Api object can make a call. |
||
83 | * |
||
84 | * @return true|WP_Error |
||
85 | */ |
||
86 | 8 | protected function can_call() { |
|
114 | |||
115 | /** |
||
116 | * Returns the repository to sync with |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | 8 | public function repository() { |
|
123 | |||
124 | /** |
||
125 | * Returns the user's oauth token |
||
126 | * |
||
127 | * @return string |
||
128 | */ |
||
129 | 8 | public function oauth_token() { |
|
132 | |||
133 | /** |
||
134 | * Returns the GitHub host to sync with (for GitHub Enterprise support) |
||
135 | */ |
||
136 | 8 | public function api_base() { |
|
139 | |||
140 | 8 | public function branch() { |
|
144 | |||
145 | /** |
||
146 | * API endpoint for the master branch reference |
||
147 | */ |
||
148 | public function reference_endpoint() { |
||
154 | |||
155 | /** |
||
156 | * Api to get and create commits |
||
157 | */ |
||
158 | public function commit_endpoint() { |
||
164 | |||
165 | /** |
||
166 | * Api to compare commits |
||
167 | */ |
||
168 | 1 | public function compare_endpoint() { |
|
174 | |||
175 | /** |
||
176 | * Api to get and create trees |
||
177 | */ |
||
178 | 6 | public function tree_endpoint() { |
|
184 | |||
185 | /** |
||
186 | * Builds the proper blob API endpoint for a given post |
||
187 | * |
||
188 | * Returns String the relative API call path |
||
189 | */ |
||
190 | 1 | public function blob_endpoint() { |
|
196 | |||
197 | /** |
||
198 | * Builds the proper content API endpoint for a given post |
||
199 | * |
||
200 | * Returns String the relative API call path |
||
201 | */ |
||
202 | 1 | public function content_endpoint( $path = false ) { |
|
212 | } |
||
213 |