You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

64 lines
2.3 KiB

//
// ReciepientServcie.swift
// GMERemittance
//
// Created by ccr on 26/08/2018.
// Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
//
import Foundation
import Alamofire
protocol FetchRecipientList: ApiServiceType {
func fetchReciepientList(username: String, success: @escaping (RecipientListWrapperContainer?) -> (), failure: @escaping (Error) -> ())
}
//http://localhost:9500/api/v1/mobile/sisir@mailinator.com/receivers?search=
extension FetchRecipientList {
func fetchReciepientList(username: String, success: @escaping (RecipientListWrapperContainer?) -> (), failure: @escaping (Error) -> ()) {
let url = baseUrl + "/mobile/" + username + "/receivers"
let params = ["search": ""]
auth.request(method: .get, url: url, params: params, encoding: URLEncoding.default, success: { (response: RecipientListContainer) in
if (response.errorCode ?? "") == "1" {
let error = NSError.init(domain: "Network", code: 0, userInfo: [NSLocalizedDescriptionKey : response.message ?? ""])
failure(error)
}else {
let model = response.data
success(model)
}
}) { (error) in
failure(error)
}
}
}
//http://localhost:9500/api/v1/mobile/receiver/remove/sisir@mailinator.com/?receiverId=143313
protocol DeleteRecipientService: ApiServiceType {
func deleteRecipient(username: String, reciepient: Recipient, success: @escaping (Recipient?) -> (), failure: @escaping (Error) -> ())
}
extension DeleteRecipientService {
func deleteRecipient(username: String, reciepient: Recipient, success: @escaping (Recipient?) -> (), failure: @escaping (Error) -> ()) {
let url = baseUrl + "/mobile/receiver/remove/" + username + "/?receiverId=\(reciepient.recipientId ?? "")"
auth.request(method: .post, url: url, params: nil, encoding: URLEncoding.default, success: { (response: RecipientContainer) in
if (response.errorCode ?? "") == "1" {
let error = NSError.init(domain: "Network", code: 0, userInfo: [NSLocalizedDescriptionKey : response.message ?? ""])
failure(error)
}else {
let model = response.data
success(model)
}
}) { (error) in
failure(error)
}
}
}