How to use the needle.put function in needle

To help you get started, we’ve selected a few needle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github prey / prey-node-client / lib / agent / providers / geo / strategies.js View on Github external
if (err) return cb(err);

            var geolocation = stdout;
            var loc_data = {
              "geolocation": geolocation,
              "wifiAccessPoints": aps,
              "provider": provider
            }
            var opts = {
              user_agent: common.system.user_agent,
              json : true
            }
            if (proxy) opts.proxy = proxy;

            // Send the new location info and process it
            needle.put(GEO_ENDPOINT, loc_data, opts, function(err, resp) {
              logger.debug("Sending location data to prey service")
              if (err) return cb(err)
              process_response(geolocation, cb);
            });

          });
github charltoons / hipchatter / hipchatter.js View on Github external
};

        // GET request
        if (type.toLowerCase() === 'get') {
            var url = payload.hasOwnProperty('token') ? this.url(path, payload, payload.token) : this.url(path, payload);
            needle.get(url, requestCallback);

        // POST request
        } else if (type.toLowerCase() === 'post') {
            var url = payload.hasOwnProperty('token') ? this.url(path, payload.token) : this.url(path);

            needle.post(url, payload, {json: true, headers:{'Content-Type': 'application/json; charset=utf-8'}}, requestCallback);

        // PUT request
        } else if (type.toLowerCase() === 'put') {
            needle.put(this.url(path), payload, {json: true, headers:{'Content-Type': 'application/json; charset=utf-8'}}, requestCallback);

        // DELETE request
        } else if (type.toLowerCase() === 'delete') {
            needle.delete(this.url(path), {}, requestCallback);

        // otherwise, something went wrong
        } else {
            if (self.isFunction(callback)) {
            callback(new Error('Invalid use of the hipchatter.request function.'));
            }
        }
    },
github senecajs / seneca-web / test / test-client.js View on Github external
url = 'http://localhost:3001/t0/a0/b0?a1=b1',
console.log('POST '+url)
needle.post(
  url,
  {a2:'b2',c:'c'},
  {json:true},
  function(err,res){
    assert.ok( !err )
    assert.deepEqual(res.body,
                     { r0: 'r0pb0', r1: 'pr1b1', r2: 'r2b2', x0: 'ry0', c: 'C' })
  })


url = 'http://localhost:3001/t0/a0/b0?a1=b1',
console.log('PUT '+url)
needle.put(
  url,
  {a2:'b2'},
  {json:true},
  function(err,res){
    assert.ok( !err )
    assert.equal( ''+res.body,
                  '{"r0":"r0undefined","r1":"r1pundefined","r2":'+
                  '"r2b2","x0":"ry0","http$":{"headers":{"h0":"i0"}},'+
                  '"o0":"p0","q0":"u0"}' )

  })


var url = 'http://localhost:3001/t0/c1?d0=e0'
console.log('GET '+url)
needle.get(url,function(err,res){
github santi8ago8 / gameserver / loginserver / routes / logic / server_list.js View on Github external
self.startOrStop = function (server, action) {
        var url = 'http://' + server.ip + ':' + server.port + '/server/' + action;
        needle.put(url,
            {serverPassword: server.serverPassword},
            function (err, resp, body) {
                if (err) {
                    fail.emit('error', err);
                }
                else {
                    //TODO: debug!
                }

            })
    };
github santi8ago8 / gameserver / loginserver / routes / sockets.js View on Github external
function emitStartOrStop(server) {
        if (socket.session.isLoged) {
            debugger;
            var url = 'http://' + server.ip + ':' + server.port + '/server/' + server.action;
            needle.put(url,
                {serverPassword: server.serverPassword},
                function (err, resp, body) {
                    if (err) {
                        //fail.emit('error', err);
                    }
                    else {
                        socket.emit('event', body);
                    }

                })
        }
    }
github santi8ago8 / gameserver / loginserver / routes / sockets.js View on Github external
socket.on('ping', function (server) {
        if (socket.session.isLoged) {
            var data = {date: new Date().getTime()};
            needle.put('http://' + server.ip + ':' + server.port + '/ping', data,
                function (err, resp, body) {
                    if (err) {
                        //fail.emit('error', err);
                    }
                    else {
                        var newTime = new Date().getTime();
                        var ping = (newTime - body.date);
                        server.ping = ping;
                        server.open = body.open;
                        socket.emit('ping', server);
                    }

                })
        }
    });
github hortonworks / cloudbreak / auth / main.js View on Github external
updatePassword = function(req, res, token, userId, newPassword, callback) {
        var passwordUpdateOptions = {
            headers: {
                'Accept': 'application/json',
                'Authorization': 'Bearer ' + token,
                'Content-Type': 'application/json'
            }
        }
        var newPasswordData = {
            'password': newPassword
        }
        needle.put(config.uaaAddress + '/Users/' + userId + '/password', JSON.stringify(newPasswordData),
            passwordUpdateOptions,
            function(err, resetResp) {
                if (resetResp.statusCode == 200) {
                    callback(resetResp)
                } else {
                    console.log('Password update failed.')
                    res.statusCode = 400
                    res.json({
                        message: 'Password update failed.'
                    })
                }
            });
    }
github hortonworks / cloudbreak / auth / main.js View on Github external
"value": members[i].value
                        })
                    }
                    newMembers.push({
                        "type": "USER",
                        "value": userId
                    })

                    var updateGroupData = {
                        "schemas": ["urn:scim:schemas:core:1.0"],
                        "id": id,
                        "displayName": displayName,
                        "members": newMembers
                    }

                    needle.put(config.uaaAddress + '/Groups/' + id, JSON.stringify(updateGroupData), updateGroupOptions,
                        function(err, updateResp) {
                            if (updateResp.statusCode == 200) {
                                console.log("PUT - update group (id:" + id + ", name: " + displayName + ") is successful.")
                            } else {
                                console.log("PUT - failed to update group (id:" + id + ", name: " + displayName + "), code: " + updateResp.statusCode)
                            }
                        });
                } else {
                    console.log("GET - cannot retrieve group: " + requestedName)
                }
            });
    }
github hortonworks / cloudbreak / auth / main.js View on Github external
getUserByName(req, res, token, email, function(userData) {
                    if (resetToken == md5(userData.id + userData['meta.lastModified'])) {
                        var userOptions = {
                            headers: {
                                'Accept': 'application/json',
                                'scope': 'password.write',
                                'aud': 'password',
                                'Authorization': 'Bearer ' + token,
                                'Content-Type': 'application/json'
                            }
                        }
                        var newPasswordData = {
                            'password': req.body.password
                        }
                        needle.put(config.uaaAddress + '/Users/' + userData.id + '/password', JSON.stringify(newPasswordData),
                            userOptions,
                            function(err, resetResp) {
                                if (resetResp.statusCode == 200) {
                                    res.json({
                                        message: 'SUCCESS'
                                    })
                                } else {
                                    res.statusCode = resetResp.statusCode
                                    res.json({
                                        message: 'Password update failed.'
                                    })
                                }
                            });
                    } else {
                        res.statusCode = 401
                        res.json({

needle

The leanest and most handsome HTTP client in the Nodelands.

MIT
Latest version published 3 months ago

Package Health Score

83 / 100
Full package analysis