Created
February 28, 2017 05:06
-
-
Save seangates/abfcfc460d4f62376df71043af9c382d to your computer and use it in GitHub Desktop.
A simple way to use Knack requests in your Node.js app.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const rp = require('request-promise'); | |
const _ = require('lodash'); | |
class Knack { | |
constructor(config) { | |
this.knackBasePath = config.knackBasePath; | |
this.knackOptions = config.knackOptions; | |
} | |
knackRequest(uri) { | |
var wait = false; | |
var self = this; | |
if (uri === 'undefined') { | |
console.error('can\'t call knackRequest with undefined URI'); | |
return; | |
} | |
uri = (uri && '/' + uri) || ''; | |
this.knackOptions = _.extend(this.knackOptions, { | |
uri: this.knackBasePath + uri | |
}); | |
return rp(this.knackOptions); | |
} | |
} | |
module.exports = Knack; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Are there any Knack libraries in NPM? I wonder.