Skip to content

Move api_version property into make_request() #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions src/ConvertKit_API.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private function create_log(string $message)
*/
public function get_account()
{
$request = $this->api_version . '/account';
$request = 'account';

$options = [
'api_secret' => $this->api_secret,
Expand All @@ -147,7 +147,7 @@ public function get_account()
*/
public function get_sequences()
{
$request = $this->api_version . '/sequences';
$request = 'sequences';

$options = [
'api_key' => $this->api_key,
Expand All @@ -169,7 +169,7 @@ public function get_sequences()
*/
public function get_sequence_subscriptions(int $sequence_id, string $sort_order = 'asc')
{
$request = $this->api_version . sprintf('/sequences/%s/subscriptions', $sequence_id);
$request = sprintf('sequences/%s/subscriptions', $sequence_id);

$options = [
'api_secret' => $this->api_secret,
Expand Down Expand Up @@ -199,7 +199,7 @@ public function get_sequence_subscriptions(int $sequence_id, string $sort_order
*/
public function add_subscriber_to_sequence(int $sequence_id, string $email)
{
$request = $this->api_version . sprintf('/courses/%s/subscribe', $sequence_id);
$request = sprintf('courses/%s/subscribe', $sequence_id);

$options = [
'api_key' => $this->api_key,
Expand Down Expand Up @@ -236,7 +236,7 @@ public function add_tag(int $tag, array $options)
throw new \InvalidArgumentException();
}

$request = $this->api_version . sprintf('/tags/%s/subscribe', $tag);
$request = sprintf('tags/%s/subscribe', $tag);

$options['api_key'] = $this->api_key;

Expand Down Expand Up @@ -271,7 +271,13 @@ public function get_resources(string $resource)
'Accept-Encoding' => 'gzip',
];

$request = sprintf('/%s/%s', $this->api_version, (($resource === 'landing_pages') ? 'forms' : $resource));
// Assign the resource to the request variable.
$request = $resource;

// Landing pages are included in the /forms endpoint.
if ($resource === 'landing_pages') {
$request = 'forms';
}

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

Expand Down Expand Up @@ -363,7 +369,7 @@ public function form_subscribe(int $form_id, array $options)
throw new \InvalidArgumentException();
}

$request = $this->api_version . sprintf('/forms/%s/subscribe', $form_id);
$request = sprintf('forms/%s/subscribe', $form_id);

$options['api_key'] = $this->api_key;

Expand All @@ -388,7 +394,7 @@ public function form_unsubscribe(array $options)
throw new \InvalidArgumentException();
}

$request = $this->api_version . '/unsubscribe';
$request = 'unsubscribe';

$options['api_secret'] = $this->api_secret;

Expand All @@ -414,7 +420,7 @@ public function get_subscriber_id(string $email_address)
throw new \InvalidArgumentException();
}

$request = $this->api_version . '/subscribers';
$request = 'subscribers';

$options = [
'api_secret' => $this->api_secret,
Expand Down Expand Up @@ -465,7 +471,7 @@ public function get_subscriber(int $subscriber_id)
throw new \InvalidArgumentException();
}

$request = $this->api_version . sprintf('/subscribers/%s', $subscriber_id);
$request = sprintf('subscribers/%s', $subscriber_id);

$options = [
'api_secret' => $this->api_secret,
Expand All @@ -492,7 +498,7 @@ public function get_subscriber_tags(int $subscriber_id)
throw new \InvalidArgumentException();
}

$request = $this->api_version . sprintf('/subscribers/%s/tags', $subscriber_id);
$request = sprintf('subscribers/%s/tags', $subscriber_id);

$options = [
'api_key' => $this->api_key,
Expand All @@ -519,7 +525,7 @@ public function list_purchases(array $options)
throw new \InvalidArgumentException();
}

$request = $this->api_version . '/purchases';
$request = 'purchases';

$options['api_secret'] = $this->api_secret;

Expand All @@ -544,7 +550,7 @@ public function create_purchase(array $options)
throw new \InvalidArgumentException();
}

$request = $this->api_version . '/purchases';
$request = 'purchases';

$options['api_secret'] = $this->api_secret;

Expand Down Expand Up @@ -771,7 +777,7 @@ public function make_request(string $endpoint, string $method, array $args = [])
throw new \InvalidArgumentException();
}

$url = $this->api_url_base . $endpoint;
$url = $this->api_url_base . $this->api_version . '/' . $endpoint;

$this->create_log(sprintf('Making request on %s.', $url));

Expand Down