Skip to content

Instantly share code, notes, and snippets.

@zhgqthomas
Last active June 30, 2017 15:07
Show Gist options
  • Save zhgqthomas/d500c32f78859eddfa7f624f255368ba to your computer and use it in GitHub Desktop.
Save zhgqthomas/d500c32f78859eddfa7f624f255368ba to your computer and use it in GitHub Desktop.

Revisions

  1. zhgqthomas revised this gist Jun 30, 2017. No changes.
  2. zhgqthomas revised this gist Jun 30, 2017. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions autodraw-cloud.js
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,10 @@ AV.Cloud.define('stencils', function (request, response) {
    hostname: 'www.autodraw.com',
    path: '/assets/stencils.json',
    port: 443,
    method: 'GET'
    method: 'GET',
    headers: {
    accept: '*/*'
    }
    };

    const req = https.request(options, function (res) {
    @@ -26,7 +29,6 @@ AV.Cloud.define('stencils', function (request, response) {

    res.on('end', function () {
    const payload = JSON.parse(output);
    console.log(payload);
    response.success(payload);
    });
    }
  3. zhgqthomas created this gist Jun 30, 2017.
    81 changes: 81 additions & 0 deletions autodraw-cloud.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,81 @@
    const https = require('https');

    AV.Cloud.define('stencils', function (request, response) {

    const options = {
    hostname: 'www.autodraw.com',
    path: '/assets/stencils.json',
    port: 443,
    method: 'GET'
    };

    const req = https.request(options, function (res) {

    if (res.statusCode < 200 || res.statusCode > 299) {

    res.on('error', function (error) {
    response.error(new Error(error.message));
    });
    } else {

    var output = '';
    res.setEncoding('utf8');
    res.on('data', function (chunk) {
    output += chunk;
    });

    res.on('end', function () {
    const payload = JSON.parse(output);
    console.log(payload);
    response.success(payload);
    });
    }
    });

    req.on('error', function (error) {
    response.error(new Error(error.message))
    });

    req.end()
    });

    AV.Cloud.define('matchDraw', function (request, response) {

    const options = {
    hostname: 'inputtools.google.com',
    path: '/request?ime=handwriting&app=autodraw&dbg=1&cs=1&oe=UTF-8',
    method: 'POST',
    headers: {
    'Content-Type': 'application/json'
    }
    };

    const req = https.request(options, function (res) {

    if (res.statusCode < 200 || res.statusCode > 299) {

    res.on('error', function (error) {
    response.error(new Error(error.message));
    });
    } else {

    var payload = '';
    res.setEncoding('utf8');
    res.on('data', function (chunk) {
    payload += chunk;
    });

    res.on('end', function () {
    response.success(payload);
    });
    }
    });

    req.write(JSON.stringify(request.params));

    req.on('error', function (error) {
    response.error(new Error(error.message))
    });

    req.end()
    });