winston-hipchat
Advanced tools
Comparing version 0.0.2 to 0.1.0
'use strict'; | ||
var util = require('util'), | ||
winston = require('winston'), | ||
request = require('request'), | ||
Stream = require('stream').Stream | ||
var util = require('util') | ||
, winston = require('winston') | ||
, request = require('request') | ||
, Stream = require('stream').Stream | ||
, _ = require('lodash') | ||
@@ -17,18 +18,12 @@ // | ||
options = options || {} | ||
if (!options.room) throw new Error('Must have a room option set.') | ||
if (!options.token) throw new Error('Must have a token option set.') | ||
this.name = 'http' | ||
this.ssl = true | ||
this.host = 'api.hipchat.com' | ||
this.port = 443 | ||
this.silent = options.silent | ||
this.token = options.token | ||
this.room = options.room | ||
this.from = options.from || 'winston' | ||
this.notify = options.notify ? 1 : 0 | ||
this.color = options.color || 'yellow' | ||
this.path = '/v1/rooms/message' | ||
this.name = 'Hipchat' | ||
this.options = _.defaults(options || {}, { | ||
from: 'winston' | ||
, notify: 0 | ||
, color: 'yellow' | ||
, messageFormat: 'text' | ||
}) | ||
} | ||
@@ -41,3 +36,3 @@ | ||
// | ||
Hipchat.prototype.name = 'http' | ||
Hipchat.prototype.name = 'Hipchat' | ||
@@ -51,25 +46,18 @@ // | ||
Hipchat.prototype._request = function (options, callback) { | ||
var auth | ||
options = options || {} | ||
options.method = 'POST' | ||
options.params.meta = Object.keys(options.params.meta).length ? JSON.stringify(options.params.meta, null, 2) : '' | ||
options.qs = { | ||
'room_id': this.room | ||
, from: this.from | ||
, 'auth_token': this.token | ||
, notify: this.notify | ||
, color: this.color | ||
, 'message_format': 'text' | ||
, message: options.params.message + (Object.keys(options.params.meta).length? '\n\n' + JSON.stringify(options.params.meta) : '') | ||
'room_id': this.options.room | ||
, from: this.options.from | ||
, 'auth_token': this.options.token | ||
, notify: this.options.notify ? 1 : 0 | ||
, color: this.options.color | ||
, 'message_format': this.options.messageFormat | ||
, message: this.options.message ? _.template(this.options.message, options.params, { | ||
interpolate: /\{\{(.*?)\}\}/g | ||
}) : options.params.message + (options.params.meta ? '\n\n' + options.params.meta : '') | ||
} | ||
options.url = 'http' | ||
+ (this.ssl ? 's' : '') | ||
+ '://' | ||
+ (auth ? auth.username + ':' : '') | ||
+ (auth ? auth.password + '@' : '') | ||
+ this.host | ||
+ ':' | ||
+ this.port | ||
+ this.path | ||
options.url = 'https://api.hipchat.com/v1/rooms/message' | ||
@@ -76,0 +64,0 @@ return request(options, callback) |
{ | ||
"name": "winston-hipchat", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "A Hipchat transport for winston", | ||
@@ -20,3 +20,4 @@ "author": "Joey Baker <joey@byjoeybaker.com>", | ||
"dependencies": { | ||
"request": "~2.27.0" | ||
"request": "~2.27.0", | ||
"lodash": "~2.2.1" | ||
}, | ||
@@ -23,0 +24,0 @@ "devDependencies": { |
@@ -24,2 +24,4 @@ # winston-hipchat | ||
* __from:__ Required. Name the message will appear be sent from. Must be less than 15 characters long. May contain letters, numbers, -, _, and spaces. | ||
* __messageFormat:__ `text` (default) or `html`. | ||
* __message:__ [lodash templates](http://lodash.com/docs#template). Gets passed the `{{message}}`, `{{level}}`, and `{{meta}}` as a JSON string. If not specified, it will print a default of `{{message}}\n\n{{meta}}` | ||
@@ -26,0 +28,0 @@ ## Installation |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13276
57
3
298
+ Addedlodash@~2.2.1
+ Addedlodash@2.2.1(transitive)