Skip to content

Commit

Permalink
Public release 1.1.0
Browse files Browse the repository at this point in the history
Public release 1.1.0
  • Loading branch information
EugeneIOs authored Jun 4, 2021
2 parents 7fe98d3 + c93af96 commit 9fb1ad0
Show file tree
Hide file tree
Showing 105 changed files with 4,765 additions and 355 deletions.
14 changes: 7 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- checkout
- run:
name: Run Tests
command: xcodebuild test -project VGSShowSDK.xcodeproj -scheme VGSShowSDKTests -destination 'platform=iOS Simulator,name=iPhone 12,OS=14.1'
command: xcodebuild test -project VGSShowSDK.xcodeproj -scheme VGSShowSDKTests -destination 'platform=iOS Simulator,name=iPhone 12,OS=14.2'
build-and-ui-test-demo-app-ios-13-14:
macos:
xcode: "12.1"
Expand All @@ -22,19 +22,19 @@ jobs:
command: >
cd VGSShowDemoApp &&
cd VGSShowDemoApp &&
cd Resources &&
cd Resources && plutil -insert pdftoken -string ${pdftoken} UITestsMockedData.plist &&
plutil -insert vaultID -string ${vaultID} UITestsMockedData.plist &&
plutil -insert path -string ${path} UITestsMockedData.plist &&
cd .. &&
cd .. &&
pod install &&
xcrun instruments -w "iPhone 12 (14.1) [" || true &&
xcrun instruments -w "iPad Air (3rd generation) (13.5) [" || true &&
xcrun instruments -w "iPhone 12 (14.2) [" || true &&
xcrun instruments -w "iPad Air (3rd generation) (13.7) [" || true &&
xcodebuild test -workspace VGSShowDemoApp.xcworkspace
-scheme VGSShowDemoAppUITests
-sdk iphonesimulator
-destination 'platform=iOS Simulator,name=iPhone 12,OS=14.1'
-destination 'platform=iOS Simulator,name=iPad Air (3rd generation),OS=13.5'
-destination 'platform=iOS Simulator,name=iPhone 12,OS=14.2'
-destination 'platform=iOS Simulator,name=iPad Air (3rd generation),OS=13.7'
build-and-ui-test-demo-app-ios-11:
macos:
xcode: "11.0"
Expand All @@ -45,7 +45,7 @@ jobs:
command: >
cd VGSShowDemoApp &&
cd VGSShowDemoApp &&
cd Resources &&
cd Resources && plutil -insert pdftoken -string ${pdftoken} UITestsMockedData.plist &&
plutil -insert vaultID -string ${vaultID} UITestsMockedData.plist &&
plutil -insert path -string ${path} UITestsMockedData.plist &&
cd .. &&
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ Check our Satellite [integration guide](https://www.verygoodsecurity.com/docs/v
## Demo Application
Demo application for collecting card data on iOS is <a href="https://github.com/verygoodsecurity/vgs-show-ios/tree/main/VGSShowDemoApp">here</a>.

Also you can reveal PDF files with VGShow iOS SDK.
Check our demo with redact and reveal pdf file [use case.](./VGSShowDemoApp/VGSShowDemoApp/Controllers/UseCases/ShowPDF/)

### Releases
To follow `VGSShowSDK` updates and changes check the [releases](https://github.com/verygoodsecurity/vgs-show-ios/releases) page.

Expand Down
19 changes: 13 additions & 6 deletions Sources/VGSShowSDK/Core/APIClient/APIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ internal class APIClient {

// MARK: - Public

internal func sendRequestWithJSON(path: String, method: VGSHTTPMethod = .post, value: VGSJSONData?, completion block: RequestCompletion) {
internal func sendRequestWithJSON(path: String, method: VGSHTTPMethod = .post, value: VGSJSONData?, requestOptions: VGSShowRequestOptions?, completion block: RequestCompletion) {

let payload = VGSRequestPayloadBody.json(value)
resolveURLForRequest(path: path, method: method, payload: payload, block: block)
resolveURLForRequest(path: path, method: method, payload: payload, requestOptions: requestOptions, block: block)
}

// MARK: - Private
Expand All @@ -133,8 +133,9 @@ internal class APIClient {
/// - path: `String` object, request path.
/// - method: `VGSHTTPMethod` object.
/// - payload: `VGSRequestPayloadBody` object.
/// - requestOptions: `VGSShowRequestOptions?` object, request options.
/// - block: `RequestCompletion` completion block.
private func resolveURLForRequest(path: String, method: VGSHTTPMethod, payload: VGSRequestPayloadBody, block: RequestCompletion) {
private func resolveURLForRequest(path: String, method: VGSHTTPMethod, payload: VGSRequestPayloadBody, requestOptions: VGSShowRequestOptions?, block: RequestCompletion) {

let url: URL?

Expand All @@ -158,7 +159,7 @@ internal class APIClient {
case .isResolving(let hostnameToResolve):
// URL is not resolved yet. Queue request.
updateHost(with: hostnameToResolve) { (url) in
self.sendDataRequestWithURL(url, path: path, method: method, payload: payload, block: block)
self.sendDataRequestWithURL(url, path: path, method: method, payload: payload, requestOptions: requestOptions, block: block)
}
return
}
Expand All @@ -174,10 +175,10 @@ internal class APIClient {
return
}

sendDataRequestWithURL(requestURL, path: path, method: method, payload: payload, block: block)
sendDataRequestWithURL(requestURL, path: path, method: method, payload: payload, requestOptions: requestOptions, block: block)
}

private func sendDataRequestWithURL(_ requestURL: URL, path: String, method: VGSHTTPMethod, payload: VGSRequestPayloadBody, block: RequestCompletion) {
private func sendDataRequestWithURL(_ requestURL: URL, path: String, method: VGSHTTPMethod, payload: VGSRequestPayloadBody, requestOptions: VGSShowRequestOptions?, block: RequestCompletion) {

let encodingResult = payload.encodeToRequestBodyData()

Expand All @@ -194,6 +195,12 @@ internal class APIClient {
request.httpMethod = method.rawValue
request.allHTTPHeaderFields = headers

if let options = requestOptions {
if let customTimeout = options.requestTimeoutInterval {
request.timeoutInterval = customTimeout
}
}

// Log request.
VGSShowRequestLogger.logRequest(request, payload: payload)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// VGSShowRequestOptions.swift
// Pods-VGSShowDemoApp
//

import Foundation

/// Holds additional request options.
public struct VGSShowRequestOptions {

/// Request timeout interval, default is `nil`.
public var requestTimeoutInterval: TimeInterval? = nil

/// :nodoc:
public init() {}
}
7 changes: 5 additions & 2 deletions Sources/VGSShowSDK/Core/Analytics/VGSAnalyticsClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum VGSAnalyticsEventType: String {
case copy = "Copy to clipboard click"
case fieldUnsubscibe = "UnsubscribeField"
case setSecureTextRange = "SetSecureTextRange"
case contentRendering = "ContentRendering"
}

/// Client responsably for managing and sending VGS Show SDK analytics events.
Expand Down Expand Up @@ -94,13 +95,15 @@ public class VGSAnalyticsClient {
}

/// :nodoc: Base function to Track analytics event
public func trackEvent(_ type: VGSAnalyticsEventType, status: AnalyticEventStatus = .success, extraData: [String: Any]? = nil) {
public func trackEvent(_ type: VGSAnalyticsEventType, status: AnalyticEventStatus? = .success, extraData: [String: Any]? = nil) {
var data = [String: Any]()
if let extraData = extraData {
data = extraData
}
data["type"] = type.rawValue
data["status"] = status.rawValue
if let eventStatus = status {
data["status"] = eventStatus.rawValue
}
data["ua"] = VGSAnalyticsClient.userAgentData
data["version"] = Utils.vgsShowVersion
data["source"] = Constants.Metadata.source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,12 @@ internal enum VGSShowDecodedContent {
- text: `String` object.
*/
case text(_ text: String)

/**
Raw data.
- Parameters:
- data: `Data` object.
*/
case rawData(_ data: Data)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

/// Format for raw decoded data.
/// Defines how to decode raw data.
internal enum VGSShowResponseDecodingFormat {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// VGSShowBase64Decoder.swift
// VGSShowSDK
//

import Foundation

/// Decodes to base64 data.
final internal class VGSShowBase64Decoder: VGSShowJSONDecoderProtocol {

// MARK: - VGSShowJSONDecoderProtocol

func decodeJSONForContentPath(_ contentPath: String, json: VGSJSONData) -> VGSShowDecodingResult {

guard let encodedDataBase64: String = json.valueForKeyPath(keyPath: contentPath) else {
return .failure(VGSShowError(type: .fieldNotFound))
}

guard let data = Data(base64Encoded: encodedDataBase64) else {
return .failure(VGSShowError(type: .invalidBase64Data))
}

let rawDataResult = VGSShowDecodedContent.rawData(data)

return .success(rawDataResult)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

final internal class VGSShowTextDecoder: VGSShowDecoderProtocol {
final internal class VGSShowTextDecoder: VGSShowJSONDecoderProtocol {

func decodeJSONForContentPath(_ contentPath: String, json: VGSJSONData) -> VGSShowDecodingResult {

Expand Down
16 changes: 12 additions & 4 deletions Sources/VGSShowSDK/Core/Show/Decoders/VGSDataDecoderFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,27 @@
import Foundation

/// Interface to implement by data decoders.
internal protocol VGSShowDecoderProtocol {
internal protocol VGSShowJSONDecoderProtocol {
func decodeJSONForContentPath(_ contentPath: String, json: VGSJSONData) -> VGSShowDecodingResult
}

/// `VGSDataDecoderFactory` provides decoders for specific decoding.
internal final class VGSDataDecoderFactory {
/// Provides decoder for specific decoding.
/// - Parameter decoder: `VGSShowDataDecoding` object. Decoding type.
/// - Returns: Decoder object implementing `VGSShowDecoderProtocol` interface.
static func provideDecorder( for decoder: VGSShowDecodingContentMode) -> VGSShowDecoderProtocol {
switch decoder {
/// - Returns: Decoder object implementing `provideJSONDecorder` interface.
internal static func provideJSONDecorder(for contentMode: VGSShowDecodingContentMode) -> VGSShowJSONDecoderProtocol? {
switch contentMode {
case .text:
return VGSShowTextDecoder()
case .pdf(let pdfFormat):
switch pdfFormat {
case .rawData(let rawDataFormat):
switch rawDataFormat {
case .base64:
return VGSShowBase64Decoder()
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// VGSShowPDFContent.swift
// VGSShowSDK
//

import Foundation

/// PDF content type.
internal enum VGSShowPDFContent {

/**
Raw data to display.
- Parameters:
- data: `Data` object.
*/
case rawData(_ data: Data)

/**
URL referring to pdf content.
- Parameters:
- url: `URL` object.
// */
// case url(_ url: URL)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// VGSShowPDFFormat.swift
// VGSShowSDK

import Foundation

/// Specifies decoding mode for pdf.
internal enum VGSShowPDFFormat {

// /**
// Decode pdf data as String URL using content path.
// */
// case url

/**
Decode as raw Data (content path is ingnored).
- Parameters:
- format: `VGSShowImageRawDataFormat`, specified raw data format.
*/
case rawData(_ format: VGSShowRawDataFormat)
}

/// Raw data format.
internal enum VGSShowRawDataFormat {

/// Decode base64 data.
case base64
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ internal enum VGSShowDecodingContentMode {

/// Decode as text.
case text

/**
Decode as PDF.
- Parameters:
- pdfFormat: `VGSShowPDFFormat` object, specifies pdf format.
*/
case pdf(_ pdfFormat: VGSShowPDFFormat)
}
46 changes: 34 additions & 12 deletions Sources/VGSShowSDK/Core/Show/Network/VGSShow+Network.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,23 @@ extension VGSShow {
- path: Inbound rout path for your organization vault.
- method: HTTPMethod, default is `.post`.
- payload: `VGSJSONData?` object, default is `nil`. Should be valid JSON.
- requestOptions: `VGSShowRequestOptions?` object, additional request options, default is `nil`.
- completion: `VGSResponse` completion block. The completion handler to call when the load request is complete.
- Note:
Errors can be returned in the `NSURLErrorDomain` and `VGSShowSDKErrorDomain`.
*/
public func request(path: String, method: VGSHTTPMethod = .post, payload: VGSJSONData? = nil, completion block: @escaping (VGSShowRequestResult) -> Void) {
public func request(path: String, method: VGSHTTPMethod = .post, payload: VGSJSONData? = nil, requestOptions: VGSShowRequestOptions? = nil, completion block: @escaping (VGSShowRequestResult) -> Void) {

// Content analytics.
var extraAnalyticsInfo = [String: Any]()
extraAnalyticsInfo["content"] = contentForAnalytics(from: payload)

var analyticsData = contentForAnalytics(from: payload)
for viewTypeName in viewTypeAnalyticsNames {
analyticsData.append(viewTypeName)
}

extraAnalyticsInfo["content"] = analyticsData

// Log warning if no subscribed views.
if !hasViewModels {
Expand All @@ -42,7 +49,7 @@ extension VGSShow {
let event = VGSLogEvent(level: .info, text: "Start json request")
logEvent(event)

apiClient.sendRequestWithJSON(path: path, method: method, value: payload ) {[weak self] (requestResult) in
apiClient.sendRequestWithJSON(path: path, method: method, value: payload, requestOptions: requestOptions) {[weak self] (requestResult) in

guard let strongSelf = self else {return}

Expand Down Expand Up @@ -108,15 +115,18 @@ extension VGSShow {

var unrevealedContentPaths = [String]()
revealModels.forEach { model in
// Reveal data.
let decoder = VGSDataDecoderFactory.provideDecorder(for: model.decodingContentMode)
let decodingResult = decoder.decodeJSONForContentPath(model.decodingContentPath, json: json)

// Update models with decoding result.
model.handleDecodingResult(decodingResult)

// Collect unrevealed contentPaths.
if decodingResult.error != nil {
if let decoder = VGSDataDecoderFactory.provideJSONDecorder(for: model.decodingContentMode) {
let decodingResult = decoder.decodeJSONForContentPath(model.decodingContentPath, json: json)

// Update models with decoding result.
model.handleDecodingResult(decodingResult)

// Collect unrevealed contentPaths.
if decodingResult.error != nil {
unrevealedContentPaths.append(model.decodingContentPath)
}
} else {
// Log! Cannot provide JSON decoder for model!
unrevealedContentPaths.append(model.decodingContentPath)
}
}
Expand Down Expand Up @@ -175,6 +185,18 @@ extension VGSShow {
content.append("custom_header")
}

switch apiClient.hostURLPolicy {
case .customHostURL(let status):
switch status {
case .resolved, .isResolving:
content.append("custom_hostname")
default:
break
}
default:
break
}

return content
}
}
Loading

0 comments on commit 9fb1ad0

Please sign in to comment.