Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
134 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,4 +34,4 @@ jspm_packages | |
.npm | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
.node_repl_history |
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,11 @@ | ||
language: node_js | ||
|
||
node_js: | ||
- node | ||
- 6 | ||
- 5 | ||
- 4 | ||
- 0.12 | ||
|
||
after_script: | ||
- npm run test-coverage |
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,4 @@ | ||
test: | ||
./node_modules/.bin/mocha --reporter spec | ||
|
||
.PHONY: test |
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 |
---|---|---|
@@ -1,2 +1,25 @@ | ||
# digitalocean-droplet-sdk | ||
A NodeJs wrapper for the DigitalOcean droplet API | ||
# DigitalOcean-Droplet-SDK | ||
|
||
[![Build Status](https://travis-ci.org/GeekyAubergine/digitalocean-droplet-sdk.svg?branch=develop)](https://travis-ci.org/GeekyAubergine/digitalocean-droplet-sdk) | ||
[![Coverage Status](https://coveralls.io/repos/github/GeekyAubergine/digitalocean-droplet-sdk/badge.svg?branch=develop)](https://coveralls.io/github/GeekyAubergine/digitalocean-droplet-sdk?branch=develop) | ||
|
||
A simple interface to get metadata about a DigitalOcean Droplet. | ||
|
||
## Install | ||
|
||
npm install digitalocean-droplet-sdk --save | ||
|
||
|
||
## Usage | ||
|
||
DigitalOcean-Droplet-SDK was designed to provide a simple and easy to use interface to get metadata about the droplet that it is running on. | ||
|
||
```js | ||
var dropletSDK = require('digitalocean-droplet-sdk'); | ||
|
||
dropletSDK.getMetadata().then(function(metadata) { | ||
/* do something with the result */ | ||
}).catch(function() { | ||
/* error :( */ | ||
}) | ||
``` |
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,18 @@ | ||
var request = require('request'); | ||
|
||
module.exports = { | ||
getMetadata: function() { | ||
return new Promise(function(resolve, reject) { | ||
var host = process.env.HOST || '169.254.169.254'; | ||
var port = process.env.PORT ? (':' + process.env.PORT) : ''; | ||
request('http://' + host + port + '/metadata/v1.json', function(error, response, body) { | ||
if (!error && response.statusCode === 200) { | ||
resolve(body); | ||
} | ||
else { | ||
reject(error); | ||
} | ||
}); | ||
}); | ||
} | ||
}; |
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,38 @@ | ||
{ | ||
"name": "digitalocean-droplet-sdk", | ||
"version": "1.0.0", | ||
"description": "A NodeJS wrapper for the DigitalOcean Droplet API", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "make test", | ||
"test-coverage": "istanbul cover node_modules/mocha/bin/_mocha && istanbul-coveralls" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/GeekyAubergine/digitalocean-droplet-sdk.git" | ||
}, | ||
"keywords": [ | ||
"digitalocean", | ||
"digital", | ||
"ocean", | ||
"droplet", | ||
"sdk", | ||
"api" | ||
], | ||
"author": "Chris Aubert | GeekyAubergine", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/GeekyAubergine/digitalocean-droplet-sdk/issues" | ||
}, | ||
"homepage": "https://github.com/GeekyAubergine/digitalocean-droplet-sdk#readme", | ||
"dependencies": { | ||
"request": "^2.74.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"chai-as-promised": "^5.3.0", | ||
"istanbul": "^0.4.5", | ||
"istanbul-coveralls": "^1.0.3", | ||
"mocha": "^3.0.2" | ||
} | ||
} |
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,37 @@ | ||
var http = require('http'), | ||
chai = require('chai'), | ||
should = chai.should(), | ||
dropletSDK = require('../index'), | ||
chaiAsPromised = require("chai-as-promised"); | ||
|
||
chai.use(chaiAsPromised); | ||
|
||
var exampleDroplet = { | ||
|
||
} | ||
|
||
var server = http.createServer(function(req, res) { | ||
res.end(JSON.stringify({ | ||
id: 123456, | ||
})); | ||
}); | ||
|
||
describe('#droplet-api', function() { | ||
before(function() { | ||
process.env.HOST = '127.0.0.1'; | ||
process.env.PORT = '7997'; | ||
server.listen(7997, '127.0.0.1', function() { | ||
console.log('testing'); | ||
}); | ||
}); | ||
|
||
after(function() { | ||
server.close(); | ||
}); | ||
|
||
it('gets metadata', function() { | ||
return dropletSDK.getMetadata().should.eventually.equal(JSON.stringify({ | ||
id: 123456, | ||
})); | ||
}); | ||
}); |