Skip to content

Commit

Permalink
[MT-1133] Update to braze-swift library (#15)
Browse files Browse the repository at this point in the history
* Test new all_events command mapping

* trying to replace braze objc with the swift library

* add more packages and some polish

* Remove all notifications methods and expose braze instance and onReady

* Remove useless public method to set the gender

* apply onReady on all methods except the initialize

* Make use of braze onReady for notifications in the example app

* fix commands list

* Update remaining keys and move int enums to strings

* Add new commands and parameters

Commands: setSdkAuthSignature, setAdTrackingEnabled
Parameters: sdkAuthSignature, adTrackingEnabled

* fix pre existing tests

* Add more tests for extensions, converter and configuration

* SPM and carthage

Carthage is not supported by braze at the moment

* Update to brazeKit 5.6 to have configuration as a class both in cocoapods and carthage

* Fix local testing

* Use our own json mapping to braze SDK for carthage

* update version and config tests

* Improve tests

* Update dependencies and create build script
  • Loading branch information
Enricoza authored Jan 10, 2023
1 parent 357d736 commit 145daaa
Show file tree
Hide file tree
Showing 28 changed files with 1,316 additions and 1,420 deletions.
5 changes: 2 additions & 3 deletions Cartfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
github "tealium/tealium-swift" ~> 2.6
binary "https://raw.githubusercontent.com/Appboy/appboy-ios-sdk/master/appboy_ios_sdk.json" ~> 4.4
github "SDWebImage/SDWebImage" ~> 5.12
github "tealium/tealium-swift" ~> 2.8
binary "https://raw.githubusercontent.com/Tealium/tealium-ios-braze-remote-command/mt-1133/braze.json" ~> 5.6
5 changes: 2 additions & 3 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
binary "https://raw.githubusercontent.com/Appboy/appboy-ios-sdk/master/appboy_ios_sdk.json" "4.4.1"
github "SDWebImage/SDWebImage" "5.12.2"
github "tealium/tealium-swift" "2.5.1"
binary "https://raw.githubusercontent.com/Tealium/tealium-ios-braze-remote-command/mt-1133/braze.json" "5.6.2"
github "tealium/tealium-swift" "2.8.2"
21 changes: 6 additions & 15 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,21 @@
"object": {
"pins": [
{
"package": "Appboy_iOS_SDK",
"repositoryURL": "https://github.com/Appboy/appboy-ios-sdk",
"package": "braze-swift-sdk",
"repositoryURL": "https://github.com/braze-inc/braze-swift-sdk",
"state": {
"branch": null,
"revision": "23ec2e8e337856b22801288a0f25ec5895e783a2",
"version": "4.4.1"
}
},
{
"package": "SDWebImage",
"repositoryURL": "https://github.com/SDWebImage/SDWebImage.git",
"state": {
"branch": null,
"revision": "a72df4849408da7e5d3c1b586797b7c601c41d1b",
"version": "5.12.1"
"revision": "aeb3213fcabcd95f4c4831d895eb01a60db26b87",
"version": "5.6.2"
}
},
{
"package": "TealiumSwift",
"repositoryURL": "https://github.com/tealium/tealium-swift",
"state": {
"branch": null,
"revision": "9bd74f09c780862de61101bd147b1c6b232f98ce",
"version": "2.5.1"
"revision": "ef4631c662546abda787b365ba0976cd49de6ffa",
"version": "2.8.2"
}
}
]
Expand Down
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ let package = Package(
.library(name: "TealiumBraze", targets: ["TealiumBraze"])
],
dependencies: [
.package(url: "https://github.com/tealium/tealium-swift", .upToNextMajor(from: "2.6.0")),
.package(url: "https://github.com/Appboy/appboy-ios-sdk", .upToNextMajor(from: "4.4.1"))
.package(url: "https://github.com/tealium/tealium-swift", .upToNextMajor(from: "2.8.0")),
.package(url: "https://github.com/braze-inc/braze-swift-sdk", .upToNextMajor(from: "5.6.2"))
],
targets: [
.target(
name: "TealiumBraze",
dependencies: [
.product(name: "AppboyUI", package: "appboy-ios-sdk"),
.product(name: "BrazeKit", package: "braze-swift-sdk"),
.product(name: "TealiumCore", package: "tealium-swift"),
.product(name: "TealiumRemoteCommands", package: "tealium-swift")
],
Expand Down
96 changes: 13 additions & 83 deletions Sources/BrazeConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ public enum BrazeConstants {
static let separator: Character = ","
static let commandId = "braze"
static let description = "Braze Remote Command"
static let version = "2.1.0"
static let version = "3.0.0"

enum Commands: String {
case initialize = "initialize"
case userIdentifier = "useridentifier"
case setSdkAuthSignature = "setsdkauthsignature"
case userAlias = "useralias"
case userAttribute = "userattribute"
case facebookUser = "facebookuser"
case twitterUser = "twitteruser"
case setCustomAttribute = "setcustomattribute"
case unsetCustomAttribute = "unsetcustomattribute"
case setCustomArrayAttribute = "setcustomarrayattribute"
Expand All @@ -33,16 +32,21 @@ public enum BrazeConstants {
case incrementCustomAttribute = "incrementcustomattribute"
case logCustomEvent = "logcustomevent"
case logPurchase = "logpurchase"
case setAdTrackingEnabled = "setadtrackingenabled"
case setLastKnownLocation = "setlastknownlocation"
case enableSDK = "enablesdk"
case disableSDK = "disablesdk"
case wipeData = "wipedata"
case flush = "flush"
case addToSubsriptionGroup = "addtosubscriptiongroup"
case removeFromSubscriptionGroup = "removefromsubscriptiongroup"
}

enum Keys {
static let apiKey = "api_key"
static let launchOptions = "launch_options"
static let pushToken = "push_token"
static let userAttribute = "user_attributes"
static let isSdkAuthEnabled = "is_sdk_authentication_enabled"
static let sdkAuthSignature = "sdk_authentication_signature"
static let userIdentifier = "user_id"
static let userAlias = "user_alias"
static let aliasLabel = "alias_label"
Expand All @@ -63,12 +67,10 @@ public enum BrazeConstants {
static let quantity = "quantity"
static let purchaseKey = "purchase"
static let purchaseProperties = "purchase_properties"
static let facebookUser = "facebook_user"
static let twitterUser = "twitter_user"
static let enableSDK = "enable_sdk"
static let sessionTimeout = "session_timeout"
static let disableLocation = "disable_location"
static let enableAutomaticLocation = "enable_automatic_location"
static let enableGeofences = "enable_geofences"
static let enableAutomaticGeofences = "enable_automatic_geofences"
static let triggerIntervalSeconds = "trigger_interval_seconds"
static let latitude = "location_latitude"
static let longitude = "location_longitude"
Expand All @@ -77,40 +79,14 @@ public enum BrazeConstants {
static let verticalAccuracy = "location_vertical_accuracy"
static let requestProcessingPolicy = "request_processing_policy"
static let flushInterval = "flush_interval"
static let adTrackingEnabled = "ad_tracking_enabled"
static let enableAdvertiserTracking = "enable_advertiser_tracking"
static let enableDeepLinkHandling = "enable_deep_link_handling"
static let customEndpoint = "custom_endpoint"
static let deviceOptions = "device_options"
static let pushStoryIdentifier = "push_story_identifier"
static let subscriptionGroupId = "subscription_group_id"
}

enum Options {
static let ABKRequestProcessingPolicyOptionKey = "ABKRequestProcessingPolicyOptionKey"
static let ABKFlushIntervalOptionKey = "ABKFlushIntervalOptionKey"
static let ABKEnableAutomaticLocationCollectionKey = "ABKEnableAutomaticLocationCollectionKey"
static let ABKEnableGeofencesKey = "ABKEnableGeofencesKey"
static let ABKIDFADelegateKey = "ABKIDFADelegateKey"
static let ABKEndpointKey = "ABKEndpointKey"
static let ABKURLDelegateKey = "ABKURLDelegateKey"
static let ABKSessionTimeoutKey = "ABKSessionTimeoutKey"
static let ABKMinimumTriggerTimeIntervalKey = "ABKMinimumTriggerTimeIntervalKey"
static let ABKDeviceWhitelistKey = "ABKDeviceWhitelistKey"
static let ABKPushStoryAppGroupKey = "ABKPushStoryAppGroupKey"
}

enum SocialMedia {
static let userInfo = "user_info"
static let friendsCount = "friends_count"
static let likes = "likes"
static let userDescription = "description"
static let twitterName = "twitter_name"
static let profileImageUrl = "profile_image_url"
static let screenName = "screen_name"
static let followersCount = "followers_count"
static let statusesCount = "statuses_count"
static let twitterId = "twitter_id"
}

}

public enum AppboyUserAttribute: String, CaseIterable {
Expand All @@ -122,51 +98,5 @@ public enum AppboyUserAttribute: String, CaseIterable {
case language
case homeCity = "home_city"
case phone
case avatarImageURL = "avatar_image_url"
case gender
}

public enum AppboyUserGenderType: Int {
case male
case female
case other
case unknown
case notApplicable
case preferNotToSay

static func from(_ value: String) -> AppboyUserGenderType {
let lowercasedGender = value.lowercased()
if lowercasedGender == "male" {
return .male
} else if lowercasedGender == "female" {
return .female
} else if lowercasedGender == "other" {
return .other
} else if lowercasedGender == "unknown" {
return .unknown
} else if lowercasedGender == "notapplicable" || lowercasedGender == "not_applicable" {
return .notApplicable
} else {
return .preferNotToSay
}
}
}

public enum AppboyNotificationSubscription: String {
case optedIn
case subscribed
case unsubscribed

static func from(_ value: String) -> AppboyNotificationSubscription? {
let lowercasedSubscription = value.lowercased()
if lowercasedSubscription == "optedin" {
return .optedIn
} else if lowercasedSubscription == "subscribed" {
return .subscribed
} else if lowercasedSubscription == "unsubscribed" {
return .unsubscribed
} else {
return nil
}
}
}
84 changes: 84 additions & 0 deletions Sources/BrazeExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//
// BrazeExtensions.swift
// TealiumBraze
//
// Created by Enrico Zannini on 04/11/22.
//

import BrazeKit

extension Braze.User.SubscriptionState {
static func from(_ value: String) -> Self? {
let lowercasedSubscription = value.lowercased()
if lowercasedSubscription == "optedin" {
return .optedIn
} else if lowercasedSubscription == "subscribed" {
return .subscribed
} else if lowercasedSubscription == "unsubscribed" {
return .unsubscribed
} else {
return Self(rawValue: value)
}
}
}

extension Braze.User.Gender {
static func from(_ value: String) -> Self {
let lowercasedGender = value.lowercased()
if lowercasedGender == "male" {
return .male
} else if lowercasedGender == "female" {
return .female
} else if lowercasedGender == "other" {
return .other
} else if lowercasedGender == "unknown" {
return .unknown
} else if lowercasedGender == "notapplicable" || lowercasedGender == "not_applicable" {
return .notApplicable
} else {
return Self(rawValue: value) ?? .preferNotToSay
}
}
}

extension Braze.Configuration.DeviceProperty {
static func from(_ value: String) -> Self? {
let lowercasedValue = value.lowercased()
switch lowercasedValue {
case "model":
return .model
case "osversion":
return .osVersion
case "resolution":
return .resolution
case "timezone":
return .timeZone
case "locale":
return .locale
case "carrier":
return .carrier
case "pushenabled":
return .pushEnabled
case "pushauthstatus":
return .pushAuthStatus
case "pushdisplayoptions":
return .pushDisplayOptions
default:
return Self(rawValue: value)
}
}
}

extension Braze.Configuration.Api.RequestPolicy {
static func from(_ value: String) -> Self? {
let lowercasedValue = value.lowercased()
switch lowercasedValue {
case "manual":
return .manual
case "automatic":
return .automatic
default:
return Self(rawValue: value)
}
}
}
Loading

0 comments on commit 145daaa

Please sign in to comment.