UNPKG

816 Btext/coffeescriptView Raw
1async = require 'async'
2
3ProductListPage = require './page/ProductListPage'
4
5
6#### retrieve product IDs.
7module.exports = (options, callback) ->
8 return callback new Error 'no options.url' if not options.url?
9
10 productIds = []
11
12 isLastPage = false
13 currentUrl = options.url
14
15 async.until ->
16 isLastPage
17 ,
18 (callback) ->
19 productListPage = new ProductListPage
20 url: currentUrl
21 ,
22 (err) ->
23 return callback err if err?
24
25 productIds = productIds.concat productListPage.getProductIds()
26 nextPageUrl = productListPage.getNextPageUrl()
27
28 if nextPageUrl?
29 currentUrl = nextPageUrl
30 else
31 isLastPage = true
32
33 callback null
34 ,
35 (err) ->
36 return callback err if err?
37
38 callback null, productIds
39
\No newline at end of file