@andrewstoliarov/apple-search-ads
Advanced tools
Comparing version 1.2.0 to 1.2.1
{ | ||
"name": "@andrewstoliarov/apple-search-ads", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Apple search ads api client.", | ||
@@ -5,0 +5,0 @@ "main": "src/appleSearchAds.js", |
@@ -188,1 +188,2 @@ 'use strict'; | ||
module.exports.queryTypes = query.queryTypes; | ||
module.exports.groupKey = query.groupKey; |
@@ -12,3 +12,8 @@ 'use strict'; | ||
const groupKey = { | ||
countryOrRegion: 'countryOrRegion' | ||
}; | ||
module.exports.measures = measures; | ||
module.exports.groupKey = groupKey; | ||
@@ -71,2 +76,13 @@ module.exports.queryTypes = { | ||
const timeZone = this.config.timeZone ? this.config.timeZone : 'UTC'; | ||
const selector = { | ||
orderBy: [{ | ||
field: "localSpend", | ||
sortOrder: "DESCENDING" | ||
}], | ||
pagination: { | ||
offset: this.config.offset ? this.config.offset : 0, | ||
limit: this.config.limit ? this.config.limit : 50 | ||
} | ||
}; | ||
this.config.body = { | ||
@@ -80,12 +96,4 @@ type: this.config.measure, | ||
returnGrandTotals: true, | ||
selector: { | ||
orderBy: [{ | ||
field: "localSpend", | ||
sortOrder: "DESCENDING" | ||
}], | ||
pagination: { | ||
offset: this.config.offset ? this.config.offset : 0, | ||
limit: this.config.limit ? this.config.limit : 50 | ||
} | ||
}, | ||
groupBy: this.config.groupBy, | ||
selector, | ||
"returnRecordsWithNoMetrics": true | ||
@@ -218,2 +226,18 @@ } | ||
Query.prototype.groupBy = function(key) { | ||
if (!key) { | ||
throw new Error('Group key not exists: ' + key); | ||
} | ||
if(Object.values(groupKey).indexOf(key) === -1) { | ||
throw new Error('Is not valid group key: ' + key); | ||
} | ||
if(!this.config.groupBy) { | ||
this.config.groupBy = []; | ||
} | ||
this.config.groupBy.push(key); | ||
return this; | ||
} | ||
Query.prototype.date = function(start, end) { | ||
@@ -220,0 +244,0 @@ this.config.start = toMomentObject(start); |
@@ -19,2 +19,3 @@ var asa = require('./../src/appleSearchAds.js'); | ||
.date('2021-02-01', '2021-02-02') | ||
.groupBy(asa.groupKey.countryOrRegion) | ||
.limit(50) | ||
@@ -21,0 +22,0 @@ .offset(0) |
17469
426