PluginProbe
Datafeedr API / 1.4.3
Datafeedr API v1.4.3
1.4.3 1.4.2 1.0.125 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.3 1.0.30 1.0.31 1.0.32 All 182 releases
← All changes | libraries/datafeedr.php +569 -135 1.0.125 → 1.4.3 View file →
@@ -39,8 +39,9 @@
39 39 protected $_transport;
40 40 protected $_https;
41 41 protected $_url;
42 42 protected $_userAgent;
43 + protected $_domain;
43 44
44 45 protected $_status;
45 46 protected $_errors;
46 47
@@ -55,9 +56,10 @@
55 56
56 57 /**
57 58 * DatafeedrApi constructor.
58 59 *
59 - * @param string $accessId Datafeedr API Access ID.
60 + * @since 1.0.0
61 + *
60 62 * @param string $secretKey Datafeedr API Secret Key.
61 63 * @param array $options Options.
62 64 *
63 65 * Possble options:
@@ -75,11 +77,11 @@
75 77 * or a callable object that should accept a URL, an array of headers and a string of post data and
76 78 * should return an array [int http response status, string response body].
77 79 *
78 80 *
81 + * @param string $accessId Datafeedr API Access ID.
82 + *
79 83 * @throws DatafeedrError Throws error if any option is invalid.
80 - * @since 1.0.0
81 - *
82 84 */
83 85 public function __construct( $accessId, $secretKey, $options = null ) {
84 86
85 87 $this->_accessId = $accessId;
@@ -99,11 +101,11 @@
99 101
100 102 /**
101 103 * Returns API status information.
102 104 *
103 - * @return array An array of API Status information.
104 105 * @since 1.0.0
105 106 *
107 + * @return array An array of API Status information.
106 108 */
107 109 public function getStatus() {
108 110 $this->apiCall( 'status' );
109 111
@@ -114,11 +116,11 @@
114 116 * Return status information from the last request.
115 117 *
116 118 * If no API request has been made, return NULL
117 119 *
118 - * @return array|null Status information or NULL.
119 120 * @since 1.0.0
120 121 *
122 + * @return array|null Status information or NULL.
121 123 */
122 124 public function lastStatus() {
123 125 return $this->_status;
124 126 }
@@ -125,15 +127,16 @@
125 127
126 128 /**
127 129 * Return the list of networks.
128 130 *
129 - * @param integer|array $networkId Optional. Network ID or an array of network IDs.
131 + * @since 1.0.0
132 + *
130 133 * @param boolean $includeEmpty Optional. If FALSE, omit networks with 0 products.
131 134 * @param array $fields Optional. An array of fields to retrieve.
132 135 *
136 + * @param integer|array $networkId Optional. Network ID or an array of network IDs.
137 + *
133 138 * @return array An array of Networks.
134 - * @since 1.0.0
135 - *
136 139 */
137 140 public function getNetworks( $networkId = null, $includeEmpty = false, $fields = null ) {
138 141
139 142 $request = array();
@@ -155,15 +158,16 @@
155 158
156 159 /**
157 160 * Return the list of merchants.
158 161 *
159 - * @param integer|array $networkId Optional. Network ID or array of Network IDs.
162 + * @since 1.0.0
163 + *
160 164 * @param bool $includeEmpty Optional. If FALSE, omit merchants with 0 products.
161 165 * @param array $fields Optional. An array of fields to retrieve.
162 166 *
167 + * @param integer|array $networkId Optional. Network ID or array of Network IDs.
168 + *
163 169 * @return array An array of merchants.
164 - * @since 1.0.0
165 - *
166 170 */
167 171 public function getMerchants( $networkId = null, $includeEmpty = false, $fields = null ) {
168 172
169 173 $request = array();
@@ -185,15 +189,16 @@
185 189
186 190 /**
187 191 * Return a list of merchants by their IDs.
188 192 *
189 - * @param integer|array $merchantId Merchant ID or array of Merchant IDs.
193 + * @since 1.0.0
194 + *
190 195 * @param boolean $includeEmpty Optional. If FALSE, omit merchants with 0 products.
191 196 * @param array $fields Optional. An array of fields to retrieve.
192 197 *
198 + * @param integer|array $merchantId Merchant ID or array of Merchant IDs.
199 + *
193 200 * @return array An array of merchants.
194 - * @since 1.0.0
195 - *
196 201 */
197 202 public function getMerchantsById( $merchantId, $includeEmpty = false, $fields = null ) {
198 203
199 204 $request = array();
@@ -211,15 +216,15 @@
211 216
212 217 /**
213 218 * Return a list of searchable fields.
214 219 *
220 + * @since 1.0.0
221 + *
215 222 * @param integer|array $networkId Optional. Network ID or array of network IDs.
216 223 *
217 224 * @return array An array of searchable fields.
218 225 * @todo - Does this return a list of all fields for a specific network or only indexed/searchable fields? Update docs accordingly.
219 226 *
220 - * @since 1.0.0
221 - *
222 227 */
223 228 public function getFields( $networkId = null ) {
224 229
225 230 $request = array();
@@ -235,14 +240,15 @@
235 240
236 241 /**
237 242 * Return a list of products by their IDs.
238 243 *
244 + * @since 1.0.0
245 + *
246 + * @param array $fields Optional. An array of fields to retrieve.
247 + *
239 248 * @param integer|array $productId Product ID or an array of products IDs.
240 - * @param array $fields Optional. An array of fields to retrieve.
241 249 *
242 250 * @return array An array of Products.
243 - * @since 1.0.0
244 - *
245 251 */
246 252 public function getProducts( $productId, $fields = null ) {
247 253
248 254 $request = array();
@@ -260,15 +266,16 @@
260 266
261 267 /**
262 268 * Return a list of Zanox merchant IDs ("zmids").
263 269 *
264 - * @param integer|array $merchantId Merchant ID or an array of merchant IDs.
270 + * @since 1.0.0
271 + *
265 272 * @param integer $adspaceId Zanox Adspace ID.
266 273 * @param string $connectId Zanox Connection ID.
267 274 *
275 + * @param integer|array $merchantId Merchant ID or an array of merchant IDs.
276 + *
268 277 * @return array An array of arrays (adspace_id, merchant_id, program_id, zmid).
269 - * @since 1.0.0
270 - *
271 278 */
272 279 public function getZanoxMerchantIds( $merchantId, $adspaceId, $connectId ) {
273 280
274 281 $request = array();
@@ -284,16 +291,17 @@
284 291
285 292 /**
286 293 * Return a list of PerformanceHorizon campaign references ("camrefs").
287 294 *
288 - * @param integer|array $merchantId Merchant ID or an array of merchant IDs.
295 + * @since 2.0.0
296 + *
289 297 * @param string $applicationKey PerformanceHorizon application_key.
290 298 * @param string $userApiKey PerformanceHorizon user_api_key.
291 299 * @param string $publisherId PerformanceHorizon publisher_id.
292 300 *
301 + * @param integer|array $merchantId Merchant ID or an array of merchant IDs.
302 + *
293 303 * @return array An array of arrays (campaign_id, camref, merchant_id).
294 - * @since 2.0.0
295 - *
296 304 */
297 305
298 306 public function getPerformanceHorizonCamrefs( $merchantId, $applicationKey, $userApiKey, $publisherId ) {
299 307
@@ -311,14 +319,15 @@
311 319
312 320 /**
313 321 * Return a list of Effiliation affiliate ids.
314 322 *
323 + * @since 2.0.2
324 + *
325 + * @param string $apiKey Effiliation api_key.
326 + *
315 327 * @param integer|array $merchantId Merchant ID or an array of merchant IDs.
316 - * @param string $apiKey Effiliation api_key.
317 328 *
318 329 * @return array An array of arrays (affiliate_id, merchant_id).
319 - * @since 2.0.2
320 - *
321 330 */
322 331
323 332 public function getEffiliationAffiliateIds( $merchantId, $apiKey ) {
324 333
@@ -334,11 +343,11 @@
334 343
335 344 /**
336 345 * Create a new DatafeedrSearchRequest object.
337 346 *
338 - * @return DatafeedrSearchRequest
339 347 * @since 1.0.0
340 348 *
349 + * @return DatafeedrSearchRequest
341 350 */
342 351 public function searchRequest() {
343 352 return new DatafeedrSearchRequest( $this );
344 353 }
@@ -345,11 +354,11 @@
345 354
346 355 /**
347 356 * Create a new DatafeedrMerchantSearchRequest object.
348 357 *
349 - * @return DatafeedrMerchantSearchRequest
350 358 * @since 1.0.0
351 359 *
360 + * @return DatafeedrMerchantSearchRequest
352 361 */
353 362 public function merchantSearchRequest() {
354 363 return new DatafeedrMerchantSearchRequest( $this );
355 364 }
@@ -356,16 +365,17 @@
356 365
357 366 /**
358 367 * Create a new DatafeedrAmazonSearchRequest object.
359 368 *
360 - * @param string $awsAccessKeyId Amazon Access Key.
369 + * @since 1.0.0
370 + *
361 371 * @param string $awsSecretKey Amazon Secret Key.
362 372 * @param string $awsAssociateTag Amazon Associates tag.
363 373 * @param string $locale The country locale code.
364 374 *
375 + * @param string $awsAccessKeyId Amazon Access Key.
376 + *
365 377 * @return DatafeedrAmazonSearchRequest
366 - * @since 1.0.0
367 - *
368 378 */
369 379 public function amazonSearchRequest( $awsAccessKeyId, $awsSecretKey, $awsAssociateTag, $locale = 'US' ) {
370 380 return new DatafeedrAmazonSearchRequest( $this, $awsAccessKeyId, $awsSecretKey, $awsAssociateTag, $locale );
371 381 }
@@ -372,32 +382,44 @@
372 382
373 383 /**
374 384 * Create a new DatafeedrAmazonLookupRequest object.
375 385 *
376 - * @param string $awsAccessKeyId Amazon Access Key.
386 + * @since 1.0.0
387 + *
377 388 * @param string $awsSecretKey Amazon Secret Key.
378 389 * @param string $awsAssociateTag Amazon Associates tag.
379 390 * @param string $locale The country locale code.
380 391 *
392 + * @param string $awsAccessKeyId Amazon Access Key.
393 + *
381 394 * @return DatafeedrAmazonLookupRequest
382 - * @since 1.0.0
383 - *
384 395 */
385 396 public function amazonLookupRequest( $awsAccessKeyId, $awsSecretKey, $awsAssociateTag, $locale = 'US' ) {
386 397 return new DatafeedrAmazonLookupRequest( $this, $awsAccessKeyId, $awsSecretKey, $awsAssociateTag, $locale );
387 398 }
388 399
400 + /** CreatorAPI */
401 + public function amazonCreatorApiSearchRequest( $capiMarketplace = 'US' ) {
402 + return new DatafeedrAmazonCreatorApiSearchRequest( $this, $capiMarketplace = 'US' );
403 + }
404 +
405 + /** CreatorAPI */
406 +// public function amazonCreatorApiLookupRequest( $awsAccessKeyId, $awsSecretKey, $awsAssociateTag, $locale = 'US' ) {
407 +// return new DatafeedrAmazonCreatorApiLookupRequest( $this, $awsAccessKeyId, $awsSecretKey, $awsAssociateTag, $locale );
408 +// }
409 +
389 410 /**
390 411 * Perform the raw API call.
391 412 *
413 + * @since 1.0.0
414 + *
415 + * @param array $request Optional. Request data.
416 + *
392 417 * @param string $action API Action. (Examples: status, merchants, networks, search, etc...)
393 - * @param array $request Optional. Request data.
394 418 *
395 419 * @return array Returns $response array.
396 420 * @throws DatafeedrHTTPError Throws error if request status is not 200.
397 421 *
398 - * @since 1.0.0
399 - *
400 422 */
401 423 public function apiCall( $action, $request = null ) {
402 424
403 425 if ( ! $request ) {
@@ -405,8 +427,9 @@
405 427 }
406 428
407 429 $request['aid'] = $this->_accessId;
408 430 $request['timestamp'] = gmdate( 'Y-m-d H:i:s' );
431 + $request['domain'] = $this->_domain;
409 432
410 433 if ( $this->_https ) {
411 434 $request['akey'] = $this->_secretKey;
412 435 } else {
@@ -468,9 +491,10 @@
468 491 'transport' => 'wordpress_or_curl',
469 492 'timeout' => 30,
470 493 'returnObjects' => false,
471 494 'retry' => 0,
472 - 'retryTimeout' => 5
495 + 'retryTimeout' => 5,
496 + 'domain' => '',
473 497 );
474 498 }
475 499
476 500 /**
@@ -475,13 +499,13 @@
475 499
476 500 /**
477 501 * Parse constructor options.
478 502 *
503 + * @since 2.0.0
504 + *
479 505 * @param array $options .
480 506 *
481 507 * @throws DatafeedrError Throws error if any option is invalid.
482 - * @since 2.0.0
483 - *
484 508 */
485 509 protected function _parseOptions( $options ) {
486 510 $opts = $this->_defaultOptions();
487 511
@@ -502,12 +526,13 @@
502 526
503 527 $this->_url = $pt . '://' . $opts['host'];
504 528 $this->_https = $opts['https'];
505 529 $this->_host = $opts['host'];
506 - $this->_timeout = intval( $opts['timeout'] );
507 - $this->_returnObjects = intval( $opts['returnObjects'] );
508 - $this->_retry = intval( $opts['retry'] );
509 - $this->_retryTimeout = intval( $opts['retryTimeout'] );
530 + $this->_timeout = (int) $opts['timeout'];
531 + $this->_returnObjects = (int) $opts['returnObjects'];
532 + $this->_retry = (int) $opts['retry'];
533 + $this->_retryTimeout = (int) $opts['retryTimeout'];
534 + $this->_domain = (string) $opts['domain'];
510 535
511 536 switch ( $tr ) {
512 537 case 'curl':
513 538 $this->_transport = array( $this, '_transportCurl' );
@@ -546,17 +571,18 @@
546 571
547 572 /**
548 573 * Perform an HTTP request.
549 574 *
550 - * @param string $url
575 + * @since 2.0.0
576 + *
551 577 * @param array $headers
552 578 * @param string $postdata
553 579 *
580 + * @param string $url
581 + *
554 582 * @return array An array of (status, responseBody)
555 583 * @throws DatafeedrConnectionError
556 584 *
557 - * @since 2.0.0
558 - *
559 585 */
560 586 protected function _performRequest( $url, $headers, $postdata ) {
561 587 $retry = $this->_retry;
562 588
@@ -577,13 +603,13 @@
577 603
578 604 /**
579 605 * Convert an ID or an array of IDs to a simple array of IDs.
580 606 *
607 + * @since 1.0.0
608 + *
581 609 * @param integer|string|array $id_or_ids An ID or an array of IDs.
582 610 *
583 611 * @return array An array of IDs.
584 - * @since 1.0.0
585 - *
586 612 */
587 613 protected function _intarray( $id_or_ids ) {
588 614
589 615 if ( is_numeric( $id_or_ids ) ) {
@@ -600,15 +626,16 @@
600 626 /**
601 627 * Returns a specific value from an array or object for a given key or property. If key or
602 628 * property does not exist, returns $default.
603 629 *
604 - * @param array|object $obj An array or object to extract value from.
630 + * @since 1.0.0
631 + *
605 632 * @param string $prop The array key or object property to get the value for.
606 633 * @param null $default Optional. The value to return if $obj or $prop does not exist.
607 634 *
635 + * @param array|object $obj An array or object to extract value from.
636 + *
608 637 * @return mixed|null The returned value.
609 - * @since 1.0.0
610 - *
611 638 */
612 639 protected function _get( $obj, $prop, $default = null ) {
613 640
614 641 if ( is_array( $obj ) && isset( $obj[ $prop ] ) ) {
@@ -624,17 +651,18 @@
624 651
625 652 /**
626 653 * Perform an HTTP POST request using the CURL library.
627 654 *
628 - * @param string $url Request url.
655 + * @since 1.0.0
656 + *
629 657 * @param array $headers Array of headers.
630 658 * @param string $postdata Post data.
631 659 *
660 + * @param string $url Request url.
661 + *
632 662 * @return array (int http status, string response body)
633 663 * @throws DatafeedrConnectionError Throws error if curl_errno() returns an error.
634 664 *
635 - * @since 1.0.0
636 - *
637 665 */
638 666 protected function _transportCurl( $url, $headers, $postdata ) {
639 667
640 668 $ch = curl_init();
@@ -661,17 +689,18 @@
661 689
662 690 /**
663 691 * Perform a HTTP post request using file functions.
664 692 *
665 - * @param string $url Request url.
693 + * @since 1.0.0
694 + *
666 695 * @param array $headers Array of headers.
667 696 * @param string $postdata Post data.
668 697 *
698 + * @param string $url Request url.
699 + *
669 700 * @return array (int http status, string response body)
670 701 * @throws DatafeedrConnectionError Throws error if $response is false.
671 702 *
672 - * @since 1.0.0
673 - *
674 703 */
675 704 protected function _transportFile( $url, $headers, $postdata ) {
676 705
677 706 $options = array(
@@ -700,18 +729,19 @@
700 729
701 730 /**
702 731 * Perform a HTTP post request using Wordpress functions.
703 732 *
704 - * @param string $url Request url.
733 + * @since 1.0.0
734 + *
705 735 * @param array $headers Array of headers.
706 736 * @param string $postdata Post data.
707 737 *
738 + * @param string $url Request url.
739 + *
708 740 * @return array (int http status, string response body)
741 + * @throws DatafeedrConnectionError Throws error if $response is WP_Error and the error code is 'http_request_failed'.
709 742 * @throws DatafeedrHTTPError Throws error if $response is WP_Error.
710 743 *
711 - * @throws DatafeedrConnectionError Throws error if $response is WP_Error and the error code is 'http_request_failed'.
712 - * @since 1.0.0
713 - *
714 744 */
715 745 protected function _transportWordpress( $url, $headers, $postdata ) {
716 746
717 747 $ha = array();
@@ -772,12 +802,12 @@
772 802
773 803 /**
774 804 * DatafeedrSearchRequestBase constructor.
775 805 *
806 + * @since 1.0.0
807 + *
776 808 * @param DatafeedrApi $api
777 809 *
778 - * @since 1.0.0
779 - *
780 810 */
781 811 public function __construct( $api ) {
782 812 $this->_api = $api;
783 813 }
@@ -784,11 +814,11 @@
784 814
785 815 /**
786 816 * Get the number of found products.
787 817 *
788 - * @return integer
789 818 * @since 1.0.0
790 819 *
820 + * @return integer
791 821 */
792 822 public function getFoundCount() {
793 823 return $this->_responseItem( 'found_count', 0 );
794 824 }
@@ -795,11 +825,11 @@
795 825
796 826 /**
797 827 * Get the number of products that can be retrieved from the server.
798 828 *
799 - * @return integer
800 829 * @since 1.0.0
801 830 *
831 + * @return integer
802 832 */
803 833 public function getResultCount() {
804 834 return $this->_responseItem( 'result_count', 0 );
805 835 }
@@ -804,8 +834,19 @@
804 834 return $this->_responseItem( 'result_count', 0 );
805 835 }
806 836
807 837 /**
838 + * Get the complexity score of the current query.
839 + *
840 + * @since 1.2.12
841 + * @return int
842 + * @throws DatafeedrError
843 + */
844 + public function getQueryScore() {
845 + return abs( (int) $this->_responseItem( 'score', 0 ) );
846 + }
847 +
848 + /**
808 849 * Returns the full response from the last search.
809 850 *
810 851 * Possible items in array include the following:
811 852 *
@@ -821,11 +862,11 @@
821 862 * 'time' => integer,
822 863 * 'version' => string,
823 864 * )
824 865 *
825 - * @return array An array of the full response.
826 866 * @since 1.0.0
827 867 *
868 + * @return array An array of the full response.
828 869 */
829 870 public function getResponse() {
830 871 return $this->_lastResponse;
831 872 }
@@ -832,16 +873,17 @@
832 873
833 874 /**
834 875 * Returns a specific item or property from the response data.
835 876 *
877 + * @since 1.0.0
878 + *
879 + * @param mixed $default Return if $prop is not found in the array or object.
880 + *
836 881 * @param string $prop The item or property to get from the response array or object.
837 - * @param mixed $default Return if $prop is not found in the array or object.
838 882 *
839 883 * @return mixed Specific item or property from response data.
840 884 * @throws DatafeedrError Throws error if $this->_lastResponse is NULL.
841 885 *
842 - * @since 1.0.0
843 - *
844 886 */
845 887 protected function _responseItem( $prop, $default ) {
846 888
847 889 if ( is_null( $this->_lastResponse ) ) {
@@ -861,13 +903,13 @@
861 903
862 904 /**
863 905 * Sets the $_lastResponse property to the the full response from the last API request.
864 906 *
865 - * @param string $action The request action (ex. status, search, merchants, networks, etc...)
907 + * @since 1.0.0
908 + *
866 909 * @param array $request The current API request.
867 910 *
868 - * @since 1.0.0
869 - *
911 + * @param string $action The request action (ex. status, search, merchants, networks, etc...)
870 912 */
871 913 function _apiCall( $action, $request = null ) {
872 914 $this->_lastResponse = $this->_api->apiCall( $action, $request );
873 915 }
@@ -891,12 +933,12 @@
891 933
892 934 /**
893 935 * DatafeedrSearchRequest constructor.
894 936 *
937 + * @since 1.0.0
938 + *
895 939 * @param DatafeedrApi $api
896 940 *
897 - * @since 1.0.0
898 - *
899 941 */
900 942 public function __construct( $api ) {
901 943
902 944 parent::__construct( $api );
@@ -913,13 +955,13 @@
913 955
914 956 /**
915 957 * Add a query filter.
916 958 *
959 + * @since 1.0.0
960 + *
917 961 * @param string $filter Query filter.
918 962 *
919 963 * @return DatafeedrSearchRequest Returns $this.
920 - * @since 1.0.0
921 - *
922 964 */
923 965 public function addFilter( $filter ) {
924 966 $this->_query[] = $filter;
925 967
@@ -928,16 +970,17 @@
928 970
929 971 /**
930 972 * Adds a sort field.
931 973 *
974 + * @since 1.0.0
975 + *
976 + * @param integer $order One of DatafeedrApi::SORT_ASCENDING or DatafeedrApi::SORT_DESCENDING
977 + *
932 978 * @param string $field Field name.
933 - * @param integer $order One of DatafeedrApi::SORT_ASCENDING or DatafeedrApi::SORT_DESCENDING
934 979 *
935 980 * @return DatafeedrSearchRequest Returns $this.
936 981 * @throws DatafeedrError Throws error if sort order is invalid.
937 982 *
938 - * @since 1.0.0
939 - *
940 983 */
941 984 public function addSort( $field, $order = DatafeedrApi::SORT_ASCENDING ) {
942 985
943 986 if ( strlen( $field ) && ( $field[0] == '+' || $field[0] == '-' ) ) {
@@ -955,8 +998,10 @@
955 998
956 999 /**
957 1000 * Set which fields to retrieve.
958 1001 *
1002 + * @since 1.0.0
1003 + *
959 1004 * @param array $fields An array of fields to return for each requested item.
960 1005 *
961 1006 * Example:
962 1007 *
@@ -967,10 +1012,8 @@
967 1012 * 'url',
968 1013 * )
969 1014 *
970 1015 * @return DatafeedrSearchRequest Returns $this.
971 - * @since 1.0.0
972 - *
973 1016 */
974 1017 public function setFields( $fields ) {
975 1018 $this->_fields = $fields;
976 1019
@@ -979,13 +1022,13 @@
979 1022
980 1023 /**
981 1024 * Exclude duplicate filter.
982 1025 *
1026 + * @since 1.0.0
1027 + *
983 1028 * @param string $filter Equality filter in form "field1 field2 | field3".
984 1029 *
985 1030 * @return DatafeedrSearchRequest Returns $this.
986 - * @since 1.0.0
987 - *
988 1031 */
989 1032 public function excludeDuplicates( $filter ) {
990 1033
991 1034 if ( is_array( $filter ) ) {
@@ -999,13 +1042,13 @@
999 1042
1000 1043 /**
1001 1044 * Set a limit of number of records to return.
1002 1045 *
1046 + * @since 1.0.0
1047 + *
1003 1048 * @param integer $limit The maximum number of records to return.
1004 1049 *
1005 1050 * @return DatafeedrSearchRequest Returns $this.
1006 - * @since 1.0.0
1007 - *
1008 1051 */
1009 1052 public function setLimit( $limit ) {
1010 1053 $this->_limit = $limit;
1011 1054
@@ -1014,13 +1057,13 @@
1014 1057
1015 1058 /**
1016 1059 * Set an offset for the search.
1017 1060 *
1061 + * @since 1.0.0
1062 + *
1018 1063 * @param integer $offset The offset.
1019 1064 *
1020 1065 * @return DatafeedrSearchRequest Returns $this.
1021 - * @since 1.0.0
1022 - *
1023 1066 */
1024 1067 public function setOffset( $offset ) {
1025 1068 $this->_offset = $offset;
1026 1069
@@ -1029,13 +1072,13 @@
1029 1072
1030 1073 /**
1031 1074 * Set a limit of results by merchant.
1032 1075 *
1076 + * @since 2.0.3
1077 + *
1033 1078 * @param integer $limit The limit.
1034 1079 *
1035 1080 * @return DatafeedrSearchRequest Returns $this.
1036 - * @since 2.0.3
1037 - *
1038 1081 */
1039 1082 public function setMerchantLimit( $limit ) {
1040 1083 $this->_merchantLimit = $limit;
1041 1084
@@ -1066,13 +1109,13 @@
1066 1109 * [min] => 19266666
1067 1110 * )
1068 1111 * )
1069 1112 *
1113 + * @since 1.0.0
1114 + *
1070 1115 * @param integer $groups Number of price groups to create.
1071 1116 *
1072 1117 * @return DatafeedrSearchRequest Returns $this.
1073 - * @since 1.0.0
1074 - *
1075 1118 */
1076 1119 public function setPriceGroups( $groups ) {
1077 1120 $this->_priceGroups = $groups;
1078 1121
@@ -1081,11 +1124,11 @@
1081 1124
1082 1125 /**
1083 1126 * Get networks found in this request.
1084 1127 *
1085 - * @return array
1086 1128 * @since 1.0.0
1087 1129 *
1130 + * @return array
1088 1131 */
1089 1132 public function getNetworks() {
1090 1133 return $this->_responseItem( 'networks', array() );
1091 1134 }
@@ -1092,11 +1135,11 @@
1092 1135
1093 1136 /**
1094 1137 * Get merchants found in this request.
1095 1138 *
1096 - * @return array
1097 1139 * @since 1.0.0
1098 1140 *
1141 + * @return array
1099 1142 */
1100 1143 public function getMerchants() {
1101 1144 return $this->_responseItem( 'merchants', array() );
1102 1145 }
@@ -1125,11 +1168,11 @@
1125 1168 * [min] => 19266666
1126 1169 * )
1127 1170 * )
1128 1171 *
1129 - * @return array An array of price groups and the product count, min and max prices in each group.
1130 1172 * @since 1.0.0
1131 1173 *
1174 + * @return array An array of price groups and the product count, min and max prices in each group.
1132 1175 */
1133 1176 public function getPriceGroups() {
1134 1177 return $this->_responseItem( 'price_groups', array() );
1135 1178 }
@@ -1136,11 +1179,11 @@
1136 1179
1137 1180 /**
1138 1181 * Create a request array to use for querying the API.
1139 1182 *
1140 - * @return array The $request array().
1141 1183 * @since 1.0.0
1142 1184 *
1185 + * @return array The $request array().
1143 1186 */
1144 1187 public function getParams() {
1145 1188
1146 1189 $request = array();
@@ -1184,13 +1227,13 @@
1184 1227
1185 1228 /**
1186 1229 * Run search and return a list of products.
1187 1230 *
1231 + * @since 1.0.0
1232 + *
1188 1233 * @return array An array of products.
1189 1234 * @throws DatafeedrError Throw error if query is empty.
1190 1235 *
1191 - * @since 1.0.0
1192 - *
1193 1236 */
1194 1237 public function execute() {
1195 1238
1196 1239 $params = $this->getParams();
@@ -1218,12 +1261,12 @@
1218 1261
1219 1262 /**
1220 1263 * DatafeedrMerchantSearchRequest constructor.
1221 1264 *
1265 + * @since 1.0.0
1266 + *
1222 1267 * @param DatafeedrApi $api
1223 1268 *
1224 - * @since 1.0.0
1225 - *
1226 1269 */
1227 1270 public function __construct( $api ) {
1228 1271
1229 1272 parent::__construct( $api );
@@ -1237,13 +1280,13 @@
1237 1280
1238 1281 /**
1239 1282 * Add a query filter.
1240 1283 *
1284 + * @since 1.0.0
1285 + *
1241 1286 * @param string $filter Query filter.
1242 1287 *
1243 1288 * @return DatafeedrMerchantSearchRequest Returns $this.
1244 - * @since 1.0.0
1245 - *
1246 1289 */
1247 1290 public function addFilter( $filter ) {
1248 1291 $this->_query [] = $filter;
1249 1292
@@ -1252,16 +1295,17 @@
1252 1295
1253 1296 /**
1254 1297 * Add a sort field.
1255 1298 *
1299 + * @since 1.0.0
1300 + *
1301 + * @param integer $order One of DatafeedrApi::SORT_ASCENDING or DatafeedrApi::SORT_DESCENDING
1302 + *
1256 1303 * @param string $field Field name.
1257 - * @param integer $order One of DatafeedrApi::SORT_ASCENDING or DatafeedrApi::SORT_DESCENDING
1258 1304 *
1259 1305 * @return DatafeedrMerchantSearchRequest Returns $this.
1260 1306 * @throws DatafeedrError Throw error if invalid sort order.
1261 1307 *
1262 - * @since 1.0.0
1263 - *
1264 1308 */
1265 1309 public function addSort( $field, $order = DatafeedrApi::SORT_ASCENDING ) {
1266 1310
1267 1311 if ( strlen( $field ) && ( $field[0] == '+' || $field[0] == '-' ) ) {
@@ -1279,13 +1323,13 @@
1279 1323
1280 1324 /**
1281 1325 * Set which fields to retrieve.
1282 1326 *
1327 + * @since 1.0.0
1328 + *
1283 1329 * @param array $fields An array of field names.
1284 1330 *
1285 1331 * @return DatafeedrMerchantSearchRequest Returns $this.
1286 - * @since 1.0.0
1287 - *
1288 1332 */
1289 1333 public function setFields( $fields ) {
1290 1334 $this->_fields = $fields;
1291 1335
@@ -1294,13 +1338,13 @@
1294 1338
1295 1339 /**
1296 1340 * Set a limit.
1297 1341 *
1342 + * @since 1.0.0
1343 + *
1298 1344 * @param integer $limit Number of items to return.
1299 1345 *
1300 1346 * @return DatafeedrMerchantSearchRequest Returns $this.
1301 - * @since 1.0.0
1302 - *
1303 1347 */
1304 1348 public function setLimit( $limit ) {
1305 1349 $this->_limit = $limit;
1306 1350
@@ -1309,13 +1353,13 @@
1309 1353
1310 1354 /**
1311 1355 * Set an offset.
1312 1356 *
1357 + * @since 1.0.0
1358 + *
1313 1359 * @param integer $offset The offset.
1314 1360 *
1315 1361 * @return DatafeedrMerchantSearchRequest Returns $this.
1316 - * @since 1.0.0
1317 - *
1318 1362 */
1319 1363 public function setOffset( $offset ) {
1320 1364 $this->_offset = $offset;
1321 1365
@@ -1324,11 +1368,11 @@
1324 1368
1325 1369 /**
1326 1370 * Get networks found in this request.
1327 1371 *
1328 - * @return array
1329 1372 * @since 1.0.0
1330 1373 *
1374 + * @return array
1331 1375 */
1332 1376 public function getNetworks() {
1333 1377 return $this->_responseItem( 'networks', array() );
1334 1378 }
@@ -1335,11 +1379,11 @@
1335 1379
1336 1380 /**
1337 1381 * Get merchants found in this request.
1338 1382 *
1339 - * @return array
1340 1383 * @since 1.0.0
1341 1384 *
1385 + * @return array
1342 1386 */
1343 1387 public function getMerchants() {
1344 1388 return $this->_responseItem( 'merchants', array() );
1345 1389 }
@@ -1346,13 +1390,13 @@
1346 1390
1347 1391 /**
1348 1392 * Run search and return an array of merchants.
1349 1393 *
1394 + * @since 1.0.0
1395 + *
1350 1396 * @return array Array of merchants
1351 1397 * @throws DatafeedrError Throws error if query is empty.
1352 1398 *
1353 - * @since 1.0.0
1354 - *
1355 1399 */
1356 1400 public function execute() {
1357 1401
1358 1402 $params = $this->getParams();
@@ -1368,11 +1412,11 @@
1368 1412
1369 1413 /**
1370 1414 * Create a request array to use for querying the API.
1371 1415 *
1372 - * @return array The $request array().
1373 1416 * @since 1.0.0
1374 1417 *
1418 + * @return array The $request array().
1375 1419 */
1376 1420 public function getParams() {
1377 1421
1378 1422 $request = array();
@@ -1419,17 +1463,18 @@
1419 1463
1420 1464 /**
1421 1465 * DatafeedrAmazonRequest constructor
1422 1466 *
1423 - * @param DatafeedrApi $api
1467 + * @since 1.0.0
1468 + *
1424 1469 * @param string $awsAccessKeyId Amazon Access Key.
1425 1470 * @param string $awsSecretKey Amazon Secret Key.
1426 1471 * @param string $awsAssociateTag Amazon Associate tag.
1427 1472 * @param string $locale Optional. Amazon locale (two-letter code).
1428 1473 *
1474 + * @param DatafeedrApi $api
1475 + *
1429 1476 * @throws DatafeedrError Throws error if Amazon Locale is invalid.
1430 - * @since 1.0.0
1431 - *
1432 1477 */
1433 1478 public function __construct( $api, $awsAccessKeyId, $awsSecretKey, $awsAssociateTag, $locale = 'US' ) {
1434 1479
1435 1480 parent::__construct( $api );
@@ -1469,11 +1514,11 @@
1469 1514
1470 1515 /**
1471 1516 * Returns all parameters.
1472 1517 *
1473 - * @return array
1474 1518 * @since 1.0.0
1475 1519 *
1520 + * @return array
1476 1521 */
1477 1522 public function getParams() {
1478 1523 return $this->_params;
1479 1524 }
@@ -1480,14 +1525,15 @@
1480 1525
1481 1526 /**
1482 1527 * Prepare am API request for Amazon.
1483 1528 *
1529 + * @since 3.0.0
1530 + *
1531 + * @param array $params
1532 + *
1484 1533 * @param string $operation
1485 - * @param array $params
1486 1534 *
1487 1535 * @return array
1488 - * @since 3.0.0
1489 - *
1490 1536 */
1491 1537 protected function _amazonRequest( $operation, $params ) {
1492 1538 return array(
1493 1539 'amz_access' => $this->_awsAccessKeyId,
@@ -1509,15 +1555,16 @@
1509 1555
1510 1556 /**
1511 1557 * Add a parameter.
1512 1558 *
1559 + * @since 1.0.0
1560 + *
1561 + * @param string $value Parameter value.
1562 + *
1513 1563 * @param string $name Parameter name.
1514 - * @param string $value Parameter value.
1515 1564 *
1516 1565 * @return DatafeedrAmazonSearchRequest Returns $this.
1517 1566 *
1518 - * @since 1.0.0
1519 - *
1520 1567 * @see https://webservices.amazon.com/paapi5/documentation/search-items.html#ItemLookup-rp
1521 1568 */
1522 1569 public function addParam( $name, $value ) {
1523 1570 $this->_params[ $name ] = $value;
@@ -1530,12 +1577,12 @@
1530 1577 *
1531 1578 * IMPORTANT - The Amazon API returns a MAXIMUM of 10 products per API request and a maximum of
1532 1579 * 50 products per search query.
1533 1580 *
1581 + * @since 1.0.0
1582 + *
1534 1583 * @return array An array of products.
1535 1584 * @throws DatafeedrError
1536 - * @since 1.0.0
1537 - *
1538 1585 */
1539 1586 public function execute() {
1540 1587
1541 1588 $params = array_filter( $this->_params );
@@ -1555,15 +1602,16 @@
1555 1602
1556 1603 /**
1557 1604 * Add a parameter.
1558 1605 *
1606 + * @since 1.0.0
1607 + *
1608 + * @param string|array $value Parameter value or an array of values (up to 10).
1609 + *
1559 1610 * @param string $name Parameter name - one of 'ASIN', 'SKU', 'UPC', 'EAN', 'ISBN'
1560 - * @param string|array $value Parameter value or an array of values (up to 10).
1561 1611 *
1562 1612 * @return DatafeedrAmazonLookupRequest Returns $this.
1563 1613 *
1564 - * @since 1.0.0
1565 - *
1566 1614 * @see https://webservices.amazon.com/paapi5/documentation/get-items.html#ItemLookup-rp
1567 1615 */
1568 1616 public function addParam( $name, $value ) {
1569 1617 $this->_params[ $name ] = $value;
@@ -1573,11 +1621,11 @@
1573 1621
1574 1622 /**
1575 1623 * Run search and return an array of products.
1576 1624 *
1577 - * @return array An array of products.
1578 1625 * @since 1.0.0
1579 1626 *
1627 + * @return array An array of products.
1580 1628 */
1581 1629 public function execute() {
1582 1630
1583 1631 $params = array_filter( $this->_params );
@@ -1600,8 +1648,394 @@
1600 1648 return $this->_responseItem( 'products', array() );
1601 1649 }
1602 1650 }
1603 1651
1652 +/** CreatorAPI */
1653 +class DatafeedrAmazonCreatorApiRequest extends DatafeedrSearchRequestBase {
1654 +
1655 + protected $_found = - 1;
1656 +
1657 + protected $_hosts;
1658 + protected $_params;
1659 +// protected $_capiCredentialId;
1660 +// protected $_capiCredentialSecret;
1661 +// protected $_capiVersion;
1662 + protected $_capiPartnerTag;
1663 + protected $_capiMarketplace;
1664 +
1665 + public const AWS_VERSION = "2026-01-05";
1666 +
1667 + public function __construct( $api, $capiMarketplace = 'US' ) {
1668 +
1669 + parent::__construct( $api );
1670 +
1671 + $capiMarketplace = strtoupper( trim( $capiMarketplace ) );
1672 +
1673 + foreach ( dfrapi_get_capi_marketplaces() as $code => $marketplace ) {
1674 + $this->_hosts[ $code ] = $marketplace['domain'];
1675 + }
1676 +
1677 + if ( ! isset( $this->_hosts[ $capiMarketplace ] ) ) {
1678 + throw new DatafeedrError( 'Invalid Amazon CAPI locale' );
1679 + }
1680 +
1681 + $this->_params = array();
1682 +
1683 +// $capiVersion = dfrapi_get_capi_marketplace( $capiMarketplace )['region']['version'];
1684 +
1685 +// $this->_capiCredentialId = $capiCredentialId;
1686 +// $this->_capiCredentialSecret = $capiCredentialSecret;
1687 +// $this->_capiVersion = $capiVersion;
1688 +// $this->_capiPartnerTag = $capiPartnerTag;
1689 + $this->_capiMarketplace = $capiMarketplace;
1690 + }
1691 +
1692 + /**
1693 + * Returns all parameters.
1694 + *
1695 + * @since 1.0.0
1696 + *
1697 + * @return array
1698 + */
1699 + public function getParams() {
1700 + return $this->_params;
1701 + }
1702 +
1703 + /**
1704 + * Prepare am API request for Amazon.
1705 + *
1706 + * @since 3.0.0
1707 + *
1708 + * @param array $params
1709 + *
1710 + * @param string $operation
1711 + *
1712 + * @return array
1713 + */
1714 +// protected function _amazonRequest( $operation, $params ) {
1715 +// return array(
1716 +// 'capi_credential_id' => $this->_capiCredentialId,
1717 +// 'capi_credential_secret' => $this->_capiCredentialSecret,
1718 +// 'capi_version' => $this->_capiVersion,
1719 +// 'capi_partner_tag' => $this->_capiPartnerTag,
1720 +// 'capi_marketplace' => $this->_capiMarketplace,
1721 +// 'operation' => $operation,
1722 +// 'params' => $params,
1723 +// );
1724 +// }
1725 +}
1726 +
1727 +/** CreatorAPI */
1728 +class DatafeedrAmazonCreatorApiSearchRequest extends DatafeedrAmazonCreatorApiRequest {
1729 +
1730 + /**
1731 + * Add a parameter.
1732 + *
1733 + * @since 1.0.0
1734 + *
1735 + * @param string $value Parameter value.
1736 + *
1737 + * @param string $name Parameter name.
1738 + *
1739 + * @return DatafeedrAmazonCreatorApiSearchRequest Returns $this.
1740 + *
1741 + * @see https://webservices.amazon.com/paapi5/documentation/search-items.html#ItemLookup-rp
1742 + */
1743 + public function addParam( $name, $value ) {
1744 + $this->_params[ $name ] = $value;
1745 +
1746 + return $this;
1747 + }
1748 +
1749 + /**
1750 + * Run search and return an array of products.
1751 + *
1752 + * IMPORTANT - The Amazon API returns a MAXIMUM of 10 products per API request and a maximum of
1753 + * 50 products per search query.
1754 + *
1755 + * @since 1.0.0
1756 + *
1757 + * @return array An array of products.
1758 + * @throws DatafeedrError
1759 + */
1760 + public function execute() {
1761 +
1762 + $access_token = dfrapi_get_capi_access_token();
1763 +
1764 + if ( is_wp_error( $access_token ) ) {
1765 + throw new DatafeedrError( $access_token->get_error_message() );
1766 + }
1767 +
1768 + $body = array_merge( array_filter( $this->_params ), [] );
1769 +
1770 + $credentials = dfrapi_get_capi_credentials();
1771 + $marketplace = dfrapi_get_capi_marketplace( $this->_capiMarketplace );
1772 +
1773 + $domain = $marketplace['domain'];
1774 + $credential_version = $marketplace['region']['version'];
1775 + $body['partnerTag'] = $credentials['partner_tag'];
1776 +
1777 + // https://affiliate-program.amazon.com/creatorsapi/docs/en-us/api-reference/operations/search-items
1778 + $resources = [
1779 +// 'browseNodeInfo.browseNodes',
1780 +// 'browseNodeInfo.browseNodes.ancestor',
1781 +// 'browseNodeInfo.browseNodes.salesRank',
1782 +// 'browseNodeInfo.websiteSalesRank',
1783 + 'customerReviews.count',
1784 + 'customerReviews.starRating',
1785 + 'images.primary.highRes',
1786 + 'images.primary.large',
1787 + 'images.primary.medium',
1788 + 'images.primary.small',
1789 +// 'images.variants.highRes',
1790 +// 'images.variants.large',
1791 +// 'images.variants.medium',
1792 +// 'images.variants.small',
1793 + 'itemInfo.byLineInfo',
1794 +// 'itemInfo.classifications',
1795 +// 'itemInfo.contentInfo',
1796 +// 'itemInfo.contentRating',
1797 + 'itemInfo.externalIds',
1798 +// 'itemInfo.features',
1799 +// 'itemInfo.manufactureInfo',
1800 + 'itemInfo.productInfo',
1801 +// 'itemInfo.technicalInfo',
1802 + 'itemInfo.title',
1803 + 'itemInfo.tradeInInfo',
1804 + 'offersV2.listings.availability',
1805 + 'offersV2.listings.condition',
1806 +// 'offersV2.listings.dealDetails',
1807 +// 'offersV2.listings.isBuyBoxWinner',
1808 +// 'offersV2.listings.loyaltyPoints',
1809 +// 'offersV2.listings.merchantInfo',
1810 + 'offersV2.listings.price',
1811 + 'offersV2.listings.type',
1812 + 'parentASIN',
1813 +// 'searchRefinements',
1814 + ];
1815 +
1816 + $body['resources'] = $resources;
1817 +
1818 + $response = wp_remote_post(
1819 + 'https://creatorsapi.amazon/catalog/v1/searchItems',
1820 + [
1821 + 'headers' => [
1822 + 'Authorization' => sprintf(
1823 + 'Bearer %s, Version %s',
1824 + $access_token,
1825 + $credential_version
1826 + ),
1827 + 'Content-Type' => 'application/json',
1828 + 'x-marketplace' => $domain,
1829 + ],
1830 + 'body' => wp_json_encode( $body ),
1831 + 'timeout' => 20,
1832 + 'httpversion' => '1.1', // important for Amazon APIs
1833 + ]
1834 + );
1835 +
1836 + if ( is_wp_error( $response ) ) {
1837 + error_log( $response->get_error_message() );
1838 +
1839 + throw new DatafeedrConnectionError( $response->get_error_message() );
1840 + }
1841 +
1842 + $status = wp_remote_retrieve_response_code( $response );
1843 +
1844 + if ( 404 === $status ) {
1845 + $body = wp_remote_retrieve_body( $response );
1846 + $data = json_decode( $body, true );
1847 + if ( isset( $data['type'] ) && 'ResourceNotFoundException' === $data['type'] ) {
1848 + return [];
1849 + }
1850 + }
1851 +
1852 + if ( 200 !== $status ) {
1853 + $error_body = wp_remote_retrieve_body( $response );
1854 + $error_data = json_decode( $error_body, true );
1855 + $status_message = wp_remote_retrieve_response_message( $response );
1856 +
1857 + if ( ! empty( $error_data['message'] ) ) {
1858 + $message = $error_data['message'];
1859 + } elseif ( ! empty( $error_data['reason'] ) ) {
1860 + $message = $error_data['reason'];
1861 + } else {
1862 + $message = $status_message;
1863 + }
1864 +
1865 + error_log( sprintf( '[Datafeedr CAPI] SearchItems error (%d): %s | Response: %s', $status, $message, $error_body ) );
1866 +
1867 + throw new DatafeedrHTTPError( $message, $status );
1868 + }
1869 +
1870 + $body = wp_remote_retrieve_body( $response );
1871 +
1872 +
1873 + /*
1874 +
1875 + [
1876 + "errors" => null,
1877 + "searchResult" => [
1878 + "items" => [
1879 + [
1880 + "asin" => "0545162076",
1881 + "browseNodeInfo" => null,
1882 + "customerReviews" => null,
1883 + "detailPageURL" => "https://www.amazon.com/dp/0545162076?tag=xyz-20&linkCode=osi&th=1&psc=1",
1884 + "images" => null,
1885 + "itemInfo" => [
1886 + "byLineInfo" => null,
1887 + "classifications" => null,
1888 + "contentInfo" => null,
1889 + "contentRating" => null,
1890 + "externalIds" => null,
1891 + "features" => null,
1892 + "manufactureInfo" => null,
1893 + "productInfo" => null,
1894 + "technicalInfo" => null,
1895 + "title" => [
1896 + "displayValue" => "Harry Potter Paperback Box Set (Books 1-7)",
1897 + "label" => "Title",
1898 + "locale" => "en_US",
1899 + ],
1900 + "tradeInInfo" => null,
1901 + ],
1902 + "offersV2" => null,
1903 + "parentASIN" => null,
1904 + "score" => null,
1905 + "variationAttributes" => null,
1906 + ],
1907 + [ ... ],
1908 + [ ... ],
1909 + [ ... ],
1910 + ],
1911 + "searchRefinements" => null,
1912 + "searchURL" => "https://www.amazon.com/s?k=Harry+Potter&rh=p_n_availability%3A2661600011&tag=xyz-20&linkCode=osi",
1913 + "totalResultCount" => 306,
1914 + ],
1915 + ]
1916 +
1917 +
1918 + */
1919 + /**
1920 + * [
1921 + * "errors" => null,
1922 + * "searchResult" => [
1923 + * "items" => [
1924 + * [
1925 + * "asin" => "0545162076",
1926 + * "browseNodeInfo" => null,
1927 + * "customerReviews" => null,
1928 + * "detailPageURL" => "https://www.amazon.com/dp/0545162076?tag=xyz-20&linkCode=osi&th=1&psc=1",
1929 + * "images" => null,
1930 + * "itemInfo" => [
1931 + * "byLineInfo" => null,
1932 + * "classifications" => null,
1933 + * "contentInfo" => null,
1934 + * "contentRating" => null,
1935 + * "externalIds" => null,
1936 + * "features" => null,
1937 + * "manufactureInfo" => null,
1938 + * "productInfo" => null,
1939 + * "technicalInfo" => null,
1940 + * "title" => [
1941 + * "displayValue" => "Harry Potter Paperback Box Set (Books 1-7)",
1942 + * "label" => "Title",
1943 + * "locale" => "en_US",
1944 + * ],
1945 + * "tradeInInfo" => null,
1946 + * ],
1947 + * "offersV2" => null,
1948 + * "parentASIN" => null,
1949 + * "score" => null,
1950 + * "variationAttributes" => null,
1951 + * ],
1952 + * [ ... ],
1953 + * [ ... ],
1954 + * [ ... ],
1955 + * ],
1956 + * "searchRefinements" => null,
1957 + * "searchURL" => "https://www.amazon.com/s?k=Harry+Potter&rh=p_n_availability%3A2661600011&tag=xyz-20&linkCode=osi",
1958 + * "totalResultCount" => 306,
1959 + * ],
1960 + * ]
1961 + */
1962 + $data = json_decode( $body, true );
1963 +
1964 + if ( ! empty( $data['errors'] ) ) {
1965 + $error = $data['errors'][0];
1966 + error_log( $error['message'] );
1967 +
1968 + throw new DatafeedrExternalError( $error['message'] );
1969 + }
1970 +
1971 + $items = $data['searchResult']['items'] ?? [];
1972 + $products = [];
1973 +
1974 + foreach ( $items as $item ) {
1975 + $products[] = dfrapi_transform_capi_item_into_datafeedr_product_array( $item );
1976 + }
1977 +
1978 + return $products;
1979 +
1980 +// $data now contains the API response
1981 +
1982 +
1983 + }
1984 +}
1985 +
1986 +/** CreatorAPI */
1987 +//class DatafeedrAmazonCreatorApiLookupRequest extends DatafeedrAmazonCreatorApiRequest {
1988 +//
1989 +// /**
1990 +// * Add a parameter.
1991 +// *
1992 +// * @since 1.0.0
1993 +// *
1994 +// * @param string|array $value Parameter value or an array of values (up to 10).
1995 +// *
1996 +// * @param string $name Parameter name - one of 'ASIN', 'SKU', 'UPC', 'EAN', 'ISBN'
1997 +// *
1998 +// * @return DatafeedrAmazonCreatorApiLookupRequest Returns $this.
1999 +// *
2000 +// * @see https://webservices.amazon.com/paapi5/documentation/get-items.html#ItemLookup-rp
2001 +// */
2002 +// public function addParam( $name, $value ) {
2003 +// $this->_params[ $name ] = $value;
2004 +//
2005 +// return $this;
2006 +// }
2007 +//
2008 +// /**
2009 +// * Run search and return an array of products.
2010 +// *
2011 +// * @since 1.0.0
2012 +// *
2013 +// * @return array An array of products.
2014 +// */
2015 +// public function execute() {
2016 +//
2017 +// $params = array_filter( $this->_params );
2018 +// $types = array( 'ASIN', 'SKU', 'UPC', 'EAN', 'ISBN', 'asin', 'sku', 'upc', 'ean', 'isbn' );
2019 +//
2020 +// foreach ( $types as $type ) {
2021 +// if ( isset( $params[ $type ] ) ) {
2022 +// $params['itemIdType'] = strtoupper( $type );
2023 +// $params['itemIds'] = $params[ $type ];
2024 +// if ( is_string( $params['itemIds'] ) ) {
2025 +// $params['itemIds'] = explode( ',', $params['itemIds'] );
2026 +// }
2027 +// unset( $params[ $type ] );
2028 +// }
2029 +// }
2030 +//
2031 +// $req = $this->_amazonRequest( 'GetItems', $params );
2032 +// $this->_apiCall( 'amazon_find', $req );
2033 +//
2034 +// return $this->_responseItem( 'products', array() );
2035 +// }
2036 +//}
2037 +
1604 2038 /**
1605 2039 * Class DatafeedrError.
1606 2040 *
1607 2041 * Generic Api error.
@@ -1670,5 +2104,5 @@
1670 2104 *
1671 2105 * API error: Internal server error.
1672 2106 */
1673 2107 class DatafeedrServerError extends DatafeedrError {
1674 -}
2108 +}