Skip to content

Instantly share code, notes, and snippets.

@iampato
Last active August 18, 2023 12:25
Show Gist options
  • Save iampato/e133ba9195ed2a31aed128f9291ea083 to your computer and use it in GitHub Desktop.
Save iampato/e133ba9195ed2a31aed128f9291ea083 to your computer and use it in GitHub Desktop.
const axios = require("axios");
const express = require("express");
const GRAPHQL_URL = "https://sports-fed-api.stage.nonprod.wmsports.io/graphql";
// querySportsFedApi
// paramaters is an objects that contains: url, token, query
// returns the response from the query or undefined if unsuccessful
const querySportsFedApiReferenceStream = async (opts) => {
// parameters
const { token } = opts;
// null handling
if (!token ) {
throw "token can't be null";
}
// create http headers
const myHeaders = {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
};
// Creating the http request body which is our graphql query
const request = {
query: `
referenceStream {
references {
id
title
description
thumbnailUrl
permalink
url
author
tag {
id
name
permalink
type
href
}
metadata {
genres
video {
analytics {
id
publishedAt
rating
ruleId
ruleName
stream
title
videoId
videoType
team
league
}
hlsUrl
mp4Url
videoId
impressionTracking {
name
url
}
width
height
state
}
}
}
}
`,
};
// using axios to call method post
const response = await axios.post(GRAPHQL_URL, request, {
headers: myHeaders,
});
console.log(response.status);
if (response.status === 200) {
// return data
return response.data;
} else {
return undefined;
}
};
//if youwant to get reference stream
const getReferenceStream = () => {
const opts = {
token:
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwczovL2FwaS9ncmFwaHFsIjp7InJvbGVzIjpbImRpcmVjdG9yIl0sInBlcm1pc3Npb25zIjpbInJlYWQ6YW55X3VzZXIiLCJyZWFkOm93bl91c2VyIl19LCJpYXQiOjE2OTEwODQzOTgsImV4cCI6MTY5ODg2MDM5OCwic3ViIjoiMTIzNDUifQ.tEcueS6EN9NZaPgwVP6QykdVgH6L-juCVGSYF08xnws",
};
querySportsFedApiReferenceStream(opts)
.then((response) => {
if (response) {
console.log(response);
} else {
//
}
})
.catch((e) => {
console.log(e);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment