class-wpml-tm-rest-ate-api.php
1.48 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
<?php
/**
* @author OnTheGo Systems
*/
class WPML_TM_REST_ATE_API extends WPML_TM_ATE_Required_Rest_Base {
const CAPABILITY_CREATE = 'manage_translations';
const CAPABILITY_READ = 'translate';
private $api;
/**
* WPML_TM_REST_AMS_Clients constructor.
*
* @param WPML_TM_ATE_API $api
*/
public function __construct( WPML_TM_ATE_API $api ) {
parent::__construct();
$this->api = $api;
}
function add_hooks() {
$this->register_routes();
}
function register_routes() {
parent::register_route(
'/ate/jobs',
array(
'methods' => 'POST',
'callback' => array( $this, 'create_jobs' ),
)
);
parent::register_route(
'/ate/jobs/(?P<ateJobId>\d+)',
array(
'methods' => 'GET',
'callback' => array( $this, 'get_job' ),
)
);
}
/**
* @param WP_REST_Request $request
*
* @return array|WP_Error
* @throws \InvalidArgumentException
*/
public function create_jobs( WP_REST_Request $request ) {
return $this->api->create_jobs( $request->get_params() );
}
/**
* @param WP_REST_Request $request
*
* @return array|WP_Error
* @throws \InvalidArgumentException
*/
public function get_job( WP_REST_Request $request ) {
$ate_job_id = $request->get_param( 'ateJobId' );
return $this->api->get_job( $ate_job_id );
}
function get_allowed_capabilities( WP_REST_Request $request ) {
if ( 'GET' === $request->get_method() ) {
return array( self::CAPABILITY_CREATE, self::CAPABILITY_READ );
}
return self::CAPABILITY_CREATE;
}
}