How to use the thingpedia.Helpers function in thingpedia

To help you get started, we’ve selected a few thingpedia 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 stanford-oval / almond-cloud / tests / test_website_selenium.js View on Github external
await Promise.all(images.map(async (img) => {
        const src = await img.getAttribute('src');

        // small optimization: we only check an image once
        // (we don't have dynamic images)
        // (we still need to use selenium to check images rather than
        // a linkchecker-style approach to make sure we catch JS-added
        // images)
        if (_checkedImages.has(src))
            return;
        _checkedImages.add(src);

        // this is not exactly what the browser does
        const res = await Tp.Helpers.Http.getStream(src, { extraHeaders: {
            Referrer: currentUrl
        }});
        assert(res.headers['content-type'].startsWith('image/'),
               `expected image/* content type for image, found ${res['content-type']}`);
        res.resume();
    }));
}
github stanford-oval / thingpedia-common-devices / com.slack / receive.js View on Github external
function channelHistory(SlackReceiveChannel, token, channel_name, channel_id, count, lastTs) {
  // Construct the proper JSON message and send to channel
  return Tp.Helpers.Http.post('https://slack.com/api/channels.history',
      'token=' + token +
      '&channel=' + encodeURIComponent(channel_id) +
      '&count=' + encodeURIComponent(count), {
        dataContentType: 'application/x-www-form-urlencoded'
      }
    )
    .then(function(response) {
      var parsed = JSON.parse(response);

      if (!parsed.ok) {
        console.log('[ERROR] invalid response from http POST (channel.history)');
        throw ("Channels.History returned status of NOT OK.");
      }

      var msgs = parsed.messages;
github stanford-oval / thingengine-core / lib / devices / builtins / matrix / matrix_messaging.js View on Github external
_getUploadable(url) {
        if (typeof url === 'string') {
            // the url might expire, so get it first, upload it and then send it

            if (url.startsWith('http')) {
                return Tp.Helpers.Http.getStream(url).spread((res) => {
                    let contentType = res.headers['content-type'];
                    return [res, contentType];
                });
            } else {
                return Tp.Helpers.Content.getStream(this._device.engine.platform, url).then((stream) => {
                    let contentType = stream.contentType;
                    return [stream, contentType];
                });
            }
        } else if (Buffer.isBuffer(url)) {
            return Q([url, 'application/octet-stream']);
        } else {
            throw new TypeError('Invalid type for call to sendPicture, must be string or buffer');
        }
    }
github stanford-oval / thingpedia-common-devices / com.fitbit / device.js View on Github external
refreshCredentials: function() {
        console.log(this.constructor.metadata.client_id);
        console.log(this.constructor.metadata.client_secret);
        return Tp.Helpers.Http.post('https://api.fitbit.com/oauth2/token',
            {
                auth: 'Basic ' + Buffer.from(this.constructor.metadata.client_id + ':' + this.constructor.metadata.client_secret).toString('base64'),
                grant_type: 'refresh_token',
                refresh_token: this.refreshToken
            }).then(function(response) {
                var parsed = JSON.parse(response);
                console.log('parsed', parsed);
                this.state.accessToken = parsed.access_token;
                this.state.refreshToken = parsed.refresh_token;
                return this.accessToken;
            });
    }
});
github stanford-oval / thingpedia-common-devices / com.linkedin / device.js View on Github external
do_share({ status }) {
        return Tp.Helpers.Http.post(SHARE_URL, JSON.stringify({
            comment: status,
            visibility: {
                code: 'anyone'
            }
        }), {
            useOAuth2: this,
            dataContentType: 'application/json',
            accept: 'application/json'
        });
    }
};
github stanford-oval / thingpedia-common-devices / com.thecatapi / device.js View on Github external
        return Tp.Helpers.Http.get(url).then((result) => Tp.Helpers.Xml.parseString(result))
        .then((parsed) => {
github stanford-oval / almond-cloud / model / migrations / db0f40b-models_redo_part2.js View on Github external
flags: JSON.stringify([
            'turking',
            'nofilter',
            'primonly',
            'policies',
            'remote_programs',
            'aggregation',
            'bookkeeping',
            'triple_commands',
            'configure_actions'
        ]),
        public: true,
        version: 0
    });

    await codeStorage.storeZipFile(await Tp.Helpers.Http.getStream('https://almond-static.stanford.edu/test-data/en-thingtalk.zip'),
        'org.thingpedia.genie.thingtalk', 0, 'template-files');

    return tmpl.id;
}
github stanford-oval / thingpedia-common-devices / com.almondmarket.dates / search.js View on Github external
invokeQuery: function(filters) {
        var url = this.url;
        return Tp.Helpers.Http.get(url).then((data) => {
            var response = JSON.parse(data);

            var posts = response.objects;
            return posts.map((post) => {
                return [
                    post.interest,
                    post.message,
                    post.poster,
                    post.phone
                ];
            });
         });
    },
});
github stanford-oval / thingpedia-common-devices / com.dropbox / device.js View on Github external
do_move({ old_name, new_name }) {
        old_name = String(old_name);
        new_name = String(new_name);
        if (!old_name.startsWith('/'))
            old_name = '/' + old_name;
        if (new_name.indexOf('/') < 0)
            new_name = path.resolve(path.dirname(old_name), new_name);
        if (!new_name.startsWith('/'))
            new_name = '/' + new_name;

        return Tp.Helpers.Http.post('https://api.dropboxapi.com/2/files/move',
                                    JSON.stringify({ from_path: old_name, to_path: new_name }),
                                    { useOAuth2: this,
                                      dataContentType: 'application/json',
                                      accept: 'application/json' });
    }
github stanford-oval / thingpedia-common-devices / us.sportradar / soccer_us_team.js View on Github external
Tp.Helpers.Http.get(BOXSCORE_URL.format(this._gameId)).then((response) => {
            return Tp.Helpers.Xml.parseString(response);
        }).then((parsed) => {
            var match = parsed.boxscore.matches[0].match[0];