Skip to content

Commit

Permalink
Merge branch 'alpha'
Browse files Browse the repository at this point in the history
  • Loading branch information
karnthis committed Nov 24, 2019
2 parents 9b0ae02 + 11940de commit de1053c
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 51 deletions.
11 changes: 7 additions & 4 deletions classes/Authenticate.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ module.exports = class Authenticate extends Core {
}
}

buildRequestURL(scopes = []) {
buildRequestURL(scopes = [], state = '') {
const useScope = (this.masterScopes.length > 0) ? this.masterScopes : scopes
if (state.includes('&')) console.error(`Request URL state: Must not contain '&' symbol. Sanitizing...`)
if (useScope.length == 0) throw new Error('must have at least 1 scope selected')
return [`https://login.eveonline.com/oauth/authorize/?response_type=code`,
`redirect_uri=${encodeURI(this.callbackURL)}`,
`client_id=${this.clientID}`,
`scope=${useScope.join(' ')}`].join('&')
`redirect_uri=${encodeURI(this.callbackURL)}`,
`client_id=${this.clientID}`,
`scope=${useScope.join(' ')}`,
`state=${state.replace(/&/g, '')}`
].join('&')
}
async setScope(scopes = []) {
if (scopes == 'all') {
Expand Down
28 changes: 14 additions & 14 deletions classes/Market.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
const Core = require('../libs/Core')

const basePath = 'ddd'
const basePath = 'markets'

module.exports = class ddd extends Core {
module.exports = class Market extends Core {
constructor(cfg = {}) {
/* cfg == { base, ver, src, agent, db, clientID, clientSecret } */
super(cfg)
}

// PUBLIC
marketHistory(region_id) {
return this._makePublicGet(`markets/${region_id}/history/`)
history(region_id) {
return this._makePublicGet(`${basePath}/${region_id}/history/`)
}
marketOrders(region_id) {
return this._makePublicGet(`markets/${region_id}/orders/`)
orders(region_id, extras) {
return this._makePublicGet(`${basePath}/${region_id}/orders/`, extras)
}
marketTypes(region_id) {
return this._makePublicGet(`markets/${region_id}/types/`)
types(region_id) {
return this._makePublicGet(`${basePath}/${region_id}/types/`)
}
marketGroups() {
return this._makePublicGet(`markets/groups/`)
groups() {
return this._makePublicGet(`${basePath}/groups/`)
}
marketGroup(market_group_id) {
return this._makePublicGet(`markets/groups/${market_group_id}/`)
group(market_group_id) {
return this._makePublicGet(`${basePath}/groups/${market_group_id}/`)
}
marketPrices() {
return this._makePublicGet(`markets/prices/`)
prices() {
return this._makePublicGet(`${basePath}/prices/`)
}

// RESTRICTED
Expand Down
4 changes: 2 additions & 2 deletions libs/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ module.exports = class Core {
}

// **** FUNCTIONS **** \\
_makePublicGet(path) {
return basicGet(path, this.dataPack)
_makePublicGet(path, extras) {
return (extras) ? basicGet(path, extras, this.dataPack) : basicGet(path, this.dataPack)
}
_makePublicPost(path, payload) {
const options = {
Expand Down
32 changes: 5 additions & 27 deletions libs/Requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ const { URL } = require('./Validate')

module.exports = {

basicGet(path, data) {
basicGet(path, extras = [], data) {
const options = {
method: 'GET',
headers: {
'User-Agent': data.userAgent
}
}
const url = `${data.urlPt1}${cleanURL(path)}${data.urlPt2}`
const partUrl = `${data.urlPt1}${cleanURL(path)}${data.urlPt2}`
const url = [partUrl, ...extras].join('&')
return allRequest(url, options)
},
sendPathRequest(path, options = {}, data, payload = '') {
Expand All @@ -27,30 +28,7 @@ module.exports = {
},
sendTokenRequest(url, options = {}) {
return allRequest(url, options)
}


// getRequest(url, options) {
// return new Promise((resolve, reject) => {
// if (URL(url)) {
// console.log(url)
// get(url, options, (res) => {
// res.setEncoding('utf8');
// let body = ''
// const status = res.statusCode
// res.on('data', (data) => {
// body += data
// })
// return res.on('end', () => {
// body = JSON.parse(body)
// resolve({ body, status })
// })
// })
// } else reject(new Error('invalid url'))
// })
// },


}
}

function cleanURL(s) {
Expand Down Expand Up @@ -81,7 +59,7 @@ function allRequest(url, options, payload) {
res.on('end', () => {
// console.dir(resBody)
resolve({
body: JSON.parse(resBody.join()),
body: JSON.parse(resBody.join('')),
status
})
})
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "esiio",
"version": "0.1.1",
"version": "0.1.2",
"description": "Single dependency library for EVE Online's ESI",
"main": "index.js",
"scripts": {
Expand All @@ -16,7 +16,7 @@
"eve online",
"ESI"
],
"author": "Erin Rivas <contact@atomicbear.com>",
"author": "Erin Rivas <me@erinrivas.com>",
"homepage": "https://github.com/karnthis/make-random#readme",
"bugs": "https://github.com/karnthis/make-random/issues",
"license": "MIT",
Expand Down
5 changes: 4 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ const Auth = new Authenticate(
}
)

const Char = new Character(auth.share())
const Char = new Character(Auth.share())
// use Char in Express route or directly
Char.corpHistory(92014574)
.then(resp => console.log(resp.body))
.catch(err => console.error(err))
```

## Supported Routes
Expand Down

0 comments on commit de1053c

Please sign in to comment.