-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Meikiem/main
Implement: Basements
- Loading branch information
Showing
86 changed files
with
16,357 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
Pod::Spec.new do |spec| | ||
|
||
spec.name = "InGrowiOS" | ||
spec.version = "1.0.0" | ||
spec.summary = "A cocoapods library written in Swift to use ingrow dynamic event streaming platform." | ||
|
||
spec.description = <<-DESC | ||
This cocoapods library helps you to use ingrow dynamic event streaming platform in iOS projects. | ||
DESC | ||
|
||
spec.homepage = "https://github.com/ingrowco/ios-sdk" | ||
|
||
# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # | ||
|
||
spec.license = { :type => "MIT", :file => "LICENSE" } | ||
|
||
# ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # | ||
|
||
spec.author = { "ingrow" => "https://ingrow.co" } | ||
|
||
# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # | ||
|
||
spec.platform = :ios | ||
spec.ios.deployment_target = "10.3" | ||
spec.swift_version = "5" | ||
|
||
# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # | ||
|
||
spec.source = { :git => "https://github.com/ingrowco/ios-sdk.git", :tag => "#{spec.version}" } | ||
|
||
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # | ||
|
||
spec.source_files = "InGrowiOS", "InGrowiOS/InGrowiOS/*.{h,m,swift}" | ||
spec.exclude_files = "InGrowiOS/InGrowiOS/*.plist" | ||
|
||
# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # | ||
|
||
spec.dependency "Alamofire", "~> 5.2" | ||
|
||
end |
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
InGrowiOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
InGrowiOS.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// | ||
// InGrowClient.swift | ||
// InGrowiOS | ||
// | ||
// Created by Meikiem on 2/1/21. | ||
// | ||
|
||
import Foundation | ||
import Network | ||
import Alamofire | ||
|
||
public final class InGrowClient { | ||
|
||
static let shared = InGrowClient() | ||
var inGrowProject: InGrowProject | ||
private var isDebugMode:Bool | ||
private var inGrowSession: InGrowSession? | ||
|
||
struct Config { | ||
var inGrowProject: InGrowProject | ||
} | ||
private static var config:Config? | ||
|
||
class func setup(_ config:Config){ | ||
InGrowClient.config = config | ||
} | ||
|
||
init(){ | ||
guard let config = InGrowClient.config else { | ||
fatalError("Error - you must call setup before accessing InGrowClient.shared") | ||
} | ||
if(config.inGrowProject.isLoggingEnable){ | ||
InGrowLogging.enableLogging() | ||
}else{ | ||
InGrowLogging.disableLogging() | ||
} | ||
inGrowProject = config.inGrowProject | ||
isDebugMode = false | ||
} | ||
|
||
public func setDebugMode(isDebugMode:Bool){ | ||
self.isDebugMode = isDebugMode | ||
} | ||
|
||
public static func client() -> InGrowClient{ | ||
return shared | ||
} | ||
|
||
static func enrichmentBySession(inGrowSession: InGrowSession) { | ||
guard InGrowClient.config != nil else { | ||
fatalError("Error - you must call setup before requesting enrichmentBySession") | ||
} | ||
shared.inGrowSession = inGrowSession | ||
} | ||
|
||
public func logEvents(events: Dictionary<String, Any>) { | ||
|
||
if(events.isEmpty){ | ||
handleFailure(message: "Error - events must not be null.") | ||
return | ||
} | ||
if(!isNetworkConnected()){ | ||
InGrowLogging.log(msg: "Error - Couldn't send events because of no network connection.") | ||
handleFailure(message: "Error - Network's not connected.") | ||
return | ||
} | ||
var main = Dictionary<String, Any>() | ||
var inGrowObject = Dictionary<String, Any>() | ||
var eventObject = Dictionary<String, Any>() | ||
var enrichmentObject = Dictionary<String, Any>() | ||
var enrichmentArray = [[String: Any]]() | ||
var inputObject = Dictionary<String, Any>() | ||
|
||
inGrowObject.updateValue(self.inGrowProject.project, forKey: Const.PROJECT) | ||
inGrowObject.updateValue(self.inGrowProject.stream, forKey: Const.STREAM) | ||
for (key, value) in events { | ||
eventObject.updateValue(value, forKey: key) | ||
} | ||
if(!self.inGrowProject.anonymousId.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty){ | ||
inputObject.updateValue(self.inGrowProject.anonymousId, forKey: Const.ANONYMOUS_ID) | ||
if(self.inGrowSession != nil && !self.inGrowSession!.userId.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty){ | ||
inputObject.updateValue(self.inGrowSession!.userId, forKey: Const.USER_ID) | ||
} else { | ||
inputObject.updateValue(self.inGrowProject.userId.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty ? "" : self.inGrowProject.userId, forKey: Const.USER_ID) | ||
} | ||
enrichmentObject.updateValue(Const.SESSION, forKey: Const.NAME) | ||
enrichmentObject.updateValue(inputObject, forKey: Const.INPUT) | ||
enrichmentArray.append(enrichmentObject as [String: Any]) | ||
main.updateValue(enrichmentArray, forKey: Const.ENRICHMENT) | ||
} | ||
main.updateValue(inGrowObject, forKey: Const.INGROW) | ||
main.updateValue(eventObject, forKey: Const.EVENT) | ||
|
||
do { | ||
let jsonData = try JSONSerialization.data(withJSONObject: main, options: .prettyPrinted) | ||
let requestString = NSString(data: jsonData, encoding: String.Encoding.utf8.rawValue) ?? "" | ||
if(!requestString.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty){ | ||
sendRequest(request: requestString) | ||
}else{ | ||
InGrowLogging.log(msg: "Error - JSON request must not be null!") | ||
} | ||
} catch { | ||
InGrowLogging.log(msg: "Error - Not a valid JSON") | ||
} | ||
} | ||
|
||
private func sendRequest(request: NSString){ | ||
|
||
RestClient.sendEvents(json: request, apiKey: self.inGrowProject.apiKey) | ||
} | ||
|
||
private func isNetworkConnected() -> Bool { | ||
return Reachability.isConnectedToNetwork() | ||
} | ||
|
||
private func handleFailure(message:String){ | ||
if(isDebugMode){ | ||
fatalError(message) | ||
}else{ | ||
InGrowLogging.log(msg: message) | ||
} | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// InGrowProject.swift | ||
// InGrowiOS | ||
// | ||
// Created by Meikiem on 2/1/21. | ||
// | ||
|
||
import Foundation | ||
|
||
struct InGrowProject { | ||
|
||
let apiKey: String | ||
let project: String | ||
let stream: String | ||
let isLoggingEnable: Bool | ||
var anonymousId: String = "" | ||
var userId: String = "" | ||
|
||
init(apiKey: String, project: String, stream: String, isLoggingEnable: Bool) { | ||
|
||
if(apiKey.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty){ | ||
fatalError("Api key should not be empty.") | ||
} | ||
|
||
if(project.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty){ | ||
fatalError("Project object should not be empty.") | ||
} | ||
|
||
if(stream.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty){ | ||
fatalError("Stream must be non-null and non-empty.") | ||
} | ||
self.project = project | ||
self.stream = stream | ||
self.apiKey = apiKey | ||
self.isLoggingEnable = isLoggingEnable | ||
} | ||
|
||
init(apiKey: String, project: String, stream: String, isLoggingEnable: Bool, anonymousId: String, userId: String?) { | ||
|
||
if(apiKey.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty){ | ||
fatalError("Error - apiKey should not be empty.") | ||
} | ||
|
||
if(project.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty){ | ||
fatalError("Error - project object should not be empty.") | ||
} | ||
|
||
if(stream.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty){ | ||
fatalError("Error - stream must be non-null and non-empty.") | ||
} | ||
if(anonymousId.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty){ | ||
fatalError("Error - anonymousId should not be empty.") | ||
} | ||
self.project = project | ||
self.stream = stream | ||
self.apiKey = apiKey | ||
self.isLoggingEnable = isLoggingEnable | ||
self.anonymousId = anonymousId | ||
if(userId != nil){ | ||
self.userId = userId! | ||
} | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// InGrowSession.swift | ||
// InGrowiOS | ||
// | ||
// Created by Meikiem on 2/1/21. | ||
// | ||
|
||
import Foundation | ||
|
||
struct InGrowSession { | ||
|
||
let userId:String | ||
|
||
init(userId: String) { | ||
|
||
if(userId.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty){ | ||
fatalError("Error - anonymousId should not be empty.") | ||
} | ||
self.userId = userId | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// Const.swift | ||
// InGrowiOS | ||
// | ||
// Created by Meikiem on 2/1/21. | ||
// | ||
|
||
import Foundation | ||
|
||
public class Const{ | ||
|
||
public static let PROJECT = "project" | ||
public static let STREAM = "stream" | ||
public static let INGROW = "ingrow" | ||
public static let EVENT = "event" | ||
public static let ENRICHMENT = "enrichment" | ||
public static let NAME = "name" | ||
public static let SESSION = "session" | ||
public static let INPUT = "input" | ||
public static let API_KEY = "api-key" | ||
public static let ANONYMOUS_ID = "anonymous_id" | ||
public static let USER_ID = "user_id" | ||
public static let SUCCESSFUL = 201 | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// InGrowLogging.swift | ||
// InGrowiOS | ||
// | ||
// Created by Meikiem on 2/1/21. | ||
// | ||
|
||
import Foundation | ||
import OSLog | ||
|
||
public class InGrowLogging{ | ||
|
||
private static var osLog: OSLog = { | ||
OSLog.disabled | ||
}() | ||
|
||
private static var osLogType: OSLogType = { | ||
OSLogType.debug | ||
}() | ||
|
||
public static func log(msg:String){ | ||
if(isLoggingEnabled()){ | ||
os_log("%@", log: osLog, type: .debug, msg) | ||
} | ||
} | ||
|
||
public static func disableLogging(){ | ||
osLog = .disabled | ||
} | ||
|
||
public static func enableLogging(){ | ||
osLog = OSLog(subsystem: "co.ingrow.ios", category: "EventOperations") | ||
} | ||
|
||
public static func isLoggingEnabled() -> Bool { | ||
return osLog.isEnabled(type: OSLogType.debug) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// InGrowiOS.h | ||
// InGrowiOS | ||
// | ||
// Created by Meikiem on 2/1/21. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
//! Project version number for InGrowiOS. | ||
FOUNDATION_EXPORT double InGrowiOSVersionNumber; | ||
|
||
//! Project version string for InGrowiOS. | ||
FOUNDATION_EXPORT const unsigned char InGrowiOSVersionString[]; | ||
|
||
// In this header, you should import all the public headers of your framework using statements like #import <InGrowiOS/PublicHeader.h> | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>$(DEVELOPMENT_LANGUAGE)</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleVersion</key> | ||
<string>$(CURRENT_PROJECT_VERSION)</string> | ||
</dict> | ||
</plist> |
Oops, something went wrong.