Skip to content

Commit 1f86dc9

Browse files
committed
Revert some changes
1 parent 719b523 commit 1f86dc9

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
namespace Helper\WPUnit;
3+
4+
/**
5+
* Helper methods and actions related to the ConvertKit API,
6+
* which are then available using $I->{yourFunctionName}.
7+
*/
8+
class API extends \Codeception\Module
9+
{
10+
/**
11+
* Sends a request to the ConvertKit API, typically used to read an endpoint to confirm
12+
* that data in an Acceptance Test was added/edited/deleted successfully.
13+
*
14+
* @param string $endpoint Endpoint.
15+
* @param string $method Method (GET|POST|PUT).
16+
* @param array $params Endpoint Parameters.
17+
* @return array
18+
*/
19+
public function apiRequest($endpoint, $method = 'GET', $params = array())
20+
{
21+
// Build query parameters.
22+
$params = array_merge(
23+
$params,
24+
[
25+
'api_key' => $_ENV['CONVERTKIT_API_KEY'],
26+
'api_secret' => $_ENV['CONVERTKIT_API_SECRET'],
27+
]
28+
);
29+
30+
// Send request.
31+
try {
32+
$client = new \GuzzleHttp\Client();
33+
$result = $client->request(
34+
$method,
35+
'https://api.convertkit.com/v3/' . $endpoint . '?' . http_build_query($params),
36+
[
37+
'headers' => [
38+
'Accept-Encoding' => 'gzip',
39+
'timeout' => 5,
40+
],
41+
]
42+
);
43+
44+
// Return JSON decoded response.
45+
return json_decode($result->getBody()->getContents(), true);
46+
} catch (\GuzzleHttp\Exception\ClientException $e) {
47+
return [];
48+
}
49+
}
50+
}

tests/wpunit.suite.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ actor: WpunitTester
66
modules:
77
enabled:
88
- WPLoader
9+
- \Helper\WPUnit\API
910

1011
# Codeception supplied classes, which provide assertions and filesystem functions
1112
- \Codeception\Module\Asserts

0 commit comments

Comments
 (0)