How to use pingBack method in wpt

Best JavaScript code snippet using wpt

pingback-networking.js

Source:pingback-networking.js Github

copy

Full Screen

1import fetch from 'isomorphic-fetch'2import cookie from 'cookie'3import getLastSearchResponseId from 'shared/util/get-last-search-id'4import _ from 'lodash'5const pingBackUrl = 'https://pingback.giphy.com/pingback?apikey=l0HlIwPWyBBUDAUgM'6// const pingBackUrl_debug = 'https://pingback.giphy.com/pingback_debug?apikey=l0HlIwPWyBBUDAUgM'7const queuedEvents = {}8const user = {}9const debouncedPingbackEvent = pingbackDebounce()10function pingbackDebounce() {11 return _.debounce(fetchPingbackRequest, 1000)12}13// for IntervalCalls and UnmountCalls14export function fetchPingbackRequest() {15 // if there are no actions lined up inside this pingbackType do nothing16 _.forEach(Object.keys(queuedEvents), pingbackTypeKeys => {17 if (Array.isArray(queuedEvents[pingbackTypeKeys])) {18 if (queuedEvents[pingbackTypeKeys].length) {19 const session = createSession(pingbackTypeKeys)20 fetch(pingBackUrl, {21 method: 'POST',22 body: JSON.stringify({23 sessions: [session]24 }),25 headers: {26 'Content-Type': 'application/json',27 },28 })29 // empty this specific batch30 queuedEvents[pingbackTypeKeys] = []31 }32 } else {33 // if the nested value is an object loop over the keys otherwise take what is there34 _.forEach(Object.keys(queuedEvents[pingbackTypeKeys]), pingBackResponseIdKeys => {35 if (queuedEvents[pingbackTypeKeys][pingBackResponseIdKeys].length) {36 const session = createSession(pingbackTypeKeys, pingBackResponseIdKeys)37 fetch(pingBackUrl, {38 method: 'POST',39 body: JSON.stringify({40 sessions: [session]41 }),42 headers: {43 'Content-Type': 'application/json',44 },45 })46 // empty this specific batch47 queuedEvents[pingbackTypeKeys][pingBackResponseIdKeys] = []48 }49 })50 }51 })52}53function createSession(pingbackType, searchResponseId) {54 const {55 giphy_pbid56 } = cookie.parse(document.cookie)57 const pingbackSessionSchemas = {58 trending_grid: {59 user: {60 user_id: giphy_pbid,61 logged_in_user_id: String(user.id || ''),62 },63 events: [{64 event_type: 'GIF_TRENDING',65 referrer: document && document.referrer ? document.referrer : null,66 actions: queuedEvents[pingbackType][searchResponseId],67 response_id: searchResponseId,68 }, ],69 },70 related_grid: {71 user: {72 user_id: giphy_pbid,73 logged_in_user_id: String(user.id || ''),74 },75 events: [{76 event_type: 'GIF_RELATED',77 referrer: document && document.referrer ? document.referrer : null,78 actions: queuedEvents[pingbackType][searchResponseId],79 response_id: searchResponseId,80 }, ],81 },82 channel_grid: {83 user: {84 user_id: giphy_pbid,85 logged_in_user_id: String(user.id || ''),86 },87 events: [{88 event_type: 'GIF_CHANNEL',89 referrer: document && document.referrer ? document.referrer : null,90 actions: queuedEvents[pingbackType][searchResponseId],91 }, ],92 },93 search_grid: {94 user: {95 user_id: giphy_pbid,96 logged_in_user_id: String(user.id || ''),97 },98 events: [{99 event_type: 'GIF_SEARCH',100 response_id: searchResponseId,101 previous_response_id: getLastSearchResponseId() || null,102 referrer: document && document.referrer ? document.referrer : null,103 actions: queuedEvents[pingbackType][searchResponseId],104 }, ],105 },106 universal_search: {107 user: {108 user_id: giphy_pbid,109 logged_in_user_id: String(user.id || ''),110 },111 events: [{112 event_type: 'GIF_SEARCH',113 response_id: searchResponseId,114 previous_response_id: getLastSearchResponseId() || null,115 referrer: document && document.referrer ? document.referrer : null,116 actions: queuedEvents[pingbackType][searchResponseId],117 }, ],118 },119 suggested_terms: {120 user: {121 user_id: giphy_pbid,122 logged_in_user_id: String(user.id || ''),123 },124 events: [{125 event_type: 'GIF_SEARCH',126 response_id: searchResponseId,127 previous_response_id: getLastSearchResponseId() || null,128 referrer: document && document.referrer ? document.referrer : null,129 actions: queuedEvents[pingbackType][searchResponseId],130 }, ],131 },132 explore_grid: {133 user: {134 user_id: giphy_pbid,135 logged_in_user_id: String(user.id || ''),136 },137 events: [{138 event_type: 'GIF_EXPLORE',139 response_id: searchResponseId,140 referrer: document && document.referrer ? document.referrer : null,141 actions: queuedEvents[pingbackType][searchResponseId],142 }, ],143 },144 trending_carousel: {145 user: {146 user_id: giphy_pbid,147 logged_in_user_id: String(user.id || ''),148 },149 events: [{150 event_type: 'GIF_TRENDING',151 response_id: searchResponseId,152 referrer: document && document.referrer ? document.referrer : null,153 actions: queuedEvents[pingbackType][searchResponseId],154 }, ],155 },156 }157 return pingbackSessionSchemas[pingbackType]158}159function queueAction(pingbackType, searchResponseId, action, userArg = {}) {160 if (userArg && userArg.id) {161 user.id = userArg.id162 }163 // the queue doesn't exist for this pingbackType yet so create it and create the corresponding searchResponseId key164 if (!queuedEvents[pingbackType] && action) {165 queuedEvents[pingbackType] = {}166 queuedEvents[pingbackType][searchResponseId] = [action]167 // the group exists but the searchRepsonseId queue does not so create it168 } else if (!queuedEvents[pingbackType][searchResponseId] && action) {169 queuedEvents[pingbackType][searchResponseId] = [action]170 // the queue exists already so just store it into the appropriate pingbackType queue171 } else if (action) {172 queuedEvents[pingbackType][searchResponseId].push(action)173 }174}175export function explorePingBackEvent(action, searchResponseId, user, skipQueue = false) {176 queueAction('explore_grid', searchResponseId, action, user)177 skipQueue ? fetchPingbackRequest() : debouncedPingbackEvent()178}179export function suggestedTermPingBackEvent(action, searchResponseId, user, skipQueue = false) {180 queueAction('suggested_terms', searchResponseId, action, user)181 skipQueue ? fetchPingbackRequest() : debouncedPingbackEvent()182}183export function universalSearchPingBackEvent(action, searchResponseId, user, skipQueue = false) {184 queueAction('universal_search', searchResponseId, action, user)185 skipQueue ? fetchPingbackRequest() : debouncedPingbackEvent()186}187export function trendingGridPingBackEvent(action, searchResponseId, user, skipQueue = false) {188 queueAction('trending_grid', searchResponseId, action, user)189 skipQueue ? fetchPingbackRequest() : debouncedPingbackEvent()190}191export function trendingCarouselPingBackEvent(action, searchResponseId, user, skipQueue = false) {192 queueAction('trending_carousel', searchResponseId, action, user)193 skipQueue ? fetchPingbackRequest() : debouncedPingbackEvent()194}195export function searchPingBackEvent(action, searchResponseId, user, skipQueue = false) {196 queueAction('search_grid', searchResponseId, action, user)197 skipQueue ? fetchPingbackRequest() : debouncedPingbackEvent()198}199export function relatedPingBackEvent(action, searchResponseId, user, skipQueue = false) {200 queueAction('related_grid', searchResponseId, action, user)201 skipQueue ? fetchPingbackRequest() : debouncedPingbackEvent()202}203export function channelPingBackEvent(action, searchResponseId, user, skipQueue = false) {204 queueAction('channel_grid', searchResponseId, action, user)205 skipQueue ? fetchPingbackRequest() : debouncedPingbackEvent()206}207export default pingbackEvent => {208 return function() {209 const {210 giphy_pbid211 } = cookie.parse(document.cookie)212 const session = {213 session_id: '',214 user: {215 user_id: giphy_pbid,216 logged_in_user_id: String(window.USER && window.USER.id ? window.USER.id : ''),217 },218 events: [pingbackEvent],219 }220 return fetch(pingBackUrl, {221 method: 'POST',222 body: JSON.stringify({223 sessions: [session]224 }),225 headers: {226 'Content-Type': 'application/json',227 },228 })229 }...

Full Screen

Full Screen

amp-access-client.js

Source:amp-access-client.js Github

copy

Full Screen

1/**2 * Copyright 2016 The AMP HTML Authors. All Rights Reserved.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS-IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16import {Services} from '#service';17import {assertHttpsUrl} from '../../../src/url';18import {dev, devAssert, userAssert} from '../../../src/log';19import {dict} from '#core/types/object';20import {getMode} from '../../../src/mode';21/** @const {string} */22const TAG = 'amp-access-client';23/** @const {number} */24const DEFAULT_AUTHORIZATION_TIMEOUT = 3000;25/** @implements {./amp-access-source.AccessTypeAdapterDef} */26export class AccessClientAdapter {27 /**28 * @param {!../../../src/service/ampdoc-impl.AmpDoc} ampdoc29 * @param {!JsonObject} configJson30 * @param {!./amp-access-source.AccessTypeAdapterContextDef} context31 */32 constructor(ampdoc, configJson, context) {33 /** @const */34 this.ampdoc = ampdoc;35 /** @const @private {!./amp-access-source.AccessTypeAdapterContextDef} */36 this.context_ = context;37 /** @const @private {string} */38 this.authorizationUrl_ = userAssert(39 configJson['authorization'],40 '"authorization" URL must be specified'41 );42 assertHttpsUrl(this.authorizationUrl_, '"authorization"');43 /** @const @private {boolean} */44 this.isPingbackEnabled_ = !configJson['noPingback'];45 /** @const @private {string} */46 this.pingbackUrl_ = configJson['pingback'];47 if (this.isPingbackEnabled_) {48 userAssert(this.pingbackUrl_, '"pingback" URL must be specified');49 assertHttpsUrl(this.pingbackUrl_, '"pingback"');50 }51 /** @const @private {number} */52 this.authorizationTimeout_ =53 this.buildConfigAuthorizationTimeout_(configJson);54 /** @const @private {!../../../src/service/xhr-impl.Xhr} */55 this.xhr_ = Services.xhrFor(ampdoc.win);56 /** @const @private {!../../../src/service/timer-impl.Timer} */57 this.timer_ = Services.timerFor(ampdoc.win);58 }59 /**60 * @param {!JsonObject} configJson61 * @return {number}62 */63 buildConfigAuthorizationTimeout_(configJson) {64 if (!configJson['authorizationTimeout']) {65 return DEFAULT_AUTHORIZATION_TIMEOUT;66 }67 let timeout = configJson['authorizationTimeout'];68 userAssert(69 typeof timeout == 'number',70 '"authorizationTimeout" must be a number'71 );72 if (!(getMode().localDev || getMode().development)) {73 timeout = Math.min(timeout, DEFAULT_AUTHORIZATION_TIMEOUT);74 }75 return timeout;76 }77 /** @override */78 getConfig() {79 return {80 'authorizationUrl': this.authorizationUrl_,81 'pingbackEnabled': this.isPingbackEnabled_,82 'pingbackUrl': this.pingbackUrl_,83 'authorizationTimeout': this.authorizationTimeout_,84 };85 }86 /**87 * @return {string}88 */89 getAuthorizationUrl() {90 return this.authorizationUrl_;91 }92 /** @override */93 isAuthorizationEnabled() {94 return true;95 }96 /**97 * @return {number}98 */99 getAuthorizationTimeout() {100 return this.authorizationTimeout_;101 }102 /** @override */103 authorize() {104 dev().fine(TAG, 'Start authorization via ', this.authorizationUrl_);105 const urlPromise = this.context_.buildUrl(106 this.authorizationUrl_,107 /* useAuthData */ false108 );109 return urlPromise.then((url) => {110 dev().fine(TAG, 'Authorization URL: ', url);111 return this.timer_112 .timeoutPromise(113 this.authorizationTimeout_,114 this.xhr_.fetchJson(url, {115 credentials: 'include',116 })117 )118 .then((res) => res.json());119 });120 }121 /** @override */122 isPingbackEnabled() {123 return this.isPingbackEnabled_;124 }125 /** @override */126 pingback() {127 const promise = this.context_.buildUrl(128 devAssert(this.pingbackUrl_),129 /* useAuthData */ true130 );131 return promise.then((url) => {132 dev().fine(TAG, 'Pingback URL: ', url);133 return this.xhr_.sendSignal(url, {134 method: 'POST',135 credentials: 'include',136 headers: dict({137 'Content-Type': 'application/x-www-form-urlencoded',138 }),139 body: '',140 });141 });142 }143 /** @override */144 postAction() {145 // Nothing to do.146 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1wptService.pingBack(function (err, data) {2 if (err) {3 console.log(err);4 } else {5 console.log(data);6 }7});8wptService.getLocations(function (err, data) {9 if (err) {10 console.log(err);11 } else {12 console.log(data);13 }14});15wptService.getTesters(function (err, data) {16 if (err) {17 console.log(err);18 } else {19 console.log(data);20 }21});22wptService.getTesters(function (err, data) {23 if (err) {24 console.log(err);25 } else {26 console.log(data);27 }28});29wptService.getTest('10000000', function (err, data) {30 if (err) {31 console.log(err);32 } else {33 console.log(data);34 }35});36wptService.getTest('10000000', function (err, data) {37 if (err) {38 console.log(err);39 } else {40 console.log(data);41 }42});43wptService.getTestResults('10000000', function (err, data) {44 if (err) {45 console.log(err);46 } else {47 console.log(data);48 }49});50wptService.getTestResults('10000000', function (err, data) {51 if (err) {52 console.log(err);53 } else {54 console.log(data);55 }56});57wptService.getTestStatus('10000000', function (err, data) {58 if (err) {59 console.log(err);60 } else {61 console.log(data);62 }63});64wptService.getTestStatus('10000000', function (err, data) {65 if (err) {66 console.log(err);67 } else {68 console.log(data);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./lib/wpt');2var pingBack = wpt.pingBack;3var options = {4};5pingBack(options, function(err, data) {6 if (err) {7 console.log(err);8 } else {9 console.log(data);10 }11});12#### wpt.getTestStatus(options, callback)13#### wpt.getTestResults(options, callback)14#### wpt.getTestInfo(options, callback)15#### wpt.getLocations(callback)

Full Screen

Using AI Code Generation

copy

Full Screen

1var WPT = require('wpt.js');2var wpt = new WPT('API_KEY');3 if (err) {4 console.log('Error: ' + err);5 } else {6 console.log('Data: ' + data);7 }8});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt.js');2var wpt = new wpt('your api key');3});4var wpt = require('wpt.js');5var wpt = new wpt('your api key');6wpt.getLocations(function (err, data) {7});8var wpt = require('wpt.js');9var wpt = new wpt('your api key');10wpt.getTesters(function (err, data) {11});12var wpt = require('wpt.js');13var wpt = new wpt('your api key');14});15var wpt = require('wpt.js');16var wpt = new wpt('your api key');17});18var wpt = require('wpt.js');19var wpt = new wpt('your api key');20});21var wpt = require('wpt.js');22var wpt = new wpt('your api key');23});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var testID = process.argv[2];3var location = process.argv[3];4var runs = process.argv[4];5var firstViewOnly = process.argv[5];6var isPrivate = process.argv[6];7wpt.pingBack(testID, location, runs, firstViewOnly, isPrivate);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.8e4d4e2e4d4e2e4d4e2e4d4e2e4d4e2e');3 if (err) {4 console.log("Error: " + err);5 } else {6 console.log("Test ID: " + data.data.testId);7 console.log("Test Status: " + data.data.statusText);8 console.log("Test URL: " + data.data.summary);9 }10});11 if (err) {12 console.log("Error: " + err);13 } else {14 console.log("Test ID: " + data.data.testId);15 console.log("Test Status: " + data.data.statusText);16 console.log("Test URL: " + data.data.summary);17 }18});19wpt.getTestStatus('160409_1G_1', function(err, data) {20 if (err) {21 console.log("Error: " + err);22 } else {23 console.log("Test ID: " + data.data.testId);24 console.log("Test Status: " + data.data.statusText);25 console.log("Test URL: " + data.data.summary);26 }27});28wpt.getTestResults('160409_1G_1', function(err, data) {29 if (err) {30 console.log("Error: " + err);31 } else {32 console.log("Test ID: " + data.data.testId);33 console.log("Test Status: " + data.data.statusText);34 console.log("Test URL: " + data.data.summary);35 }36});37wpt.getLocations(function(err, data) {38 if (err) {39 console.log("Error: " + err);40 } else {41 console.log("Test ID: " + data.data.testId);42 console.log("Test Status: " + data.data.statusText);43 console.log("Test URL: " + data.data.summary);44 }45});46wpt.getTesters(function(err, data

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var client = wpt('www.webpagetest.org');3var testId = '140904_7Y_8d8e2b2f9c9d1e1e0c8c4f4a2a2c4b4d';4var test = client.pingBack(testId, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11var wpt = require('webpagetest');12var client = wpt('www.webpagetest.org');13var test = client.getLocations(function(err, data) {14 if (err) {15 console.log(err);16 } else {17 console.log(data);18 }19});20var wpt = require('webpagetest');21var client = wpt('www.webpagetest.org');22var test = client.getTesters(function(err, data) {23 if (err) {24 console.log(err);25 } else {26 console.log(data);27 }28});29var wpt = require('webpagetest');30var client = wpt('www.webpagetest.org');31var test = client.getTesters(function(err, data) {32 if (err) {33 console.log(err);34 } else {35 console.log(data);36 }37});38var wpt = require('webpagetest');39var client = wpt('www.webpagetest.org');40var testId = '140904_7Y_8d8e2b2f9c9d1e1e0c8c4f4a2a2c4b4d';41var test = client.getTestStatus(testId, function(err, data) {42 if (err) {43 console.log(err);44 } else {45 console.log(data);46 }47});48var wpt = require('webpagetest');49var client = wpt('www.webpagetest.org');

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful