Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Alamofire
- import SwiftyJSON
- ///HTTP-Layer
- ///Creates with DeviceToken the URL to request the user-credentials
- class TokenConverterConnector {
- static let GOOGLETOKENURL = "https://www.googleapis.com/oauth2/v1/userinfo?access_token="
- static func requestGoogleCredentials(accessToken:String, completion: @escaping (_ jsonObject: SwiftyJSON?) -> Void) {
- let url = GOOGLETOKENURL + accessToken
- Alamofire.request(url).responseJSON {
- response in
- var jsonValue:SwiftyJSON?
- if let JSON = response.result.value {
- jsonValue = SwiftyJSON(JSON)
- }
- completion(jsonValue)
- }
- }
- }
- ///Service-Layer
- ///Converts Device Token of the User into his E-Mail, which is necessary for the Backend.
- class TokenConverterService {
- static func extractGoogleToken(accessToken:String, completion: @escaping (_ extraionSuccessful:Bool) -> Void) {
- TokenConverterConnector.requestGoogleCredentials(accessToken: accessToken, completion: {
- (jsonObject) in
- var extractionSuccessful:Bool = false
- if let json = jsonObject {
- let email = json["email"].string
- if let newMail = email {
- SettingsService.saveMail(newMail)
- extractionSuccessful = true
- }
- }
- completion(extractionSuccessful)
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement