Commit 85e244a6 authored by Jose Blaya's avatar Jose Blaya
Browse files

Add credentials object to request

parent 85f8e247
......@@ -48,5 +48,5 @@ protocol WebServices: class {
func invitesInformation(_ callback: LibraryCallback<InvitesInformation>?)
func invite(name: String, email: String, _ callback: SuccessLibraryCallback?)
func invite(credentials: Credentials, name: String, email: String, _ callback: SuccessLibraryCallback?)
}
......@@ -283,7 +283,12 @@ class DefaultAccountProvider: AccountProvider, ConfigurationAccess, DatabaseAcce
}
func invite(name: String, email: String, _ callback: SuccessLibraryCallback?) {
webServices.invite(name: name, email: email, { result in
guard let user = currentUser else {
preconditionFailure()
}
webServices.invite(credentials: user.credentials, name: name, email: email, { result in
callback?(result)
})
}
......
......@@ -278,17 +278,18 @@ class PIAWebServices: WebServices, ConfigurationAccess {
}
func invite(name: String, email: String, _ callback: SuccessLibraryCallback?) {
func invite(credentials: Credentials, name: String, email: String, _ callback: SuccessLibraryCallback?) {
let endpoint = ClientEndpoint.invites
let status = [200, 400]
let status = [200, 400, 401]
let errors: [Int: ClientError] = [
400: .badReceipt
400: .badReceipt,
401: .unauthorized
]
let parameters = ["invitee_name": name,
"invitee_email": email]
req(nil, .post, endpoint, parameters, status, JSONRequestExecutor() { (json, status, error) in
req(credentials, .post, endpoint, parameters, status, DataRequestExecutor() { (json, status, error) in
if let knownError = self.knownError(endpoint, status, errors) {
callback?(knownError)
return
......
......@@ -77,7 +77,7 @@ class MockWebServices: WebServices {
callback?(result, error)
}
func invite(name: String, email: String, _ callback: SuccessLibraryCallback?) {
func invite(credentials: Credentials, name: String, email: String, _ callback: SuccessLibraryCallback?) {
callback?(nil)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment