PluginProbe
Depicter — Popup & Slider Builder / 1.3.3
Depicter — Popup & Slider Builder v1.3.3
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Services / ClientService.php

ClientService.php in Depicter — Popup & Slider Builder 1.3.3, at app/src/Services/ClientService.php

107 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Depicter\Services;
3
4 use Averta\WordPress\Utility\JSON;
5 use Depicter\GuzzleHttp\Exception\GuzzleException;
6
7 class ClientService
8 {
9 /**
10 * ClientService constructor.
11 */
12 public function __construct(){
13 if ( empty( \Depicter::options()->get( 'version_initial' ) ) ) {
14 \Depicter::options()->set( 'version_initial', DEPICTER_VERSION );
15 }
16 }
17
18 /**
19 * Register client info
20 *
21 * @return void
22 */
23 public function authorize() {
24
25 if ( ! empty( \Depicter::cache('base')->get( 'is_client_registered' ) ) ) {
26 return;
27 }
28
29 $params = [
30 'form_params' => [
31 'version' => DEPICTER_VERSION,
32 'version_initial' => \Depicter::options()->get('version_initial'),
33 'info' => \Depicter::options()->get('info')
34 ]
35 ];
36
37 try{
38 $endpoint = \Depicter::remote()->endpoint() . 'v1/client/register';
39 $response = \Depicter::remote()->post( $endpoint, $params );
40
41 if ( $response->getStatusCode() == 200 || $response->getStatusCode() == 204 ) {
42 $payload = JSON::decode( $response->getBody(), true );
43
44 if ( ! empty( $payload['client_key'] ) ) {
45 \Depicter::options()->set( 'client_key', $payload['client_key'] );
46 }
47 }
48
49 } catch ( GuzzleException $e ) {
50 try{
51 $this->reportError([
52 'issueType' => 'depicter-wp-api',
53 'issueRelatesTo' => 'client-registration',
54 'userDescription' => $e->getMessage(). ' | ' . $params['headers']['user-agent']
55 ]);
56 } catch( GuzzleException $e ){}
57 }
58
59 \Depicter::cache('base')->set( 'is_client_registered', true, DAY_IN_SECONDS );
60 }
61
62 /**
63 * Send user feedback
64 *
65 * @param array $bodyParams
66 *
67 * @return bool
68 * @throws GuzzleException
69 */
70 public function reportIssue( $bodyParams = [] ) {
71 $response = \Depicter::remote()->post( 'v1/report/issue', [
72 'form_params' => $bodyParams
73 ]);
74 return $response->getStatusCode() == 200;
75 }
76
77 /**
78 * Send user error reports
79 *
80 * @param array $bodyParams
81 *
82 * @return bool
83 * @throws GuzzleException
84 */
85 public function reportError( $bodyParams = [] ) {
86 $response = \Depicter::remote()->post( 'v1/report/error', [
87 'form_params' => $bodyParams
88 ]);
89 return $response->getStatusCode() == 200;
90 }
91
92 /**
93 * send subscriber
94 * @param array $bodyParams
95 *
96 * @return bool
97 * @throws GuzzleException
98 */
99 public function subscribe( $bodyParams = [] ) {
100 $response = \Depicter::remote()->post( 'v1/subscriber/store', [
101 'form_params' => $bodyParams
102 ]);
103 return $response->getStatusCode() == 200;
104 }
105
106 }
107