Add on-demand media URL refresh for expired MLS Grid tokens
MLS Grid media URLs expire after ~24 hours. Instead of running scheduled syncs, this adds on-demand refresh when images are requested: - Add is_url_expired() to parse expires timestamp from media URLs - Add refresh_media_urls() to fetch fresh URLs from API for one listing - Add get_property_media() API method using ListingId filter - Image endpoint checks URL expiration before fetching - If expired, refreshes URLs from API then proceeds with fetch This is more efficient than scheduled full syncs because: - Only refreshes URLs for listings actually being viewed - Zero overhead for unviewed listings - Scales naturally with traffic 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -378,6 +378,42 @@ class MLS_API_Client {
|
||||
return $this->request('Property', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single property by listing ID with media
|
||||
*
|
||||
* Used to refresh media URLs for a specific listing without
|
||||
* fetching the entire dataset.
|
||||
*
|
||||
* Note: MLS Grid only allows filtering by ListingId (not ListingKey)
|
||||
* for the Property resource. The caller must provide the listing_id.
|
||||
*
|
||||
* @param string $listing_id The MLS listing ID (not listing_key)
|
||||
* @return array|WP_Error Property data with Media or error
|
||||
*/
|
||||
public function get_property_media($listing_id) {
|
||||
$params = array();
|
||||
|
||||
$system = $this->options->get_originating_system();
|
||||
|
||||
// Filter by ListingId (MLS Grid only allows certain fields for filtering)
|
||||
$params['$filter'] = "OriginatingSystemName eq '{$system}' and ListingId eq '{$listing_id}'";
|
||||
$params['$expand'] = 'Media';
|
||||
$params['$top'] = 1;
|
||||
|
||||
$response = $this->request('Property', $params);
|
||||
|
||||
if (is_wp_error($response)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
// Return first result or null
|
||||
if (isset($response['value']) && !empty($response['value'])) {
|
||||
return $response['value'][0];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get next page of results
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user