Simple "pixel" library for component, inspired heavily by superagent.
$ component install redventures/pixel
Instantitates a new pixel for the given type
. The supported types are:
- image
- script
var pixel = require('pixel');
pixel('image')
.send({ key1: 'value1' })
.send({ key2: 'value2' })
.end();
pixel('script')
.send('key1', 'value1')
.send('key2', 'value2')
.end(function(){
// optional callback
});
Appends key=value
as a querystring parameter of the pixel request. Note that this will urlencode the values for you.
pixel('image')
.send('key1', 'value 1')
.send({ key2: 'value 2' })
.send({
key3: 'value 3',
key4: 'value 4'
})
.end();
Sets the configuration value for the request. If you want to change it for all requests, see .defaults()
.
pixel('script')
.set('host', 'foo.com')
.set('path', '/bar.js')
.send('key', 'value')
.end();
Sends the actual HTTP request for the pixel, invoking the optional callback
.
Sets the defaults for every pixel instantiated. The options and predefined defaults are:
host
: Remote hostname. Defaults tolocation.hostname
.path
: Remote path. Defaults to/pixel
.protocol
: Remote protocol. Defaults tolocation.protocol
cacheBust
: Whether to append a random "cache bust" to the URL.
var pixel = require('pixel');
pixel.defaults({
host: '//google.com',
path: '/api'
});
pixel('script')
.send('key', 'value')
.end();
- more tests, specially IE and mobile.
- passing responses back to
.end(callback)
. Probably only forscript
type.
Copyright 2012 Red Ventures
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.