async function processAndRecur (html, opts, savedApps, mappings) { if (R.is(String, html)) { html = scriptData.parse(html); } const processedApps = appList.extract(mappings.apps, html); const apps = opts.fullDetail ? await processFullDetailApps(processedApps, opts) : processedApps; const token = R.path(mappings.token, html); return checkFinished(opts, [...savedApps, ...apps], token); }
function processShortPermissionsData (html) { if (R.is(String, html)) { html = scriptData.parse(html); } const commonPermissions = html[c.permission.COMMON]; if (!commonPermissions) { return []; } const validPermissions = commonPermissions.filter(permission => permission.length); const permissionNames = R.chain(permission => permission[MAPPINGS.type], validPermissions); return permissionNames; }
async function processReviewsAndGetNextPage (html, opts, savedReviews) { const processAndRecurOptions = Object.assign({}, opts, { requestType: REQUEST_TYPE.paginated }); const { appId, paginate, num } = processAndRecurOptions; const parsedHtml = R.is(String, html) ? scriptData.parse(html) : html; if (parsedHtml.length === 0) { return formatReviewsResponse({ reviews: savedReviews, token: null, num }); } // PROCESS REVIEWS EXTRACTION const reviews = reviewsList.extract(REQUEST_MAPPINGS.reviews, parsedHtml, appId); const token = R.path(REQUEST_MAPPINGS.token, parsedHtml); const reviewsAccumulator = [...savedReviews, ...reviews]; return (!paginate && token && reviewsAccumulator.length < num) ? makeReviewsRequest(processAndRecurOptions, reviewsAccumulator, token) : formatReviewsResponse({ reviews: reviewsAccumulator, token, num }); }
/** * Map the MAPPINGS object, applying each field spec to the parsed data. * If the mapping value is an array, use it as the path to the extract the * field's value. If it's an object, extract the value in object.path and pass * it to the function in object.fun * * @param {array} mappings The mappings object */ function extractor (mappings) { return function extractFields (parsedData) { debug('parsedData: %o', parsedData); return R.map((spec) => { if (R.is(Array, spec)) { return R.path(spec, parsedData); } // extractDataWithServiceRequestId explanation: // https://github.com/facundoolano/google-play-scraper/pull/412 // assume spec object const input = (spec.useServiceRequestId) ? extractDataWithServiceRequestId(parsedData, spec) : R.path(spec.path, parsedData); return spec.fun(input, parsedData); }, mappings); }; }
function processPermissionData (html) { if (R.is(String, html)) { html = scriptData.parse(html); } debug(`html %o`, html); const permissions = Object.values(c.permission).reduce((permissionAccummulator, permission) => { if (!html[permission]) { return permissionAccummulator; } permissionAccummulator.push( ...R.chain(flatMapPermissions, html[permission]) ); return permissionAccummulator; }, []); debug(`Permissions %o`, permissions); return permissions; }
/* * Extract navigation tokens for next pages, parse results and call * `checkFinished` to repeat the process with next page if necessary. */ function processAndRecur (html, opts, savedApps, mappings) { if (R.is(String, html)) { html = scriptData.parse(html); } const apps = appList.extract(mappings.apps, html); const token = R.path(mappings.token, html); return checkFinished(opts, [...savedApps, ...apps], token); }
const wrap = (middleware, app, req) => new Promise((resolve, reject) => { const dispatch = res => flow(res) const finish = ifElse(is(Error), reject, resolve) const store = { dispatch, getState: noop } const flow = apply(compose, map(thrush(store), prepend(promise, middleware)) )(finish) flow(app(req)) })
const chooseOrigin = (allowed, origin) => cond([ [equals('*'), always('*')], [equals(true), always(origin)], [both(is(RegExp), flip(test)(origin)), always(origin)], [T, always('false')], ])(allowed)
function handleError (error) { const amioErrors = path(['response', 'data', 'errors'], error); if(is(Array, amioErrors)) throw new AmioApiError(error.response.data) throw error }
// process STARTUP actions export function * startup (action) { const avatar = yield select(selectAvatar) // only get if we don't have it yet if (!is(String, avatar)) { yield put(GithubActions.userRequest('GantMan')) } yield put(AppStateActions.setRehydrationComplete()) const isLoggedIn = yield select(selectLoggedInStatus) if (isLoggedIn) { yield put(LoggedInActions.autoLogin()) } }
R.when( R.compose( R.is(Object), R.prop("info") ), obj => Object.assign(obj, { additional_info: obj.info }) )
addQuickReply(quickReply) { if (is(Object, quickReply)) { this.quickReplies.push(quickReply) } else { this.quickReplies.push({ type: quickReply }) } return this }
/** * Is this not a string? * * @param value The value to check * @return True if it is not a string, otherwise false */ function isNotString(value: any): boolean { return !is(String, value) }
R.when( R.compose( R.is(String), R.prop("dependentOn") ), obj => Object.assign(obj, { dependentOn: { serviceName: obj.dependentOn } }) )
async function processAndRecur (html, opts, savedApps, mappings) { if (R.is(String, html)) { html = scriptData.parse(html); } const processedApps = appList.extract(mappings.apps, html); const apps = opts.fullDetail ? await processFullDetailApps(processedApps, opts) : processedApps; const token = R.path(mappings.token, html); return checkFinished(opts, [...savedApps, ...apps], token); }