- added clicks api

This commit is contained in:
Bilal
2024-08-14 01:05:32 +05:30
parent 400974e58c
commit dcbc96f9e6
3 changed files with 104 additions and 0 deletions

View File

@@ -142,6 +142,10 @@ struct APIEndPoints {
// Other links...
}
struct Analytics{
static let user_clicks = makeURL(path: "v2/user_clicks")
}
// Helper method to construct full URL from base URL and path
private static func makeURL(path: String) -> URL {
guard let baseURL = baseURLForCurrentEnvironment() else {

View File

@@ -144,6 +144,29 @@ class NetworkManager{
}
return ("","")
}
/// This function will do the network call for POST With RAWJSON & Encoding is URLEncoding with contentType ["application/json"]
///
///
/// - Warning: The returned string is not localized.
///
/// Usage:
///
/// Alamofire network call POST(RawJSON).
///
/// - Parameter (header : HTTPHeaders , Params :[String : Any] , URL , Dedocable Generic T Struct.)
///
/// - Returns: This function returns a GENERIC response base on the T Model & ERROR .
func nwCallRawJSon<T: Decodable>(url : String, param : [String : Any],decodable: T.Type,onCompletion: @escaping (T?,Error?) -> Void){
AF.request(url, method: .post, parameters : param, encoding: JSONEncoding.default, headers: nil, requestModifier : { $0.timeoutInterval = 30 }).validate(contentType: ["application/json"]).responseDecodable { (response: DataResponse<T,AFError>) in
switch response.result {
case .success(let data):
onCompletion(data,nil)
case .failure(let error):
onCompletion(nil,error)
}
}
}
}

View File

@@ -547,6 +547,69 @@ class ThemeOneVM{
vc.timer = Timer.scheduledTimer(timeInterval: 60, target: self, selector: #selector(handleBackground), userInfo: nil, repeats: true)
}
func updateClicks(){
let headers : HTTPHeaders = ["access-token" : AuthFunc.shareInstance.getAccessToken()]
let params : [[String: Any]]
var totalClicks = [ClicksAnalytics]()
totalClicks.append(ClicksAnalytics(postID: 0, postType: 15, numberOfClicks: 12, deviceType: 2, categoryID: 0))
// Convert the array to a dictionary for the JSON body
do {
let encoder = JSONEncoder()
let jsonData = try encoder.encode(totalClicks)
let jsonArray = try JSONSerialization.jsonObject(with: jsonData, options: []) as? [[String: Any]]
if let jsonArray = jsonArray {
NetworkManager.shareInstance.nwCallRawJSon(url: "your_api_url", param: ["data": jsonArray], decodable: CommonResponseModel.self) { response, error in
switch response{
case .success:
guard let self else{
Utilities.dismissProgressHUD()
return
}
case .failure(let error):
guard let self else{
Utilities.dismissProgressHUD()
return
}
Utilities.dismissProgressHUD()
}
}
}
} catch {
print("Error encoding JSON: \(error)")
}
// NetworkManager.shareInstance.apiRequest(url: APIEndPoints.Analytics.user_clicks , method: .post,parameters: params,headers: headers) { [weak self](result : Result<BaseResponseModel<KaraokeListingDM>, NetworkManager.APIError>) in
// switch result{
// case .success(let data):
// guard let self else{
// Utilities.dismissProgressHUD()
// return
// }
// switch data.success{
// case 0:
// /*
// Error
// */
// Utilities.dismissProgressHUD()
//
// case 1:
// Utilities.dismissProgressHUD()
// default:
// break
// }
// case .failure(let error):
// guard let self else{
// Utilities.dismissProgressHUD()
// return
// }
// Utilities.dismissProgressHUD()
// }
// }
}
}
//class CustomLiveTVView: UIView {
@@ -563,3 +626,17 @@ class ThemeOneVM{
// return nil
// }
//}
// MARK: - StaticURLs
struct ClicksAnalytics : Codable {
let postID, postType, numberOfClicks, deviceType: Int?
let categoryID: Int?
enum CodingKeys: String, CodingKey {
case postID = "post_id"
case postType = "post_type"
case numberOfClicks = "number_of_clicks"
case deviceType = "device_type"
case categoryID = "category_id"
}
}