Skip to content

Commit

Permalink
Release v0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
himshikhar-am authored Jun 5, 2024
1 parent 90ee51f commit 370102c
Show file tree
Hide file tree
Showing 42 changed files with 2,134 additions and 669 deletions.
2 changes: 1 addition & 1 deletion PushEngage.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |spec|

spec.name = "PushEngage"
spec.version = "0.0.2"
spec.version = "0.0.3"
spec.summary = "iOS Framework which provides easy way to start with Push notification in your native iOS Applications."
spec.description = "To make your users interact with your application even when they are not using your application, push notifications plays the most important role and our product will make this very easy for you to integrate with your applications."
spec.homepage = "https://github.com/awesomemotive/pushengage-ios-sdk.git"
Expand Down
114 changes: 91 additions & 23 deletions PushEngage.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions PushEngage/Constants/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ internal struct NetworkConstants {
static let requestHeaderContentTypeKey = "Content-Type"
static let requestHeaderAuthorizationKey = "Authorization"
static let requestHeaderRefererKey = "referer"
static let requestHeaderClientKey = "X-Pe-Client"
static let requestHeaderClientVersionKey = "X-Pe-Client-Version"
static let requestHeaderSdkVersionKey = "X-Pe-Sdk-Version"
static let requestHeaderAppIdKey = "X-Pe-App-Id"
static let requestHeaderUserAgentKey = "User-Agent"

// MARK: - Values
static let requestHeaderAuthorizationValue = "Bearer "
static let requestHeaderContentTypeValue = "application/json"
static let requestHeaderContentTypeValueForcharSet = "application/x-www-form-urlencoded; charset=utf-8"
static let requestHeaderRefererValue = "https://pushengage.com/service-worker.js"

static let requestHeaderClientValue = "iOS"
// MARK: - BASE URL

static let baseURL = PENetworkURLs.backendBaseURL
Expand All @@ -46,7 +51,7 @@ internal struct NetworkConstants {

// MARK: - SDK version

static let sdkVersion = "0.0.2"
static let sdkVersion = "0.0.3"

// MARK: - URL relative - path
static let addSubscriberPath = "subscriber/add"
Expand All @@ -66,12 +71,16 @@ internal struct NetworkConstants {
static let updateTrigger = "subscriber/updatetriggerstatus"
static let updateSubscriber = "subscriber/%@"
static let syncSubscriber = "sites/%@/sync/ios"
static let addAlert = "alerts"

// MARK: - Notification relative path
static let notificationView = "notification/view"
static let notificationClicked = "notification/click"
static let sponsoreFetch = "notification/fetch"

// MARK: Goal tracking
static let sendGoal = "goals"

// MARK: - Error logging relative path
static let logs = "logs"

Expand Down Expand Up @@ -183,6 +192,7 @@ extension String {
static let viewCountTrackingFailed = "viewCountTrackingFailed"
static let clickCountTrackingFailed = "clickCountTrackingFailed"
static let notificationRefetchFailed = "notificationRefetchFailed"
static let invalidInput = "One or more inputs provided are not valid."
}

// MARK: - Registration Messages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,13 @@ internal final class DependencyInitialize {

// MARK: - TriggerCampaignProtocol

.register(TriggerCampaignType.self) { resolver in
.register(TriggerCampaignManagerType.self) { resolver in
let networkRouter = resolver.resolve(NetworkRouterType.self)
let userDefaultService = resolver.resolve(UserDefaultsType.self)
let dataSource = resolver.resolve(DataSourceType.self)
return TriggerCampaignManager(userDefaultService: userDefaultService,
networkService: networkRouter)
networkService: networkRouter,
dataSource: dataSource)
}

// MARK: - PEViewModel
Expand All @@ -127,7 +129,7 @@ internal final class DependencyInitialize {
let subscriberService = resolver.resolve(SubscriberServiceType.self)
let userDefaultService = resolver.resolve(UserDefaultsType.self)
let notificationLifeCycleService = resolver.resolve(NotificationLifeCycleServiceType.self)
let triggerCampaiginService = resolver.resolve(TriggerCampaignType.self)
let triggerCampaiginService = resolver.resolve(TriggerCampaignManagerType.self)

return PEManager(applicationService: applicationService,
notificationService: notificationService,
Expand Down
112 changes: 91 additions & 21 deletions PushEngage/Interface/PushEngage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public typealias PENotificationDisplayNotification = (_ notification: PENotifica
public typealias PENotificationWillShowInForeground
= (PENotification, _ completion: PENotificationDisplayNotification) -> Void

@objc public enum TriggerStatusType: Int {
case enabled = 1
case disabled = 0
}

@objcMembers
@objc final public class PushEngage: NSObject {

Expand Down Expand Up @@ -340,16 +345,92 @@ public typealias PENotificationWillShowInForeground
manager.add(dynamic: dynamicSegments, completionHandler: completionHandler)
}

/// Update trigger status
/// Update the trigger status of the notification
/// Update trigger campaign status
/// - Parameters:
/// - status: status type to enable or disable trigger campaign status
/// - completionHandler: A closure that provides a response indicating whether the operation was successful (`true` if successful, `false` otherwise) and an optional error object if any error occurs during the operation.
///
/// Example usage:
/// ```
/// PushEngage.automatedNotification(status: .enabled) { result, error in
/// if result {
/// print("Trigger enabled successfully")
/// } else {
/// print("Failure")
/// }
/// }
/// ```
@objc public static func automatedNotification(status: TriggerStatusType,
completionHandler: ((_ response: Bool,
_ error: Error?) -> Void)?) {
manager.automatedNotification(status: status, completionHandler: completionHandler)
}

/// Sends a goal event with the provided callback for handling the response.
/// - Parameters:
/// - goal: Goal object representing the goal to be tracked.
/// - completionHandler: A closure that provides a response indicating whether the operation was successful (`true` if successful, `false` otherwise) and an optional error object if any error occurs during the operation.
///
/// Example usage:
/// ```
/// let goal = Goal(name: "revenue", count: 1, value: 10.0)
/// PushEngage.sendGoal(goal: goal) { result, error in
/// if result {
/// print("Goal Added Successfully")
/// } else {
/// print("Failure")
/// }
/// }
/// ```
@objc public static func sendGoal(goal: Goal,
completionHandler: ((_ response: Bool,
_ error: Error?) -> Void)?) {
manager.sendGoal(goal: goal, completionHandler: completionHandler)
}

/// Sends a trigger event for a specific campaign with the provided callback for handling the response.
/// - Parameters:
/// - status: boolean flag wheather user has accepted for trigger enabled or not
/// - completionHandler: call back provide response boolean and Error type.
/// Private for now
@objc private static func updateTrigger(status: Bool,
completionHandler: ((_ response: Bool,
_ error: Error?) -> Void)?) {
manager.updateTrigger(status: status, completionHandler: completionHandler)
/// - triggerCampaign: The TriggerCampaign object representing the campaign event to be triggered.
/// - completionHandler: A closure that provides a response indicating whether the operation was successful (`true` if successful, `false` otherwise) and an optional error object if any error occurs during the operation.
///
/// Example usage:
/// ```
/// let triggerCampaign = TriggerCampaign(campaignName: "name_of_campaign", eventName: "name_of_event", data: ["title": "New Subscriber"])
///
/// PushEngage.sendTriggerEvent(triggerCampaign: triggerCampaign) { result, error in
/// if result {
/// print("Send Trigger Alert Successful")
/// } else {
/// print("Failure")
/// }
/// }
/// ```
@objc public static func sendTriggerEvent(triggerCampaign: TriggerCampaign,
completionHandler: ((_ response: Bool,
_ error: Error?) -> Void)?) {
manager.sendTriggerEvent(trigger: triggerCampaign, completionHandler: completionHandler)
}

/// Adds an alert to be triggered with the provided callback for handling the response.
/// - Parameters:
/// - triggerAlert: The TriggerAlert object representing the alert to be added.
/// - completionHandler: A closure that provides a response indicating whether the operation was successful (`true` if successful, `false` otherwise) and an optional error object if any error occurs during the operation.
///
/// Example usage:
/// ```
/// let triggerAlert = TriggerAlert(type: .inventory, productId: "279a", link: "www.pushengage.com/products", price: 100.0, data: ["title": "New Subscriber"])
///
/// PushEngage.addAlert(triggerAlert: triggerAlert) { result, error in
/// if result {
/// print("Add Alert Successful")
/// } else {
/// print("Failure")
/// }
/// }
/// ```
@objc public static func addAlert(triggerAlert: TriggerAlert, completionHandler: ((_ response: Bool,
_ error: Error?) -> Void)?) {
manager.addAlert(triggerAlert: triggerAlert, completionHandler: completionHandler)
}

/// Get Subscriber Details
Expand Down Expand Up @@ -383,17 +464,6 @@ public typealias PENotificationWillShowInForeground
manager.getSubscriberDetails(for: keys, completionHandler: completionHandler)
}

// Trigger Campiagn Handler
/// Use this method to create the trigger for the campiagn
/// - Parameters:
/// - details: provide the insctance of the Trigger campaign object and pass the details on
/// - completionHandler: call back provides the response as true or false.
/// Private for now
@objc private static func createTriggerCampaign(for details: TriggerCampaign,
completionHandler: ((_ response: Bool) -> Void)?) {
manager.createCampaign(for: details, completionHandler: completionHandler)
}

/// Silent Push Notification Handler
///
/// Use this method to set the silent notification handler to handle silent push notifications.
Expand All @@ -405,7 +475,7 @@ public typealias PENotificationWillShowInForeground
/// that don't display any visible content to the user but allow your app to perform tasks in the background. When a silent
/// push notification is received, the provided closure will be called, allowing you to process the notification's content
/// and perform necessary background tasks.
@objc public static func silentPushHandler(_ completion: PESilentPushBackgroundHandler?) {
@objc private static func silentPushHandler(_ completion: PESilentPushBackgroundHandler?) {
manager.setbackGroundSilentPushHandler(block: completion)
}

Expand Down
28 changes: 28 additions & 0 deletions PushEngage/Model/GoalModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// GoalModel.swift
// PushEngage
//
// Created by Himshikhar Gayan on 18/12/23.
//

import Foundation

@objcMembers
@objc public class Goal: NSObject {
let name: String
let count: Int?
let value: Double?

public init(name: String, count: Int?, value: Double?) {
self.name = name
self.count = count
self.value = value
}

@objc public init(name: String, count: NSNumber?, value: NSNumber?) {
self.name = name
self.count = count?.intValue
self.value = value?.doubleValue
}

}
17 changes: 15 additions & 2 deletions PushEngage/Model/NetworkResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,34 @@ struct NetworkResponse: Codable {
let errorCode: Int?
let errorMessage: String?
let error: NetworkError?
let data: Data?

enum CodingKeys: String, CodingKey {
case errorCode = "error_code"
case errorMessage = "error_message"
case error
case data
}

struct Data: Codable {
let success: Bool?
}
}

struct NetworkError: Codable {
let message: String
let code: Int
let message: String?
let code: Int?
let details: NetworkErrorDetail?

enum CodingKeys: String, CodingKey {
case message
case code
case details
}

struct NetworkErrorDetail: Codable {
let message: String?
let path: String?
}
}

Expand Down
7 changes: 6 additions & 1 deletion PushEngage/Model/SubscriberDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ struct SubscriberDetails: Codable {
var segments: [Segment]?
var segmentId: Int?
var notificationDisabled: Bool?
var goalCount: Int?
var goalValue: Double?
var goalName: String?

enum CodingKeys: String, CodingKey {
case siteID = "site_id"
Expand All @@ -35,7 +38,9 @@ struct SubscriberDetails: Codable {
case deviceToken = "device_token"
case segmentId = "segment_id"
case notificationDisabled = "delete_on_notification_disable"

case goalCount = "count"
case goalValue = "value"
case goalName = "name"
}
}

Expand Down
Loading

0 comments on commit 370102c

Please sign in to comment.