cocoahero / pubg-swift

A Swift library for working with the PUBG Developer API.
MIT License
7 stars 3 forks source link

Brief tutorial? #1

Open ritteraf opened 6 years ago

ritteraf commented 6 years ago

Hey cocoahero - thanks for the awesome PUBG API wrapper. Would it be possible for you to write a brief tutorial for using this library? I've gotten as far as adding the library via carthage, and all is working well there. I just have no idea what commands are now available to me after adding this library to access the PUBG API. If you don't have time to write a tutorial, could you just point me in the right direction for using it? Thanks!

cocoahero commented 6 years ago

Hi @ritteraf. The library is still currently a WIP, it doesn't do much of anything at the moment. I've attempted to hit the PUBG API a couple times, but it doesn't seem to be functioning correctly. Once it is, I'll resume development of this wrapper.

ritteraf commented 6 years ago

Oh so the PUBG API is still not fully functional? That's a bummer. Let me know if I can help in any way. I've seen you around in the Shopify Mobile Buy SDK - it would seem we have very similar interests :)

cocoahero commented 6 years ago

Every time I try and request a list of players filtered by username, it always gives me back an empty result set. I think anyone can register for an API key now, so maybe try it and see what you can find?

{"errors":[{"title":"Not Found","detail":"No players found matching criteria"}]}
ritteraf commented 6 years ago

Will do

ritteraf commented 6 years ago

Hey @cocoahero I finally got around to doing some of my own testing today. I was successfully able to grab the user data for my pubg account with the following swift code: `func attemptPubgIDLookup (playerName: String, completion: @escaping (String) -> Void) {

let region = "pc-na"

let urlString = "https://api.playbattlegrounds.com/shards/" + region + "/players?filter[playerNames]=" + playerName

let headers: HTTPHeaders = [

    "Authorization": "Bearer \(pubgApiKey)",

    "accept": "application/json"

]

Alamofire.request(urlString, method: .get, headers: headers)

    .responseJSON { (response) in

        debugPrint(response)

}

}`

cocoahero commented 6 years ago

Hmm, for whatever reason when searching for my player name, I don't get any results back. Can you paste what you get in the response?

ritteraf commented 6 years ago

[Request]: GET https://api.playbattlegrounds.com/shards/pc-na/players?filter%5BplayerNames%5D=AltenaBlue [Response]: <NSHTTPURLResponse: 0x1cc031c20> { URL: https://api.playbattlegrounds.com/shards/pc-na/players?filter%5BplayerNames%5D=AltenaBlue } { Status Code: 200, Headers { "Content-Encoding" = ( gzip ); "Content-Length" = ( 700 ); "Content-Type" = ( "application/json" ); Date = ( "Mon, 09 Apr 2018 23:21:42 GMT" ); Vary = ( "Accept-Encoding" ); Via = ( "1.1 0a67f6cab5e0fc8020a30636dad56244.cloudfront.net (CloudFront)" ); "x-amz-cf-id" = ( "uR6YsiT82vNBE8xUiEE4GQyP2JSdz19EHdMg8L4jK1g-umYwEIbCWg==" ); "x-cache" = ( "Miss from cloudfront" ); "x-ratelimit-limit" = ( 10 ); "x-ratelimit-remaining" = ( 9 ); "x-ratelimit-reset" = ( 1523316162 ); "x-request-id" = ( "58caeaa2-35a5-4197-a478-cf0a76da16f2" ); } } [Data]: 1474 bytes [Result]: SUCCESS: { data = ( { attributes = { createdAt = "2018-04-05T14:36:25Z"; name = AltenaBlue; patchVersion = ""; shardId = "pc-na"; stats = ""; titleId = "bluehole-pubg"; updatedAt = "2018-04-05T14:36:25Z"; }; id = "account.69a0587badc340f09a97771109eff2a8"; links = { schema = ""; self = "https://api.playbattlegrounds.com/shards/pc-na/players/account.69a0587badc340f09a97771109eff2a8"; }; relationships = { assets = { data = ( ); }; matches = { data = ( { id = "86601274-1d36-4cff-84f1-41fefa5ef7ae"; type = match; }, { id = "6a3f4634-0b17-4647-b646-7ab3629efde4"; type = match; }, { id = "876b8d99-e7fa-4388-8cb9-c18d651c362f"; type = match; }, { id = "519b6804-fee2-4bc9-9b4e-dd59a7cc23a5"; type = match; }, { id = "497bd36f-d7dd-4eba-9781-a1c36fdc0dd4"; type = match; }, { id = "de5f23e2-ad11-470e-ad20-d167eb504d12"; type = match; }, { id = "7e317302-3b8f-47c2-80ee-2e4c283bf389"; type = match; }, { id = "1f51f26f-466f-4e65-aeb5-4950e5ecd4aa"; type = match; }, { id = "ac9b24b2-ad91-430b-9908-9b83266193d3"; type = match; }, { id = "aebaef44-fd2a-4271-8c6c-6964de2baae3"; type = match; }, { id = "098064b8-fe50-4103-9dbc-ecfcc260cb45"; type = match; }, { id = "99ed0b9a-5a15-4cf2-8a03-a864a537216f"; type = match; }, { id = "ddf1712b-c425-4efd-8b16-95cb1eba1f91"; type = match; }, { id = "f77f3f24-e10d-4903-b1f4-233b3b5a64da"; type = match; }, { id = "e8e87271-dd62-4b94-9160-c1616b726dd2"; type = match; } ); }; }; type = player; } ); links = { self = "https://api.playbattlegrounds.com/shards/pc-na/players?filter[playerNames]=AltenaBlue"; }; meta = { }; } [Timeline]: Timeline: { "Request Start Time": 545008901.962, "Initial Response Time": 545008902.281, "Request Completed Time": 545008902.284, "Serialization Completed Time": 545008902.286, "Latency": 0.319 secs, "Request Duration": 0.322 secs, "Serialization Duration": 0.001 secs, "Total Duration": 0.324 secs }

ritteraf commented 6 years ago

That's on my player name. We should pwn some noobs sometime ;)

cocoahero commented 6 years ago

Odd. Whenever I try my player name, or any of my friends, I don't get any data back. AltenaBlue is the first I've seen that worked.

ritteraf commented 6 years ago

Are you sure you're setting the right region abbrevation? The docs don't say it, but I'm pretty sure you have to have played at least one game on the region server for it to work.

cocoahero commented 6 years ago

Yup, pc-na. Try it for yourself, my player name is cocoahero.

ritteraf commented 6 years ago

I'll try your username with my code if you hook me up

ritteraf commented 6 years ago

Yea, cocoahero, Cocoahero, and CocoaHero didn't return anything. I just tried it on one of my friends, and it worked as well. MaverickHS

cocoahero commented 6 years ago

Hmm, yeah I tried a different capitalization of one of my friends and it worked. Must be case-sensitive, which is annoying. Still haven't figured out what my capitalization is. =(

ritteraf commented 6 years ago

Yep. Definitely case sensitive. If you log into the game it shows you.

cocoahero commented 6 years ago

Well, apparently it is cocoahero, but data wasn't showing up until I played a few rounds. /shrug

ritteraf commented 6 years ago

Yea, it seems the only real functionality of the user lookup is to get match ID's, which is a shame.