Source: rest/conversations/v1/configuration.js

  1. 'use strict';
  2. /* jshint ignore:start */
  3. /**
  4. * This code was generated by
  5. * \ / _ _ _| _ _
  6. * | (_)\/(_)(_|\/| |(/_ v1.0.0
  7. * / /
  8. */
  9. /* jshint ignore:end */
  10. var Q = require('q'); /* jshint ignore:line */
  11. var _ = require('lodash'); /* jshint ignore:line */
  12. var util = require('util'); /* jshint ignore:line */
  13. var Page = require('../../../base/Page'); /* jshint ignore:line */
  14. var WebhookList = require('./configuration/webhook').WebhookList;
  15. var values = require('../../../base/values'); /* jshint ignore:line */
  16. var ConfigurationList;
  17. var ConfigurationPage;
  18. var ConfigurationInstance;
  19. var ConfigurationContext;
  20. /* jshint ignore:start */
  21. /**
  22. * Initialize the ConfigurationList
  23. *
  24. * @constructor Twilio.Conversations.V1.ConfigurationList
  25. *
  26. * @param {Twilio.Conversations.V1} version - Version of the resource
  27. */
  28. /* jshint ignore:end */
  29. ConfigurationList = function ConfigurationList(version) {
  30. /* jshint ignore:start */
  31. /**
  32. * @function configuration
  33. * @memberof Twilio.Conversations.V1#
  34. *
  35. * @param {string} sid - sid of instance
  36. *
  37. * @returns {Twilio.Conversations.V1.ConfigurationContext}
  38. */
  39. /* jshint ignore:end */
  40. function ConfigurationListInstance(sid) {
  41. return ConfigurationListInstance.get(sid);
  42. }
  43. ConfigurationListInstance._version = version;
  44. // Path Solution
  45. ConfigurationListInstance._solution = {};
  46. // Components
  47. ConfigurationListInstance._webhooks = undefined;
  48. /* jshint ignore:start */
  49. /**
  50. * Constructs a configuration
  51. *
  52. * @function get
  53. * @memberof Twilio.Conversations.V1.ConfigurationList#
  54. *
  55. * @returns {Twilio.Conversations.V1.ConfigurationContext}
  56. */
  57. /* jshint ignore:end */
  58. ConfigurationListInstance.get = function get() {
  59. return new ConfigurationContext(this._version);
  60. };
  61. Object.defineProperty(ConfigurationListInstance,
  62. 'webhooks', {
  63. get: function webhooks() {
  64. if (!this._webhooks) {
  65. this._webhooks = new WebhookList(this._version);
  66. }
  67. return this._webhooks;
  68. }
  69. });
  70. /* jshint ignore:start */
  71. /**
  72. * Provide a user-friendly representation
  73. *
  74. * @function toJSON
  75. * @memberof Twilio.Conversations.V1.ConfigurationList#
  76. *
  77. * @returns Object
  78. */
  79. /* jshint ignore:end */
  80. ConfigurationListInstance.toJSON = function toJSON() {
  81. return this._solution;
  82. };
  83. ConfigurationListInstance[util.inspect.custom] = function inspect(depth,
  84. options) {
  85. return util.inspect(this.toJSON(), options);
  86. };
  87. return ConfigurationListInstance;
  88. };
  89. /* jshint ignore:start */
  90. /**
  91. * Initialize the ConfigurationPage
  92. *
  93. * @constructor Twilio.Conversations.V1.ConfigurationPage
  94. *
  95. * @param {V1} version - Version of the resource
  96. * @param {Response<string>} response - Response from the API
  97. * @param {ConfigurationSolution} solution - Path solution
  98. *
  99. * @returns ConfigurationPage
  100. */
  101. /* jshint ignore:end */
  102. ConfigurationPage = function ConfigurationPage(version, response, solution) {
  103. // Path Solution
  104. this._solution = solution;
  105. Page.prototype.constructor.call(this, version, response, this._solution);
  106. };
  107. _.extend(ConfigurationPage.prototype, Page.prototype);
  108. ConfigurationPage.prototype.constructor = ConfigurationPage;
  109. /* jshint ignore:start */
  110. /**
  111. * Build an instance of ConfigurationInstance
  112. *
  113. * @function getInstance
  114. * @memberof Twilio.Conversations.V1.ConfigurationPage#
  115. *
  116. * @param {ConfigurationPayload} payload - Payload response from the API
  117. *
  118. * @returns ConfigurationInstance
  119. */
  120. /* jshint ignore:end */
  121. ConfigurationPage.prototype.getInstance = function getInstance(payload) {
  122. return new ConfigurationInstance(this._version, payload);
  123. };
  124. /* jshint ignore:start */
  125. /**
  126. * Provide a user-friendly representation
  127. *
  128. * @function toJSON
  129. * @memberof Twilio.Conversations.V1.ConfigurationPage#
  130. *
  131. * @returns Object
  132. */
  133. /* jshint ignore:end */
  134. ConfigurationPage.prototype.toJSON = function toJSON() {
  135. let clone = {};
  136. _.forOwn(this, function(value, key) {
  137. if (!_.startsWith(key, '_') && ! _.isFunction(value)) {
  138. clone[key] = value;
  139. }
  140. });
  141. return clone;
  142. };
  143. ConfigurationPage.prototype[util.inspect.custom] = function inspect(depth,
  144. options) {
  145. return util.inspect(this.toJSON(), options);
  146. };
  147. /* jshint ignore:start */
  148. /**
  149. * Initialize the ConfigurationContext
  150. *
  151. * @constructor Twilio.Conversations.V1.ConfigurationInstance
  152. *
  153. * @property {string} accountSid -
  154. * The SID of the Account responsible for this configuration.
  155. * @property {string} defaultChatServiceSid -
  156. * The SID of the default Conversation Service that every new conversation is associated with.
  157. * @property {string} defaultMessagingServiceSid -
  158. * The SID of the default Messaging Service that every new conversation is associated with.
  159. * @property {string} defaultInactiveTimer -
  160. * Default ISO8601 duration when conversation will be switched to `inactive` state.
  161. * @property {string} defaultClosedTimer -
  162. * Default ISO8601 duration when conversation will be switched to `closed` state.
  163. * @property {string} url - An absolute URL for this global configuration.
  164. * @property {string} links -
  165. * Absolute URLs to access the webhook and default service configurations.
  166. *
  167. * @param {V1} version - Version of the resource
  168. * @param {ConfigurationPayload} payload - The instance payload
  169. */
  170. /* jshint ignore:end */
  171. ConfigurationInstance = function ConfigurationInstance(version, payload) {
  172. this._version = version;
  173. // Marshaled Properties
  174. this.accountSid = payload.account_sid; // jshint ignore:line
  175. this.defaultChatServiceSid = payload.default_chat_service_sid; // jshint ignore:line
  176. this.defaultMessagingServiceSid = payload.default_messaging_service_sid; // jshint ignore:line
  177. this.defaultInactiveTimer = payload.default_inactive_timer; // jshint ignore:line
  178. this.defaultClosedTimer = payload.default_closed_timer; // jshint ignore:line
  179. this.url = payload.url; // jshint ignore:line
  180. this.links = payload.links; // jshint ignore:line
  181. // Context
  182. this._context = undefined;
  183. this._solution = {};
  184. };
  185. Object.defineProperty(ConfigurationInstance.prototype,
  186. '_proxy', {
  187. get: function() {
  188. if (!this._context) {
  189. this._context = new ConfigurationContext(this._version);
  190. }
  191. return this._context;
  192. }
  193. });
  194. /* jshint ignore:start */
  195. /**
  196. * fetch a ConfigurationInstance
  197. *
  198. * @function fetch
  199. * @memberof Twilio.Conversations.V1.ConfigurationInstance#
  200. *
  201. * @param {function} [callback] - Callback to handle processed record
  202. *
  203. * @returns {Promise} Resolves to processed ConfigurationInstance
  204. */
  205. /* jshint ignore:end */
  206. ConfigurationInstance.prototype.fetch = function fetch(callback) {
  207. return this._proxy.fetch(callback);
  208. };
  209. /* jshint ignore:start */
  210. /**
  211. * update a ConfigurationInstance
  212. *
  213. * @function update
  214. * @memberof Twilio.Conversations.V1.ConfigurationInstance#
  215. *
  216. * @param {object} [opts] - Options for request
  217. * @param {string} [opts.defaultChatServiceSid] -
  218. * The SID of the default Conversation Service that every new conversation will be associated with.
  219. * @param {string} [opts.defaultMessagingServiceSid] -
  220. * The SID of the default Messaging Service that every new conversation will be associated with.
  221. * @param {string} [opts.defaultInactiveTimer] -
  222. * Default ISO8601 duration when conversation will be switched to `inactive` state.
  223. * @param {string} [opts.defaultClosedTimer] -
  224. * Default ISO8601 duration when conversation will be switched to `closed` state.
  225. * @param {function} [callback] - Callback to handle processed record
  226. *
  227. * @returns {Promise} Resolves to processed ConfigurationInstance
  228. */
  229. /* jshint ignore:end */
  230. ConfigurationInstance.prototype.update = function update(opts, callback) {
  231. return this._proxy.update(opts, callback);
  232. };
  233. /* jshint ignore:start */
  234. /**
  235. * Provide a user-friendly representation
  236. *
  237. * @function toJSON
  238. * @memberof Twilio.Conversations.V1.ConfigurationInstance#
  239. *
  240. * @returns Object
  241. */
  242. /* jshint ignore:end */
  243. ConfigurationInstance.prototype.toJSON = function toJSON() {
  244. let clone = {};
  245. _.forOwn(this, function(value, key) {
  246. if (!_.startsWith(key, '_') && ! _.isFunction(value)) {
  247. clone[key] = value;
  248. }
  249. });
  250. return clone;
  251. };
  252. ConfigurationInstance.prototype[util.inspect.custom] = function inspect(depth,
  253. options) {
  254. return util.inspect(this.toJSON(), options);
  255. };
  256. /* jshint ignore:start */
  257. /**
  258. * Initialize the ConfigurationContext
  259. *
  260. * @constructor Twilio.Conversations.V1.ConfigurationContext
  261. *
  262. * @param {V1} version - Version of the resource
  263. */
  264. /* jshint ignore:end */
  265. ConfigurationContext = function ConfigurationContext(version) {
  266. this._version = version;
  267. // Path Solution
  268. this._solution = {};
  269. this._uri = `/Configuration`;
  270. };
  271. /* jshint ignore:start */
  272. /**
  273. * fetch a ConfigurationInstance
  274. *
  275. * @function fetch
  276. * @memberof Twilio.Conversations.V1.ConfigurationContext#
  277. *
  278. * @param {function} [callback] - Callback to handle processed record
  279. *
  280. * @returns {Promise} Resolves to processed ConfigurationInstance
  281. */
  282. /* jshint ignore:end */
  283. ConfigurationContext.prototype.fetch = function fetch(callback) {
  284. var deferred = Q.defer();
  285. var promise = this._version.fetch({uri: this._uri, method: 'GET'});
  286. promise = promise.then(function(payload) {
  287. deferred.resolve(new ConfigurationInstance(this._version, payload));
  288. }.bind(this));
  289. promise.catch(function(error) {
  290. deferred.reject(error);
  291. });
  292. if (_.isFunction(callback)) {
  293. deferred.promise.nodeify(callback);
  294. }
  295. return deferred.promise;
  296. };
  297. /* jshint ignore:start */
  298. /**
  299. * update a ConfigurationInstance
  300. *
  301. * @function update
  302. * @memberof Twilio.Conversations.V1.ConfigurationContext#
  303. *
  304. * @param {object} [opts] - Options for request
  305. * @param {string} [opts.defaultChatServiceSid] -
  306. * The SID of the default Conversation Service that every new conversation will be associated with.
  307. * @param {string} [opts.defaultMessagingServiceSid] -
  308. * The SID of the default Messaging Service that every new conversation will be associated with.
  309. * @param {string} [opts.defaultInactiveTimer] -
  310. * Default ISO8601 duration when conversation will be switched to `inactive` state.
  311. * @param {string} [opts.defaultClosedTimer] -
  312. * Default ISO8601 duration when conversation will be switched to `closed` state.
  313. * @param {function} [callback] - Callback to handle processed record
  314. *
  315. * @returns {Promise} Resolves to processed ConfigurationInstance
  316. */
  317. /* jshint ignore:end */
  318. ConfigurationContext.prototype.update = function update(opts, callback) {
  319. if (_.isFunction(opts)) {
  320. callback = opts;
  321. opts = {};
  322. }
  323. opts = opts || {};
  324. var deferred = Q.defer();
  325. var data = values.of({
  326. 'DefaultChatServiceSid': _.get(opts, 'defaultChatServiceSid'),
  327. 'DefaultMessagingServiceSid': _.get(opts, 'defaultMessagingServiceSid'),
  328. 'DefaultInactiveTimer': _.get(opts, 'defaultInactiveTimer'),
  329. 'DefaultClosedTimer': _.get(opts, 'defaultClosedTimer')
  330. });
  331. var promise = this._version.update({uri: this._uri, method: 'POST', data: data});
  332. promise = promise.then(function(payload) {
  333. deferred.resolve(new ConfigurationInstance(this._version, payload));
  334. }.bind(this));
  335. promise.catch(function(error) {
  336. deferred.reject(error);
  337. });
  338. if (_.isFunction(callback)) {
  339. deferred.promise.nodeify(callback);
  340. }
  341. return deferred.promise;
  342. };
  343. /* jshint ignore:start */
  344. /**
  345. * Provide a user-friendly representation
  346. *
  347. * @function toJSON
  348. * @memberof Twilio.Conversations.V1.ConfigurationContext#
  349. *
  350. * @returns Object
  351. */
  352. /* jshint ignore:end */
  353. ConfigurationContext.prototype.toJSON = function toJSON() {
  354. return this._solution;
  355. };
  356. ConfigurationContext.prototype[util.inspect.custom] = function inspect(depth,
  357. options) {
  358. return util.inspect(this.toJSON(), options);
  359. };
  360. module.exports = {
  361. ConfigurationList: ConfigurationList,
  362. ConfigurationPage: ConfigurationPage,
  363. ConfigurationInstance: ConfigurationInstance,
  364. ConfigurationContext: ConfigurationContext
  365. };