UNPKG

2.19 kBJavaScriptView Raw
1/*!
2 * apiai
3 * Copyright(c) 2015 http://api.ai/
4 * Apache 2.0 Licensed
5 */
6
7'use strict';
8
9var Request = require('./request').Request;
10var util = require('util');
11
12exports.QueryRequest = module.exports.QueryRequest = QueryRequest;
13
14util.inherits(QueryRequest, Request);
15
16function QueryRequest (application, options) {
17 var self = this;
18
19 self.language = application.language;
20
21 if ('timezone' in options) {
22 self.timezone = options.timezone;
23 }
24
25 if ('resetContexts' in options) {
26 self.resetContexts = options.resetContexts;
27 }
28
29 if ('contexts' in options) {
30 self.contexts = options.contexts;
31 }
32
33 if ('entities' in options) {
34 self.entities = options.entities;
35 }
36
37 if ('sessionId' in options) {
38 self.sessionId = options.sessionId;
39 }
40
41 if ('version' in options) {
42 self.version = options.version;
43 }
44
45 if ('requestSource' in application) {
46 self.requestSource = application.requestSource;
47 }
48
49 if ('originalRequest' in options) {
50 self.originalRequest = options.originalRequest;
51 }
52
53 QueryRequest.super_.apply(this, arguments);
54}
55
56QueryRequest.prototype._requestOptions = function() {
57 var self = this;
58
59 var path = 'query';
60
61 if (self.hasOwnProperty("version")) {
62 path += '?v=' + self.version;
63 }
64
65 var request_options = QueryRequest.super_.prototype._requestOptions.apply(this, arguments);
66
67 request_options['path'] = self.endpoint + path;
68 request_options['method'] = 'POST';
69
70 return request_options
71};
72
73QueryRequest.prototype._jsonRequestParameters = function() {
74 var self = this;
75
76 var json = {
77 'lang': self.language,
78 'timezone': self.timezone
79 };
80
81 if ('resetContexts' in self) {
82 json['resetContexts'] = self.resetContexts;
83 }
84
85 if ('contexts' in self) {
86 json['contexts'] = self.contexts;
87 }
88
89 if ('entities' in self) {
90 json['entities'] = self.entities;
91 }
92
93 if ('sessionId' in self) {
94 json['sessionId'] = self.sessionId;
95 }
96
97 if ('originalRequest' in self) {
98 json['originalRequest'] = self.originalRequest;
99 }
100
101 return json;
102};