<repo_name>ChaonengTan/FEW2.1-GTranslateAPILib<file_sep>/README.md
![npm (scoped)](https://img.shields.io/npm/v/@chaonengtan/few2.1-gtranslateapilib) ![GitHub repo size](https://img.shields.io/github/repo-size/ChaonengTan/FEW2.1-GTranslateAPILib) ![GitHub issues](https://img.shields.io/github/issues/ChaonengTan/FEW2.1-GTranslateAPILib) 

API Source: https://english.api.rakuten.net/googlecloud/api/google-translate1

About:
A twist on rakuten's google translate API
for personal use but also if anyone else wants

How to use:
note* : REQUIRES APIKEY FROM API Source!!!
1) require module
2) create new gt object with perameter APIKEY
3) call any function part of this package

Includes:
.translate([payload], [targetLanguage(default=english)], [sourceLanguage(optional)]) =>
  returns JSON.parsed Promise
.previous() =>
  returns previous JSON data
.setKey([newApiKey]) =>
  changes APIKEY to newApiKey<file_sep>/src/index.js
class gt{
    constructor(APIKEY){
        this._APIKEY = APIKEY
        this.options = {
            method: 'POST',
            url: 'https://google-translate1.p.rapidapi.com/language/translate/v2',
            headers: {
                'content-type': 'application/x-www-form-urlencoded',
                'accept-encoding': 'application/gzip',
                'x-rapidapi-key': `${this._APIKEY}`,
                'x-rapidapi-host': 'google-translate1.p.rapidapi.com',
                useQueryString: true
            },
            form: undefined
        }
    }
    translate(query, target = 'en', source = null){
        this.options.form = {q: query, target: target, source: source}
        const request = require('request-promise-native')
        return request(this.options)
            .then(res => JSON.parse(res))
            .then(res => {
                console.log(res.data.translations[0].translatedText)
                this.prevCall = res
                return(res)
            })
            .catch(err => {
                throw new Error(err)
            })
    }
    previous(){ if(this.prevCall) return this.prevCall }
    setKey(APIKEY){
        this._APIKEY = APIKEY
    }
}
module.exports = {
    gt:gt,
}
