DeactivationTracker
3 weeks ago
OptInNotice
3 weeks ago
SenderRegistrator.php
3 weeks ago
SenderToOctolize.php
3 weeks ago
TrackerInitializer.php
3 weeks ago
SenderToOctolize.php
47 lines
| 1 | <?php |
| 2 | |
| 3 | namespace FSVendor\Octolize\Tracker; |
| 4 | |
| 5 | /** |
| 6 | * Can send tracked data to Octolize. |
| 7 | */ |
| 8 | class SenderToOctolize implements \WPDesk_Tracker_Sender |
| 9 | { |
| 10 | /** |
| 11 | * URL to the WP Desk Tracker API endpoint. |
| 12 | * @var string |
| 13 | */ |
| 14 | private $api_url = 'https://data.octolize.org/?track=1'; |
| 15 | private $test_api_url = 'https://testdata.octolize.org/?track=1'; |
| 16 | /** |
| 17 | * Sends payload to predefined receiver. |
| 18 | * |
| 19 | * @param array $payload Payload to send. |
| 20 | * |
| 21 | * @return array If succeeded. Array containing 'headers', 'body', 'response', 'cookies', 'filename'. |
| 22 | * @throws \WPDesk_Tracker_Sender_Exception_WpError Error if send failed. |
| 23 | * |
| 24 | */ |
| 25 | public function send_payload(array $payload) |
| 26 | { |
| 27 | \FSVendor\WPDesk_Logger_Factory::log_message("Target URL: " . $this->get_api_url(), 'octolize-sender', \FSVendor\WPDesk_Logger::DEBUG); |
| 28 | $response = \wp_remote_post($this->get_api_url(), array('method' => 'POST', 'timeout' => 5, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => \false, 'headers' => array('user-agent' => 'OctolizeSender'), 'body' => json_encode($payload), 'cookies' => array())); |
| 29 | if ($response instanceof \WP_Error) { |
| 30 | throw new \FSVendor\WPDesk_Tracker_Sender_Exception_WpError('Payload send error', $response); |
| 31 | } else { |
| 32 | return $response; |
| 33 | } |
| 34 | } |
| 35 | /** |
| 36 | * @return string |
| 37 | */ |
| 38 | private function get_api_url() |
| 39 | { |
| 40 | $api_url = $this->api_url; |
| 41 | if (apply_filters('wpdesk_tracker_use_testdata', \false)) { |
| 42 | $api_url = $this->test_api_url; |
| 43 | } |
| 44 | return $api_url; |
| 45 | } |
| 46 | } |
| 47 |