Api_Server
Class Api.
Source Source
File: src/core/classes/class-api-server.php
class Api_Server { public static $url; /** * __construct * * @return void */ public function __construct() { add_filter( 'http_request_args', array( $this, 'add_api_headers' ), 10, 2 ); self::$url = apply_filters( 'automator_api_url', AUTOMATOR_API_URL ); } /** * add_api_headers * * @param array $args * @param string $request_url * * @return array */ public function add_api_headers( $args, $request_url ) { $license_key = self::get_license_key(); if ( ! $license_key ) { return $args; } // If the request URL starts with the Automator API url if ( substr( $request_url, 0, strlen( self::$url ) ) === self::$url ) { $args['headers']['license-key'] = $license_key; $args['headers']['site-name'] = self::get_site_name(); $args['headers']['item-name'] = self::get_item_name(); } return $args; } /** * get_license_type * * @return string */ public static function get_license_type() { if ( defined( 'AUTOMATOR_PRO_FILE' ) && 'valid' === get_option( 'uap_automator_pro_license_status' ) ) { return 'pro'; } elseif ( 'valid' === get_option( 'uap_automator_free_license_status' ) ) { return 'free'; } return false; } /** * get_license_key * * @return string */ public static function get_license_key() { $license_type = self::get_license_type(); $licence_key = get_option( 'uap_automator_' . $license_type . '_license_key' ); return $licence_key; } /** * get_item_name * * @return string */ public static function get_item_name() { $license_type = strtoupper( self::get_license_type() ); if ( ! $license_type ) { return ''; } if ( 'PRO' === $license_type ) { return constant( 'AUTOMATOR_AUTOMATOR_' . $license_type . '_ITEM_NAME' ); } return constant( 'AUTOMATOR_' . $license_type . '_ITEM_NAME' ); } /** * get_site_name * * @return string */ public static function get_site_name() { return preg_replace( '(^https?://)', '', get_home_url() ); } }
Expand full source code Collapse full source code View on Github
Methods Methods
- __construct — __construct
- add_api_headers — Method add_api_headers
- add_endpoint_parts — Method add_endpoint_parts
- api_call — api_call
- call — call
- charge_credit — charge_credit
- create_payload — create_payload
- filter_params — Method filter_params
- get_instance — get_instance
- get_item_name — Method get_item_name
- get_license — get_license
- get_license_key — Method get_license_key
- get_license_type — Method get_license_type
- get_site_name — Method get_site_name
- has_credits — has_credits
- has_valid_license — has_valid_license
- maybe_add_optional_params — maybe_add_optional_params