Commit 1da24ae9 authored by Erick Hitter's avatar Erick Hitter
Browse files

Start adding SMS support

* Basic API method for requesting an SMS.
* Setup method to check account for SMS support.

See #4.
parent f5620dc1
......@@ -126,4 +126,28 @@ class Authy_WP_API {
return false;
}
/**
*
*/
public function send_sms( $authy_id, $force = false ) {
// Build API endpoint
$endpoint = sprintf( '%s/protected/json/sms/%d', $this->api_endpoint, $authy_id );
$endpoint = add_query_arg( array(
'api_key' => $this->api_key
), $endpoint );
if ( $force )
$endpoint = add_query_arg( 'force', 'true', $endpoint );
// Make API request up to three times and check responding status code
for ( $i = 1; $i <= 3; $i ++ ) {
$response = wp_remote_get( $endpoint );
$status_code = wp_remote_retrieve_response_code( $response );
return (int) $status_code;
}
return false;
}
}
......@@ -39,6 +39,7 @@ class Authy_WP {
// Is API ready, should plugin act?
protected $ready = false;
protected $sms = false;
// Authy API
protected $api = null;
......@@ -114,6 +115,9 @@ class Authy_WP {
// Anything other than plugin configuration belongs in here.
// Important to consider plugin state so we only load code when needed.
if ( $this->ready ) {
// Check SMS availability
add_action( 'init', array( $this, 'check_sms_availability' ) );
// User settings
add_action( 'show_user_profile', array( $this, 'action_show_user_profile' ) );
add_action( 'edit_user_profile', array( $this, 'action_edit_user_profile' ) );
......@@ -310,6 +314,18 @@ class Authy_WP {
), admin_url( 'admin-ajax.php' ) );
}
/**
* Check basic SMS availability.
* Subscription level dictates availability.
*
* @uses this::api::send_sms
* @return null
*/
protected function check_sms_availability() {
if ( 503 != $this->api->send_sms( 1 ) )
$this->sms = true;
}
/**
* GENERAL OPTIONS PAGE
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment