Skip to content

Commit 69523a4

Browse files
committed
Adds get, post, put and delete function calls
1 parent 4aff3b7 commit 69523a4

File tree

1 file changed

+72
-13
lines changed

1 file changed

+72
-13
lines changed

src/ConvertKit_API.php

Lines changed: 72 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function get_account()
136136

137137
$this->create_log(sprintf('GET account: %s, %s', $request, json_encode($options)));
138138

139-
return $this->make_request($request, 'GET', $options);
139+
return $this->get($request, $options);
140140
}
141141

142142

@@ -155,7 +155,7 @@ public function get_sequences()
155155

156156
$this->create_log(sprintf('GET sequences: %s, %s', $request, json_encode($options)));
157157

158-
return $this->make_request($request, 'GET', $options);
158+
return $this->get($request, $options);
159159
}
160160

161161

@@ -185,7 +185,7 @@ public function get_sequence_subscriptions(int $sequence_id, string $sort_order
185185
)
186186
);
187187

188-
return $this->make_request($request, 'GET', $options);
188+
return $this->get($request, $options);
189189
}
190190

191191

@@ -216,7 +216,7 @@ public function add_subscriber_to_sequence(int $sequence_id, string $email)
216216
)
217217
);
218218

219-
return $this->make_request($request, 'POST', $options);
219+
return $this->post($request, $options);
220220
}
221221

222222

@@ -242,7 +242,7 @@ public function add_tag(int $tag, array $options)
242242

243243
$this->create_log(sprintf('POST add tag: %s, %s, %s', $request, json_encode($options), $tag));
244244

245-
return $this->make_request($request, 'POST', $options);
245+
return $this->post($request, $options);
246246
}
247247

248248

@@ -275,7 +275,7 @@ public function get_resources(string $resource)
275275

276276
$this->create_log(sprintf('GET request %s, %s', $request, json_encode($options)));
277277

278-
$resources = $this->make_request($request, 'GET', $options);
278+
$resources = $this->get($request, $options);
279279

280280
if (!$resources) {
281281
$this->create_log('No resources');
@@ -369,7 +369,7 @@ public function form_subscribe(int $form_id, array $options)
369369

370370
$this->create_log(sprintf('POST form subscribe: %s, %s, %s', $request, json_encode($options), $form_id));
371371

372-
return $this->make_request($request, 'POST', $options);
372+
return $this->post($request, $options);
373373
}
374374

375375

@@ -394,7 +394,7 @@ public function form_unsubscribe(array $options)
394394

395395
$this->create_log(sprintf('PUT form unsubscribe: %s, %s', $request, json_encode($options)));
396396

397-
return $this->make_request($request, 'PUT', $options);
397+
return $this->put($request, $options);
398398
}
399399

400400

@@ -431,7 +431,7 @@ public function get_subscriber_id(string $email_address)
431431
)
432432
);
433433

434-
$subscribers = $this->make_request($request, 'GET', $options);
434+
$subscribers = $this->get($request, $options);
435435

436436
if (!$subscribers) {
437437
$this->create_log('No subscribers');
@@ -473,7 +473,7 @@ public function get_subscriber(int $subscriber_id)
473473

474474
$this->create_log(sprintf('GET subscriber tags: %s, %s, %s', $request, json_encode($options), $subscriber_id));
475475

476-
return $this->make_request($request, 'GET', $options);
476+
return $this->get($request, $options);
477477
}
478478

479479

@@ -500,7 +500,7 @@ public function get_subscriber_tags(int $subscriber_id)
500500

501501
$this->create_log(sprintf('GET subscriber tags: %s, %s, %s', $request, json_encode($options), $subscriber_id));
502502

503-
return $this->make_request($request, 'GET', $options);
503+
return $this->get($request, $options);
504504
}
505505

506506

@@ -525,7 +525,7 @@ public function list_purchases(array $options)
525525

526526
$this->create_log(sprintf('GET list purchases: %s, %s', $request, json_encode($options)));
527527

528-
return $this->make_request($request, 'GET', $options);
528+
return $this->get($request, $options);
529529
}
530530

531531

@@ -550,7 +550,7 @@ public function create_purchase(array $options)
550550

551551
$this->create_log(sprintf('POST create purchase: %s, %s', $request, json_encode($options)));
552552

553-
return $this->make_request($request, 'POST', $options);
553+
return $this->post($request, $options);
554554
}
555555

556556

@@ -694,6 +694,65 @@ private function strip_html_head_body_tags(string $markup)
694694
return $markup;
695695
}
696696

697+
/**
698+
* Performs a GET request to the API.
699+
*
700+
* @param string $endpoint API Endpoint.
701+
* @param array $args Request arguments.
702+
*
703+
* @throws \InvalidArgumentException If the provided arguments are not of the expected type.
704+
*
705+
* @return false|mixed
706+
*/
707+
public function get(string $endpoint, array $args = [])
708+
{
709+
return $this->make_request($endpoint, 'GET', $args);
710+
}
711+
712+
/**
713+
* Performs a POST request to the API.
714+
*
715+
* @param string $endpoint API Endpoint.
716+
* @param array $args Request arguments.
717+
*
718+
* @throws \InvalidArgumentException If the provided arguments are not of the expected type.
719+
*
720+
* @return false|mixed
721+
*/
722+
public function post(string $endpoint, array $args = [])
723+
{
724+
return $this->make_request($endpoint, 'POST', $args);
725+
}
726+
727+
/**
728+
* Performs a PUT request to the API.
729+
*
730+
* @param string $endpoint API Endpoint.
731+
* @param array $args Request arguments.
732+
*
733+
* @throws \InvalidArgumentException If the provided arguments are not of the expected type.
734+
*
735+
* @return false|mixed
736+
*/
737+
public function put(string $endpoint, array $args = [])
738+
{
739+
return $this->make_request($endpoint, 'PUT', $args);
740+
}
741+
742+
/**
743+
* Performs a DELETE request to the API.
744+
*
745+
* @param string $endpoint API Endpoint.
746+
* @param array $args Request arguments.
747+
*
748+
* @throws \InvalidArgumentException If the provided arguments are not of the expected type.
749+
*
750+
* @return false|mixed
751+
*/
752+
public function delete(string $endpoint, array $args = [])
753+
{
754+
return $this->make_request($endpoint, 'DELETE', $args);
755+
}
697756

698757
/**
699758
* Performs an API request using Guzzle.

0 commit comments

Comments
 (0)