Commit 84b5b8ec authored by Jose Blaya's avatar Jose Blaya
Browse files

Merge branch '140-add-credentials-to-post-invite-service' into 'release/2.1.0'

Resolve "Add credentials to POST invite service"

See merge request ios/client-library-apple!196
parents 85f8e247 6eae57a5
......@@ -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)
}
......
......@@ -218,6 +218,40 @@ extension Macros {
}
/**
Shortcut to display a success `EKImageNoteMessageView`.
- Parameter image: The note image
- Parameter message: The note message
- Parameter duration: Optional duration of the note
*/
public static func displaySuccessImageNote(withImage image: UIImage,
message: String,
andDuration duration: Double? = nil) {
var attributes = EKAttributes()
attributes = .topToast
attributes.hapticFeedbackType = .success
attributes.entryBackground = .color(color: UIColor.piaGreenDark20)
attributes.positionConstraints.size = .init(width: EKAttributes.PositionConstraints.Edge.fill,
height: EKAttributes.PositionConstraints.Edge.constant(value: bannerHeight))
if let duration = duration {
attributes.displayDuration = duration
}
let labelContent = EKProperty.LabelContent(text: message,
style: .init(font: TextStyle.textStyle7.font!,
color: .white))
let imageContent = EKProperty.ImageContent(image: image)
let contentView = EKImageNoteMessageView(with: labelContent,
imageContent: imageContent)
SwiftEntryKit.display(entry: contentView,
using: attributes)
}
/**
Shortcut to display an infinite `EKImageNoteMessageView`.
......
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