├── .jshintrc ├── .gitignore ├── examples ├── run_source.js ├── compile_source.js ├── run_source_promise.js └── compile_source_promise.js ├── contributing.md ├── .travis.yml ├── gulpFile.js ├── test.js ├── package.json ├── .jscs.json ├── source └── index.js ├── README.md └── distribution └── index.js /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "undef" : true, 3 | "esversion" : 6, 4 | "node": true 5 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /build 3 | /cache 4 | npm-debug.log 5 | .DS_Store 6 | /*.env 7 | server.js -------------------------------------------------------------------------------- /examples/run_source.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const HackerEarth = require('./hackerEarth-js'); 4 | 5 | const hackerEarth = new HackerEarth( 6 | '**********', //client secret key 7 | '' 8 | ); 9 | 10 | const config = {}; 11 | 12 | config.time_limit = 1; 13 | 14 | config.memory_limit = 323244; 15 | 16 | config.source = 'Your Code'; 17 | 18 | config.input = "5"; 19 | 20 | hackerEarth.run(config, (err, res) => { 21 | if (err) { 22 | console.log(err); 23 | } 24 | console.log(JSON.parse(res)); 25 | }); 26 | -------------------------------------------------------------------------------- /examples/compile_source.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const HackerEarth = require('./hackerEarth-js'); 4 | 5 | const hackerEarth = new HackerEarth( 6 | '**********', //client secret key 7 | '' 8 | ); 9 | 10 | const config = {}; 11 | 12 | config.time_limit = 1; 13 | 14 | config.memory_limit = 323244; 15 | 16 | config.source = 'Your Code'; 17 | 18 | config.input = "5"; 19 | 20 | hackerEarth.compile(config, (err, res) => { 21 | if (err) { 22 | console.log(err); 23 | } 24 | console.log(JSON.parse(res)); 25 | }); 26 | 27 | -------------------------------------------------------------------------------- /examples/run_source_promise.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const HackerEarth = require('./hackerEarth-js'); 4 | 5 | const hackerEarth = new HackerEarth( 6 | '**********', //client secret key 7 | '' 8 | ); 9 | 10 | const config = {}; 11 | 12 | config.time_limit = 1; 13 | 14 | config.memory_limit = 323244; 15 | 16 | config.source = 'Your Code'; 17 | 18 | config.input = "5"; 19 | 20 | hackerEarth.run(config) 21 | .then((res) => { 22 | //deal with result 23 | }) 24 | .catch((err) => { 25 | //deal with error 26 | }); -------------------------------------------------------------------------------- /examples/compile_source_promise.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const HackerEarth = require('./hackerEarth-js'); 4 | 5 | const hackerEarth = new HackerEarth( 6 | '**********', //client secret key 7 | '' 8 | ); 9 | 10 | const config = {}; 11 | 12 | config.time_limit = 1; 13 | 14 | config.memory_limit = 323244; 15 | 16 | config.source = 'Your Code'; 17 | 18 | config.input = "5"; 19 | 20 | hackerEarth.compile(config) 21 | .then((result) => { 22 | //deal with result 23 | }) 24 | .catch((err) => { 25 | //deal with errr 26 | }); 27 | 28 | -------------------------------------------------------------------------------- /contributing.md: -------------------------------------------------------------------------------- 1 |

Welcome

2 | 3 | Feel free to open an issue for bug or a PR for feature. 4 | 5 | I would be more than happy to see it and fix/merge it. So go ahead :). 6 | 7 |

How to

8 | - Clone this repo. 9 | - Run `npm install` or it's shorthand `npm i`. 10 | - Source files are in `source\` directory. 11 | - Make changes in `source\` directory. 12 | - Run your code against linting errors using `npm run lint` 13 | * If passed then go ahead. 14 | * If failed please see the reason and fix it because code quality of our project should remain high. 15 | - If you wants to see build files then run `npm run build` . 16 | * It will create a `distribution\` directory of final transpiled build. 17 | - Else Just submit a patch or PR. 18 | 19 |

Thanks and All the best.

-------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 4 4 | - 5 5 | - 6 6 | env: 7 | secure: "ANHEk54OKqa/4Md/y2f4T1FVrgmXPHG6Wyh5quFrB5zTjxwoONYYkWLdi2BpPwR0s2cRCfM78Ju+NO+dnz6YcAz5ImT4jAvRR4bk9ZBXmdN6O6v28fO74IIhHArBEh5V3hGKemswm6jz/kF7J87FZ66gGdSEaaqHEtrLICxal06YCsHyIYvPTyR9LHzOWBj8bq5c2L/cgDet9A7iHsvN6rm7GYUA9KOCCDbDfy1on+dSPdwBxFDfXnhaqZ9igQEF6SmH+tJutdoq4rGkWsPR3Rc3Ij8gcH1BSzk+dGuZrQNfvnN66DstYgTrYPd5+TVWF1TjrEK7JPQv6Ckchp8sGE/hBFVqOsQEHMX9iE9WTmZ9O4QIDp3d1UxZU0jVZqZkRCrNvVWHpB9a7ks0EA8kL2V6zIp6s+dMkgBYrjte+qyfiuhJ1EgMHOU4JuFOqZfn1jwIK+9lLO1qjnenUBnOp1758nhqeOmdQP7Wr4mdl/hv370S9Xn8XvnDFCeJuZrlQGDJYK0r8ZA6wVhGsElzZQzbuxAvRaay5kgYJBuYS8F+sqoVlM3/gF86Iw7NyhcFNCN4AhYSaZjM6S2wMLKoRKKnJPmrXYjGaDI6d/fNUQ8GScU2Qb1ttmxLFQwINXGkyRygVZoMWEdFPO9hsQemQ+ageErz6yJzbcmfJEY/UwE=" 8 | before_script: 9 | - npm install -g gulp 10 | script: gulp 11 | -------------------------------------------------------------------------------- /gulpFile.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | const gulp = require('gulp'); 3 | const jscs = require('gulp-jscs'); 4 | const jshint = require('gulp-jshint'); 5 | const map = require('map-stream'); 6 | const babel = require('gulp-babel'); 7 | const files=[ '*.js',"examples/*.js","source/*.js"]; 8 | gulp.task('transpile',_ => { 9 | return gulp.src('source/*.js') 10 | .pipe(babel({ 11 | presets: ['es2015'] 12 | })) 13 | .pipe(gulp.dest('distribution')); 14 | }); 15 | gulp.task('jscs',_ => { 16 | return gulp.src(files) 17 | .pipe(jscs()); 18 | }); 19 | 20 | gulp.task('lint',_ => { 21 | return gulp.src(files) 22 | .pipe(jshint()) 23 | .pipe(jshint.reporter('jshint-stylish')) 24 | .pipe(jshint.reporter("fail")); 25 | }); 26 | //ava task intentionally removed for now coz of HE api bugs 27 | gulp.task('test',['transpile','jscs','lint']); 28 | gulp.task('default', ['test']); 29 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | 3 | var HE = require('./distribution/'); 4 | 5 | const hackerEarth = new HE( 6 | process.env.HE_KEY, //client secret key 7 | '' 8 | ); 9 | 10 | const config = { 11 | time_limit:1, 12 | memory_limit:323244, 13 | source:'print "Hello World"', 14 | language:"Py" 15 | }; 16 | 17 | test('should be equal to run url',t => { 18 | t.is(hackerEarth.runURL,"https://api.hackerearth.com/v3/code/run/"); 19 | }); 20 | 21 | test('should be equal to compile url',t => { 22 | t.is(hackerEarth.compileURL,'https://api.hackerearth.com/v3/code/compile/'); 23 | }); 24 | 25 | test('should compile with callback',t => { 26 | return hackerEarth.compile(config,(err,op) => { 27 | const res=JSON.parse(op); 28 | t.is(res.compile_status,'OK'); 29 | }); 30 | }); 31 | test('should compile with promise',t => { 32 | return hackerEarth.compile(config).then(op=> { 33 | op=JSON.parse(op); 34 | t.is(op.compile_status,'OK'); 35 | }); 36 | }); 37 | test('should run with promise',t => { 38 | return hackerEarth.run(config).then(op=> { 39 | op=JSON.parse(op); 40 | t.is(op.run_status.status,'AC'); 41 | }); 42 | }); 43 | 44 | test('should run with callback',t => { 45 | return hackerEarth.run(config,(err,op) => { 46 | const res=JSON.parse(op); 47 | t.is(res.run_status.status,'AC'); 48 | }); 49 | }); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hackerearth-node", 3 | "version": "2.3.9", 4 | "description": "nodeJS library for using HackerEarth API", 5 | "main": "./distribution/index.js", 6 | "scripts": { 7 | "test": "gulp ", 8 | "prepublish": "npm run test" 9 | }, 10 | "files": [ 11 | "distribution/" 12 | ], 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/tarungarg546/HackerEarth-node.git" 16 | }, 17 | "engines": { 18 | "node": ">=4.x.x" 19 | }, 20 | "keywords": [ 21 | "HackerEarth", 22 | "HE", 23 | "Online", 24 | "compiler", 25 | "Compiler", 26 | "Online", 27 | "Hacker", 28 | "APi" 29 | ], 30 | "author": "Tarun Garg", 31 | "license": "MIT", 32 | "bugs": { 33 | "url": "https://github.com/tarungarg546/HackerEarth-node/issues" 34 | }, 35 | "homepage": "https://github.com/tarungarg546/HackerEarth-node", 36 | "dependencies": { 37 | "debug": "^2.2.0", 38 | "request-promise": "^3.0.0" 39 | }, 40 | "devDependencies": { 41 | "babel-polyfill": "^6.9.1", 42 | "babel-preset-es2015": "^6.9.0", 43 | "gulp": "^3.9.1", 44 | "gulp-babel": "^6.1.2", 45 | "gulp-jscs": "^3.0.2", 46 | "gulp-jscs-stylish": "^1.4.0", 47 | "gulp-jshint": "^2.0.1", 48 | "jshint": "^2.9.2", 49 | "jshint-stylish": "^2.2.0", 50 | "map-stream": "0.0.6" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /.jscs.json: -------------------------------------------------------------------------------- 1 | { 2 | "requireCurlyBraces": ["if", "else", "for", "while", "do", "try", "catch", "case", "default"], 3 | "requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"], 4 | "requireParenthesesAroundIIFE": true, 5 | "requireSpacesInFunctionExpression": { "beforeOpeningCurlyBrace": true }, 6 | "disallowSpacesInFunctionExpression": { "beforeOpeningRoundBrace": true }, 7 | "requireMultipleVarDecl": true, 8 | "disallowEmptyBlocks": true, 9 | "disallowSpacesInsideObjectBrackets": true, 10 | "disallowSpacesInsideArrayBrackets": true, 11 | "disallowSpacesInsideParentheses": true, 12 | "disallowQuotedKeysInObjects": "allButReserved", 13 | "requireCommaBeforeLineBreak": true, 14 | "requireOperatorBeforeLineBreak": ["?", "+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="], 15 | "disallowLeftStickedOperators": ["?", "+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="], 16 | "requireRightStickedOperators": ["!"], 17 | "disallowRightStickedOperators": ["?", "+", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="], 18 | "requireLeftStickedOperators": [","], 19 | "disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"], 20 | "disallowSpaceBeforePostfixUnaryOperators": ["++", "--"], 21 | "requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="], 22 | "requireSpaceAfterBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="], 23 | "disallowKeywords": ["with"], 24 | "disallowMultipleLineBreaks": true, 25 | "validateLineBreaks": "LF", 26 | "validateQuoteMarks": "'", 27 | "disallowMixedSpacesAndTabs": true, 28 | "disallowTrailingWhitespace": true, 29 | "disallowKeywordsOnNewLine": ["else"], 30 | "requireLineFeedAtFileEnd": true, 31 | "maximumLineLength": 120, 32 | "requireCapitalizedConstructors": true, 33 | "requireDotNotation": true, 34 | "excludeFiles": ["node_modules/**"] 35 | } -------------------------------------------------------------------------------- /source/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const rp = require('request-promise'); 3 | const debug = require('debug')('HE'); 4 | require('babel-polyfill'); 5 | class helpers { 6 | constructor() { 7 | 8 | } 9 | getQueryData({language,time_limit,memory_limit,source,input},clientSecret,mode) { 10 | const obj ={ 11 | client_secret:clientSecret, 12 | async:mode, 13 | source:source, 14 | lang:this.getLanuage(language), 15 | input:input, 16 | time_limit:time_limit||1, 17 | memory_limit:memory_limit||262144 18 | }; 19 | return obj; 20 | } 21 | getLanuage(language) { 22 | let lang; 23 | if (language === 'C++') { 24 | lang = 'CPP'; 25 | } else if (language === 'C') { 26 | lang = 'C'; 27 | } else if (language === 'Py') { 28 | lang = 'PYTHON'; 29 | } else if (language === 'C#') { 30 | lang = 'CSHARP'; 31 | } else { 32 | lang = language.toUpperCase(); 33 | } 34 | return lang; 35 | } 36 | 37 | getRequestPostJSON(data,url) { 38 | return { 39 | method: 'POST', 40 | uri: url, 41 | form: data, 42 | gzip: true 43 | }; 44 | } 45 | 46 | doOperation(rpData,callback) { 47 | return new Promise((resolve, reject) => { 48 | rp(rpData) 49 | .then((body) => { 50 | return body; 51 | }) 52 | .then((res) => { 53 | if(callback) { 54 | callback(null,res); 55 | } 56 | resolve(res); 57 | }) 58 | .catch((err) => { 59 | if(callback) { 60 | callback(err,null); 61 | } 62 | reject(err); 63 | }); 64 | }); 65 | } 66 | 67 | } 68 | 69 | class HackerEarth extends helpers { 70 | constructor(clientSecret, mode) { 71 | super(); 72 | this._runURL = 'https://api.hackerearth.com/v3/code/run/'; 73 | this._compileURL = 'https://api.hackerearth.com/v3/code/compile/'; 74 | this._clientSecret = clientSecret; 75 | this._mode = mode || 0; 76 | debug('Bootstraping HackerEarth module with clientSecret as %s and mode as %s', clientSecret,mode); 77 | } 78 | 79 | get runURL() { 80 | return this._runURL; 81 | } 82 | 83 | get compileURL() { 84 | return this._compileURL; 85 | } 86 | 87 | get clientSecret() { 88 | return this._clientSecret; 89 | } 90 | 91 | get mode() { 92 | return this._mode; 93 | } 94 | compile(config, callback) { 95 | let data = super.getQueryData(config,this.clientSecret,this.mode); 96 | debug('In HackerEarth:Compile Data sent to API is %s',JSON.stringify(data)); 97 | let rpData = super.getRequestPostJSON(data,this.compileURL); 98 | return super.doOperation(rpData,callback); 99 | } 100 | 101 | run(config, callback) { 102 | let data = super.getQueryData(config,this.clientSecret,this.mode); 103 | debug('In HackerEarth:Run Data sent to API is %s',JSON.stringify(data)); 104 | let rpData=super.getRequestPostJSON(data,this.runURL); 105 | return super.doOperation(rpData,callback); 106 | } 107 | } 108 | 109 | module.exports = HackerEarth; 110 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HackerEarth-node 2 | 3 | [![NPM](https://nodei.co/npm/hackerearth-node.png)](https://nodei.co/npm/hackerearth-node/) Dark badge 4 | 5 | ![awesome](https://img.shields.io/badge/awesome-yes-green.svg)[![Build Status](https://travis-ci.org/tarungarg546/HackerEarth-node.svg?branch=master)](https://travis-ci.org/tarungarg546/HackerEarth-node) 6 | 7 | 8 | >Node JS library for using HackerEarth API 9 | 10 | This library helps you to compile your code with [HackerEarth API v3](https://www.hackerearth.com/docs/api/developers/code/legacy/) 11 | 12 | Using HackerEarth API you can compile and run your code using their [codeTable](https://code.hackerEarth.com) 13 | 14 |

PreRequisite

15 | - Make sure you are using latest version of nodeJS. 16 | - You have to obtain your client secret key from [HackerEarth Here](http://www.hackerearth.com/api/register/) and voila you are done! 17 | 18 |

Install

19 | 20 | >npm install hackerearth-node 21 | 22 |

Set Up

23 | 24 | ``` js 25 | var hackerEarth=require('hackerearth-node'); //require the Library 26 | //Now set your application 27 | var hackerEarth=new hackerEarth( 28 | '**********', //Your Client Secret Key here this is mandatory 29 | '' //mode sync=1 or async(optional)=0 or null async is by default and preferred for nodeJS 30 | ); 31 | var config={}; 32 | config.time_limit=1; //your time limit in integer 33 | config.memory_limit=323244; //your memory limit in integer 34 | config.source=''; //your source code for which you want to use hackerEarth api 35 | config.input=""; //input against which you have to test your source code 36 | config.language="C/C++/Py/C#"; //optional choose any one of them or none 37 | 38 | ``` 39 |

Compile Your code

40 | 41 | - Using Callbacks 42 | 43 | ``` javascript 44 | //compile your code 45 | hackerEarth.compile(config,function(err,response){ 46 | if(err) { 47 | //deal with error 48 | } else { 49 | //deal with response 50 | } 51 | }); 52 | 53 | ``` 54 | 55 | - Using Promises 56 | 57 | ``` javascript 58 | //compile your code 59 | hackerEarth.compile(config) 60 | .then(result => { 61 | //Handle Result 62 | }) 63 | .catch(err => { 64 | //Handle Error 65 | }); 66 | 67 | ``` 68 | 69 | 70 |

Run Your Code

71 | 72 | - Using Callbacks 73 | 74 | ``` javascript 75 | //compile your code 76 | hackerEarth.run(config,function(err,response){ 77 | if(err) { 78 | //deal with error 79 | } else { 80 | //deal with response 81 | } 82 | }); 83 | 84 | ``` 85 | - Using Promises 86 | 87 | ``` javascript 88 | //compile your code 89 | hackerEarth.run(config) 90 | .then(result => { 91 | //Handle Result 92 | }) 93 | .catch(err => { 94 | //Handle Error 95 | }); 96 | 97 | ``` 98 | 99 |

Wanna Debug ?

100 | 101 | > Append `debug=HE` before your node server command (or whatever is calling HackerEarth-node module) and analyse the logs printed on commandline to debug. 102 | 103 |

Todos

104 | 105 | - [x] Use ES6 in source and transpile to babel for older version and put it into distribution/ 106 | - [x] Promisify whole package 107 | - [ ] Using travis build tools for testing 108 | 109 |

Contact me on

110 | [![Twitter][1.1]][1] 111 | [![Facebook][2.1]][2] 112 | [1.1]: http://i.imgur.com/tXSoThF.png 113 | [2.1]: http://i.imgur.com/P3YfQoD.png 114 | [1]: http://www.twitter.com/Tarun_Garg2 115 | [2]: http://www.facebook.com/tarungarg546 116 | -------------------------------------------------------------------------------- /distribution/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; 4 | 5 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); 6 | 7 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } 8 | 9 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } 10 | 11 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 12 | 13 | var rp = require('request-promise'); 14 | var debug = require('debug')('HE'); 15 | require('babel-polyfill'); 16 | 17 | var helpers = function () { 18 | function helpers() { 19 | _classCallCheck(this, helpers); 20 | } 21 | 22 | _createClass(helpers, [{ 23 | key: 'getQueryData', 24 | value: function getQueryData(_ref, clientSecret, mode) { 25 | var language = _ref.language; 26 | var time_limit = _ref.time_limit; 27 | var memory_limit = _ref.memory_limit; 28 | var source = _ref.source; 29 | var input = _ref.input; 30 | 31 | var obj = { 32 | client_secret: clientSecret, 33 | async: mode, 34 | source: source, 35 | lang: this.getLanuage(language), 36 | input: input, 37 | time_limit: time_limit || 1, 38 | memory_limit: memory_limit || 262144 39 | }; 40 | return obj; 41 | } 42 | }, { 43 | key: 'getLanuage', 44 | value: function getLanuage(language) { 45 | var lang = void 0; 46 | if (language === 'C++') { 47 | lang = 'CPP'; 48 | } else if (language === 'C') { 49 | lang = 'C'; 50 | } else if (language === 'Py') { 51 | lang = 'PYTHON'; 52 | } else if (language === 'C#') { 53 | lang = 'CSHARP'; 54 | } else { 55 | lang = language.toUpperCase(); 56 | } 57 | return lang; 58 | } 59 | }, { 60 | key: 'getRequestPostJSON', 61 | value: function getRequestPostJSON(data, url) { 62 | return { 63 | method: 'POST', 64 | uri: url, 65 | form: data, 66 | gzip: true 67 | }; 68 | } 69 | }, { 70 | key: 'doOperation', 71 | value: function doOperation(rpData, callback) { 72 | return new Promise(function (resolve, reject) { 73 | rp(rpData).then(function (body) { 74 | return body; 75 | }).then(function (res) { 76 | if (callback) { 77 | callback(null, res); 78 | } 79 | resolve(res); 80 | }).catch(function (err) { 81 | if (callback) { 82 | callback(err, null); 83 | } 84 | reject(err); 85 | }); 86 | }); 87 | } 88 | }]); 89 | 90 | return helpers; 91 | }(); 92 | 93 | var HackerEarth = function (_helpers) { 94 | _inherits(HackerEarth, _helpers); 95 | 96 | function HackerEarth(clientSecret, mode) { 97 | _classCallCheck(this, HackerEarth); 98 | 99 | var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(HackerEarth).call(this)); 100 | 101 | _this._runURL = 'https://api.hackerearth.com/v3/code/run/'; 102 | _this._compileURL = 'https://api.hackerearth.com/v3/code/compile/'; 103 | _this._clientSecret = clientSecret; 104 | _this._mode = mode || 0; 105 | debug('Bootstraping HackerEarth module with clientSecret as %s and mode as %s', clientSecret, mode); 106 | return _this; 107 | } 108 | 109 | _createClass(HackerEarth, [{ 110 | key: 'compile', 111 | value: function compile(config, callback) { 112 | var data = _get(Object.getPrototypeOf(HackerEarth.prototype), 'getQueryData', this).call(this, config, this.clientSecret, this.mode); 113 | debug('In HackerEarth:Compile Data sent to API is %s', JSON.stringify(data)); 114 | var rpData = _get(Object.getPrototypeOf(HackerEarth.prototype), 'getRequestPostJSON', this).call(this, data, this.compileURL); 115 | return _get(Object.getPrototypeOf(HackerEarth.prototype), 'doOperation', this).call(this, rpData, callback); 116 | } 117 | }, { 118 | key: 'run', 119 | value: function run(config, callback) { 120 | var data = _get(Object.getPrototypeOf(HackerEarth.prototype), 'getQueryData', this).call(this, config, this.clientSecret, this.mode); 121 | debug('In HackerEarth:Run Data sent to API is %s', JSON.stringify(data)); 122 | var rpData = _get(Object.getPrototypeOf(HackerEarth.prototype), 'getRequestPostJSON', this).call(this, data, this.runURL); 123 | return _get(Object.getPrototypeOf(HackerEarth.prototype), 'doOperation', this).call(this, rpData, callback); 124 | } 125 | }, { 126 | key: 'runURL', 127 | get: function get() { 128 | return this._runURL; 129 | } 130 | }, { 131 | key: 'compileURL', 132 | get: function get() { 133 | return this._compileURL; 134 | } 135 | }, { 136 | key: 'clientSecret', 137 | get: function get() { 138 | return this._clientSecret; 139 | } 140 | }, { 141 | key: 'mode', 142 | get: function get() { 143 | return this._mode; 144 | } 145 | }]); 146 | 147 | return HackerEarth; 148 | }(helpers); 149 | 150 | module.exports = HackerEarth; --------------------------------------------------------------------------------