| @@ 483-504 (lines=22) @@ | ||
| 480 | ); |
|
| 481 | } |
|
| 482 | ||
| 483 | public static function get_plans( $request ) { |
|
| 484 | $request = Client::wpcom_json_api_request_as_user( |
|
| 485 | '/plans?_locale=' . get_user_locale(), |
|
| 486 | '2', |
|
| 487 | array( |
|
| 488 | 'method' => 'GET', |
|
| 489 | 'headers' => array( |
|
| 490 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 491 | ), |
|
| 492 | ) |
|
| 493 | ); |
|
| 494 | ||
| 495 | $body = wp_remote_retrieve_body( $request ); |
|
| 496 | if ( 200 === wp_remote_retrieve_response_code( $request ) ) { |
|
| 497 | $data = $body; |
|
| 498 | } else { |
|
| 499 | // something went wrong so we'll just return the response without caching |
|
| 500 | return $body; |
|
| 501 | } |
|
| 502 | ||
| 503 | return $data; |
|
| 504 | } |
|
| 505 | ||
| 506 | public static function submit_survey( $request ) { |
|
| 507 | ||
| @@ 506-530 (lines=25) @@ | ||
| 503 | return $data; |
|
| 504 | } |
|
| 505 | ||
| 506 | public static function submit_survey( $request ) { |
|
| 507 | ||
| 508 | $wpcom_request = Client::wpcom_json_api_request_as_user( |
|
| 509 | '/marketing/survey', |
|
| 510 | 'v2', |
|
| 511 | array( |
|
| 512 | 'method' => 'POST', |
|
| 513 | 'headers' => array( |
|
| 514 | 'Content-Type' => 'application/json', |
|
| 515 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 516 | ), |
|
| 517 | ), |
|
| 518 | $request->get_json_params() |
|
| 519 | ); |
|
| 520 | ||
| 521 | $wpcom_request_body = json_decode( wp_remote_retrieve_body( $wpcom_request ) ); |
|
| 522 | if ( 200 === wp_remote_retrieve_response_code( $wpcom_request ) ) { |
|
| 523 | $data = $wpcom_request_body; |
|
| 524 | } else { |
|
| 525 | // something went wrong so we'll just return the response without caching |
|
| 526 | return $wpcom_request_body; |
|
| 527 | } |
|
| 528 | ||
| 529 | return $data; |
|
| 530 | } |
|
| 531 | ||
| 532 | /** |
|
| 533 | * Asks for a jitm, unless they've been disabled, in which case it returns an empty array |
|