-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete refactoring for Version 2, basic structure in place
- Loading branch information
Showing
17 changed files
with
483 additions
and
226 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env node | ||
|
||
// == Imports =============================================================== | ||
|
||
const PostageApp = require('../lib/postageapp'); | ||
|
||
// == Main ================================================================== | ||
|
||
var program = require('commander'); | ||
|
||
var postageApp = new PostageApp(); | ||
|
||
console.log(postageApp.version); | ||
console.log(postageApp.config()); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// == Imports =============================================================== | ||
|
||
const Promise = require('bluebird').Promise; | ||
const uuid = require('uuid'); | ||
|
||
// == Exported Class ======================================================== | ||
|
||
class ApiCall { | ||
constructor(method, args, uid, apiKey) { | ||
this.method = method; | ||
this.uid = uid || uuid.v4(); | ||
this.arguments = args || { }; | ||
this.apiKey = apiKey; | ||
} | ||
|
||
toJSON() { | ||
return { | ||
api_key: this.apiKey, | ||
uid: this.uid, | ||
method: this.method, | ||
arguments: this.arguments | ||
}; | ||
} | ||
|
||
serialize(pretty) { | ||
if (pretty) { | ||
return JSON.stringify(this, null, 2); | ||
} | ||
|
||
return JSON.stringify(this); | ||
} | ||
} | ||
|
||
// == Exports =============================================================== | ||
|
||
module.exports = ApiCall; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// == Imports ================================================================ | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
// == Local Variables ======================================================== | ||
|
||
const defaults = { | ||
host: 'api.postageapp.com', | ||
port: 443, | ||
secure: true, | ||
apiKey: undefined | ||
}; | ||
|
||
// == Initialization ======================================================== | ||
|
||
if (process.env.POSTAGEAPP_HOST) { | ||
defaults.host = process.env.POSTAGEAPP_HOST; | ||
} | ||
|
||
if (process.env.POSTAGEAPP_PORT) { | ||
defaults.port = process.env.POSTAGEAPP_PORT; | ||
} | ||
|
||
if (process.env.POSTAGEAPP_SECURE) { | ||
defaults.secure = !!process.env.POSTAGEAPP_SECURE; | ||
} | ||
|
||
if (process.env.POSTAGEAPP_API_KEY) { | ||
defaults.apiKey = process.env.POSTAGEAPP_API_KEY; | ||
} | ||
|
||
// == Exported Class ======================================================== | ||
|
||
class Config { | ||
constructor(options) { | ||
if (!options) { | ||
options = process.env.POSTAGEAPP_CONFIG; | ||
} | ||
|
||
this.merge(defaults); | ||
|
||
switch (typeof(options)) { | ||
case 'string': | ||
var configPath = path.resolve(process.cwd(), options); | ||
|
||
if (fs.existsSync(configPath)) {8 | ||
this.merge(require(configPath)); | ||
} | ||
else if (options.match(/^\w+$/)) { | ||
this.apiKey = options; | ||
} | ||
|
||
break; | ||
case 'object': | ||
this.merge(options); | ||
break; | ||
case 'undefined': | ||
// Work with defaults. | ||
break; | ||
} | ||
} | ||
|
||
merge(options) { | ||
Object.keys(options).forEach((k) => { | ||
this[k] = options[k]; | ||
}); | ||
} | ||
} | ||
|
||
// == Exports =============================================================== | ||
|
||
module.exports = Config; |
Oops, something went wrong.