Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions includes/oauthhelper/class-oauth-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public function __construct()
add_filter('simple_calendar_oauth_get_calendars', [$this, 'oauth_helper_get_calendar'], 10, 3);

add_filter('simple_calendar_oauth_schedule_events', [$this, 'oauth_helper_schedule_events'], 10, 2);

add_filter(
'simple_calendar_oauth_get_events_cover_base64image',
[$this, 'auth_get_events_cover_base64image'],
10,
2
);
}

/**
Expand Down Expand Up @@ -155,6 +162,21 @@ public function oauth_helper_schedule_events($calendarId, $event_data)
$get_calendars = $Oauth_Ajax->oauth_helper_schedule_event_action($calendarId, $event_data);
return $get_calendars;
}
/**
* Get events cover base64 image.
*
* @since 1.0.0
*
* @param string $fileid
* @param array $args
* @return array
*/
public function auth_get_events_cover_base64image($fileid, $args)
{
$Oauth_Ajax = new Oauth_Ajax();
$get_events_cover_image = $Oauth_Ajax->auth_get_events_cover_base64image($fileid, $args);
return $get_events_cover_image;
}
}

new Auth_Service_Helpers();
39 changes: 39 additions & 0 deletions includes/oauthhelper/oauth-service-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,45 @@ public function oauth_helper_schedule_event_action($calendarId, $event_data)
return $response;
}
}

/*
* Get calendar Cover Image Base64
*/
public function auth_get_events_cover_base64image($fileid, $args)
{
$send_data = [
'site_url' => self::$my_site_url,
'auth_token' => get_option('simple_calendar_auth_site_token'),
'fileid' => $fileid,
'arguments' => $args,
];
$request = wp_remote_post(self::$url . 'auth_get_events_cover_base64image', [
'method' => 'POST',
'body' => $send_data,
'timeout' => 30,
'cookies' => [],
]);

$response = wp_remote_retrieve_body($request);
$response_arr = json_decode($response, true);

if (isset($response_arr['response']) && !empty($response_arr['response'])) {
if ($response_arr['response']) {
return $response_arr;
}
} elseif (isset($response_arr['message']) && !empty($response_arr['message'])) {
$response = [
'Error' => $response_arr['message'],
];
return $response;
} else {
$response = [
'response' => false,
'message' => __('Network issue.', 'google-calendar-events'),
];
return $response;
}
}
Comment on lines +254 to +288
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Inconsistent error response structure in network error case.

The network error response structure differs from similar methods in this class. Line 282-286 returns ['response' => false, 'message' => ...], while auth_get_calendarsevents (line 201-204) returns ['Error' => ...] for the same scenario. This inconsistency complicates error handling for callers.

Apply this diff to align with the existing pattern:

 		} else {
 			$response = [
-				'response' => false,
-				'message' => __('Network issue.', 'google-calendar-events'),
+				'Error' => __('Network issue.', 'google-calendar-events'),
 			];
 			return $response;
 		}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public function auth_get_events_cover_base64image($fileid, $args)
{
$send_data = [
'site_url' => self::$my_site_url,
'auth_token' => get_option('simple_calendar_auth_site_token'),
'fileid' => $fileid,
'arguments' => $args,
];
$request = wp_remote_post(self::$url . 'auth_get_events_cover_base64image', [
'method' => 'POST',
'body' => $send_data,
'timeout' => 30,
'cookies' => [],
]);
$response = wp_remote_retrieve_body($request);
$response_arr = json_decode($response, true);
if (isset($response_arr['response']) && !empty($response_arr['response'])) {
if ($response_arr['response']) {
return $response_arr;
}
} elseif (isset($response_arr['message']) && !empty($response_arr['message'])) {
$response = [
'Error' => $response_arr['message'],
];
return $response;
} else {
$response = [
'response' => false,
'message' => __('Network issue.', 'google-calendar-events'),
];
return $response;
}
}
public function auth_get_events_cover_base64image($fileid, $args)
{
$send_data = [
'site_url' => self::$my_site_url,
'auth_token' => get_option('simple_calendar_auth_site_token'),
'fileid' => $fileid,
'arguments' => $args,
];
$request = wp_remote_post(self::$url . 'auth_get_events_cover_base64image', [
'method' => 'POST',
'body' => $send_data,
'timeout' => 30,
'cookies' => [],
]);
$response = wp_remote_retrieve_body($request);
$response_arr = json_decode($response, true);
if (isset($response_arr['response']) && !empty($response_arr['response'])) {
if ($response_arr['response']) {
return $response_arr;
}
} elseif (isset($response_arr['message']) && !empty($response_arr['message'])) {
$response = [
'Error' => $response_arr['message'],
];
return $response;
} else {
$response = [
'Error' => __('Network issue.', 'google-calendar-events'),
];
return $response;
}
}
🤖 Prompt for AI Agents
In includes/oauthhelper/oauth-service-actions.php around lines 254 to 288, the
network-error branch returns an object with keys ['response' => false, 'message'
=> ...] which is inconsistent with other methods (e.g. auth_get_calendarsevents)
that return ['Error' => ...]; change the final else branch to return an array
with a single 'Error' key containing the __('Network issue.',
'google-calendar-events') message so callers receive the same error structure as
other methods.

} //class End

new Oauth_Ajax();