forked from MONEI/Shopify-api-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasset.js
74 lines (64 loc) · 1.74 KB
/
asset.js
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
'use strict';
const assign = require('lodash/assign');
const pick = require('lodash/pick');
const baseChild = require('../mixins/base-child');
/**
* Creates an Asset instance.
*
* @param {Shopify} shopify Reference to the Shopify instance
* @constructor
* @public
*/
function Asset(shopify) {
this.shopify = shopify;
this.parentName = 'themes';
this.name = 'assets';
this.key = 'asset';
}
assign(Asset.prototype, pick(baseChild, ['list', 'buildUrl']));
/**
* Get a single asset by its ID.
*
* @param {Number} themeId Theme ID
* @param {Object} params Query parameters
* @return {Promise} Promise that resolves with the result
* @public
*/
Asset.prototype.get = function get(themeId, params) {
const url = this.buildUrl(themeId, undefined, params);
return this.shopify.request(url, 'GET', this.key);
};
/**
* Creates an asset.
*
* @param {Number} themeId Theme ID
* @param {Object} params Asset properties
* @return {Promise} Promise that resolves with the result
* @public
*/
Asset.prototype.create = function create(themeId, params) {
const url = this.buildUrl(themeId);
return this.shopify.request(url, 'PUT', this.key, params);
};
/**
* Updates an asset.
*
* @param {Number} themeId Theme ID
* @param {Object} params Asset properties
* @return {Promise} Promise that resolves with the result
* @public
*/
Asset.prototype.update = Asset.prototype.create;
/**
* Deletes an asset.
*
* @param {Number} themeId Theme ID
* @param {Object} params Query parameters
* @return {Promise} Promise that resolves with the result
* @public
*/
Asset.prototype.delete = function remove(themeId, params) {
const url = this.buildUrl(themeId, undefined, params);
return this.shopify.request(url, 'DELETE');
};
module.exports = Asset;