Skip to content

Commit

Permalink
#3 チケット情報のREST APIはなかった。
Browse files Browse the repository at this point in the history
  • Loading branch information
fumikito committed Jan 21, 2024
1 parent cf00ed8 commit 4b94130
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
31 changes: 27 additions & 4 deletions lib/WCTokyo/WpCheckin/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ class Command extends \WP_CLI_Command {
* @return void
*/
public function is_valid() {
$me = $this->rest_request( '/wp/v2/users/me', 'GET', [
$me = $this->rest_request( '/wp/v2/users/me', 'GET', [
'context' => 'edit',
] );
if ( is_wp_error( $me ) ) {
\WP_CLI::error( $me->get_error_message() );
}
$table = new Table();
$table->setHeaders( [ 'Property', 'Value' ] );
foreach ( $me as $key => $value ) {
Expand All @@ -42,4 +39,30 @@ public function is_valid() {
$table->display();
\WP_CLI::success( __( 'ユーザー情報を取得しました。', 'wp-checkin' ) );
}

/**
* Display API.
*
* @return void
*/
public function namespaces() {
$response = $this->rest_request( '/' );
foreach ( $response['namespaces'] as $namespace ) {
\WP_CLI::line( sprintf( '%s/wp-json/%s', trailingslashit( get_option( 'wordcamp_site_url' ) ), $namespace ) );
}
\WP_CLI::line( '' );
// translators: %d is number of namespaces.
\WP_CLI::success( sprintf( __( '%dの名前空間があります。', 'wp-checkin' ), count( $response['namespaces'] ) ) );
}

/**
* {@see Request::rest_request()}
*/
private function request( $path, $method = 'GET', $data = [] ) {
$response = $this->rest_request( $path, $method, $data );
if ( is_wp_error( $response ) ) {
\WP_CLI::error( $response->get_error_message() );
}
return $response;
}
}
2 changes: 1 addition & 1 deletion lib/WCTokyo/WpCheckin/Screen/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function register_option() {
'wp_checkin_settings',
__( 'WordCamp チェックイン設定', 'wp-checkin' ),
function() {
printf( '<p>%s</p>', esc_html__( 'WordCampのチェックインシステムに必要な設定を行います。', 'wp-checkin' ) );
printf( '<p>%s</p>', esc_html__( 'WordCampのチェックインシステムに必要な設定を行います。', 'wp-checkin' ) );
},
'general'
);
Expand Down
4 changes: 2 additions & 2 deletions lib/WCTokyo/WpCheckin/Utilities/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function rest_request( $path, $method = 'GET', $data = [] ) {
'status' => 400,
] );
}
$url = get_option( 'wordcamp_site_url' );
$url = get_option( 'wordcamp_site_url' );
$user = get_option( 'wordcamp_user_login' );
$pass = get_option( 'application_password' );
if ( ! $url || ! $user || ! $pass ) {
Expand All @@ -33,7 +33,7 @@ protected function rest_request( $path, $method = 'GET', $data = [] ) {
] );
}
$endpoint = trailingslashit( $url ) . 'wp-json/' . ltrim( $path, '/' );
$args = [
$args = [
'method' => $method,
'timeout' => (int) apply_filters( 'wp_checkin_timeout', 30, $path, $method, $data ),
'headers' => [
Expand Down

0 comments on commit 4b94130

Please sign in to comment.