PHP Класс WDS_WP_REST_API\OAuth1\Connect

API Documentation https://github.com/WP-API/WP-API/tree/master/docs OAuth Authentication API https://github.com/WP-API/OAuth1/blob/master/docs/spec.md The OAuth 1.0 Protocol http://tools.ietf.org/html/rfc5849
Автор: Justin Sternberg ([email protected])
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$json_desc
$response
$response_code

Защищенные свойства (Protected)

Свойство Тип Описание
$access_token
$access_token_secret
$api_url
$autoredirect_authoriziation
$callback_uri
$client_key
$client_secret
$endpoint_url
$headers
$is_authorizing
$key
$method
$server WPServer OAuth1 Client
$store WDS_WP_REST_API\Storage\Store_Interface Options Store
$transient WDS_WP_REST_API\Storage\Transient_Interface Transients Store

Открытые методы

Метод Описание
__construct ( array $storage_classes = [] ) Connect object constructor.
__get ( string $field ) : mixed Magic getter for our object.
api_url ( string $path = '' ) : string Get the api_url and append included path
args ( ) : array Get current object data for debugging.
auth_delete_request ( string $path, $data = [] ) : object | WP_Erro\WP_Error Perform an authenticated DELETE request
auth_get_request ( string $path, array $data = [] ) : object | WP_Erro\WP_Error Perform an authenticated GET request
auth_head_request ( string $path, array $data = [] ) : object | WP_Erro\WP_Error Perform an authenticated HEAD request
auth_post_request ( string $path, array $data = [] ) : object | WP_Erro\WP_Error Perform an authenticated POST request
auth_request ( string $path, array $request_args = [], string $method = 'GET' ) : object | WP_Erro\WP_Error Perform an authenticated request
cache_api_description_for_api_url ( ) : mixed Fetches and caches the API Description object
connected ( ) : boolean Tests whether connection has been created.
delete_option ( $option = '' ) : boolean Handles deleting the stored data for a connection
delete_stored_error ( ) : mixed Fetches the wp_rest_api_connect_error option value
discovered ( ) : boolean Tests whether API discovery has been completed.
do_authorization ( string $oauth_token, string $oauth_verifier ) : mixed Swap temporary credentials for permanent authorized credentials.
do_discovery ( string $url = '' ) : string | WP_Erro\WP_Error Do the API discovery.
get_api_description ( ) : object Retrieves the API Description object
get_authorization_url ( ) : string | WP_Erro\WP_Error Get the authorization (login) URL for the server.
get_json_if_json ( string $body ) : mixed Determines if a string is JSON, and if so, decodes it and returns it. Else returns unchanged body object.
get_option ( string $option = 'all' ) : mixed Retrieve stored option
get_requested_url ( ) : string Get the current URL
get_server ( ) : WPServer Get WPServer object
get_stored_error ( ) : mixed Fetches the wp_rest_api_connect_error option value.
get_stored_error_message ( ) : string Fetches the wp_rest_api_connect_error message.
get_stored_error_request_args ( ) : string Fetches the wp_rest_api_connect_error request_args.
get_stored_error_request_response ( ) : string Fetches the wp_rest_api_connect_error request_response.
get_user ( ) : mixed Get's authorized user. Useful for testing authenticated connection.
init ( array $args ) Initate our connect object
is_authorizing ( ) : boolean Check if the authorization callback has been initiated.
is_json ( string $string ) : boolean | array Determines if a string is JSON, and if so, decodes it.
key ( ) : string Get the stored-data key
maybe_redirect_to_authorization ( ) : boolean | WP_Erro\WP_Error If autoredirect is enabled, and we are not yet authorized, redirect to the server to get authorization.
redirect_to_login ( ) : mixed Do the redirect to the authorization (login) URL.
request_access_url ( ) : mixed Gets the access URL from the JSON description object
request_authorize_url ( ) : mixed Gets the authorization base URL from the JSON description object
request_token_url ( ) : mixed Gets the request URL from the JSON description object
reset_connection ( ) Deletes all stored data for this connection.
set_api_url ( string $value ) Sets the api_url object property
set_callback_uri ( string $value ) Sets the callback_uri object property
set_client_key ( string $value ) Sets the client_key object property
set_client_secret ( string $value ) Sets the client_secret object property
set_endpoint_url ( string $value ) Sets the endpoint_url object property
set_headers ( $headers ) Sets the headers object property
set_method ( string $method ) : string Set request method
set_object_properties ( ) Get the options from the DB and set the object properties.
update_option ( string $option, mixed $value, boolean $set = true ) : Original Update the options array
update_stored_error ( string $error = '' ) : void Updates/replaces the wp_rest_api_connect_error option.

Защищенные методы

Метод Описание
instantiate_storage_objects ( WDS_WP_REST_API\Storage\Store_Interface $store, WDS_WP_REST_API\Storage\Store_Interface $error_store, WDS_WP_REST_API\Storage\Transient_Interface $transient ) Instantiates the storage objects for the options and transients.

Описание методов

__construct() публичный Метод

Connect object constructor.
С версии: 0.2.0
public __construct ( array $storage_classes = [] )
$storage_classes array (optional) override the storage classes.

__get() публичный Метод

Magic getter for our object.
public __get ( string $field ) : mixed
$field string
Результат mixed

api_url() публичный Метод

Get the api_url and append included path
С версии: 0.1.0
public api_url ( string $path = '' ) : string
$path string Option path to append
Результат string REST request URL

args() публичный Метод

Get current object data for debugging.
С версии: 0.2.0
public args ( ) : array
Результат array

auth_delete_request() публичный Метод

Perform an authenticated DELETE request
С версии: 0.1.0
public auth_delete_request ( string $path, $data = [] ) : object | WP_Erro\WP_Error
$path string Url endpoint path to resource
Результат object | WP_Erro\WP_Error Updated object, or WP_Error

auth_get_request() публичный Метод

Perform an authenticated GET request
С версии: 0.1.0
public auth_get_request ( string $path, array $data = [] ) : object | WP_Erro\WP_Error
$path string Url endpoint path to resource
$data array Array of data to send in request.
Результат object | WP_Erro\WP_Error Updated object, or WP_Error

auth_head_request() публичный Метод

Perform an authenticated HEAD request
С версии: 0.1.0
public auth_head_request ( string $path, array $data = [] ) : object | WP_Erro\WP_Error
$path string Url endpoint path to resource
$data array Array of data to send in request.
Результат object | WP_Erro\WP_Error Updated object, or WP_Error

auth_post_request() публичный Метод

Perform an authenticated POST request
С версии: 0.1.0
public auth_post_request ( string $path, array $data = [] ) : object | WP_Erro\WP_Error
$path string Url endpoint path to resource
$data array Array of data to send in request.
Результат object | WP_Erro\WP_Error Updated object, or WP_Error

auth_request() публичный Метод

Perform an authenticated request
С версии: 0.1.0
public auth_request ( string $path, array $request_args = [], string $method = 'GET' ) : object | WP_Erro\WP_Error
$path string Url endpoint path to resource
$request_args array Array of data to send in request.
$method string Request method. Defaults to GET
Результат object | WP_Erro\WP_Error Updated object, or WP_Error

cache_api_description_for_api_url() публичный Метод

Fetches and caches the API Description object
С версии: 0.1.0
public cache_api_description_for_api_url ( ) : mixed
Результат mixed Description object for api_url

connected() публичный Метод

Tests whether connection has been created.
С версии: 0.2.0
public connected ( ) : boolean
Результат boolean

delete_option() публичный Метод

Handles deleting the stored data for a connection
С версии: 0.1.3
public delete_option ( $option = '' ) : boolean
Результат boolean Result of delete_option

delete_stored_error() публичный Метод

Fetches the wp_rest_api_connect_error option value
С версии: 0.1.3
public delete_stored_error ( ) : mixed
Результат mixed wp_rest_api_connect_error option value

discovered() публичный Метод

Tests whether API discovery has been completed.
С версии: 0.2.0
public discovered ( ) : boolean
Результат boolean

do_authorization() публичный Метод

Swap temporary credentials for permanent authorized credentials.
С версии: 0.2.0
public do_authorization ( string $oauth_token, string $oauth_verifier ) : mixed
$oauth_token string
$oauth_verifier string
Результат mixed WP_Error if failure, else redirect to callback_uri.

do_discovery() публичный Метод

Do the API discovery.
С версии: 0.2.0
public do_discovery ( string $url = '' ) : string | WP_Erro\WP_Error
$url string The URL to discover.
Результат string | WP_Erro\WP_Error The API endpoint URL or WP_Error.

get_api_description() публичный Метод

Retrieves the API Description object
С версии: 0.1.0
public get_api_description ( ) : object
Результат object Description object for api_url

get_authorization_url() публичный Метод

Get the authorization (login) URL for the server.
С версии: 0.2.0
public get_authorization_url ( ) : string | WP_Erro\WP_Error
Результат string | WP_Erro\WP_Error Authorization URL or WP_Error.

get_json_if_json() публичный Метод

Determines if a string is JSON, and if so, decodes it and returns it. Else returns unchanged body object.
С версии: 0.1.2
public get_json_if_json ( string $body ) : mixed
$body string HTTP retrieved body
Результат mixed Decoded JSON object or unchanged body

get_option() публичный Метод

Retrieve stored option
С версии: 0.1.0
public get_option ( string $option = 'all' ) : mixed
$option string Option array key
Результат mixed Value of option requested

get_requested_url() публичный Метод

Get the current URL
С версии: 0.2.0
public get_requested_url ( ) : string
Результат string current URL

get_server() публичный Метод

Get WPServer object
С версии: 0.2.0
public get_server ( ) : WPServer
Результат WPServer

get_stored_error() публичный Метод

Fetches the wp_rest_api_connect_error option value.
С версии: 0.1.3
public get_stored_error ( ) : mixed
Результат mixed wp_rest_api_connect_error option value.

get_stored_error_message() публичный Метод

Fetches the wp_rest_api_connect_error message.
С версии: 0.1.3
public get_stored_error_message ( ) : string
Результат string Stored error message value.

get_stored_error_request_args() публичный Метод

Fetches the wp_rest_api_connect_error request_args.
С версии: 0.1.3
public get_stored_error_request_args ( ) : string
Результат string Stored error request_args value.

get_stored_error_request_response() публичный Метод

Fetches the wp_rest_api_connect_error request_response.
С версии: 0.1.3
public get_stored_error_request_response ( ) : string
Результат string Stored error request_response value.

get_user() публичный Метод

Get's authorized user. Useful for testing authenticated connection.
С версии: 0.2.0
public get_user ( ) : mixed
Результат mixed User object or WP_Error object.

init() публичный Метод

Initate our connect object
С версии: 0.1.0
public init ( array $args )
$args array Arguments containing 'client_key', 'client_secret', 'api_url', 'headers', 'callback_uri', 'autoredirect_authoriziation'

instantiate_storage_objects() защищенный Метод

Instantiates the storage objects for the options and transients.
С версии: 0.2.0
protected instantiate_storage_objects ( WDS_WP_REST_API\Storage\Store_Interface $store, WDS_WP_REST_API\Storage\Store_Interface $error_store, WDS_WP_REST_API\Storage\Transient_Interface $transient )
$store WDS_WP_REST_API\Storage\Store_Interface Option storage
$error_store WDS_WP_REST_API\Storage\Store_Interface Error option storage
$transient WDS_WP_REST_API\Storage\Transient_Interface Transient storage

is_authorizing() публичный Метод

Check if the authorization callback has been initiated.
С версии: 0.2.0
public is_authorizing ( ) : boolean
Результат boolean

is_json() публичный Метод

Determines if a string is JSON, and if so, decodes it.
С версии: 0.1.0
public is_json ( string $string ) : boolean | array
$string string String to check if is JSON
Результат boolean | array Decoded JSON object or false

key() публичный Метод

Get the stored-data key
С версии: 0.2.0
public key ( ) : string
Результат string

maybe_redirect_to_authorization() публичный Метод

If autoredirect is enabled, and we are not yet authorized, redirect to the server to get authorization.
С версии: 0.2.0
public maybe_redirect_to_authorization ( ) : boolean | WP_Erro\WP_Error
Результат boolean | WP_Erro\WP_Error WP_Error is an issue, else redirects.

redirect_to_login() публичный Метод

Do the redirect to the authorization (login) URL.
С версии: 0.2.0
public redirect_to_login ( ) : mixed
Результат mixed WP_Error if authorization URL lookup fails.

request_access_url() публичный Метод

Gets the access URL from the JSON description object
С версии: 0.1.0
public request_access_url ( ) : mixed
Результат mixed Access URL or error

request_authorize_url() публичный Метод

Gets the authorization base URL from the JSON description object
С версии: 0.1.0
public request_authorize_url ( ) : mixed
Результат mixed Authorization URL or error

request_token_url() публичный Метод

Gets the request URL from the JSON description object
С версии: 0.1.0
public request_token_url ( ) : mixed
Результат mixed Request URL or error

reset_connection() публичный Метод

Deletes all stored data for this connection.
С версии: 0.2.0
public reset_connection ( )

set_api_url() публичный Метод

Sets the api_url object property
С версии: 0.2.0
public set_api_url ( string $value )
$value string Value to set

set_callback_uri() публичный Метод

Sets the callback_uri object property
С версии: 0.2.0
public set_callback_uri ( string $value )
$value string Value to set

set_client_key() публичный Метод

Sets the client_key object property
С версии: 0.2.0
public set_client_key ( string $value )
$value string Value to set

set_client_secret() публичный Метод

Sets the client_secret object property
С версии: 0.2.0
public set_client_secret ( string $value )
$value string Value to set

set_endpoint_url() публичный Метод

Sets the endpoint_url object property
С версии: 0.2.0
public set_endpoint_url ( string $value )
$value string Value to set

set_headers() публичный Метод

Sets the headers object property
С версии: 0.2.0
public set_headers ( $headers )

set_method() публичный Метод

Set request method
С версии: 0.1.1
public set_method ( string $method ) : string
$method string Request method
Результат string New request method

set_object_properties() публичный Метод

Get the options from the DB and set the object properties.
С версии: 0.2.0

update_option() публичный Метод

Update the options array
С версии: 0.1.0
public update_option ( string $option, mixed $value, boolean $set = true ) : Original
$option string Option array key
$value mixed Value to be updated
$set boolean Whether to set the updated value in the DB.
Результат Original $value if successful

update_stored_error() публичный Метод

Updates/replaces the wp_rest_api_connect_error option.
С версии: 0.1.3
public update_stored_error ( string $error = '' ) : void
$error string Error message
Результат void

Описание свойств

$access_token защищенное свойство

protected $access_token

$access_token_secret защищенное свойство

protected $access_token_secret

$api_url защищенное свойство

protected $api_url

$autoredirect_authoriziation защищенное свойство

protected $autoredirect_authoriziation

$callback_uri защищенное свойство

protected $callback_uri

$client_key защищенное свойство

protected $client_key

$client_secret защищенное свойство

protected $client_secret

$endpoint_url защищенное свойство

protected $endpoint_url

$headers защищенное свойство

protected $headers

$is_authorizing защищенное свойство

protected $is_authorizing

$json_desc публичное свойство

public $json_desc

$key защищенное свойство

protected $key

$method защищенное свойство

protected $method

$response публичное свойство

public $response

$response_code публичное свойство

public $response_code

$server защищенное свойство

OAuth1 Client
protected WPServer,WDS_WP_REST_API\OAuth1 $server
Результат WPServer

$store защищенное свойство

Options Store
protected Store_Interface,WDS_WP_REST_API\Storage $store
Результат WDS_WP_REST_API\Storage\Store_Interface

$transient защищенное свойство

Transients Store
protected Transient_Interface,WDS_WP_REST_API\Storage $transient
Результат WDS_WP_REST_API\Storage\Transient_Interface