Skip to content

fix buffer concatenation & add support for some more API endpoints#6

Open
ceejbot wants to merge 12 commits intodyninc:masterfrom
npm:master
Open

fix buffer concatenation & add support for some more API endpoints#6
ceejbot wants to merge 12 commits intodyninc:masterfrom
npm:master

Conversation

@ceejbot
Copy link

@ceejbot ceejbot commented Sep 4, 2015

npm, Inc uses Dyn as its DNS provider, and I recently wrote a command-line tool to help us automate some operational tasks that require DNS changes. I made the following modifications to our fork of the module to make this tool function.

  • made http requests use concat-stream to properly concatenate buffers to build a request result
  • wrapped json parsing in a function that catches exceptions
  • added support for the GET /REST/Job/<id> API endpoint
  • added support for the DELETE /REST/Node/<zone>/<fqdn>/ API endpoint
  • removed the ruby one-liner to compile & replaced it with an npm script target; do npm run compile to compile the single source file
  • added coffee-script to the dev dependencies so compilation works
  • removed the apparently unused Grunt coffeescript file
  • landed extant PRs against the repo

elopezanaya and others added 12 commits September 26, 2014 23:17
there is a problem when the call to  obtain the status of a sender return false, the callback for the promise is never reached because the errorCase function is throwing an exception that never is catched

with my changes now no matter the result of the status, the respond is always reached 

function to validate the new changes propossed
++++++++++++++++
function isAvalidSender(email) {

  var result = dyn.senders.status(email).then(function(x) {
    console.log('CALLBACK!!!');

    console.log('response %s', JSON.stringify(x));

    if (x) {
      return true;

    }

    return false;

  });

}
I forgot to remove try catch
in order to no affect other operations, I just added throwResponse definition and changed the call for messaging.senders.status

  messaging.senders.status            = (email)          -> callWithError messaging.senders._status._call(messaging, {}, _.defaults({emailaddress:email}, {apikey:messaging.defaults.apikey})), "senders.status", msgIsOk, extractMsgData, throwResponse


the level of impact is minor and the response is reached by the client whom call the action

response {"status":404,"message":"Not Found","data":{"emailaddress":"whatever@veo.tv"}}

response {"ready":1}
No more uncaught exceptions on JSON parse
merge in elopezanaya's fork
Added coffee-script to the dev dependencies.
Added an npm script target to run it, in lieu of the ruby one-liner.
Ran it on the coffeescript source with pull requests merged.
Now we concatenate buffers from readable streams properly,
and we handle the errors they might emit, who knows.

JSON.parse() can throw exceptions. Catch them.
The npm `compile` script target does all that's needed here.
If x.data is an array, we want to parse it as a list of strings.
If x.data is already an object, we want to return it.

This makes API calls like `dyn.record._CNAME.get()` actually work.

While I was there, bumped deps.
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

Successfully merging this pull request may close these issues.

3 participants