Skip to content
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

Ability to delete urls #16

Closed
rithvikvibhu opened this issue May 8, 2017 · 5 comments
Closed

Ability to delete urls #16

rithvikvibhu opened this issue May 8, 2017 · 5 comments

Comments

@rithvikvibhu
Copy link

Quite surprised to see there isn't any delete method. Could you please add it or give me a basic idea on how I could go about this? Thanks

@neocotic
Copy link
Owner

neocotic commented May 8, 2017

This library is really just a wrapper around the official YOURLS API which is read only for some reason.

If you'd like to see delete functionality, you probably want to open a feature request issue on their repository or, better yet, a pull request that implements it.

If delete functionally is added to the live API, I will be able to add it here.

@rithvikvibhu
Copy link
Author

@neocotic Huh. That's weird. I found a plugin on their Plugins List.
https://github.com/claytondaley/yourls-api-delete adds a delete action to the standard API.

I know that this library is a wrapper for the official API only, but considering that this is a basic necessary feature, I hope you will agree to supporting this.

@neocotic
Copy link
Owner

neocotic commented May 8, 2017

I am reluctant to support individual unofficial YOURLS plugins as part of this library, however, the code is fully open source so you are free to fork and extend it. Alternatively, you could create a plugin for this library itself (see #9).

@rithvikvibhu
Copy link
Author

I think I'll go the custom API route, doesn't seem difficult. I'll let you know how it goes. Thanks!

@rithvikvibhu
Copy link
Author

For others' reference, I got it working with this:

  1. Install the yourls-api-delete plugin and enable it on the plugins page.
  2. Insert this somewhere in your script:
yourls.deleteUrl = function(url, callback) {
  var data = {
    action: 'delete',
    shorturl: url
  };
  this.sendRequest(data, ['statusCode', 'simple', 'message'], callback);
  return this;
};
  1. Use it this way:
yourls.deleteUrl(url, (result, response) => {
  console.log(result, response);
  if (result.statusCode == 200) {
    alert('Deleted url.');
  } else {
    alert('Error deleting. Check console.');
  }
});

It would be neater to hack the URL instead of yourls itself, but hey, who reads the code right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants