Skip to content

Commit

Permalink
Merge pull request #32 from the-markup/v3-api
Browse files Browse the repository at this point in the history
V2->V3 of Shlink API
  • Loading branch information
BatMiles committed May 31, 2024
2 parents 93c4433 + a483c26 commit 7263c8d
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 15 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
**Requires at least:** 4.5
**Tested up to:** 6.5.3
**Requires PHP:** 7.3
**Stable tag:** 0.1.1
**Stable tag:** 0.2.0
**License:** GPLv2 or later
**License URI:** https://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -61,6 +61,9 @@ __Running tests:__

## Changelog ##

### 0.2.0 ###
* Update to Shlink v3 API

### 0.1.1 ###
* Fix a bug with the Short Links manager
* Upgrade dependencies
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "the-markup/smol-links",
"description": "Create and manage Shlink short links from WordPress",
"version": "0.2.0",
"type": "wordpress-plugin",
"require-dev": {
"phpunit/phpunit": "^9.6",
Expand Down
2 changes: 1 addition & 1 deletion languages/smol-links.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is distributed under the GPL-2.0-or-later.
msgid ""
msgstr ""
"Project-Id-Version: Smol Links 0.1.1\n"
"Project-Id-Version: Smol Links 0.2.0\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/smol-links\n"
"POT-Creation-Date: 2024-05-30 17:33:07+00:00\n"
"MIME-Version: 1.0\n"
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "smol-links",
"version": "0.1.1",
"version": "0.2.0",
"description": "Create and manage Shlink short links from WordPress",
"main": "build/index.js",
"author": "The Markup",
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tags: short url, shlink
Requires at least: 4.5
Tested up to: 6.5.3
Requires PHP: 7.3
Stable tag: 0.1.1
Stable tag: 0.2.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -61,6 +61,9 @@ __Running tests:__

== Changelog ==

= 0.2.0 =
* Update to Shlink v3 API

= 0.1.1 =
* Fix a bug with the Short Links manager
* Upgrade dependencies
Expand Down
2 changes: 1 addition & 1 deletion smol-links.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Description: Create and manage Shlink short links from WordPress
* Requires at least: 4.5
* Requires PHP: 7.0
* Version: 0.1.1
* Version: 0.2.0
* Author: The Markup
* Author URI: https://themarkup.org/
* License: GPL-2.0-or-later
Expand Down
8 changes: 4 additions & 4 deletions src/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@ function __construct($plugin) {

function create_shlink($args) {
$base_url = $this->plugin->options->get('base_url');
$endpoint = "$base_url/rest/v2/short-urls";
$endpoint = "$base_url/rest/v3/short-urls";
return $this->request('POST', $endpoint, $args);
}

function update_shlink($short_code, $args) {
$base_url = $this->plugin->options->get('base_url');
$endpoint = "$base_url/rest/v2/short-urls/$short_code";
$endpoint = "$base_url/rest/v3/short-urls/$short_code";
return $this->request('PATCH', $endpoint, $args);
}

function get_shlinks($args = null) {
$base_url = $this->plugin->options->get('base_url');
$endpoint = "$base_url/rest/v2/short-urls";
$endpoint = "$base_url/rest/v3/short-urls";
return $this->request('GET', $endpoint, $args);
}

function get_domains() {
$base_url = $this->plugin->options->get('base_url');
$endpoint = "$base_url/rest/v2/domains";
$endpoint = "$base_url/rest/v3/domains";
return $this->request('GET', $endpoint);
}

Expand Down
10 changes: 7 additions & 3 deletions src/js/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ class SmolLinksManager {
}

getItemContentHTML(shlink) {
let title = shlink.title || shlink.longUrl;
const title = shlink.title || shlink.longUrl;
const clickTotal = shlink.visitsSummary.total;

return `<div class="smol-links-item__content">
<div class="smol-links-item__clicks">
${shlink.visitsCount} clicks
${clickTotal} click${(clickTotal !== 1) ? 's' : ''}
</div>
<div class="smol-links-item__links">
<div class="smol-links-item__long-url">${title}</div>
Expand Down Expand Up @@ -154,7 +156,9 @@ class SmolLinksManager {
shortCode: shortCodeField.value,
title: titleField.value,
shortUrl: '',
visitsCount: 0,
visitsSummary: {
total: 0,
},
}) + list.innerHTML;
let item = list.querySelectorAll('.smol-links-item')[0];
item.classList.add('smol-links-item--is-saving');
Expand Down
4 changes: 3 additions & 1 deletion tests/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ function request($method, $endpoint, $args = null) {
"shortUrl" => "https://example.com/xxxxx",
"longUrl" => $args['longUrl'],
"dateCreated" => current_time(DATE_RFC3339),
"visitsCount" => 0,
"visitsSummary" => [
"total" => 0
],
"tags" => $tags,
"meta" => [
"validSince" => null,
Expand Down
10 changes: 10 additions & 0 deletions tests/TestPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,17 @@ public function test_save_post() {
'post_title' => 'Testing generate_on_save'
]);
$shlink = $this->plugin->get_post_shlink(get_post($post_id));

$this->assertEquals($shlink['short_code'], 'xxxxx');
$this->assertEquals($shlink['short_url'], 'https://example.com/xxxxx');
$this->assertEquals($shlink['long_url'], 'http://example.org/?p='.$post_id);
}

public function test_expected_permalink() {
$post_id = self::factory()->post->create();
$post = get_post($post_id);
$link = $this->plugin->get_expected_permalink($post);

$this->assertEquals($link, 'http://example.org/?p='.$post_id);
}
}

0 comments on commit 7263c8d

Please sign in to comment.