Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AuxiliaryRequests {
- static func getSocketData(currentViewController: UIViewController, closure: @escaping () -> ()) {
- let timestampSeconds = Int(NSDate().timeIntervalSince1970)
- _ = APIManager.sharedInstance.getSocketData(timestamp: timestampSeconds){ error, json in
- if let e = error {
- print(e)
- if json != nil {
- print(json!)
- if let message = json!["message"].string {
- print("GET SOCKET DATA MESSAGE: \(message)")
- if message == "invalid_token" || message == "not_authorized_device" {
- AuxiliaryFunctions.logOut(currentViewController: currentViewController)
- }
- }
- }
- } else {
- //print(json!)
- print("SOCKET DATA GET")
- UserDefaults.standard.setSocketSocId(value: json!["data"]["socid"].stringValue)
- UserDefaults.standard.setSocketUId(value: json!["data"]["uid"].stringValue)
- UserDefaults.standard.setSocketVerify(value: json!["data"]["verify"].stringValue)
- getSocketHost(currentViewController: currentViewController, closure: closure)
- }
- }
- }
- static func getSocketHost(currentViewController: UIViewController, closure: @escaping () -> ()) {
- let parameters: Parameters = [
- "socid": UserDefaults.standard.getSocketSocId(),
- "uid": UserDefaults.standard.getSocketUId(),
- "verify": UserDefaults.standard.getSocketVerify()
- ]
- let timestampSeconds = Int(NSDate().timeIntervalSince1970)
- _ = APIManager.sharedInstance.getSocketHost(timestamp: timestampSeconds, parameters: parameters){ error, json in
- if let e = error {
- print(e)
- if json != nil {
- print(json!)
- if let message = json!["message"].string {
- print("GET SOCKET HOST MESSAGE: \(message)")
- if message == "invalid_token" || message == "not_authorized_device" {
- AuxiliaryFunctions.logOut(currentViewController: currentViewController)
- }
- }
- }
- } else {
- //print(json!)
- print("SOCKET HOST GET")
- UserDefaults.standard.setSocketHost(value: json!["data"]["host"].stringValue)
- closure()
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement