Last active
March 11, 2025 00:47
-
-
Save ErickWendel/145ad20b7b2c465e2c36c61acc678349 to your computer and use it in GitHub Desktop.
Example of how to automate contribution submissions on GDE API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require('axios') | |
class GDEAPI { | |
constructor({ token }) { | |
this.token = token | |
} | |
async submitContributions(body) { | |
const headers = { | |
"accept": "application/json, text/plain, */*", | |
"accept-language": "en-US,en;q=0.9", | |
"authorization": `Bearer ${this.token}`, | |
"cache-control": "no-cache", | |
"content-type": "application/json", | |
"pragma": "no-cache", | |
"sec-fetch-dest": "empty", | |
"sec-fetch-mode": "cors", | |
"sec-fetch-site": "same-site", | |
"sec-gpc": "1" | |
} | |
return axios.post("https://api-gde.advocu.com/activities", body, { | |
headers, | |
}); | |
} | |
baseObj(contribution, type) { | |
return { | |
category: 'Web Technologies', | |
type, | |
city: null, | |
country: null, | |
date: new Date(contribution.date).getTime(), | |
title: contribution.title, | |
description: contribution.description, | |
reach: contribution.reach, | |
link: contribution.link, | |
tags: contribution.tags, | |
publishable: true | |
} | |
} | |
prepareData(contribution) { | |
const type = { | |
'article': (contribution) => { | |
return { | |
...this.baseObj(contribution, 'written'), | |
subtype: 'article', | |
} | |
}, | |
'video': (contribution) => { | |
return { | |
...this.baseObj(contribution, 'video'), | |
subtype: 'video', | |
} | |
}, | |
'talk': (contribution) => { | |
return { | |
...this.baseObj(contribution, 'talk'), | |
subtype: null, | |
onlineActivity: true | |
} | |
}, | |
} | |
return type[contribution.type.toLowerCase()](contribution) | |
} | |
} | |
// Your should get your token from Google Page (inpect element on google requests, on request header get Bearer token | |
// Your token will be a JWT token | |
// such as | |
const token = '' | |
const gdeApi = new GDEAPI({ token }) | |
// post an article | |
const contribution = { | |
"category": "Web Technologies", | |
"type": "article", | |
"date": "2021-02-13", | |
"title": "Your amazing title", | |
"description": "Your amazing description", | |
"reach": "10000", | |
"link": "your.amazing.link.com", | |
"tags": ["Web Technologies"], | |
} | |
const body = gdeApi.prepareData(contribution) | |
const result = await gdeApi.submitContributions(body) | |
console.log(result) | |
/* | |
{ key: '09213avb' } | |
*/ | |
// other contribution types | |
/* | |
const video = { | |
"category": "Web Technologies", | |
"type": "video", | |
"date": "2021-02-13", | |
"title": "Your amazing title", | |
"description": "Your amazing description", | |
"reach": "10000", | |
"link": "your.amazing.link.com", | |
"tags": ["Web Technologies"], | |
} | |
const talk = { | |
"category": "Web Technologies", | |
"type": "talk", | |
"date": "2021-02-13", | |
"title": "Your amazing title", | |
"description": "Your amazing description", | |
"reach": "10000", | |
"link": "your.amazing.link.com", | |
"tags": ["Web Technologies"], | |
} | |
const article = { | |
"category": "Web Technologies", | |
"type": "article", | |
"date": "2021-02-13", | |
"title": "Your amazing title", | |
"description": "Your amazing description", | |
"reach": "10000", | |
"link": "your.amazing.link.com", | |
"tags": ["Web Technologies"], | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What a pleasing piece of code to read. Nice!