mIRC Home    About    Download    Register    News    Help

Print Thread
Not understanding this API pull #243506 24/11/13 01:20 PM
Joined: Nov 2013
Posts: 49
L
lindenkron Offline OP
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Nov 2013
Posts: 49
If I call var %titles = $json(%url,titles) on https://eu.battle.net/api/wow/character/stormscale/bookmark?fields=pvp,titles shouldn't that return the value(amount) of the list "titles"? I get this to 41 lines.

Code:
"titles":[
{"id":28,"name":"High Warlord %s"},
{"id":44,"name":"Rival %s"},
{"id":45,"name":"Challenger %s"},
{"id":47,"name":"Conqueror %s"},
{"id":63,"name":"%s of the Shattered Sun"},
{"id":78,"name":"%s the Explorer"},
{"id":79,"name":"%s the Diplomat"},
{"id":82,"name":"Arena Master %s"},
{"id":121,"name":"Twilight Vanquisher %s"},
{"id":124,"name":"%s the Hallowed"},
{"id":127,"name":"%s of the Horde"},
{"id":129,"name":"%s, Champion of the Frozen Wastes"},
{"id":130,"name":"Ambassador %s"},
{"id":140,"name":"%s of the Nightfall"},
{"id":143,"name":"%s Jenkins"},
{"id":155,"name":"%s the Noble"},
{"id":172,"name":"%s the Patient"},
{"id":173,"name":"%s the Light of Dawn"},
{"id":175,"name":"%s the Kingslayer"},
{"id":176,"name":"%s of the Ashen Verdict"},
{"id":259,"name":"Warbringer %s"},
{"id":194,"name":"%s, Veteran of the Horde"},
{"id":209,"name":"Scout %s"},{"id":210,"name":"Grunt %s"},
{"id":211,"name":"Sergeant %s"},
{"id":212,"name":"Senior Sergeant %s"},
{"id":213,"name":"First Sergeant %s"},
{"id":214,"name":"Stone Guard %s"},
{"id":215,"name":"Blood Guard %s"},
{"id":216,"name":"Legionnaire %s"},
{"id":217,"name":"Centurion %s"},
{"id":218,"name":"Champion %s"},
{"id":219,"name":"Lieutenant General %s"},
{"id":220,"name":"General %s"},
{"id":221,"name":"Warlord %s"},
{"id":222,"name":"High Warlord %s"},
{"id":224,"name":"%s, Hero of the Horde","selected":true},
{"id":225,"name":"%s, the Bloodthirsty"},
{"id":227,"name":"%s, Defender of a Shattered World"},
{"id":287,"name":"%s, Destroyer's End"},
{"id":314,"name":"%s the Undaunted"},
{"id":333,"name":"Brawler %s"}],


I'm not sure why it returns the value "48835248".

Edit: So just learned that this number is continuously increasing - now it's "49170944", and higher every time I check it. confused

If anyone have some clarity on this I'd appreciate it.

Last edited by lindenkron; 24/11/13 01:35 PM.
Re: Not understanding this API pull [Re: lindenkron] #243509 24/11/13 03:27 PM
Joined: Jan 2004
Posts: 1,276
L
Loki12583 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,276
That's probably a pointer of some kind, if you want the length of the array, specify 0 as the index: $json(%url,titles,0)

Last edited by Loki12583; 24/11/13 03:28 PM.
Re: Not understanding this API pull [Re: Loki12583] #243510 24/11/13 05:20 PM
Joined: Nov 2013
Posts: 49
L
lindenkron Offline OP
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Nov 2013
Posts: 49
Originally Posted By: Loki12583
That's probably a pointer of some kind, if you want the length of the array, specify 0 as the index: $json(%url,titles,0)


Still returns these sort of numbers 49273312 with
Code:
var %titles = $json(%url,titles,0)
$msg($chan,%titles)

Last edited by lindenkron; 24/11/13 05:20 PM.
Re: Not understanding this API pull [Re: lindenkron] #243513 24/11/13 07:10 PM
Joined: Jan 2004
Posts: 1,276
L
Loki12583 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,276
My bad, you actually need to use the count property: $json(%url,titles).count

Re: Not understanding this API pull [Re: Loki12583] #243514 24/11/13 08:12 PM
Joined: Nov 2013
Posts: 49
L
lindenkron Offline OP
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Nov 2013
Posts: 49
Originally Posted By: Loki12583
My bad, you actually need to use the count property: $json(%url,titles).count


Sweet. I would've never gotten that. Can you elaborate on why .count does that - and what it is? smile

Also little side question if you're not too busy, the script mentioned in another thread were replied in http://www.mircscripts.org/comments.php?cid=4407 doesn't interpret æøå so when ever you try to do an API call on a URL with æøå in it, it returns as false.
Example: "https://eu.battle.net/api/wow/character/Outland/Livb%C3%A5ten?fields=pvp,titles" calling that gives "false".

Re: Not understanding this API pull [Re: lindenkron] #243515 24/11/13 08:29 PM
Joined: Jan 2004
Posts: 1,276
L
Loki12583 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,276
It works with .count because that's how the script works. Read the help provided with the script.

Code:
//var %url = https://eu.battle.net/api/wow/character/Outland/Livb%C3%A5ten?fields=pvp,titles | echo -ag $json(%url, name)


This works perfectly fine.

Re: Not understanding this API pull [Re: Loki12583] #243516 24/11/13 10:28 PM
Joined: Nov 2013
Posts: 49
L
lindenkron Offline OP
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Nov 2013
Posts: 49
Originally Posted By: Loki12583
It works with .count because that's how the script works. Read the help provided with the script.

Code:
//var %url = https://eu.battle.net/api/wow/character/Outland/Livb%C3%A5ten?fields=pvp,titles | echo -ag $json(%url, name)


This works perfectly fine.


I've read the Syntax and Examples part of the help for json countless amounts of times just to understand the basics of how to use it (lol), I see that there's ".count" after but I never understood why that was. I guess it's just one of those things that I don't need to understand smile

Maybe the link I provided works (Livb%C3%A5ten) because I copy pasted that. If I type in any name (tested) with æøå and do an API pull with it it gives an unable to retrieve information error. Works with any non-æøå name though.

Something is going wrong in translation somewhere.
Typing: https://eu.battle.net/api/wow/character/Outland/Livbåten?fields=pvp,titles
Typing that in URL gives results, but doing !rating Livbåten Outland eu does not work.
(Also when copy pasting this URL I get https://eu.battle.net/api/wow/character/Outland/Livb%C3%A5ten?fields=pvp,titles) for some reason.

Is the JSON not parsing it as UTF-8 or something. I'm unsure as to why it doesn't work.

Any suggestion for trouble shooting. I'm at a loss.
<3

Re: Not understanding this API pull [Re: lindenkron] #243517 24/11/13 11:23 PM
Joined: Jan 2004
Posts: 1,276
L
Loki12583 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,276
You need to url encode the text to escape invalid characters:

$urlencode(Livbåten) will return Livb%C3%A5ten

Code:
alias urlencode return $regsubex($1-,/([^A-Z0-9])/gi,$+(%,$base($asc(\1),10,16)))

Re: Not understanding this API pull [Re: Loki12583] #243519 24/11/13 11:41 PM
Joined: Nov 2013
Posts: 49
L
lindenkron Offline OP
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Nov 2013
Posts: 49
Originally Posted By: Loki12583
You need to url encode the text to escape invalid characters:

$urlencode(Livbåten) will return Livb%C3%A5ten

Code:
alias urlencode return $regsubex($1-,/([^A-Z0-9])/gi,$+(%,$base($asc(\1),10,16)))


That worked brilliantly.
Thx Lokisan.

Re: Not understanding this API pull [Re: lindenkron] #243520 25/11/13 12:38 AM
Joined: Oct 2012
Posts: 164
D
Deega Offline
Vogon poet
Offline
Vogon poet
D
Joined: Oct 2012
Posts: 164
Check your json script, under the heading Syntax.
Quote:
$json.enc(<URL>)
Encodes a URL. Uses JavaScript's encodeURI().


Re: Not understanding this API pull [Re: Deega] #243525 25/11/13 01:45 AM
Joined: Nov 2013
Posts: 49
L
lindenkron Offline OP
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Nov 2013
Posts: 49
Originally Posted By: Deega
Check your json script, under the heading Syntax.
Quote:
$json.enc(<URL>)
Encodes a URL. Uses JavaScript's encodeURI().



Yes, I see it there but with my knowledge poll it's quite limited what that tells me. Or what it does/how to use it properly wink
Edit: Of cause I understand it now that Loki explained it etc, but thanks for pointing it out that it was there all along :P.

Last edited by lindenkron; 25/11/13 01:47 AM.