Skip to content

Instantly share code, notes, and snippets.

@yoshprogrammer
Last active February 5, 2016 22:29

Revisions

  1. yoshprogrammer revised this gist Feb 5, 2016. No changes.
  2. yoshprogrammer revised this gist Feb 5, 2016. No changes.
  3. yoshprogrammer revised this gist Feb 5, 2016. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions Create::User.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    //LIBS
    app.post('/api/user', function (req, res) {
    //LIBS - The libs I used for this call.
    //var _ = require('lodash'),
    // Curl = require('node-libcurl').Curl,
    // express = require('express'),
    @@ -15,7 +16,7 @@
    encodedHash = new Buffer(hash).toString('base64'),
    curl = new Curl(),
    url = 'api.weeblycloud.com/user';

    curl.setOpt('URL', url);
    curl.setOpt('POSTFIELDS', dataArray);
    curl.setOpt('CUSTOMREQUEST', 'POST');
    @@ -32,4 +33,5 @@
    this.close();
    });

    curl.on('error', curl.close.bind( curl ));
    curl.on('error', curl.close.bind( curl ));
    }
  4. yoshprogrammer created this gist Feb 5, 2016.
    35 changes: 35 additions & 0 deletions Create::User.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    //LIBS
    //var _ = require('lodash'),
    // Curl = require('node-libcurl').Curl,
    // express = require('express'),
    // app = express();

    var body = _.pick(req.body, 'email'),
    dataArray = JSON.stringify({
    "email": body.email
    }),
    hashRequest = 'POST' + '\n' + 'user' + '\n' + dataArray,
    key = YOURAPIKEY,
    apiSecret = YOURAPISECRET,
    hash = crypto.createHmac('sha256', apiSecret).update(hashRequest).digest("hex"),
    encodedHash = new Buffer(hash).toString('base64'),
    curl = new Curl(),
    url = 'api.weeblycloud.com/user';

    curl.setOpt('URL', url);
    curl.setOpt('POSTFIELDS', dataArray);
    curl.setOpt('CUSTOMREQUEST', 'POST');
    curl.setOpt('HTTPHEADER', [
    'Content-type: application/json',
    'X-Public-Key: ' + key,
    'X-Signed-Request-Hash: ' + encodedHash
    ]);

    curl.setOpt('VERBOSE', true ); //Verbose logging, you'll want to turn this off in production
    curl.perform();
    curl.on( 'end', function( statusCode, body ) {
    body = JSON.parse(body);
    this.close();
    });

    curl.on('error', curl.close.bind( curl ));