Skip to content

Commit

Permalink
checked code
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillkotov committed Oct 20, 2020
1 parent a59a4f0 commit 89ea303
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 155 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion HyberSDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |spec|
#

spec.name = "HyberSDK"
spec.version = "1.0.0.4"
spec.version = "1.0.0.5"
spec.summary = "A short description of HyberSDK."

# This description is used to generate tags and improve search results.
Expand Down
8 changes: 4 additions & 4 deletions HyberSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
21CF6E7C440E8C87EFF44A94 /* Pods_HyberSDKTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 36BCB4E46C2F114CEAD245C7 /* Pods_HyberSDKTests.framework */; };
BA1A13B4253E85D700E93196 /* HyberSDK.podspec in Resources */ = {isa = PBXBuildFile; fileRef = BA1A13B3253E85D700E93196 /* HyberSDK.podspec */; };
BA1C39F6253CB69000052185 /* HyberSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BA1C39EC253CB69000052185 /* HyberSDK.framework */; };
BA1C39FB253CB69000052185 /* HyberSDKTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA1C39FA253CB69000052185 /* HyberSDKTests.swift */; };
BA1C39FD253CB69000052185 /* HyberSDK.h in Headers */ = {isa = PBXBuildFile; fileRef = BA1C39EF253CB69000052185 /* HyberSDK.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand All @@ -18,7 +19,6 @@
BA8D3418253CC12E005BDC33 /* hyber_answer_func.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA8D3415253CC12E005BDC33 /* hyber_answer_func.swift */; };
BA8D3419253CC12E005BDC33 /* params.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA8D3416253CC12E005BDC33 /* params.swift */; };
BA8D341C253CC14A005BDC33 /* hyber_adapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA8D341B253CC14A005BDC33 /* hyber_adapter.swift */; };
BA8D341E253CCA24005BDC33 /* HyberSDK.xcworkspace in Resources */ = {isa = PBXBuildFile; fileRef = BA8D341D253CCA24005BDC33 /* HyberSDK.xcworkspace */; };
C04482AA53327CA7596F1B6C /* Pods_HyberSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8BE323D9F391699D4AA1D26E /* Pods_HyberSDK.framework */; };
/* End PBXBuildFile section */

Expand All @@ -39,6 +39,7 @@
36BCB4E46C2F114CEAD245C7 /* Pods_HyberSDKTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_HyberSDKTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
62EFA8335FEA29B595B9A5BB /* Pods-HyberSDKTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HyberSDKTests.debug.xcconfig"; path = "Target Support Files/Pods-HyberSDKTests/Pods-HyberSDKTests.debug.xcconfig"; sourceTree = "<group>"; };
8BE323D9F391699D4AA1D26E /* Pods_HyberSDK.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_HyberSDK.framework; sourceTree = BUILT_PRODUCTS_DIR; };
BA1A13B3253E85D700E93196 /* HyberSDK.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = HyberSDK.podspec; sourceTree = "<group>"; };
BA1C39EC253CB69000052185 /* HyberSDK.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = HyberSDK.framework; sourceTree = BUILT_PRODUCTS_DIR; };
BA1C39EF253CB69000052185 /* HyberSDK.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HyberSDK.h; sourceTree = "<group>"; };
BA1C39F0253CB69000052185 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand All @@ -52,7 +53,6 @@
BA8D3415253CC12E005BDC33 /* hyber_answer_func.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = hyber_answer_func.swift; sourceTree = "<group>"; };
BA8D3416253CC12E005BDC33 /* params.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = params.swift; sourceTree = "<group>"; };
BA8D341B253CC14A005BDC33 /* hyber_adapter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = hyber_adapter.swift; sourceTree = "<group>"; };
BA8D341D253CCA24005BDC33 /* HyberSDK.xcworkspace */ = {isa = PBXFileReference; lastKnownFileType = wrapper.workspace; path = HyberSDK.xcworkspace; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -88,7 +88,7 @@
BA1C39E2253CB68F00052185 = {
isa = PBXGroup;
children = (
BA8D341D253CCA24005BDC33 /* HyberSDK.xcworkspace */,
BA1A13B3253E85D700E93196 /* HyberSDK.podspec */,
BA1C39EE253CB69000052185 /* HyberSDK */,
BA1C39F9253CB69000052185 /* HyberSDKTests */,
BA1C39ED253CB69000052185 /* Products */,
Expand Down Expand Up @@ -254,7 +254,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
BA8D341E253CCA24005BDC33 /* HyberSDK.xcworkspace in Resources */,
BA1A13B4253E85D700E93196 /* HyberSDK.podspec in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file not shown.
28 changes: 24 additions & 4 deletions HyberSDK/HyberSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import Foundation
import UIKit
import CryptoSwift
//import SwiftyBeaver
import SwiftyBeaver
//
//import CoreData
//import FirebaseCore
Expand All @@ -29,10 +29,11 @@ public extension Notification.Name {

public class HyberSDK {

private let log = SwiftyBeaver.self

public init(
//platform_branch: PushSdkParametersPublic,
log_level: String = "error",
kk: String = "h"
platform_branch: PushSdkParametersPublic.BranchStructObj = PushSdkParametersPublic.branchMasterValue,
log_level: String = "error"
)
{
Constants.registrationstatus = UserDefaults.standard.bool(forKey: "registrationstatus")
Expand All @@ -41,10 +42,27 @@ public class HyberSDK {
Constants.firebase_registration_token = UserDefaults.standard.string(forKey: "firebase_registration_token")
Constants.hyber_user_msisdn = UserDefaults.standard.string(forKey: "hyber_user_msisdn")
Constants.hyber_user_password = UserDefaults.standard.string(forKey: "hyber_user_password")

Constants.platform_branch_active = platform_branch
Constants.log_level_active = log_level

let console = ConsoleDestination()
console.format = "$DHH:mm:ss$d $L $M"
let file = FileDestination()
Constants.logger.addDestination(console)

Constants.logger.addDestination(file)
if (log_level == "debug")
{
let debug_out = Constants.logger.Level.debug
print(debug_out)
}
}

private let processor = Processing.init()



//answer codes
//200 - Ok

Expand Down Expand Up @@ -84,6 +102,8 @@ public class HyberSDK {
//subscribers password (optional, for future use)
public func hyber_register_new(user_phone: String, user_password: String, x_hyber_sesion_id: String, x_hyber_ios_bundle_id: String, X_Hyber_Client_API_Key: String)->HyberFunAnswerRegister {

Constants.logger.debug("Any")


if (Constants.registrationstatus==false){
if (user_phone != "" && x_hyber_sesion_id != "" && X_Hyber_Client_API_Key != "" ) {
Expand Down
50 changes: 29 additions & 21 deletions HyberSDK/api/hyber_adapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class HyberAPI {
//1 procedure
func hyber_device_register(X_Hyber_Client_API_Key: String, X_Hyber_Session_Id: String, X_Hyber_IOS_Bundle_Id: String, device_Name:String, device_Type:String, os_Type:String, sdk_Version:String, user_Pass:String, user_Phone:String)-> HyberFunAnswerRegister {

Constants.logger.debug("Start function hyber_device_register")


//var answ: String = String()
var genAnsw: HyberFunAnswerRegister = HyberFunAnswerRegister(code: 0, result: "", description: "", deviceId: "", token: "", userId: "", userPhone: "", createdAt: "")
Expand All @@ -42,7 +44,7 @@ class HyberAPI {
"userPhone": user_Phone
] as Dictionary<String, AnyObject>

let urlString = NSString(format: Constants.url_Http_Registration as NSString);
let urlString = NSString(format: Constants.platform_branch_active.url_Http_Registration as NSString);
processor.file_logger(message: "hyber_device_register url string is \(urlString)", loglevel: ".debug")

let request : NSMutableURLRequest = NSMutableURLRequest()
Expand All @@ -61,8 +63,8 @@ class HyberAPI {

request.httpBody = try! JSONSerialization.data(withJSONObject: params, options: [])

print(request.httpBody ?? "")
print(request.allHTTPHeaderFields ?? "")
Constants.logger.debug(request.httpBody ?? "")
Constants.logger.debug(request.allHTTPHeaderFields ?? "")

let dataTask = session.dataTask(with: request as URLRequest)
{
Expand All @@ -71,6 +73,7 @@ class HyberAPI {
guard let httpResponse = response as? HTTPURLResponse, let receivedData = data
else {
print("error: not a valid http response")
semaphore7.signal()
return
}
print(httpResponse)
Expand Down Expand Up @@ -100,10 +103,11 @@ class HyberAPI {

let response = NSString (data: receivedData, encoding: String.Encoding.utf8.rawValue)

print(String(response ?? ""))
Constants.logger.debug(String(response ?? ""))

let str_resp = String(response ?? "")
print(str_resp)

Constants.logger.debug(str_resp)

let resp_register_parsed = self.jsonparser.registerJParse(str_resp: str_resp)

Expand All @@ -126,7 +130,7 @@ class HyberAPI {

UserDefaults.standard.synchronize()

print(resp_register_parsed.token ?? "")
Constants.logger.debug(resp_register_parsed.token ?? "")

if response == "SUCCESS"
{
Expand All @@ -142,8 +146,6 @@ class HyberAPI {
dataTask.resume()
semaphore7.wait()
return genAnsw


}

//2 procedure
Expand All @@ -156,7 +158,7 @@ class HyberAPI {
let semaphore6 = DispatchSemaphore(value: 0)

let params = ["devices": dev_list] as Dictionary<String, AnyObject>
let urlString = NSString(format: Constants.url_Http_Revoke);
let urlString = NSString(format: Constants.platform_branch_active.url_Http_Revoke as NSString);

print("params: \(dev_list)")

Expand Down Expand Up @@ -201,6 +203,7 @@ class HyberAPI {
guard let httpResponse = response as? HTTPURLResponse, let receivedData = data
else {
print("error: not a valid http response")
semaphore6.signal()
return
}

Expand Down Expand Up @@ -260,6 +263,7 @@ class HyberAPI {
//3 procedure
//for update device from hyber server
func hyber_device_update(fcm_Token: String, os_Type: String, os_Version: String, device_Type: String, device_Name: String, sdk_Version: String, X_Hyber_Session_Id: String, X_Hyber_Auth_Token:String) -> HyberGeneralAnswerStruct {
Constants.logger.debug("Start function hyber_device_update")
let procedure_name = "hyber_device_update"
let configuration = URLSessionConfiguration .default
let session = URLSession(configuration: configuration)
Expand All @@ -274,7 +278,7 @@ class HyberAPI {
"deviceName":device_Name,
"sdkVersion":sdk_Version
] as Dictionary<String, AnyObject>
let urlString = NSString(format: Constants.url_Http_Update);
let urlString = NSString(format: Constants.platform_branch_active.url_Http_Update as NSString);
processor.file_logger(message: "\(procedure_name) url string is \(urlString)", loglevel: ".debug")
processor.file_logger(message: "\(procedure_name) params is \(params.description)", loglevel: ".debug")

Expand Down Expand Up @@ -303,8 +307,8 @@ class HyberAPI {

request.httpBody = try! JSONSerialization.data(withJSONObject: params, options: [])

print(request.allHTTPHeaderFields as Any)
print(params)
Constants.logger.debug(request.allHTTPHeaderFields as Any)
Constants.logger.debug(params)

let dataTask = session.dataTask(with: request as URLRequest)
{
Expand All @@ -313,6 +317,7 @@ class HyberAPI {
guard let httpResponse = response as? HTTPURLResponse, let receivedData = data
else {
print("error: not a valid http response")
semaphore5.signal()
return
}

Expand All @@ -332,16 +337,15 @@ class HyberAPI {

self.processor.file_logger(message: "\(procedure_name) response debugDescription is \(httpResponse.debugDescription)", loglevel: ".debug")

print(jsonData as Any)
print(httpResponse.statusCode)
Constants.logger.debug(jsonData as Any)
Constants.logger.debug(httpResponse.statusCode)

switch (httpResponse.statusCode)
{
case 200:

let response = NSString (data: receivedData, encoding: String.Encoding.utf8.rawValue)


if response == "SUCCESS"
{
self.processor.file_logger(message: "\(procedure_name) success response body is \(String(describing: response))", loglevel: ".debug") }
Expand Down Expand Up @@ -374,7 +378,7 @@ class HyberAPI {

let escaped_utc = String(utc_time).addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)

let urlString = NSString(format: "\(Constants.url_Http_Mess_history)\(String(describing: escaped_utc))" as NSString);
let urlString = NSString(format: "\(Constants.platform_branch_active.url_Http_Mess_history)\(String(describing: escaped_utc))" as NSString);
processor.file_logger(message: "\(procedure_name) url string is \(urlString)", loglevel: ".debug")

let request : NSMutableURLRequest = NSMutableURLRequest()
Expand Down Expand Up @@ -410,6 +414,7 @@ class HyberAPI {
guard let httpResponse = response as? HTTPURLResponse, let receivedData = data
else {
print("error: not a valid http response")
semaphore4.signal()
return
}

Expand Down Expand Up @@ -482,7 +487,7 @@ class HyberAPI {
"messageId":message_Id
//"receivedAt":received_At
] as Dictionary<String, AnyObject>
let urlString = NSString(format: Constants.url_Http_Mess_dr);
let urlString = NSString(format: Constants.platform_branch_active.url_Http_Mess_dr as NSString);
processor.file_logger(message: "\(procedure_name) url string is \(urlString)", loglevel: ".debug")
processor.file_logger(message: "\(procedure_name) params is \(params.description)", loglevel: ".debug")

Expand Down Expand Up @@ -524,6 +529,7 @@ class HyberAPI {
guard let httpResponse = response as? HTTPURLResponse, let receivedData = data
else {
print("error: not a valid http response")
semaphore3.signal()
return
}

Expand Down Expand Up @@ -585,7 +591,7 @@ class HyberAPI {
"messageId": message_Id,
"answer": answer
] as Dictionary<String, AnyObject>
let urlString = NSString(format: Constants.url_Http_Mess_callback);
let urlString = NSString(format: Constants.platform_branch_active.url_Http_Mess_callback as NSString);
processor.file_logger(message: "\(procedure_name) url string is \(urlString)", loglevel: ".debug")
processor.file_logger(message: "\(procedure_name) params is \(params.description)", loglevel: ".debug")

Expand Down Expand Up @@ -623,6 +629,7 @@ class HyberAPI {
guard let httpResponse = response as? HTTPURLResponse, let receivedData = data
else {
print("error: not a valid http response")
semaphore2.signal()
return
}

Expand Down Expand Up @@ -687,7 +694,7 @@ class HyberAPI {

let semaphore = DispatchSemaphore(value: 0)

let urlString = NSString(format: Constants.url_Http_Device_getall);
let urlString = NSString(format: Constants.platform_branch_active.url_Http_Device_getall as NSString);
processor.file_logger(message: "\(procedure_name) url string is \(urlString)", loglevel: ".debug")

let request : NSMutableURLRequest = NSMutableURLRequest()
Expand Down Expand Up @@ -726,6 +733,7 @@ class HyberAPI {
guard let httpResponse = response as? HTTPURLResponse, let receivedData = data
else {
print("error: not a valid http response")
semaphore.signal()
return
}

Expand Down Expand Up @@ -842,7 +850,6 @@ class HyberAPI {
print(new2String)
let new3String = new2String.replacingOccurrences(of: "\"", with: "", options: .literal, range: nil)
print(new3String)

listdev.append(new3String)
}

Expand All @@ -861,7 +868,7 @@ class HyberAPI {
let semaphore2 = DispatchSemaphore(value: 0)
var answ: HyberFunAnswerGeneral?
let params = [:] as Dictionary<String, AnyObject>
let urlString = NSString(format: Constants.hyber_url_mess_queue);
let urlString = NSString(format: Constants.platform_branch_active.hyber_url_mess_queue as NSString);
processor.file_logger(message: "\(procedure_name) url string is \(urlString)", loglevel: ".debug")
processor.file_logger(message: "\(procedure_name) params is \(params.description)", loglevel: ".debug")

Expand Down Expand Up @@ -899,6 +906,7 @@ class HyberAPI {
guard let httpResponse = response as? HTTPURLResponse, let receivedData = data
else {
print("error: not a valid http response")
semaphore2.signal()
return
}

Expand Down
Loading

0 comments on commit 89ea303

Please sign in to comment.