This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Created by Rashid Ramazanov on 18/01/2017. | |
// Converted from Java snippet in https://en.wikipedia.org/wiki/Vehicle_identification_number#Example_Code | |
// | |
import Foundation | |
extension String { | |
var isValidChassisNo: Bool { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
struct User: Decodable { | |
var username: String? | |
var name: String? | |
var surname: String? | |
var email: String? | |
var uid: String? | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
struct Coupon: Decodable { | |
var id: String = "" | |
var name: String = "" | |
var no: String = "" | |
var isOpen: Bool = false | |
var matches: [PMatches] = [] // PMatches is also a decodable struct. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"message" : "", | |
"status" : 1, | |
"data" : { | |
"uid" : "XXX-XXX-XXX", | |
"surname" : "Ramazanov", | |
"username" : "Rashid", | |
"email" : "[email protected]", | |
"name" : "Rashid", | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"message": "", | |
"status": 0, | |
"data": { | |
"cpnid": "XXX-XXX-XXX", | |
"couponname": "29.Kupon", | |
"couponno": "29", | |
"iscouponopen" : false, | |
"matches": [ | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
struct PanpaResponse<T>: Decodable where T: Decodable { | |
private var statusInt: Int? | |
var status: Status { | |
if statusInt == 1 || statusInt == 0 { | |
return .success | |
} | |
return .failed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Alamofire | |
... | |
func login() { | |
let urlStr = "\(serverUrl)\(EndpointTails.login.rawValue)" | |
AF.request(urlStr, method: .get).responseDecodable { (response: DataResponse<PanpaResponse<User>, AFError>) in | |
if let panpaResponse = response.value { | |
switch panpaResponse.status { | |
case .success: | |
guard let user: User = panpaResponse.data else { return } | |
print(user.username) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Alamofire | |
... | |
private func getCoupon() { | |
let urlStr = "\(serverUrl)\(EndpointTails.group_last_coupon_one.rawValue)" | |
AF.request(urlStr, method: .get).responseDecodable { (response: DataResponse<PanpaResponse<Coupon>, AFError>) in | |
if let panpaResponse = response.value { | |
switch panpaResponse.status { | |
case .success: | |
guard let coupon: Coupon = panpaResponse.data else { return } | |
print(coupon.name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"message": "", | |
"status": 0, | |
"coupon": { | |
"cpnid": "XXX-XXX-XXX", | |
"couponname": "29.Kupon", | |
"couponno": "29", | |
"iscouponopen" : false, | |
"matches": [ | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"message" : "", | |
"status" : 1, | |
"user" : { | |
"uid" : "XXX-XXX-XXX", | |
"surname" : "Ramazanov", | |
"username" : "Rashid", | |
"email" : "[email protected]", | |
"name" : "Rashid", | |
} |
OlderNewer