Skip to content

Instantly share code, notes, and snippets.

@MickaelCruzDB
Created March 31, 2021 05:44
Show Gist options
  • Save MickaelCruzDB/5d02905b94b3a2fdbefc428b29c758f5 to your computer and use it in GitHub Desktop.
Save MickaelCruzDB/5d02905b94b3a2fdbefc428b29c758f5 to your computer and use it in GitHub Desktop.
static
func badge(_ completion: @escaping (Result<(HTTPURLResponse, Int?), Error>) -> Void) {
struct Payload: Decodable {
var value: Int
}
GalaxyRouter
.request(.myBadge)
.build(headers: ["Authorization": "Bearer \(getUserInfos()?.value(forKeyPath: "token") as! String)", ])
.build(parameters: [
"device": UIDevice.current.identifierForVendor?.uuidString,
])
.completion(Payload.self) { result in
print("result : fonction badge : \(result)") ---> retourne 400
switch result {
case .success((let response, let payload)):
if payload != nil {
if let payload = payload {
// setUserInfos(badge: 9000001)
// completion(.success((response, 9000001)))
setUserInfos(badge: payload.value)
print("BADGE ==> \(payload.value)")
completion(.success((response, payload.value)))
} else { completion(.success((response, nil))) }
}
case .failure(let error):
completion(.failure(error))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment