-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathresult.js
More file actions
executable file
·107 lines (103 loc) · 2.8 KB
/
result.js
File metadata and controls
executable file
·107 lines (103 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import * as Utils from '../lib/utils';
/**
* @class Result
* @summary Creates an instance of `Result`.
* @description An initializer is responsible for creating Result object.
* @param {Object} object - API result object
* @example
* blogEntry.then(function (result) {
* // success function
* },function (error) {
* // error function
* })
* @example
* assetQuery.then(function (result) {
* // success function
* },function (error) {
* // error function
* })
* @returns {Result}
* @instance
*/
export default class Result {
constructor (object) {
if (object) {
this.object = function () {
return object;
};
}
return this;
}
/**
* @method toJSON
* @memberOf Result
* @description Converts `Result` to plain javascript object.
* @example
* blogEntry.then(function (result) {
* result = result[0][0].toJSON()
* },function (error) {
* // error function
* })
* @example
* assetQuery.then(function (result) {
* result = result[0][0].toJSON()
* },function (error) {
* // error function
* })
* @returns {object}
* @instance
*/
toJSON () {
return (this.object()) ? Utils.mergeDeep(JSON.parse(JSON.stringify({})), this.object()) : null;
}
/**
* @method get
* @memberOf Result
* @description Retrieve details of a field based on the UID provided
* @param field_uid uid of the field
* @example
* blogEntry.then(function (result) {
* let value = result[0][0].get(field_uid)
* },function (error) {
* // error function
* })
* @example
* assetQuery.then(function (result) {
* let value = result[0][0].get(field_uid)
* },function (error) {
* // error function
* })
* @returns {promise}
* @instance
*/
get (key) {
if (this.object() && key) {
const fields = key.split('.');
const value = fields.reduce(function (prev, field) {
return prev[field];
}, this.object());
return value;
}
}
/**
* @method getDownloadUrl
* @memberOf Result
* @description Retrieves the download URL based on the disposition value.
* @param {String} string - disposition value
* @example
* assetQuery.then(function (result) {
* let value = result[0][0].getDownloadUrl(disposition_value)
* },function (error) {
* // error function
* })
* @returns {Object}
* @instance
*/
getDownloadUrl (disposition) {
if (this.object()) {
const url = (this.object().url) ? this.object().url : null;
const _disposition = (disposition && typeof disposition === 'string') ? disposition : 'attachment';
return (url) ? url + '?disposition=' + _disposition : null;
}
}
}