Skip to content

Commit

Permalink
Merge branch 'develop' into renovate/actions-setup-node-3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffpaul authored Mar 1, 2022
2 parents a37049c + 3782696 commit daf60ea
Show file tree
Hide file tree
Showing 7 changed files with 810 additions and 560 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file, per [the Ke

## [Unreleased] - TBD

## [1.0.10] - 2022-02-28
### Changed
- Sets the default timeout of the first Sophi request and the cron request to 3 seconds (props [@oscarssanchez](https://github.com/oscarssanchez), [@barryceelen](https://github.com/barryceelen), [@felipeelia](https://github.com/felipeelia), [@tott](https://github.com/tott) via [#198](https://github.com/globeandmail/sophi-for-wordpress/pull/198)).

### Security
- Update dependency `snowplow/snowplow-tracker` from 0.4.0 to 0.5.0 (props [@renovate](https://github.com/apps/renovate) via [#186](https://github.com/globeandmail/sophi-for-wordpress/pull/186)).

## [1.0.9] - 2022-02-18
### Added
- `hostname` and `path` fields to schema (props [@Rahmon](https://github.com/Rahmon), [@dinhtungdu](https://github.com/dinhtungdu) via [#164](https://github.com/globeandmail/sophi-for-wordpress/pull/164)).
Expand Down Expand Up @@ -118,6 +125,7 @@ All notable changes to this project will be documented in this file, per [the Ke
- Initial public release! 🎉

[Unreleased]: https://github.com/globeandmail/sophi-for-wordpress/compare/trunk...develop
[1.0.10]: https://github.com/globeandmail/sophi-for-wordpress/compare/1.0.9...1.0.10
[1.0.9]: https://github.com/globeandmail/sophi-for-wordpress/compare/1.0.8...1.0.9
[1.0.8]: https://github.com/globeandmail/sophi-for-wordpress/compare/1.0.7...1.0.8
[1.0.7]: https://github.com/globeandmail/sophi-for-wordpress/compare/1.0.6...1.0.7
Expand Down
2 changes: 1 addition & 1 deletion CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The following individuals are responsible for curating the list of issues, respo

Thank you to all the people who have already contributed to this repository via bug reports, code, design, ideas, project management, translation, testing, etc.

[Jeffrey Paul (@jeffpaul)](https://github.com/jeffpaul), [Tung Du (@dinhtungdu)](https://github.com/dinhtungdu), [Darin Kotter (@dkotter)](https://github.com/dkotter), [Helen Hou-Sandí (@helen)](https://github.com/helen), [Diana Padron (@dianapadron)](https://profiles.wordpress.org/dianapadron), [Jozsef Kozo (@kojraai)](https://github.com/kojraai), [Barry Ceelen (@barryceelen)](https://github.com/barryceelen), [Ramon Ahnert (@Rahmon)](https://github.com/Rahmon), [Felipe Elia (@felipeelia)](https://github.com/felipeelia), [Thorsten Ott (@tott)](https://github.com/tott), [Alasdair McKie (@amckie)](https://github.com/amckie), [Oscar Sanchez S. (@oscarssanchez)](https://github.com/oscarssanchez).
[Jeffrey Paul (@jeffpaul)](https://github.com/jeffpaul), [Tung Du (@dinhtungdu)](https://github.com/dinhtungdu), [Darin Kotter (@dkotter)](https://github.com/dkotter), [Helen Hou-Sandí (@helen)](https://github.com/helen), [Diana Padron (@dianapadron)](https://profiles.wordpress.org/dianapadron), [Jozsef Kozo (@kojraai)](https://github.com/kojraai), [Barry Ceelen (@barryceelen)](https://github.com/barryceelen), [Ramon Ahnert (@Rahmon)](https://github.com/Rahmon), [Felipe Elia (@felipeelia)](https://github.com/felipeelia), [Thorsten Ott (@tott)](https://github.com/tott), [Alasdair McKie (@amckie)](https://github.com/amckie), [Oscar Sanchez S. (@oscarssanchez)](https://github.com/oscarssanchez), [Thorsten Ott (@tott)](https://github.com/tott).

## Libraries

Expand Down
20 changes: 12 additions & 8 deletions includes/classes/SiteAutomation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ public function __construct( $auth ) {
*
* @param string $page Page name.
* @param string $widget Widget name.
* @param float $timeout The request timeout value.
*
* @return array|bool
*/
public function get( $page, $widget ) {
public function get( $page, $widget, $timeout = 3 ) {
$this->page = $page;
$this->widget = $widget;
$this->api_url = $this->set_api_url( $page, $widget );
Expand Down Expand Up @@ -103,7 +104,7 @@ public function get( $page, $widget ) {
return $site_automation_data;
}

$response = $this->request();
$response = $this->request( $timeout );

if ( is_wp_error( $response ) ) {
$this->set_status(
Expand Down Expand Up @@ -147,7 +148,7 @@ private function retry() {
* @param string $widget Widget name.
*/
public function do_cron( $page, $widget ) {
$this->get( $page, $widget );
$this->get( $page, $widget, 3 );
}

/**
Expand Down Expand Up @@ -187,9 +188,11 @@ private function set_status( $data ) {
/**
* Get curated data from Sophi Site Automation API.
*
* return
* @param float $timeout The request timeout value.
*
* @return mixed WP_Error on failure or body request on success.
*/
private function request() {
private function request( $timeout ) {
$access_token = $this->auth->get_access_token();

if ( is_wp_error( $access_token ) ) {
Expand All @@ -200,13 +203,14 @@ private function request() {
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $access_token,
]
],
];

if ( function_exists( 'vip_safe_wp_remote_get' ) ) {
$request = vip_safe_wp_remote_get( $this->api_url, false, 3, 1, 20, $args );
$request = vip_safe_wp_remote_get( $this->api_url, '', 3, $timeout, 20, $args );
} else {
$request = wp_remote_get( $this->api_url, $args ); // phpcs:ignore
$args['timeout'] = $timeout;
$request = wp_remote_get( $this->api_url, $args ); // phpcs:ignore
}

if ( is_wp_error( $request ) ) {
Expand Down
Loading

0 comments on commit daf60ea

Please sign in to comment.