Skip to content
This repository was archived by the owner on Jan 19, 2020. It is now read-only.

chackle/player-auth-me

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PlayerAuthMe


A simple framework for implementing player.me OAuth API

Setting your clientId and clientSecret

These are requested from player.me. They should be statically set within your app and not reused across apps.

var playerAuthMe = PlayerAuthMe.sharedInstance
    playerAuthMe.clientId("your_client_id")
    playerAuthMe.clientSecret("your_client_secret")

Authentication with username/email and password

The idea here is that we authenticate once with the player.me servers. Once a session is active the library handles all authenticated requests automatically. If playerAuthMe.endSession() is called, the session will no longer be active and any requests requiring authentication will fail.

var playerAuthMe = PlayerAuthMe.sharedInstance
    playerAuthMe.authenticateUser("username", withPassword: "password")
    .onSuccess { (result) -> () in
      println("Success! Result: \(result)")
    }
    .onFailure { (error) -> () in
      println("Failure :( \(error)")
    }

Refreshing current user access

In order to refresh access we need to have obtained access in the first place. For this reason the session must be passed into refreshAccessTokenForSession. Dependency injection is used here in case you need to check the session validity before the request is attempted.

if let session = playerAuthMe.activeSession() {
  playerAuthMe.refreshAccessTokenForSession(session)
  .onSuccess({ () -> () in
    println("Refresh success!")
  })
  .onFailure({ (error) -> () in
    println("Refresh error! \(error)")
  })
}

Getting a Specific User’s Info

A simple request which does not require authentication.

playerAuthMe.requestPlayerWithId(1)
.onSuccess { (players) -> () in
  println("Have queried 1.. have gotten \(players[0].toDictionary())")
}
.onFailure { (error) -> () in
  println("Request Player Error! \(error)")
}

Searching for a User based on a string

The string passed in will be queried against player usernames.

playerAuthMe.requestPlayerSearch("cha", andLimit: 20, andPage: 1)
.onSuccess { (players) -> () in
  println("Have queried 'cha'.. have gotten \(players)")
}
.onFailure { (error) -> () in
  println("Search Players Error! \(error)")
}

..or a query!

A query allows a filter to be passed in order to order the data. Sadly it seems this is only possible when not searching with a string also.

playerAuthMe.requestPlayerSearch(FilterType.Popular.rawValue, andLimit: 20, andPage: 1)
.onSuccess { (players) -> () in
  println("Have queried ‘_filter:popular’.. have gotten \(players)")
}
.onFailure { (error) -> () in
  println("Search Players Error! \(error)")
}

Getting all current user’s followed players online

This is a chained request with three stages in order to return the data requested.

  1. Requests the user ids for the logged in user’s online followed list
  2. Creates a call for each user, piggy backing off requestPlayerWithId
  3. Returns full details of all requested players
playerAuthMe.requestOnlineFollowedPlayersForSession(session)
.onSuccess({ (players) -> () in
  println("Request online players success \(players)")
})
.onFailure({ (error) -> () in
  println("Request online players error \(error)")
})

Post using the Authenticated User’s Session

This request is very powerful. It can be implemented as a standard ‘make a post’ function OR it can be used to post a high score screenshot ‘share with your friends via player.me’ function. At the moment it takes in an array of UIImage, but this will later be compatible with all forms of displaying content including UIView and CALayer.

playerAuthMe.postToFeedUsingSession(session, withText: textField.text, andImages: [imageView.image!])
.onSuccess({ () -> () in
  println("Successful post!")
})
.onFailure({ (error) -> () in
  println("Failed to post! \(error)")
})

Here is the end result using the example packaged in the project: ![alt text](http://i.imgur.com/xqqkrwU.png “End Result of Example“)

Request the Current Feed

This request is restricted for now due to the sheer flexibility of it. For now it returns the standard public feed. Most of the response is packaged up nicely into useable objects, structs and enums. Some things are missing, but this will change with a bit of time. Below is an example of how to use this GET request.

playerAuthMe.requestFeedUsingSession(session, withLimit: 50, andPage: 0, fromSources: FeedSource.allValues)
.onSuccess({ (posts) -> () in
  println("posts \(posts)")
})
.onFailure({ (error) -> () in
  println("Request Feed Error \(error)")
})

Change the authenticated user’s main profile details

This request updates all details set in the wrapper. This does not include password or other private or ’extra’ profile settings.

let details = PlayerDetailsWrapper()
              .changeUsername("chackle")
              .changeLongDescription("Follow me, I'm awesome!")
              .changeEmail("[email protected]")
              .changeAccountType(AccountType.User)
self.playerAuthMe.editPlayerForSession(session, withDetails:details)
.onSuccess({ () -> () in
  println("Request Player Edit success!")
})
.onFailure({ (error) -> () in
  println("Request Player Edit error \(error)")
})

Change the authenticated user’s privacy settings

This consists of three different requests which all begin editPlayerForSession. Each have their own variations of parameters, altering the with parameter each time. Below is an example of changing the account privacy.

playerAuthMe.editPlayerForSession(session, withAccountPrivacy: AccountPrivacy.Private)
.onSuccess({ () -> () in
  println("Request player privacy edit success!")
})
.onFailure({ (error) -> () in
  println("Request player Privacy edit error \(error)")
})

Getting Specific Game

Returns a single Game object with a bunch of mandatory values and a lot of optional values.

playerAuthMe.requestGameWithId(1)
.onSuccess({ (games) -> () in
  println("Successfully got game \(games[0])")
})
.onFailure({ (error) -> () in
  println("Did not get game \(error)")
})

Searching Full Game Library

This is similar to searching for users. Pass in a query or filter and receive results as usable objects.

playerAuthMe.requestGameSearch("Starcraft", andLimit: 20, andPage: 1)
.onSuccess({ (games) -> () in
  println("Got games \(games)")
})
.onFailure({ (error) -> () in
  println("Did not get the games \(error)")
})

About

A simple iOS framework for implementing player.me OAuth API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages