set_endpoint( 'authorize', 'https://runkeeper.com/apps/authorize', 'GET' ); $this->set_endpoint( 'access_token', 'https://runkeeper.com/apps/token', 'POST' ); $this->set_endpoint( 'deauthorize', 'https://runkeeper.com/apps/de-authorize', 'POST' ); $this->set_endpoint( 'user', 'https://api.runkeeper.com/user', 'GET' ); $this->set_endpoint( 'profile', 'https://api.runkeeper.com/profile', 'GET' ); $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 = 'Bearer'; $this->authorization_parameter = false; } function basic_ui_intro() { echo '

' . __( "You'll need to register a new application on RunKeeper so that you can connect. Be sure to check the Read Health Information option under Permissions Requests (and explain why you want to read that data). You will also be required to set an Estimated Date of Publication.", 'keyring' ) . '

'; echo '

' . __( "Once you've registered your application, click the Application Keys and URLs next to it, and copy the Client ID into the API Key field below, and the Client Secret value into API Secret.", 'keyring' ) . '

'; } function build_token_meta( $token ) { $this->set_token( new Keyring_Access_Token( $this->get_name(), $token['access_token'], array() ) ); $response = $this->request( $this->user_url, array( 'method' => $this->user_method ) ); if ( Keyring_Util::is_error( $response ) ) { $meta = array(); } else { // Only useful thing in that request is userID $meta = array( 'user_id' => (int) $response->userID ); // Now get the rest of their profile $profile = $this->request( $this->profile_url, array( 'method' => $this->profile_method ) ); if ( !Keyring_Util::is_error( $profile ) ) { $meta['username'] = substr( $profile->profile, strrpos( $profile->profile, '/' ) + 1 ); $meta['name'] = $profile->name; $meta['picture'] = $profile->large_picture; } return apply_filters( 'keyring_access_token_meta', $meta, 'runkeeper', $token, $profile, $this ); } return array(); } function get_display( Keyring_Access_Token $token ) { return $token->get_meta( 'name' );; } } add_action( 'keyring_load_services', array( 'Keyring_Service_RunKeeper', 'init' ) );