class-wpml-tp-project-api.php
2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
use WPML\TM\TranslationProxy\Services\Project\Project;
use WPML\TM\TranslationProxy\Services\Project\SiteDetails;
class WPML_TP_Project_API extends WPML_TP_API {
const API_VERSION = 1.1;
const PROJECTS_ENDPOINT = '/projects.json';
/**
* @throws WPML_TP_API_Exception
*/
public function refresh_language_pairs() {
$this->log( 'Refresh language pairs -> Request sent' );
$request = new WPML_TP_API_Request( self::PROJECTS_ENDPOINT );
$request->set_method( 'PUT' );
$request->set_params(
[
'project' => [ 'refresh_language_pairs' => 1 ],
'refresh_language_pairs' => 1,
'project_id' => $this->project->get_id(),
'accesskey' => $this->project->get_access_key(),
]
);
$this->client->send_request( $request );
}
/**
* @param stdClass $service
* @param SiteDetails $site_details
*
* @return stdClass
* @throws WPML_TP_API_Exception
*/
public function create_project( \stdClass $service, SiteDetails $site_details ) {
$project_data = array_merge(
$site_details->getBlogInfo(),
[
'delivery_method' => $site_details->getDeliveryMethod(),
'sitekey' => WP_Installer_API::get_site_key( 'wpml' ),
'client_external_id' => WP_Installer_API::get_ts_client_id(),
]
);
$params = [
'api_version' => self::API_VERSION,
'service' => [ 'id' => $service->id ],
'project' => $project_data,
'custom_fields' => $service->custom_fields_data,
'client' => $site_details->getClientData(),
'linked_by' => \TranslationProxy::get_service_linked_by_suid( $service->suid ),
];
$request = new WPML_TP_API_Request( self::PROJECTS_ENDPOINT );
$request->set_method( 'POST' );
$request->set_params( $params );
return $this->client->send_request( $request );
}
/**
* @param Project $project
* @param \stdClass $credentials
*
* @throws WPML_TP_API_Exception
*/
public function update_project_credentials( Project $project, \stdClass $credentials ) {
$request = new WPML_TP_API_Request( self::PROJECTS_ENDPOINT );
$request->set_method( 'PUT' );
$request->set_params(
[
'api_version' => self::API_VERSION,
'accesskey' => $project->accessKey,
'project' => [
'custom_fields' => (array) $credentials,
],
]
);
$this->client->send_request( $request );
}
/**
* @param Project $project
*
* @return array|mixed|stdClass|string
* @throws WPML_TP_API_Exception
*/
public function get_extra_fields( Project $project ) {
$params = [
'accesskey' => $project->accessKey,
'api_version' => self::API_VERSION,
'project_id' => $project->id,
];
$request = new WPML_TP_API_Request( '/projects/{project_id}/extra_fields.json' );
$request->set_method( 'GET' );
$request->set_params( $params );
return $this->client->send_request( $request );
}
}