Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Site | |
0.00% |
0 / 22 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
| get_site_info | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
12 | |||
| get_purchases | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Provides site data sourced from WPCOM |
| 4 | * |
| 5 | * @package automattic/jetpack-videopress |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\VideoPress; |
| 9 | |
| 10 | use Automattic\Jetpack\Connection\Client; |
| 11 | use WP_Error; |
| 12 | |
| 13 | /** |
| 14 | * Provides site data sourced from WPCOM |
| 15 | */ |
| 16 | class Site { |
| 17 | |
| 18 | /** |
| 19 | * Returns all the data provided by WPCOM for the site. |
| 20 | * |
| 21 | * @return int|WP_Error the total of plays for today, or WP_Error on failure. |
| 22 | */ |
| 23 | public static function get_site_info() { |
| 24 | $error = new WP_Error( |
| 25 | 'videopress_site_error', |
| 26 | __( 'Could not fetch site information from the service', 'jetpack-videopress-pkg' ) |
| 27 | ); |
| 28 | |
| 29 | $request_path = sprintf( 'sites/%d?force=wpcom', Data::get_blog_id() ); |
| 30 | $response = Client::wpcom_json_api_request_as_blog( $request_path, '1.1', array(), null, 'rest' ); |
| 31 | |
| 32 | if ( is_wp_error( $response ) ) { |
| 33 | return $error; |
| 34 | } |
| 35 | |
| 36 | $response_code = wp_remote_retrieve_response_code( $response ); |
| 37 | if ( 200 !== $response_code ) { |
| 38 | return $error; |
| 39 | } |
| 40 | |
| 41 | $body = wp_remote_retrieve_body( $response ); |
| 42 | |
| 43 | return json_decode( $body, true ); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Returns all the purchases provided by WPCOM for the site. |
| 48 | * |
| 49 | * @return array the list of purchases, or an empty list on failure. |
| 50 | */ |
| 51 | public static function get_purchases() { |
| 52 | $request_path = sprintf( 'sites/%1$d/purchases?locale=%2$s', Data::get_blog_id(), get_user_locale() ); |
| 53 | $response = Client::wpcom_json_api_request_as_blog( $request_path, '1.1', array(), null, 'rest' ); |
| 54 | |
| 55 | if ( is_wp_error( $response ) ) { |
| 56 | return array(); |
| 57 | } |
| 58 | |
| 59 | $response_code = wp_remote_retrieve_response_code( $response ); |
| 60 | if ( 200 !== $response_code ) { |
| 61 | return array(); |
| 62 | } |
| 63 | |
| 64 | $body = wp_remote_retrieve_body( $response ); |
| 65 | |
| 66 | return json_decode( $body, true ); |
| 67 | } |
| 68 | } |