Skip to content

Instantly share code, notes, and snippets.

@martin-wintz
Created April 27, 2015 18:43
Show Gist options
  • Save martin-wintz/8b86159081f25dd51250 to your computer and use it in GitHub Desktop.
Save martin-wintz/8b86159081f25dd51250 to your computer and use it in GitHub Desktop.
Error in user YAML: (<unknown>): found character that cannot start any token while scanning for the next token at line 1 column 1
---

`_processRequest` is unecessary indirection. People expect methods to get called, not pass in as parameters.

If we want to factor out `parseJson`, we should make a patched version of the request methods that automatically parse json, that way we reduce duplication without introducing a confusing method call.

---

These tests don't do anything. Not only are they broken because even though they are asynchronous, the done() parameter isn't being used, but even when I get them working, I can delete most of the method body and still get the tests to pass.


A lot of these endpoints, such as list and search take in a params endpoint. What are valid parameters? Is this just a pass-through to the assets api?


The Param classes that were created are worse than having long parameter lists. Now you have a bunch of tiny "data classes" with duplicated fields that provide no helpful abstraction. It's the equivalent of sweeping a problem under the rug rather than fixing it.

Here are a few refactorings that could improve the design of these methods and reduce the parameter list.

  • itemGuid and contentType do seem to be related. Those could be grouped into an Item class (bad name, but you get the idea).
  • accessKey is duplicated across calls, why not instantiate the client with the accessKey instead of passing in to every method?
  • You could take this a step further and initialize the client with the folder guid as well, to have folder specific clients.

The resulting code would look like this:

var folderClient = new NewscredAssets.FolderClient(accesskey, folderGuid);
var item = new NewscredAssets.Item(itemGuid, contentType);
var folderClient.addItem(item);

The softDelete parameter is a flag argument and should be avoided. Better to have two separate methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment