PHP Class 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
Author: Justin Sternberg ([email protected])
Afficher le fichier Open project: webdevstudios/wds-wp-rest-api-connect Class Usage Examples

Méthodes publiques

Свойство Type Description
$json_desc
$response
$response_code

Protected Properties

Свойство Type Description
$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

Méthodes publiques

Méthode Description
__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.

Méthodes protégées

Méthode Description
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.

Method Details

__construct() public méthode

Connect object constructor.
Since: 0.2.0
public __construct ( array $storage_classes = [] )
$storage_classes array (optional) override the storage classes.

__get() public méthode

Magic getter for our object.
public __get ( string $field ) : mixed
$field string
Résultat mixed

api_url() public méthode

Get the api_url and append included path
Since: 0.1.0
public api_url ( string $path = '' ) : string
$path string Option path to append
Résultat string REST request URL

args() public méthode

Get current object data for debugging.
Since: 0.2.0
public args ( ) : array
Résultat array

auth_delete_request() public méthode

Perform an authenticated DELETE request
Since: 0.1.0
public auth_delete_request ( string $path, $data = [] ) : object | WP_Erro\WP_Error
$path string Url endpoint path to resource
Résultat object | WP_Erro\WP_Error Updated object, or WP_Error

auth_get_request() public méthode

Perform an authenticated GET request
Since: 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.
Résultat object | WP_Erro\WP_Error Updated object, or WP_Error

auth_head_request() public méthode

Perform an authenticated HEAD request
Since: 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.
Résultat object | WP_Erro\WP_Error Updated object, or WP_Error

auth_post_request() public méthode

Perform an authenticated POST request
Since: 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.
Résultat object | WP_Erro\WP_Error Updated object, or WP_Error

auth_request() public méthode

Perform an authenticated request
Since: 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
Résultat object | WP_Erro\WP_Error Updated object, or WP_Error

cache_api_description_for_api_url() public méthode

Fetches and caches the API Description object
Since: 0.1.0
public cache_api_description_for_api_url ( ) : mixed
Résultat mixed Description object for api_url

connected() public méthode

Tests whether connection has been created.
Since: 0.2.0
public connected ( ) : boolean
Résultat boolean

delete_option() public méthode

Handles deleting the stored data for a connection
Since: 0.1.3
public delete_option ( $option = '' ) : boolean
Résultat boolean Result of delete_option

delete_stored_error() public méthode

Fetches the wp_rest_api_connect_error option value
Since: 0.1.3
public delete_stored_error ( ) : mixed
Résultat mixed wp_rest_api_connect_error option value

discovered() public méthode

Tests whether API discovery has been completed.
Since: 0.2.0
public discovered ( ) : boolean
Résultat boolean

do_authorization() public méthode

Swap temporary credentials for permanent authorized credentials.
Since: 0.2.0
public do_authorization ( string $oauth_token, string $oauth_verifier ) : mixed
$oauth_token string
$oauth_verifier string
Résultat mixed WP_Error if failure, else redirect to callback_uri.

do_discovery() public méthode

Do the API discovery.
Since: 0.2.0
public do_discovery ( string $url = '' ) : string | WP_Erro\WP_Error
$url string The URL to discover.
Résultat string | WP_Erro\WP_Error The API endpoint URL or WP_Error.

get_api_description() public méthode

Retrieves the API Description object
Since: 0.1.0
public get_api_description ( ) : object
Résultat object Description object for api_url

get_authorization_url() public méthode

Get the authorization (login) URL for the server.
Since: 0.2.0
public get_authorization_url ( ) : string | WP_Erro\WP_Error
Résultat string | WP_Erro\WP_Error Authorization URL or WP_Error.

get_json_if_json() public méthode

Determines if a string is JSON, and if so, decodes it and returns it. Else returns unchanged body object.
Since: 0.1.2
public get_json_if_json ( string $body ) : mixed
$body string HTTP retrieved body
Résultat mixed Decoded JSON object or unchanged body

get_option() public méthode

Retrieve stored option
Since: 0.1.0
public get_option ( string $option = 'all' ) : mixed
$option string Option array key
Résultat mixed Value of option requested

get_requested_url() public méthode

Get the current URL
Since: 0.2.0
public get_requested_url ( ) : string
Résultat string current URL

get_server() public méthode

Get WPServer object
Since: 0.2.0
public get_server ( ) : WPServer
Résultat WPServer

get_stored_error() public méthode

Fetches the wp_rest_api_connect_error option value.
Since: 0.1.3
public get_stored_error ( ) : mixed
Résultat mixed wp_rest_api_connect_error option value.

get_stored_error_message() public méthode

Fetches the wp_rest_api_connect_error message.
Since: 0.1.3
public get_stored_error_message ( ) : string
Résultat string Stored error message value.

get_stored_error_request_args() public méthode

Fetches the wp_rest_api_connect_error request_args.
Since: 0.1.3
public get_stored_error_request_args ( ) : string
Résultat string Stored error request_args value.

get_stored_error_request_response() public méthode

Fetches the wp_rest_api_connect_error request_response.
Since: 0.1.3
public get_stored_error_request_response ( ) : string
Résultat string Stored error request_response value.

get_user() public méthode

Get's authorized user. Useful for testing authenticated connection.
Since: 0.2.0
public get_user ( ) : mixed
Résultat mixed User object or WP_Error object.

init() public méthode

Initate our connect object
Since: 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() protected méthode

Instantiates the storage objects for the options and transients.
Since: 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() public méthode

Check if the authorization callback has been initiated.
Since: 0.2.0
public is_authorizing ( ) : boolean
Résultat boolean

is_json() public méthode

Determines if a string is JSON, and if so, decodes it.
Since: 0.1.0
public is_json ( string $string ) : boolean | array
$string string String to check if is JSON
Résultat boolean | array Decoded JSON object or false

key() public méthode

Get the stored-data key
Since: 0.2.0
public key ( ) : string
Résultat string

maybe_redirect_to_authorization() public méthode

If autoredirect is enabled, and we are not yet authorized, redirect to the server to get authorization.
Since: 0.2.0
public maybe_redirect_to_authorization ( ) : boolean | WP_Erro\WP_Error
Résultat boolean | WP_Erro\WP_Error WP_Error is an issue, else redirects.

redirect_to_login() public méthode

Do the redirect to the authorization (login) URL.
Since: 0.2.0
public redirect_to_login ( ) : mixed
Résultat mixed WP_Error if authorization URL lookup fails.

request_access_url() public méthode

Gets the access URL from the JSON description object
Since: 0.1.0
public request_access_url ( ) : mixed
Résultat mixed Access URL or error

request_authorize_url() public méthode

Gets the authorization base URL from the JSON description object
Since: 0.1.0
public request_authorize_url ( ) : mixed
Résultat mixed Authorization URL or error

request_token_url() public méthode

Gets the request URL from the JSON description object
Since: 0.1.0
public request_token_url ( ) : mixed
Résultat mixed Request URL or error

reset_connection() public méthode

Deletes all stored data for this connection.
Since: 0.2.0
public reset_connection ( )

set_api_url() public méthode

Sets the api_url object property
Since: 0.2.0
public set_api_url ( string $value )
$value string Value to set

set_callback_uri() public méthode

Sets the callback_uri object property
Since: 0.2.0
public set_callback_uri ( string $value )
$value string Value to set

set_client_key() public méthode

Sets the client_key object property
Since: 0.2.0
public set_client_key ( string $value )
$value string Value to set

set_client_secret() public méthode

Sets the client_secret object property
Since: 0.2.0
public set_client_secret ( string $value )
$value string Value to set

set_endpoint_url() public méthode

Sets the endpoint_url object property
Since: 0.2.0
public set_endpoint_url ( string $value )
$value string Value to set

set_headers() public méthode

Sets the headers object property
Since: 0.2.0
public set_headers ( $headers )

set_method() public méthode

Set request method
Since: 0.1.1
public set_method ( string $method ) : string
$method string Request method
Résultat string New request method

set_object_properties() public méthode

Get the options from the DB and set the object properties.
Since: 0.2.0

update_option() public méthode

Update the options array
Since: 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.
Résultat Original $value if successful

update_stored_error() public méthode

Updates/replaces the wp_rest_api_connect_error option.
Since: 0.1.3
public update_stored_error ( string $error = '' ) : void
$error string Error message
Résultat void

Property Details

$access_token protected_oe property

protected $access_token

$access_token_secret protected_oe property

protected $access_token_secret

$api_url protected_oe property

protected $api_url

$autoredirect_authoriziation protected_oe property

protected $autoredirect_authoriziation

$callback_uri protected_oe property

protected $callback_uri

$client_key protected_oe property

protected $client_key

$client_secret protected_oe property

protected $client_secret

$endpoint_url protected_oe property

protected $endpoint_url

$headers protected_oe property

protected $headers

$is_authorizing protected_oe property

protected $is_authorizing

$json_desc public_oe property

public $json_desc

$key protected_oe property

protected $key

$method protected_oe property

protected $method

$response public_oe property

public $response

$response_code public_oe property

public $response_code

$server protected_oe property

OAuth1 Client
protected WPServer,WDS_WP_REST_API\OAuth1 $server
Résultat WPServer

$store protected_oe property

Options Store
protected Store_Interface,WDS_WP_REST_API\Storage $store
Résultat WDS_WP_REST_API\Storage\Store_Interface

$transient protected_oe property

Transients Store
protected Transient_Interface,WDS_WP_REST_API\Storage $transient
Résultat WDS_WP_REST_API\Storage\Transient_Interface