Making WordPress.org

Changeset 11728


Ignore:
Timestamp:
04/01/2022 03:30:53 AM (3 years ago)
Author:
dd32
Message:

Plugin Directory: Stats Report: Fix the first request to the HelpScout API endpoints.

  • The first non-cached request to the HelpScout API failed to use the proper Authorization header format, due to a missing BEARER prefix.
  • Increased the API timeout for HelpScout to 15s, although it probably doesn't need it.
  • Make it more obvious that something is wrong with the HelpScout details, by returning 0's for all numbers, rather than just one or two of them.

See #4306.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/tools/class-stats-report.php

    r11726 r11728  
    171171        $email_report    = HelpScout::api( '/v2/reports/email', $api_payload );
    172172
     173        // If any of the API's are unavailable, make it obvious that the requests have failed, but returning 0's for everything.
     174        if ( ! $company_report || ! $mailbox_overall || ! $email_report ) {
     175            $company_report = $mailbox_overall = $email_report = false;
     176        }
     177
    173178        $stats['helpscout_queue_total_conversations']     = $mailbox_overall->current->totalConversations ?? 0;
    174179        $stats['helpscout_queue_new_conversations']       = $mailbox_overall->current->newConversations ?? 0;
    175180        $stats['helpscout_queue_customers']               = $mailbox_overall->current->customers ?? 0;
    176181        $stats['helpscout_queue_conversations_per_day']   = $mailbox_overall->current->conversationsPerDay ?? 0;
    177         $stats['helpscout_queue_busiest_day']             = gmdate( 'l', strtotime( 'Sunday +' . $mailbox_overall->busiestDay->day . ' days' ) ); // Hacky? but works
     182        $stats['helpscout_queue_busiest_day']             = gmdate( 'l', strtotime( 'Sunday +' . ( $mailbox_overall->busiestDay->day ?? 0 ) . ' days' ) ); // Hacky? but works
    178183        $stats['helpscout_queue_messages_received']       = $mailbox_overall->current->messagesReceived ?? 0;
    179184        $stats['helpscout_queue_replies_sent']            = $company_report->current->totalReplies;
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/clients/class-helpscout.php

    r11726 r11728  
    99class HelpScout {
    1010    const API_BASE = 'https://api.helpscout.net';
     11
     12    /**
     13     * The HTTP timeout for the HelpScout API.
     14     */
     15    const TIMEOUT = 15;
    1116
    1217    public static function api( $url, $args = null, $method = 'GET' ) {
     
    3338                    'Authorization' => self::get_auth_string(),
    3439                ],
     40                'timeout' => self::TIMEOUT,
    3541                'body'    => ( 'POST' === $method && $args ) ? $args : null,
    3642            )
     
    5258            self::API_BASE . '/v2/oauth2/token',
    5359            array(
    54                 'body' => array(
     60                'timeout' => self::TIMEOUT,
     61                'body'    => array(
    5562                    'grant_type'    => 'client_credentials',
    5663                    'client_id'     => HELPSCOUT_APP_ID,
     
    7279        set_site_transient( __CLASS__ . 'get_auth_token', [ 'exp' => time() + $expiry, 'token' => $token ], $expiry );
    7380
    74         return $token;
     81        return 'BEARER ' . $token;
    7582    }
    7683
Note: See TracChangeset for help on using the changeset viewer.