Giter Club home page Giter Club logo

op.gg-api's Introduction

op.gg-api

Serves op.gg web pages as json.

Getting Started

npm install op.gg-api

Example

Using the client

var gg = new (require('node_modules/op.gg-api/client.js'))

gg.Live('kr')
	.then((json) => {
		console.log(json)
	})
	.catch((error) => {
		console.error(error)
	})

gg.Live('kr', function(error, data) {
	console.log(error || data)
})

Using the server

node node_modules/op.gg-api/server

Endpoints

v2.0 documentation currently in progress. For now, refer to server.js for endpoints and tests_spec.js for models.

Licence

Copyright (c) 2015 Stephen Poole

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

op.gg-api's People

Contributors

jigawhat avatar justinsmid avatar miasmos avatar rlstephenpoole avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

op.gg-api's Issues

"TypeError: validate.Summoner is not a function"

Whenever I make a function call that validates a summoner, I receive this error:

TypeError: validate.Summoner is not a function
    at opgg.Summary (C:\***\node_modules\op.gg-api\client.js:73:26)
    at Object.<anonymous> (C:\***\index.js:17:18)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:390:7)
    at startup (bootstrap_node.js:150:9)
    at bootstrap_node.js:505:3

The code I use to call it is simply just:

var opgg = new (require('op.gg-api/client.js'))
console.log('loaded')

var xayah = opgg.Summary('na', 'zuurah')
.then((json) => {
	console.log(json)
})
.catch((error) => {
	console.error(error)
})

Am I calling something improperly, or is the function just not working at the moment?

Some returned values are `undefined`

Hi,
I'm writing an app for a Discord server but some returned values are undefined. I leave a link to my PrivateBin with the returned response.

As you can see, some values are NaN or undefined.

Reproducing

  1. Require the library like so:
const opgg = new (require('op.gg-api/client.js'))({
    api_key: process.env.LOLAPIKEY
});
  1. Then, fetch the API with the library with a specific username
let summoner_summary = await opgg.Summary('euw', requestedSummoner)
// Where requestedSummoner is... the requested LoL summoner, i.e. xxpafadelcraftxx
  1. Console.log everything and you should see that some values are undefined or NaN which can be a bit annoying if I want to integrate the API in my application...

Am I doing something wrong or it's a bug on the library side ?

match history does not fail gracefully when summoner has been inactive

First of all, thanks for taking the time to write this API and upload it. I'm quite happy with it so far as it saved me a lot of potential time.
However, i noticed a bug.

When a summoner has been inactive for a long time and has no matches in his history the request to that summoner will crash the server:

parsing http://euw.op.gg/summoner/userName=khiranhi
C:\op.gg-api-master\server.js:179
recent.wins = parseInt(temp[2].slice(0,-1));
^
TypeError: Cannot read property 'slice' of undefined
at Request.parseSummoner [as _callback](C:op.gg-api-masterserver.js:179:3
4)
at Request.self.callback (C:\op.gg-api-master\node_modules\request\request.j
s:237:22)
at Request.emit (events.js:110:17)
at Request. (C:\op.gg-api-master\node_modules\request\request.js:
1146:14)
at Request.emit (events.js:129:20)
at IncomingMessage. (C:\op.gg-api-master\node_modules\request\req
uest.js:1097:12)
at IncomingMessage.emit (events.js:129:20)
at _stream_readable.js:908:16

an example summoner: http://euw.op.gg/summoner/userName=mYi+Salor

RequestError: TypeError: The header content contains invalid characters

So, I'm thinking I'm getting this error:

{ RequestError: TypeError: The header content contains invalid characters
    at new RequestError (C:\Users\Tyler\workspace\javascript\node_modules\request-promise-core\lib\errors.js:14:15)
    at Request.plumbing.callback (C:\Users\Tyler\workspace\javascript\node_modules\request-promise-core\lib\plumbing.js:87:29)
    at Request.RP$callback [as _callback] (C:\Users\Tyler\workspace\javascript\node_modules\request-promise-core\lib\plumbing.js:46:31)
    at self.callback (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:188:22)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:188:7)
    at Request.start (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:757:10)
    at Request.end (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:1525:10)
    at end (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:567:14)
    at Immediate.<anonymous> (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:581:7)
    at runCallback (timers.js:672:20)
    at tryOnImmediate (timers.js:645:5)
    at processImmediate [as _immediateCallback] (timers.js:617:5)
  name: 'RequestError',
  message: 'TypeError: The header content contains invalid characters',
  cause: 
   TypeError: The header content contains invalid characters
       at ClientRequest.OutgoingMessage.setHeader (_http_outgoing.js:360:11)
       at new ClientRequest (_http_client.js:85:14)
       at Object.exports.request (http.js:31:10)
       at Request.start (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:755:32)
       at Request.end (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:1525:10)
       at end (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:567:14)
       at Immediate.<anonymous> (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:581:7)
       at runCallback (timers.js:672:20)
       at tryOnImmediate (timers.js:645:5)
       at processImmediate [as _immediateCallback] (timers.js:617:5),
  error: 
   TypeError: The header content contains invalid characters
       at ClientRequest.OutgoingMessage.setHeader (_http_outgoing.js:360:11)
       at new ClientRequest (_http_client.js:85:14)
       at Object.exports.request (http.js:31:10)
       at Request.start (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:755:32)
       at Request.end (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:1525:10)
       at end (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:567:14)
       at Immediate.<anonymous> (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:581:7)
       at runCallback (timers.js:672:20)
       at tryOnImmediate (timers.js:645:5)
       at processImmediate [as _immediateCallback] (timers.js:617:5),
  options: 
   { headers: 
      { 'Content-Type': 'text/html',
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36',
        'Accept-Language': 'en-GB,en-US;q=0.8,en;q=0.6' },
     uri: 'http://na.op.gg/summoner/?userName=LëëŠin&',
     callback: [Function: RP$callback],
     transform: undefined,
     simple: true,
     resolveWithFullResponse: false,
     transform2xxOnly: false },
  response: undefined }

Whenever a summoner name includes a special character, i.e. "ƒiøra"

While Riot doesn't allow new users to create names with special characters, many long term users are still allowed to have these characters in their names until they do a name change. These users definitely exist and I can look them up with the special characters in their name on op.gg without any issues. Any ideas what might be causing this, or is this just a validation check in the API that corresponds to Riot's new naming conventions?

Mysterious server crashes

There is a mysterious error that will crash the server from time to time. I have not been able to reproduce it reliably. it doesnt seem to be linked to specific summoners. (But i will keep investigating)

parsing http://na.op.gg/summoner/ajax/update.json/?summonerId=35488173
undefined:1
undefined
^
SyntaxError: Unexpected token u
at Object.parse (native)
at Request.parseSummonerRefresh [as _callback](C:op.gg-api-masterserver.j
s:320:20)
at self.callback (C:\op.gg-api-master\node_modules\request\request.js:237:22
)
at Request.emit (events.js:107:17)
at ClientRequest.self.clientErrorHandler (C:\op.gg-api-master\node_modules\r
equest\request.js:342:10)
at ClientRequest.emit (events.js:107:17)
at Socket.socketOnData (_http_client.js:322:9)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
at Socket.Readable.push (_stream_readable.js:126:10)
at TCP.onread (net.js:538:20)

C:\op.gg-api-master>

Can't retrieve ranked stats by

I'm getting this when trying to go to /na/summary/summoner/ranked

{
"status": 500,
"error": "Cannot read property 'attribs' of undefined",
"data": {}
}

Error: Invalid summoner name.

while debugging I noticed I kept getting the following error:

{ Error: Invalid summoner name.
    at ErrorExtended (C:\Users\Tyler\workspace\javascript\node_modules\op.gg-api\lib\Responses\Error.js:4:3)
    at SummaryNormal.Promise (C:\Users\Tyler\workspace\javascript\node_modules\op.gg-api\client.js:151:48)
    at Promise._execute (C:\Users\Tyler\workspace\javascript\node_modules\bluebird\js\release\debuggability.js:300:9)
    at Promise._resolveFromExecutor (C:\Users\Tyler\workspace\javascript\node_modules\bluebird\js\release\promise.js:483:18)
    at new Promise (C:\Users\Tyler\workspace\javascript\node_modules\bluebird\js\release\promise.js:79:10)
    at opgg.SummaryNormal (C:\Users\Tyler\workspace\javascript\node_modules\op.gg-api\client.js:149:14)
    at getData (C:\Users\Tyler\workspace\javascript\index.js:44:22)
    at getNeighbors (C:\Users\Tyler\workspace\javascript\index.js:106:4)
    at opgg.SummaryNormal.catch.then.error (C:\Users\Tyler\workspace\javascript\index.js:71:5)
    at tryCatcher (C:\Users\Tyler\workspace\javascript\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (C:\Users\Tyler\workspace\javascript\node_modules\bluebird\js\release\promise.js:512:31)
    at Promise._settlePromise (C:\Users\Tyler\workspace\javascript\node_modules\bluebird\js\release\promise.js:569:18)
    at Promise._settlePromise0 (C:\Users\Tyler\workspace\javascript\node_modules\bluebird\js\release\promise.js:614:10)
    at Promise._settlePromises (C:\Users\Tyler\workspace\javascript\node_modules\bluebird\js\release\promise.js:693:18)
    at Async._drainQueue (C:\Users\Tyler\workspace\javascript\node_modules\bluebird\js\release\async.js:133:16)
    at Async._drainQueues (C:\Users\Tyler\workspace\javascript\node_modules\bluebird\js\release\async.js:143:10)
    at Immediate.Async.drainQueues (C:\Users\Tyler\workspace\javascript\node_modules\bluebird\js\release\async.js:17:14)
    at runCallback (timers.js:672:20)
    at tryOnImmediate (timers.js:645:5)
    at processImmediate [as _immediateCallback] (timers.js:617:5) code: 400 }

The names that cause it seem to be pretty arbitrary, some contain spaces which throw the error while others that have a space search without a problem. Special characters also seem to be arbitrarily causing this.

I've tried escaping all regular expression characters and that doesn't seem to work either. As you can see, the list of names that throw the invalid summoner name seems a little arbitrary.

A short list of names causing this error:

PrtyPinkPrincess
AirMarshal50Cent
RiotMustachinato
Cptn+JakeSparrow
ÉFX
ReadyForSumSalad
Tentative+Toucan
MajTom2GrndCntrl
Cautious+Ostrich
tugginonmypuddin

Long list of names checked:

  • Zuurah
  • enfant+calcium
  • Neko++Kush
  • Xodiqc
  • vBreaker
  • Figgu
  • Locomon
  • LutsWaffle
  • Wolf+Samurai
  • Dierka
  • Tallicus
  • RpkZ150
  • Kanzza
  • Joshuarrichie
  • hinamiu
  • TimmyPage
  • Mr+Cupcake
  • His+Paragon
  • PrtyPinkPrincess
  • Delicious808
  • Papashan
  • pYrre
  • HalfSaiyan
  • MikkieP33
  • urzu2
  • lldeejeell
  • Apple+Paiii
  • AirMarshal50Cent
  • Khal+Hodor
  • liverpooty
  • RaleighRhodes
  • TheNupuis
  • Riot+Adabard
  • RiotMustachinato
  • Xephei
  • Ericb1
  • Spartians11
  • Weimu
  • Diashi001
  • Zeetzo
  • zewm
  • Andiscar
  • Skeythera
  • Scroobe
  • L0n3D0gz
  • Asuv
  • CottonyTuna
  • Sanastin
  • happykitty9
  • Implankton
  • Capt+Cad
  • BardOpieOP
  • Super+Yams
  • bahamut0sic
  • farslash
  • Luckdraw
  • PureNoLove
  • WickedSyyk
  • N0ragami
  • Son+0f+Athena
  • MDS+IS+KING
  • HAOBI
  • Paquay
  • Tojo+Ookami
  • techh
  • Baeo
  • Arufa+Ookami+
  • Master+Lycan
  • SycamoreJoe
  • Kalamity1001
  • Shiverblaze
  • xProphet
  • Inda+Skies
  • Ravec90
  • Cptn+JakeSparrow
  • rawked
  • KUYMY
  • Giggling+Peanut
  • MachineIH
  • Eat+Sleep+Game
  • Wavelength79
  • Gangblank
  • zandreameow
  • Nagaharu
  • Mid+Lane+Mage
  • Im+Urgot
  • King+Gankins
  • BerserkerRL
  • Zoom+Boom+Raka
  • 6oogle
  • SexualPanda2
  • SexualPanda21
  • Jin+Astora
  • sixpack69
  • Harry+McRainbow
  • Stêvøy
  • Jointedcape6
  • SpadesXZ
  • Moon+Mooon
  • Omar218
  • Marixza+Bot
  • Apachies
  • akame115
  • XoCandyoX
  • The+NaCl+Lord
  • C4+In+My+Turban
  • ÉFX
  • AndreaaLynn
  • JarDian101
  • goofballpikachu
  • IronWraith
  • AmbientPanic
  • Bird+Lamb+Rock
  • CH1CKENGH0ST
  • ThrowsWithBaron
  • Cheesus+Christ
  • Ashaya
  • JimblesNotronbo
  • Im+Yorick+Mori
  • bossupforacheck
  • dungood1852
  • Lehmbjerg
  • Lucious+Lyon
  • SqµirtleSquad
  • Big+Wang+Theory
  • AnotherCookie
  • Mr+jogo
  • Virgil+Borgia
  • DeAtH066
  • MissDeath066
  • Dougyfresh009
  • Sirblueshue
  • ReadyForSumSalad
  • Pikajewfro
  • Nunaniminks
  • JHill36
  • TmTrollDaddy
  • C9+Vitto
  • pugman15
  • ShowMeTheLight
  • exreaper
  • Tweek808
  • SuperPhung
  • BBQ+Leona+Only
  • DerpasaurusRex
  • Garign
  • whip++sage
  • Tentative+Toucan
  • MajTom2GrndCntrl
  • sub+saharan
  • Cautious+Ostrich
  • SkumbagJohnny
  • Sleazay
  • tugginonmypuddin
  • MaitreCorbo
  • VritraReiRei
  • Selolius
  • ChronoMakers
  • TheWickedKing

calling the items array only contains trinket slot

for some reason, the function that pulls the items from op.gg returns only the trinket slot.

loaded
http://na.op.gg/summoner/?userName=zuurah&
http://na.op.gg/summoner/matches/ajax/averageAndList/?type=normal&summonerId=62272886&
1
{ name: 'Farsight Alteration',
image: '//opgg-static.akamaized.net/images/lol/item/3363.png?image=c_scale,w_32',
slot: 7,
id: 3363 }
1
{ name: 'Farsight Alteration',
image: '//opgg-static.akamaized.net/images/lol/item/3363.png?image=c_scale,w_32',
slot: 7,
id: 3363 }
1
{ name: 'Farsight Alteration',
image: '//opgg-static.akamaized.net/images/lol/item/3363.png?image=c_scale,w_32',
slot: 7,
id: 3363 }

The code:

var opgg = new (require('op.gg-api/client.js'))
console.log('loaded')

var summoner = opgg.SummaryNormal('na', 'zuurah')
.then((json) => {
	for(var i = 0; i < json.games.length; i++){
		var leng = json.games[i].items.length
		console.log(leng)
		for(var j = 0; j < leng; j++)
			console.log(json.games[i].items[j])
	}
})
.catch((error) => {
	console.error(error)
})

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.