UNPKG

1.09 kBJavaScriptView Raw
1/*!
2 * apiai
3 * Copyright(c) 2015 http://api.ai/
4 * Apache 2.0 Licensed
5 */
6
7'use strict';
8
9var QueryRequest = require('./query_request').QueryRequest;
10var util = require('util');
11
12exports.TextRequest = module.exports.TextRequest = TextRequest;
13
14util.inherits(TextRequest, QueryRequest);
15
16function TextRequest (application, query, options) {
17 TextRequest.super_.apply(this, [application, options]);
18
19 var self = this;
20 self.query = query;
21}
22
23TextRequest.prototype._headers = function() {
24 var headers = TextRequest.super_.prototype._headers.apply(this, arguments);
25
26 headers['Content-Type'] = 'application/json; charset=utf-8';
27
28 return headers;
29};
30
31TextRequest.prototype._jsonRequestParameters = function() {
32 var self = this;
33
34 var json = TextRequest.super_.prototype._jsonRequestParameters.apply(this, arguments);
35
36 json['query'] = self.query;
37
38 return json;
39};
40
41TextRequest.prototype.end = function() {
42 var self = this;
43
44 self.write(JSON.stringify(self._jsonRequestParameters()));
45
46 TextRequest.super_.prototype.end.apply(this, arguments);
47};