# flywp/1.0/includes/FlyApi.php

FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel, version 1.0. 102 lines.

- Page: https://pluginprobe.com/plugins/flywp/1.0/code/includes/FlyApi.php
- Raw: https://pluginprobe.com/plugins/flywp/1.0/raw/includes/FlyApi.php
- Modified: 2023-12-10T09:45:24+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/flywp/1.0/code/includes/FlyApi.php#L10-L20`.

```php
<?php

namespace FlyWP;

class FlyApi {

    /**
     * Get the site's info.
     *
     * @return array|false
     */
    public function site_info() {
        return $this->get( '/info' );
    }

    /**
     * Set the site's cache status.
     *
     * @param string $action
     *
     * @return array|false
     */
    public function cache_toggle( $action = 'enable' ) {
        return $this->post(
            '/cache-toggle',
            [
                'action' => $action,
            ]
        );
    }

    /**
     * Get the API endpoint.
     *
     * @return string
     */
    protected function get_endpoint() {
        return apply_filters( 'flywp_api_endpoint', 'https://app.flywp.com/api/site-api' );
    }

    /**
     * Send a GET request to the API.
     *
     * @param string $path
     *
     * @return array|false
     */
    public function get( $path ) {
        $url = $this->get_endpoint() . $path;

        $response = wp_remote_get(
            $url,
            [
                'headers' => [
                    'Authorization' => 'Bearer ' . flywp()->get_key(),
                ],
            ]
        );

        if ( is_wp_error( $response ) ) {
            // Handle error if needed
            return false;
        }

        $body = wp_remote_retrieve_body( $response );
        $data = json_decode( $body, true );

        return $data;
    }

    /**
     * Send a POST request to the API.
     *
     * @param string $path
     * @param array  $data
     *
     * @return array|false
     */
    public function post( $path, $data = [] ) {
        $url = $this->get_endpoint() . $path;

        $response = wp_remote_post(
            $url,
            [
                'headers' => [
                    'Authorization' => 'Bearer ' . flywp()->get_key(),
                ],
                'body' => $data,
            ]
        );

        if ( is_wp_error( $response ) ) {
            return false;
        }

        $body = wp_remote_retrieve_body( $response );
        $data = json_decode( $body, true );

        return $data;
    }
}

```
