neocotic / yourls-api

JavaScript bindings for the YOURLS API
https://neocotic.com/yourls-api
MIT License
24 stars 8 forks source link

custom api action #9

Open joshp23 opened 7 years ago

joshp23 commented 7 years ago

As it is trivial to create an api action for YOURLS, it would novel if there was an equally trivial way to define custom api actions for yourls-api.js. Is there such a hook? edit and delete seem particularly handy.

neocotic commented 7 years ago

@joshp23 I'm in the process of a bit of refactoring relating to how the library makes requests (see #6) which might make this possible since the sendRequest method will be exposed. But it's really just a matter of importing and modifying the yourls object to add the methods you want. If they're URL-specific, you might have more trouble since the URL constructor isn't exposed, but I guess you could do something hacky like this:

yourls.yourCustomAction = function() {
    // ...

    return this
}

var URL = yourls.url('_').constructor
URL.prototype.yourCustomAction = function() {
    // ...

    return this
}