|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* API Persist client. |
|
4
|
|
|
* @package Writing_On_GitHub |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class Writing_On_GitHub_Persist_Client |
|
9
|
|
|
*/ |
|
10
|
|
|
class Writing_On_GitHub_Persist_Client extends Writing_On_GitHub_Base_Client { |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Get the data for the current user. |
|
14
|
|
|
* |
|
15
|
|
|
* @return array |
|
16
|
|
|
*/ |
|
17
|
1 |
|
protected function export_user() { |
|
18
|
1 |
|
$user_id = get_current_user_id(); |
|
|
|
|
|
|
19
|
1 |
|
$user = get_userdata( $user_id ); |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
1 |
|
if ( $user ) { |
|
22
|
|
|
return array( |
|
23
|
|
|
'name' => $user->display_name, |
|
24
|
|
|
'email' => $user->user_email, |
|
25
|
|
|
); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
1 |
|
return false; |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Delete the file. |
|
33
|
|
|
* |
|
34
|
|
|
* @return array |
|
35
|
|
|
*/ |
|
36
|
1 |
|
public function delete_file( $path, $sha, $message ) { |
|
37
|
1 |
|
$body = new stdClass(); |
|
38
|
1 |
|
$body->message = $message; |
|
39
|
1 |
|
$body->sha = $sha; |
|
40
|
1 |
|
$body->branch = $this->branch(); |
|
41
|
|
|
|
|
42
|
1 |
|
if ( $author = $this->export_user() ) { |
|
43
|
|
|
$body->author = $author; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
1 |
|
return $this->call( 'DELETE', $this->content_endpoint( $path ), $body ); |
|
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Create the file. |
|
51
|
|
|
* |
|
52
|
|
|
* @return array |
|
53
|
|
|
*/ |
|
54
|
|
|
public function create_file( $blob, $message ) { |
|
55
|
|
|
$body = $blob->to_body(); |
|
56
|
|
|
$body->message = $message; |
|
57
|
|
|
$body->branch = $this->branch(); |
|
58
|
|
|
unset($body->sha); |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
if ( $author = $this->export_user() ) { |
|
61
|
|
|
$body->author = $author; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return $this->call( 'PUT', $this->content_endpoint( $blob->path() ), $body ); |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Update the file. |
|
69
|
|
|
* |
|
70
|
|
|
* @return array |
|
71
|
|
|
*/ |
|
72
|
|
|
public function update_file( $blob, $message ) { |
|
73
|
|
|
$body = $blob->to_body(); |
|
74
|
|
|
$body->message = $message; |
|
75
|
|
|
$body->branch = $this->branch(); |
|
76
|
|
|
|
|
77
|
|
|
if ( $author = $this->export_user() ) { |
|
78
|
|
|
$body->author = $author; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return $this->call( 'PUT', $this->content_endpoint( $blob->path() ), $body ); |
|
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|