PluginProbe
Sendy / 3.0.7
Sendy v3.0.7
3.4.6 3.4.7 trunk 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 All 32 releases
sendy / src / ApiClientFactory.php

ApiClientFactory.php in Sendy 3.0.7, at src/ApiClientFactory.php

45 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Sendy\WooCommerce;
4
5 use Sendy\Api\Connection;
6
7 class ApiClientFactory
8 {
9 public static function buildBaseConnection(): Connection
10 {
11 return (new Connection())
12 ->setClientId(get_option('sendy_client_id'))
13 ->setClientSecret(get_option('sendy_client_secret'))
14 ->setUserAgentAppendix(
15 sprintf('WordPress/%s WooCommerce/%s Sendy/%s', get_bloginfo('version'), WC_VERSION, Plugin::VERSION)
16 )
17 ->setOauthClient(true)
18 ->setRedirectUrl(sendy_oauth_redirect_url())
19 ->setTokenUpdateCallback(function (Connection $connection) {
20 update_option('sendy_access_token', $connection->getAccessToken());
21 update_option('sendy_refresh_token', $connection->getRefreshToken());
22 update_option('sendy_token_expires', $connection->getTokenExpires());
23 })
24 ;
25 }
26
27 public static function buildConnectionUsingCode(string $code): Connection
28 {
29 return self::buildBaseConnection()->setAuthorizationCode($code);
30 }
31
32 public static function buildConnectionUsingTokens(): Connection
33 {
34 if (get_option('sendy_access_token') == '' || get_option('sendy_refresh_token') == '' || get_option('sendy_token_expires') == '') {
35 throw new \RuntimeException('Please authenticate first before using this method');
36 }
37
38 return self::buildBaseConnection()
39 ->setAccessToken(get_option('sendy_access_token'))
40 ->setRefreshToken(get_option('sendy_refresh_token'))
41 ->setTokenExpires(get_option('sendy_token_expires'))
42 ;
43 }
44 }
45