<commit_before>//
//  AdjustBridge.swift
//  Adjust
//
//  Created by eps on 8/19/20.
//

import Adjust

private let kPrefix = "AdjustBridge"
private let kInitialize = "\(kPrefix)Initialize"
private let kSetEnabled = "\(kPrefix)SetEnabled"
private let kGetAdvertisingIdentifier = "\(kPrefix)GetAdvertisingIdentifier"
private let kGetDeviceIdentifier = "\(kPrefix)GetDeviceIdentifier"
private let kSetPushToken = "\(kPrefix)SetPushToken"
private let kTrackEvent = "\(kPrefix)TrackEvent"

@objc(EEAdjustBridge)
public class AdjustBridge: NSObject, IPlugin {
    private let _bridge: IMessageBridge
    
    public required init(_ bridge: IMessageBridge) {
        _bridge = bridge
        super.init()
        registerHandlers()
    }
    
    public func destroy() {
        deregisterHandlers()
    }
    
    func registerHandlers() {
        _bridge.registerHandler(kInitialize) { message in
            let dict = EEJsonUtils.convertString(toDictionary: message)
            guard
                let token = dict["token"] as? String,
                let environment = dict["environment"] as? Int,
                let logLevel = dict["logLevel"] as? Int,
                let useAppSecret = dict["useAppSecret"] as? Bool,
                let eventBufferingEnabled = dict["eventBufferingEnabled"] as? Bool,
                let secretId = dict["secretId"] as? UInt64,
                let info1 = dict["info1"] as? UInt64,
                let info2 = dict["info2"] as? UInt64,
                let info3 = dict["info3"] as? UInt64,
                let info4 = dict["info4"] as? UInt64
            else {
                assert(false, "Invalid argument")
                return ""
            }
            self.initialize(
                token, self.parseEnvironment(environment),
                self.parseLogLevel(logLevel), eventBufferingEnabled,
                useAppSecret, secretId, info1, info2, info3, info4)
            return ""
        }
        _bridge.registerHandler(kSetEnabled) { message in
            self.setEnabled(Utils.toBool(message))
            return ""
        }
        _bridge.registerAsyncHandler(kGetAdvertisingIdentifier) { _, resolver in
            resolver(Adjust.adid() ?? "")
        }
        _bridge.registerHandler(kGetDeviceIdentifier) { _ in<commit_msg>Fix getting idfa on ios.<commit_after>//
//  AdjustBridge.swift
//  Adjust
//
//  Created by eps on 8/19/20.
//

import Adjust

private let kPrefix = "AdjustBridge"
private let kInitialize = "\(kPrefix)Initialize"
private let kSetEnabled = "\(kPrefix)SetEnabled"
private let kGetAdvertisingIdentifier = "\(kPrefix)GetAdvertisingIdentifier"
private let kGetDeviceIdentifier = "\(kPrefix)GetDeviceIdentifier"
private let kSetPushToken = "\(kPrefix)SetPushToken"
private let kTrackEvent = "\(kPrefix)TrackEvent"

@objc(EEAdjustBridge)
public class AdjustBridge: NSObject, IPlugin {
    private let _bridge: IMessageBridge
    
    public required init(_ bridge: IMessageBridge) {
        _bridge = bridge
        super.init()
        registerHandlers()
    }
    
    public func destroy() {
        deregisterHandlers()
    }
    
    func registerHandlers() {
        _bridge.registerHandler(kInitialize) { message in
            let dict = EEJsonUtils.convertString(toDictionary: message)
            guard
                let token = dict["token"] as? String,
                let environment = dict["environment"] as? Int,
                let logLevel = dict["logLevel"] as? Int,
                let useAppSecret = dict["useAppSecret"] as? Bool,
                let eventBufferingEnabled = dict["eventBufferingEnabled"] as? Bool,
                let secretId = dict["secretId"] as? UInt64,
                let info1 = dict["info1"] as? UInt64,
                let info2 = dict["info2"] as? UInt64,
                let info3 = dict["info3"] as? UInt64,
                let info4 = dict["info4"] as? UInt64
            else {
                assert(false, "Invalid argument")
                return ""
            }
            self.initialize(
                token, self.parseEnvironment(environment),
                self.parseLogLevel(logLevel), eventBufferingEnabled,
                useAppSecret, secretId, info1, info2, info3, info4)
            return ""
        }
        _bridge.registerHandler(kSetEnabled) { message in
            self.setEnabled(Utils.toBool(message))
            return ""
        }
        _bridge.registerAsyncHandler(kGetAdvertisingIdentifier) { _, resolver in
            resolver(Adjust.idfa() ?? "")
        }
        _bridge.registerHandler(kGetDeviceIdentifier) { _ in
{'fraction_non_alphanumeric': 0.09802216909367528, 'fraction_numerical': 0.011736579004564224, 'mean_word_length': 2.231741573033708, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1547283', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1232, 'n_words': 301}