Skip to content

Commit

Permalink
Adjust missing key reporting. Add successful request tracking var.
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardbeecroft committed May 20, 2023
1 parent ccc4cbb commit c0860e7
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 30 deletions.
2 changes: 2 additions & 0 deletions Examples/Examples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
752195BC2A04F8C900F47BE7 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
752195BF2A04F8C900F47BE7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
752195C12A04F8C900F47BE7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
753FE1512A140CF500470029 /* quickverse-ios-sdk */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = "quickverse-ios-sdk"; path = ..; sourceTree = "<group>"; };
755AF07C2A002B5D0006233B /* SwiftUI-Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "SwiftUI-Example.app"; sourceTree = BUILT_PRODUCTS_DIR; };
755AF07F2A002B5D0006233B /* SwiftUIExampleApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIExampleApp.swift; sourceTree = "<group>"; };
755AF0812A002B5D0006233B /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -104,6 +105,7 @@
755AF0732A002B5D0006233B = {
isa = PBXGroup;
children = (
753FE1512A140CF500470029 /* quickverse-ios-sdk */,
75D19C792A0526CB005B7A58 /* Shared */,
752195B22A04F8C600F47BE7 /* UIKit-Example */,
755AF07E2A002B5D0006233B /* SwiftUI-Example */,
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion QuickVerse.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = "QuickVerse"
spec.version = "1.4.2"
spec.version = "1.4.3"
spec.summary = "Effortlessly integrate your quickverse.io localisations into your iOS app, for instant, over-the-air updates & more."
spec.description = <<-DESC
QuickVerse lets you translate your web and mobile apps with ease. Powered by instant, over-the-air updates, you can change your app copy anytime, anywhere.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Version](https://img.shields.io/static/v1?label=pod&message=1.4.2&color=blue&style=flat)](#cocoapods)
[![Version](https://img.shields.io/static/v1?label=pod&message=1.4.3&color=blue&style=flat)](#cocoapods)
[![SwiftPM compatible](https://img.shields.io/badge/SwiftPM-compatible-success.svg?style=flat)](#Swift-Package-Manager)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-success.svg?style=flat)](#carthage)
[![Twitter](https://img.shields.io/twitter/follow/quickverse_io?style=social)](https://twitter.com/quickverse_io)
Expand Down Expand Up @@ -36,7 +36,7 @@ The library should have been added to the Swift Package Dependencies section, an

```
pod 'QuickVerse' // Always use the latest version
pod 'QuickVerse', '~> 1.4.2' // Or pin to a specific version
pod 'QuickVerse', '~> 1.4.3' // Or pin to a specific version
```
2. In a terminal window, navigate to the directory of your `Podfile`, and run `pod install --repo-update`

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation

class LocalizationManager {
var successfulFetch: Bool = false
private let apiClient: API
init(apiClient: API) {
self.apiClient = apiClient
Expand All @@ -13,7 +14,9 @@ extension LocalizationManager {
return completion(.failure(.invalidURL))
}
let request = Request(url: url, httpMethod: .get, body: nil)
apiClient.makeRequest(request: request) { (result: Result<QuickVerseResponse, APIError>) in
apiClient.makeRequest(request: request) { [weak self] (result: Result<QuickVerseResponse, APIError>) in
guard let self else { return completion(.failure(.generic(500))) }
if case .success = result { successfulFetch = true }
completion(result)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/QuickVerse/Internal/Networking/APIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ protocol API {

class APIClient: API {
var apiKey: String!
private let sdkVersion = "1.4.2"
private let sdkVersion = "1.4.3"

private let session: URLSession
init(session: URLSession) {
Expand Down
28 changes: 17 additions & 11 deletions Sources/QuickVerse/Public/QuickVerseManager.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Foundation

/// Convenience global accessor, allowing you to call QuickVerse methods with shorter footprint, for example: QuickVerse.getLocalizations(
/// Convenience global accessors, allowing you to call QuickVerse methods with shorter footprint, for example: QuickVerse.getLocalizations(, or QV.getLocalizations(,
public let QuickVerse = QuickVerseManager.shared
public let QV = QuickVerseManager.shared

public class QuickVerseManager {
public static let shared = QuickVerseManager()
Expand Down Expand Up @@ -49,19 +50,18 @@ extension QuickVerseManager {

/**
Use these methods to retrieve values for the localizations you fetched using one of the "get" methods above.
You can call these from anywhere in your app, e.g. Quickverse.stringFor(key: "Onboarding.Welcome.Title")
You can call these from anywhere in your app, e.g. Quickverse.stringFor(key: "Onboarding.Demo.Title")
*/
extension QuickVerseManager {
/// Returns the value for a specific key, falling back to a default value
public func stringFor(key: String, defaultValue: String) -> String {
let value = stringFor(key: key)
return value ?? defaultValue
logRequestedKey(key, defaultValue: defaultValue)
return getValueFor(key: key) ?? defaultValue
}
/// Returns the value for a specific key, or null if one does not exist
public func stringFor(key: String) -> String? {
let value = localizations.first(where: { $0.key == key })?.value
logRequestedKey(key, defaultValue: "", wasPresent: value != nil)
return value
logRequestedKey(key, defaultValue: "")
return getValueFor(key: key)
}
}

Expand Down Expand Up @@ -109,6 +109,9 @@ private extension QuickVerseManager {
}
}
}
func getValueFor(key: String) -> String? {
return localizations.first(where: { $0.key == key })?.value
}
}

extension QuickVerseManager {
Expand All @@ -127,16 +130,19 @@ extension QuickVerseManager {
}

private extension QuickVerseManager {
func logRequestedKey(_ key: String, defaultValue: String, wasPresent: Bool) {
if wasPresent {
func logRequestedKey(_ key: String, defaultValue: String) {
let isPresent = localizations.contains(where: { $0.key == key })
if isPresent {
reportingManager.logUtilisedKey(key)
} else {
if localizations.isEmpty {
LoggingManager.log("🚨 WARN: No localizations have been received. Have you added at least one localization to your quickverse account? If yes, did your fetchLocaliZations request succeed?")
LoggingManager.log("🚨 WARN: No localizations have been received. Have you added at least one localization to your quickverse account? If yes, have you called fetchLocalizations( in your launch sequence?")
} else {
LoggingManager.log("🚨 WARN: Value not found for referenced key: \(key). Please check this key exists in your quickverse.io account.")
}
reportingManager.logMissingKey(key, defaultValue: defaultValue)
if localizationManager.successfulFetch {
reportingManager.logMissingKey(key, defaultValue: defaultValue)
}
}
}
}

0 comments on commit c0860e7

Please sign in to comment.