set_endpoint( 'request_token', 'http://www.tumblr.com/oauth/request_token', 'POST' ); $this->set_endpoint( 'authorize', 'http://www.tumblr.com/oauth/authorize', 'GET' ); $this->set_endpoint( 'access_token', 'http://www.tumblr.com/oauth/access_token', 'POST' ); $creds = $this->get_credentials(); $this->app_id = $creds['app_id']; $this->key = $creds['key']; $this->secret = $creds['secret']; $this->consumer = new OAuthConsumer( $this->key, $this->secret, $this->callback_url ); $this->signature_method = new OAuthSignatureMethod_HMAC_SHA1; $this->authorization_header = true; // Send OAuth token in the header, not querystring $this->authorization_realm = 'tumblr.com'; } function basic_ui_intro() { echo '

' . sprintf( __( "To get started, register an application with Tumblr. The Default callback URL should be set to %s, and you can enter whatever you like in the other fields.", 'keyring' ), Keyring_Util::admin_url( 'tumblr', array( 'action' => 'verify' ) ) ) . '

'; echo '

' . __( "Once you've created your app, copy the OAuth Consumer Key into the API Key field below. Click the Show secret key link, and then copy the Secret Key value into the API Secret field below. You don't need an App ID value for Tumblr.", 'keyring' ) . '

'; } function parse_response( $response ) { return json_decode( $response ); } function build_token_meta( $token ) { // Set the token so that we can make requests using it $this->set_token( new Keyring_Access_Token( 'tumblr', new OAuthToken( $token['oauth_token'], $token['oauth_token_secret'] ) ) ); $response = $this->request( 'http://api.tumblr.com/v2/user/info', array( 'method' => 'POST' ) ); if ( Keyring_Util::is_error( $response ) ) { $meta = array(); } else { $this->person = $response->response->user; $meta = array( 'name' => $this->person->name, ); } return apply_filters( 'keyring_access_token_meta', $meta, 'tumblr', $token, $response, $this ); } function get_display( Keyring_Access_Token $token ) { return $token->get_meta( 'name' ); } function test_connection() { $res = $this->request( 'http://api.tumblr.com/v2/user/info', array( 'method' => 'POST' ) ); if ( !Keyring_Util::is_error( $res ) ) return true; return $res; } } add_action( 'keyring_load_services', array( 'Keyring_Service_Tumblr', 'init' ) );