@@ -386,31 +386,77 @@ public function get_growth_stats(\DateTime $starting = null, \DateTime $ending =
386
386
}
387
387
388
388
/**
389
- * Gets all forms.
389
+ * Get forms.
390
+ *
391
+ * @param string $status Form status (active|archived|trashed|all).
392
+ * @param boolean $include_total_count To include the total count of records in the response, use true.
393
+ * @param string $after_cursor Return results after the given pagination cursor.
394
+ * @param string $before_cursor Return results before the given pagination cursor.
395
+ * @param integer $per_page Number of results to return.
390
396
*
391
397
* @since 1.0.0
392
398
*
393
399
* @see https://developers.convertkit.com/v4.html#convertkit-api-forms
394
400
*
395
- * @return false|mixed
401
+ * @return false|array<int,\stdClass>
396
402
*/
397
- public function get_forms ()
398
- {
399
- return $ this ->get_resources ('forms ' );
403
+ public function get_forms (
404
+ string $ status = 'active ' ,
405
+ bool $ include_total_count = false ,
406
+ string $ after_cursor = '' ,
407
+ string $ before_cursor = '' ,
408
+ int $ per_page = 100
409
+ ) {
410
+ return $ this ->get (
411
+ endpoint: 'forms ' ,
412
+ args: $ this ->build_total_count_and_pagination_params (
413
+ params: [
414
+ 'type ' => 'embed ' ,
415
+ 'status ' => $ status ,
416
+ ],
417
+ include_total_count: $ include_total_count ,
418
+ after_cursor: $ after_cursor ,
419
+ before_cursor: $ before_cursor ,
420
+ per_page: $ per_page
421
+ )
422
+ );
400
423
}
401
424
402
425
/**
403
- * Gets all landing pages.
426
+ * Get landing pages.
427
+ *
428
+ * @param string $status Form status (active|archived|trashed|all).
429
+ * @param boolean $include_total_count To include the total count of records in the response, use true.
430
+ * @param string $after_cursor Return results after the given pagination cursor.
431
+ * @param string $before_cursor Return results before the given pagination cursor.
432
+ * @param integer $per_page Number of results to return.
404
433
*
405
434
* @since 1.0.0
406
435
*
407
436
* @see https://developers.convertkit.com/v4.html#convertkit-api-forms
408
437
*
409
- * @return false|mixed
438
+ * @return false|array<int,\stdClass>
410
439
*/
411
- public function get_landing_pages ()
412
- {
413
- return $ this ->get_resources ('landing_pages ' );
440
+ public function get_landing_pages (
441
+ string $ status = 'active ' ,
442
+ bool $ include_total_count = false ,
443
+ string $ after_cursor = '' ,
444
+ string $ before_cursor = '' ,
445
+ int $ per_page = 100
446
+ ) {
447
+ return $ this ->get (
448
+ endpoint: 'forms ' ,
449
+ args: $ this ->build_total_count_and_pagination_params (
450
+ params: [
451
+ 'type ' => 'hosted ' ,
452
+ 'status ' => $ status ,
453
+ ],
454
+ include_total_count: $ include_total_count ,
455
+ after_cursor: $ after_cursor ,
456
+ before_cursor: $ before_cursor ,
457
+ per_page: $ per_page
458
+ )
459
+ );
414
460
}
415
461
416
462
/**
@@ -883,121 +929,6 @@ public function get_email_templates(
883
929
);
884
930
}
885
931
886
- /**
887
- * Gets a resource index
888
- * Possible resources: forms, landing_pages, subscription_forms, tags
889
- *
890
- * GET /{$resource}/
891
- *
892
- * @param string $resource Resource type.
893
- *
894
- * @throws \InvalidArgumentException If the resource argument is not a supported resource type.
895
- *
896
- * @return array<int|string, mixed|\stdClass> API response
897
- */
898
- public function get_resources (string $ resource )
899
- {
900
- // Assign the resource to the request variable.
901
- $ request = $ resource ;
902
-
903
- // Landing pages are included in the /forms endpoint.
904
- if ($ resource === 'landing_pages ' ) {
905
- $ request = 'forms ' ;
906
- }
907
-
908
- // Fetch resources.
909
- $ resources = $ this ->get ($ request );
910
-
911
- $ this ->create_log (sprintf ('%s response %s ' , $ resource , json_encode ($ resources )));
912
-
913
- // Return a blank array if no resources exist.
914
- if (!$ resources ) {
915
- $ this ->create_log ('No resources ' );
916
- return [];
917
- }
918
-
919
- // Build array of resources.
920
- $ _resource = [];
921
- switch ($ resource ) {
922
- // Forms.
923
- case 'forms ' :
924
- // Bail if no forms are set.
925
- if (!isset ($ resources ->forms )) {
926
- $ this ->create_log ('No form resources ' );
927
- return [];
928
- }
929
-
930
- // Build array of forms.
931
- foreach ($ resources ->forms as $ form ) {
932
- // Exclude archived forms.
933
- if (isset ($ form ->archived ) && $ form ->archived ) {
934
- continue ;
935
- }
936
-
937
- // Exclude hosted forms.
938
- if ($ form ->type === 'hosted ' ) {
939
- continue ;
940
- }
941
-
942
- $ _resource [] = $ form ;
943
- }
944
- break ;
945
-
946
- // Landing Pages.
947
- case 'landing_pages ' :
948
- // Bail if no landing pages are set.
949
- if (!isset ($ resources ->forms )) {
950
- $ this ->create_log ('No landing page resources ' );
951
- return [];
952
- }
953
-
954
- foreach ($ resources ->forms as $ form ) {
955
- // Exclude archived landing pages.
956
- if (isset ($ form ->archived ) && $ form ->archived ) {
957
- continue ;
958
- }
959
-
960
- // Exclude non-hosted (i.e. forms).
961
- if ($ form ->type !== 'hosted ' ) {
962
- continue ;
963
- }
964
-
965
- $ _resource [] = $ form ;
966
- }
967
- break ;
968
-
969
- // Subscription Forms.
970
- case 'subscription_forms ' :
971
- // Exclude archived subscription forms.
972
- foreach ($ resources as $ mapping ) {
973
- if (isset ($ mapping ->archived ) && $ mapping ->archived ) {
974
- continue ;
975
- }
976
-
977
- $ _resource [$ mapping ->id ] = $ mapping ->form_id ;
978
- }
979
- break ;
980
-
981
- // Tags.
982
- case 'tags ' :
983
- // Bail if no tags are set.
984
- if (!isset ($ resources ->tags )) {
985
- $ this ->create_log ('No tag resources ' );
986
- return [];
987
- }
988
-
989
- foreach ($ resources ->tags as $ tag ) {
990
- $ _resource [] = $ tag ;
991
- }
992
- break ;
993
-
994
- default :
995
- throw new \InvalidArgumentException ('An unsupported resource was specified. ' );
996
- }//end switch
997
-
998
- return $ _resource ;
999
- }
1000
-
1001
932
/**
1002
933
* List subscribers.
1003
934
*
0 commit comments