Skip to content

Commit

Permalink
1.6.35
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Korney committed Jul 29, 2024
1 parent 55c51f8 commit 4f1b63e
Show file tree
Hide file tree
Showing 23 changed files with 118 additions and 72 deletions.
2 changes: 1 addition & 1 deletion AffiseAttributionLib.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Pod::Spec.new do |spec|
spec.name = "AffiseAttributionLib"
spec.version = ENV['LIB_VERSION'] || "1.6.34"
spec.version = ENV['LIB_VERSION'] || "1.6.35"
spec.summary = "Affise Attribution iOS library"
spec.description = "Affise SDK is a software you can use to collect app usage statistics, device identifiers, deeplink usage, track install referrer."
spec.homepage = "https://github.com/affise/sdk-ios"
Expand Down
7 changes: 5 additions & 2 deletions AffiseAttributionLib/Classes/AffiseComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ internal class AffiseComponent: AffiseApi {
dependencies: [
stringToSha256Converter,
networkService,
providersToJsonStringConverter
providersToJsonStringConverter,
postBackModelFactory,
postBackModelToJsonStringConverter
]
)

Expand Down Expand Up @@ -90,10 +92,11 @@ internal class AffiseComponent: AffiseApi {
eventsStorage: internalEventsStorage
)
lazy var networkService:NetworkService = NetworkServiceImpl(urlSession: urlSession)
lazy var postBackModelToJsonStringConverter:PostBackModelToJsonStringConverter = PostBackModelToJsonStringConverter()
lazy var cloudRepository:CloudRepository = CloudRepositoryImpl(
networkService: networkService,
userAgentProvider: postBackModelFactory.getProvider(),
converter: PostBackModelToJsonStringConverter()
converter: postBackModelToJsonStringConverter
)
lazy var sessionManager:SessionManager = SessionManagerImpl(
preferences: preferences,
Expand Down
8 changes: 0 additions & 8 deletions AffiseAttributionLib/Classes/converter/Converter.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
//
// Converter.swift
// app
//
// Created by Sergey Korney
//


/**
* Interface for convert object to another object
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* Converter List<PostBackModel> to String
*/
class PostBackModelToJsonStringConverter : Converter {
public class PostBackModelToJsonStringConverter : Converter {

typealias T = Array<PostBackModel>
typealias R = String
public typealias T = Array<PostBackModel>
public typealias R = String

private let EVENTS_KEY = "events"
private let SDK_EVENTS_KEY = "sdk_events"
Expand All @@ -14,7 +14,7 @@ class PostBackModelToJsonStringConverter : Converter {
/**
* Convert [from] list of PostBackModel to json string
*/
func convert(from: Array<PostBackModel>) -> String {
public func convert(from: Array<PostBackModel>) -> String {
let res = from.map { model in
parameters(obj: model)
}.joined(separator: ",")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Serialized event to store
*/
struct SerializedEvent {
public struct SerializedEvent {
/**
* Event id
*/
Expand Down
2 changes: 1 addition & 1 deletion AffiseAttributionLib/Classes/internal/BuildConfig.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation

internal struct BuildConfig {
static let AFFISE_VERSION = "1.6.34"
static let AFFISE_VERSION = "1.6.35"
}
10 changes: 1 addition & 9 deletions AffiseAttributionLib/Classes/logs/SerializedLog.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
//
// SerializedLog.swift
// app
//
// Created by Sergey Korney
//


/**
* Serialized log contains [id] identification, [type] and log [data]
*/
struct SerializedLog{
public struct SerializedLog{

/**
* Log id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import Foundation

enum AffiseModuleError: Error {
public enum AffiseModuleError: Error {
case version(name: AffiseModules, module: AffiseModule)
case initModule(name: AffiseModules)
}

extension AffiseModuleError : LocalizedError {
public var errorDescription: String? {
switch self {
case .version(name: let name, module: let module):
return NSLocalizedString("AffiseModuleError.version(module [\(name.description.lowercased()):\(module.version)] version is incompatible with [attribution:\(BuildConfig.AFFISE_VERSION)], use same version as attribution)", comment: "")
case .initModule(name: let name):
return NSLocalizedString("module [\(name.description)] init failed", comment: "")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extension CloudRepositoryImpl: CloudRepository {
//Create request
let response = createRequest(url: url, data: data)

if isHttpValid(response.code) {
if response.isHttpValid() {
//Send is ok
send = true
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
struct PostBackModel {
public struct PostBackModel {
let parameters: [(ProviderType, Any?)]

let events: Array<SerializedEvent>?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
internal class PostBackModelFactory {
public class PostBackModelFactory {

private var providers: [Provider]

Expand All @@ -11,7 +11,7 @@ internal class PostBackModelFactory {
*
* @return PostBackModel
*/
func create(
public func create(
events: Array<SerializedEvent> = [],
logs: Array<SerializedLog> = [],
metrics: Array<SerializedEvent> = [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ extension ImmediateSendToServerUseCaseImpl: ImmediateSendToServerUseCase {
guard let self = self else { return }

let response = self.sendNow(event: event, url: it)
if isHttpValid(response.code) {
if response.isHttpValid() {
success()
} else {
let _ = failed(response)
Expand Down
2 changes: 1 addition & 1 deletion AffiseInternal.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |spec|
spec.name = "AffiseInternal"
spec.version = ENV['LIB_VERSION'] || "1.6.34"
spec.version = ENV['LIB_VERSION'] || "1.6.35"
spec.summary = "Affise Internal library"
spec.description = "Affise Internal wrapper library for crossplatform"
spec.homepage = "https://github.com/affise/sdk-ios"
Expand Down
2 changes: 1 addition & 1 deletion AffiseModule.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = "AffiseModule"
s.version = ENV["LIB_VERSION"] || "1.6.34"
s.version = ENV["LIB_VERSION"] || "1.6.35"
s.summary = "Affise Modules"
s.description = "Affise module collection"
s.homepage = "https://github.com/affise/sdk-ios"
Expand Down
2 changes: 1 addition & 1 deletion AffiseModule/Advertising/Classes/AdvertisingModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Foundation
@objc(AffiseAdvertisingModule)
public final class AdvertisingModule: AffiseModule {

public override var version: String { "1.6.34" }
public override var version: String { "1.6.35" }

private lazy var advertisingIdManager: AdvertisingIdManager = AdvertisingIdManagerImpl()

Expand Down
11 changes: 8 additions & 3 deletions AffiseModule/Link/Classes/LinkModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@ import AffiseAttributionLib
@objc(AffiseLinkModule)
public final class LinkModule: AffiseModule {

public override var version: String { "1.6.34" }
public override var version: String { "1.6.35" }

private var useCase: LinkResolveUseCase? = nil

public override func start() {
guard let networkService: NetworkService = get() else { return }
let networkService: NetworkService? = get()
if networkService == nil
{
print(AffiseModuleError.initModule(name: .Link).localizedDescription)
return
}

useCase = LinkResolveUseCaseImpl(
networkService: networkService
networkService: networkService!
)
}
}
Expand Down
25 changes: 19 additions & 6 deletions AffiseModule/Status/Classes/StatusModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,36 @@ import AffiseAttributionLib
@objc(AffiseStatusModule)
public final class StatusModule: AffiseModule {

public override var version: String { "1.6.34" }
public override var version: String { "1.6.35" }

private var checkStatusUseCase: CheckStatusUseCase? = nil
private var referrerUseCase: ReferrerUseCase? = nil

private lazy var stringToKeyValueConverter: StringToKeyValueConverter = StringToKeyValueConverter()

public override func start() {
guard let providersToJsonStringConverter: ProvidersToJsonStringConverter = get() else { return }
guard let networkService: NetworkService = get() else { return }
let providersToJsonStringConverter: ProvidersToJsonStringConverter? = get()
let networkService: NetworkService? = get()
let postBackModelFactory: PostBackModelFactory? = get()
let postBackModelToJsonStringConverter: PostBackModelToJsonStringConverter? = get()

if providersToJsonStringConverter == nil ||
networkService == nil ||
postBackModelFactory == nil ||
postBackModelToJsonStringConverter == nil
{
print(AffiseModuleError.initModule(name: .Status).localizedDescription)
return
}

checkStatusUseCase = CheckStatusUseCaseImpl(
affiseModule: self,
logsManager: logsManager,
networkService: networkService,
converter: providersToJsonStringConverter,
keyValueConverter: stringToKeyValueConverter
networkService: networkService!,
converter: providersToJsonStringConverter!,
keyValueConverter: stringToKeyValueConverter,
postBackModelFactory: postBackModelFactory!,
postBackModelToJsonStringConverter: postBackModelToJsonStringConverter!
)

referrerUseCase = ReferrerUseCaseImpl(
Expand Down
46 changes: 39 additions & 7 deletions AffiseModule/Status/Classes/usecase/CheckStatusUseCaseImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,59 @@ internal class CheckStatusUseCaseImpl {

let PATH: String = "check_status"
var url: String = ""
var isPostBackSend: Bool = false

let logsManager: LogsManager?
let converter: ProvidersToJsonStringConverter
let keyValueConverter: StringToKeyValueConverter
let networkService: NetworkService
let postBackModelFactory: PostBackModelFactory
let postBackModelToJsonStringConverter: PostBackModelToJsonStringConverter

let providers: [Provider]

init(
affiseModule: AffiseModule,
logsManager: LogsManager?,
networkService: NetworkService,
converter: ProvidersToJsonStringConverter,
keyValueConverter: StringToKeyValueConverter
keyValueConverter: StringToKeyValueConverter,
postBackModelFactory: PostBackModelFactory,
postBackModelToJsonStringConverter: PostBackModelToJsonStringConverter
) {
self.logsManager = logsManager
self.converter = converter
self.keyValueConverter = keyValueConverter
self.networkService = networkService
self.postBackModelFactory = postBackModelFactory
self.postBackModelToJsonStringConverter = postBackModelToJsonStringConverter
self.providers = affiseModule.getRequestProviders()

self.url = CloudConfig.getURL(PATH)
}

private func createRequest() -> HttpResponse {
private func createRequest(_ data: String) -> HttpResponse {
guard let httpsUrl = url.toURL() else { return HttpResponse(0, "", nil) }

//Create request
return networkService.executeRequest(
httpsUrl: httpsUrl,
method: .POST,
data: converter.convert(from: providers).toData(),
data: data.toData(),
timeout: TIMEOUT_SEND,
headers: CloudConfig.headers,
redirect: true
)
}

func providersData() -> String {
return converter.convert(from: providers)
}

func postBackData() -> String {
let data = postBackModelFactory.create(events: [], logs: [], metrics: [], internalEvents: [])
return postBackModelToJsonStringConverter.convert(from: [data])
}
}

extension CheckStatusUseCaseImpl: CheckStatusUseCase {
Expand All @@ -66,9 +83,22 @@ extension CheckStatusUseCaseImpl: CheckStatusUseCase {

//While has attempts and not send
while (attempts != 0 && !send) {
let response = createRequest()
if isHttpValid(response.code) {
onComplete(keyValueConverter.convert(from: response.body))
var postBackResponse: HttpResponse? = nil
var response: HttpResponse? = nil

if isPostBackSend == false {
postBackResponse = createRequest(postBackData())
if let postBackResponse = postBackResponse {
isPostBackSend = postBackResponse.isHttpValid()
}
}

if isPostBackSend == true {
response = createRequest(providersData())
}

if isPostBackSend && response?.isHttpValid() == true {
onComplete(keyValueConverter.convert(from: response?.body ?? ""))

//Send is ok
send = true
Expand All @@ -77,7 +107,9 @@ extension CheckStatusUseCaseImpl: CheckStatusUseCase {
//Check attempts
if (attempts == 0) {
onComplete([])
let error = AffiseError.network(status: response.code, message: response.body)

let httpResponse = response ?? postBackResponse
let error = AffiseError.network(status: httpResponse?.code ?? 0, message: httpResponse?.body)
//Log error
logsManager?.addSdkError(error: AffiseError.cloud(url: url, error: error, attempts: ATTEMPTS_TO_SEND, retry: true))
} else {
Expand Down
2 changes: 1 addition & 1 deletion AffiseModule/Subscription/Classes/SubscriptionModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import AffiseAttributionLib
@objc(AffiseSubscriptionModule)
public final class SubscriptionModule: AffiseModule {

public override var version: String { "1.6.34" }
public override var version: String { "1.6.35" }

lazy var storeManager: StoreManager = StoreManager()

Expand Down
2 changes: 1 addition & 1 deletion AffiseSKAdNetwork.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Pod::Spec.new do |spec|
spec.name = "AffiseSKAdNetwork"
spec.version = ENV['LIB_VERSION'] || "1.6.34"
spec.version = ENV['LIB_VERSION'] || "1.6.35"
spec.summary = "AffiseSKAdNetwork iOS library"
spec.description = "Affise library for StoreKit Ad Network (SKAdNetwork)"
spec.homepage = "https://github.com/affise/sdk-ios"
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [1.6.35] - 2024-07-29

### Fixed

- Api `Affise.Module.getStatus`.

## [1.6.34] - 2024-07-26

### Added
Expand Down
Loading

0 comments on commit 4f1b63e

Please sign in to comment.