Browse Source

Merge pull request #14 from egut/master

Support http proxy
pull/17/head
Brett Langdon 11 years ago
parent
commit
6fd091efcb
5 changed files with 50 additions and 6 deletions
  1. +26
    -0
      README.md
  2. +1
    -1
      lib/api/graph.js
  3. +6
    -2
      lib/client.js
  4. +14
    -1
      lib/index.js
  5. +3
    -2
      package.json

+ 26
- 0
README.md View File

@ -41,6 +41,32 @@ var options = {
dogapi.initialize(options); dogapi.initialize(options);
``` ```
### HTTPS Proxy
If you are behind a proxy you need to a proxy agent. You can use the https proxy agent from
http://blog.vanamco.com/proxy-requests-in-node-js/ if you like.
To configure dogapi with the agent just add it to the options.
```javascript
var dogapi = require("dogapi");
//Code from http://blog.vanamco.com/proxy-requests-in-node-js/
var HttpsProxyAgent = require("./httpsproxyagent");
var agent = new HttpsProxyAgent({
proxyHost: "MY_PROXY_HOST",
proxyPort: 3128
});
var options = {
api_key: "YOUR_KEY_HERE",
app_key: "YOUR_KEY_HERE",
proxy_agent: agent
};
dogapi.initialize(options);
```
## CLI Usage ## CLI Usage
`dogapi` now ships with a command line interface `dogapi`. To use it you `dogapi` now ships with a command line interface `dogapi`. To use it you


+ 1
- 1
lib/api/graph.js View File

@ -18,7 +18,7 @@ var client = require("../client");
* dogapi.initialize(options); * dogapi.initialize(options);
* var query = "system.cpu.idle{*}"; * var query = "system.cpu.idle{*}";
* var to = dogapi.now(); * var to = dogapi.now();
* var from = from - 3600; // an hour ago
* var from = to - 3600; // an hour ago
* dogapi.graph.snapshot(query, from, to, function(err, res){ * dogapi.graph.snapshot(query, from, to, function(err, res){
* console.dir(res); * console.dir(res);
* }); * });


+ 6
- 2
lib/client.js View File

@ -3,7 +3,6 @@ var https = require("https");
var url = require("url"); var url = require("url");
var util = require("util"); var util = require("util");
/*section: client /*section: client
*comment: | *comment: |
* the constructor for _client_ object * the constructor for _client_ object
@ -14,6 +13,7 @@ var util = require("util");
var client = function(){ var client = function(){
this.api_key = null; this.api_key = null;
this.app_key = null; this.app_key = null;
this.proxy_agent = null;
this.api_version = "v1"; this.api_version = "v1";
this.api_host = "app.datadoghq.com"; this.api_host = "app.datadoghq.com";
}; };
@ -69,9 +69,13 @@ client.prototype.request = function(method, path, params, callback){
hostname: this.api_host, hostname: this.api_host,
port: 443, port: 443,
method: method.toUpperCase(), method: method.toUpperCase(),
path: path,
path: path
}; };
if(this.proxy_agent){
http_options["agent"] = this.proxy_agent;
}
if(["POST", "PUT"].indexOf(http_options["method"]) >= 0){ if(["POST", "PUT"].indexOf(http_options["method"]) >= 0){
http_options["headers"] = { http_options["headers"] = {
"Content-Type": "application/json", "Content-Type": "application/json",


+ 14
- 1
lib/index.js View File

@ -11,13 +11,26 @@ require("./api")(module.exports);
* * app_key: your app key * * app_key: your app key
* * api_version: the version of the api [default: `v1`] * * api_version: the version of the api [default: `v1`]
* * api_host: the host to call [default: `api.datadoghq.com`] * * api_host: the host to call [default: `api.datadoghq.com`]
* * proxy_agent: Optional, A Https Proxy agent.
*example: *example:
* | * |
* ```javascript * ```javascript
* var dogapi = require("dogapi"); * var dogapi = require("dogapi");
*
* // Optional for Proxy -------8<----------
* // Code from http://blog.vanamco.com/proxy-requests-in-node-js/
* var HttpsProxyAgent = require("./httpsproxyagent");
*
* var agent = new HttpsProxyAgent({
* proxyHost: "MY_PROXY_HOST",
* proxyPort: 3128
* });
* // Optional for Proxy -------->8----------
*
* var options = { * var options = {
* api_key: "<API_KEY_HERE>", * api_key: "<API_KEY_HERE>",
* app_key: "<APP_KEY_HERE>"
* app_key: "<APP_KEY_HERE>",
* proxy_agent: agent // Optional for Proxy
* }; * };
* dogapi.initialize(options); * dogapi.initialize(options);
* dogapi.event.create(...); * dogapi.event.create(...);


+ 3
- 2
package.json View File

@ -1,6 +1,6 @@
{ {
"name": "dogapi", "name": "dogapi",
"version": "1.0.0",
"version": "1.0.1",
"description": "Datadog API Node.JS Client", "description": "Datadog API Node.JS Client",
"main": "lib/index.js", "main": "lib/index.js",
"scripts": { "scripts": {
@ -25,7 +25,8 @@
"author": "Brett Langdon <brett@blangdon.com> (http://brett.is)", "author": "Brett Langdon <brett@blangdon.com> (http://brett.is)",
"contributors": [ "contributors": [
"colinjonesx (http://www.thetestpeople.com)", "colinjonesx (http://www.thetestpeople.com)",
"dalehamel (http://blog.srvthe.net)"
"dalehamel (http://blog.srvthe.net)",
"egut (https://github.com/egut)"
], ],
"license": "MIT", "license": "MIT",
"readmeFilename": "README.md", "readmeFilename": "README.md",


Loading…
Cancel
Save