PATH:
home
/
letacommog
/
camarsac
/
wp-content
/
plugins
/
jet-engine
/
includes
/
modules
/
rest-api-listings
/
inc
<?php namespace Jet_Engine\Modules\Rest_API_Listings; class Request { private $endpoint; private $url; private $error; public function set_endpoint( $endpoint ) { $this->endpoint = $endpoint; $this->url = ! empty( $this->endpoint['url'] ) ? $this->endpoint['url'] : false; return $this; } public function get_endpoint() { return $this->endpoint; } public function get_error() { return $this->error; } public function set_error( $error ) { $this->error = $error; } public function send_request( $query_args = array(), $type = 'get' ) { do_action( 'jet-engine/rest-api-listings/request/before-send', $this ); $args = isset( $this->endpoint['args'] ) ? $this->endpoint['args'] : array(); if ( ! isset( $args['timeout'] ) ) { $args['timeout'] = 30; } $args = apply_filters( 'jet-engine/rest-api-listings/request/args', $args, $this ); $url = $this->url; if ( ! empty( $query_args ) ) { if ( is_array( $query_args ) ) { $url = add_query_arg( $query_args, $url ); } else { $url = trailingslashit( $url ) . $query_args; } } switch ( $type ) { case 'post': return wp_remote_post( $url, $args ); default: return wp_remote_get( $url, $args ); } } public function get_items( $query_args = array() ) { $response = $this->send_request( $query_args ); if ( is_wp_error( $response ) ) { $this->set_error( $response->get_error_message() ); return false; } if ( 200 !== wp_remote_retrieve_response_code( $response ) ) { $this->set_error( wp_remote_retrieve_response_message( $response ) ); return false; } $body = json_decode( wp_remote_retrieve_body( $response ) ); if ( empty( $body ) ) { $this->set_error( __( 'Reponse body is empty', 'jet-engine' ) ); return false; } $items = $this->recursive_find_items( $body ); if ( false === $items ) { $this->set_error( __( 'Items not found in the request by given path', 'jet-engine' ) ); return false; } else { return $items; } } public function recursive_find_items( $body = array(), $key_index = false ) { if ( ! is_object( $body ) && ! is_array( $body ) ) { return false; } $key_data = $this->get_key_data(); if ( false === $key_index ) { if ( empty( $key_data ) ) { return $body; } else { $key_index = 0; } } $key = $key_data[ $key_index ]; if ( ! isset( $body->$key ) ) { return false; } if ( $key_index === ( count( $key_data ) - 1 ) ) { return $body->$key; } else { return $this->recursive_find_items( $body->$key, $key_index++ ); } } public function get_key_data() { $path = ! empty( $this->endpoint['items_path'] ) ? $this->endpoint['items_path'] : '/'; if ( '/' === $path ) { return array(); } return explode( '/', trim( $path, '/' ) ); } }
[+]
..
[-] settings.php
[edit]
[-] forms.php
[edit]
[-] data.php
[edit]
[+]
listings
[+]
templates
[-] request.php
[edit]
[-] module.php
[edit]
[+]
assets
[+]
auth-types