Skip to content

Commit

Permalink
fix: TikiSdk.license method parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobrg committed Mar 22, 2023
1 parent 99e8b1d commit 0aff5b5
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 109 deletions.
2 changes: 1 addition & 1 deletion Sources/TikiSdk/Core/Req/ReqLicense.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ struct ReqLicense: Encodable {
var terms: String?
var titleDescription: String?
var licenseDescription: String?
var origin: String?
var uses: [LicenseUse] = []
var tags: [TitleTag] = []
var expiry: Date?
var origin: String?
}
40 changes: 24 additions & 16 deletions Sources/TikiSdk/TikiSdk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,27 +212,35 @@ public class TikiSdk{


/**
* Create a new LicenseRecord.
*
* If a TitleRecord for the Offer.ptr is not found, a new TitleRecord is created.
* If a TitleRecord is found, Offer.tags and Offer.description parameters are ignored.
* Creates a new LicenseRecord.
*
* If a TitleRecord for the ptr and origin is not found, a new TitleRecord is created. If a TitleRecord is found, tags and titleDescription parameters are ignored.

* - Parameters:
* - offer: The Offer object containing details of the offer.
* - accepted: The date when the license was accepted.
* - Returns: The newly created LicenseRecord object.
*/
public static func license(offer: Offer) async throws -> LicenseRecord {

* ptr: The Pointer Records identifies data stored in your system, similar to a foreign key. Learn more about selecting good pointer records at
* https://docs.mytiki.com/docs/selecting-a-pointer-record.
* uses: A List defining how and where an asset may be used, in the format of usecases and destinations, per the terms of the license. Learn more about defining uses
* https://docs.mytiki.com/docs/specifying-terms-and-usage.
* terms: The legal terms of the contract (a lot of words).
* origin: An optional override of the default origin specified in init. Follow a reverse-DNS syntax. i.e. com.myco.myapp.
* tags: A List of metadata tags included in the TitleRecord describing the asset, for your use in record search and filtering. Learn more about adding tags at *
* https://docs.mytiki.com/docs/adding-tags. Only set IF a title does not already exist for the ptr.
* titleDescription: Sets the TitleRecord description IF a title does not already exist for the ptr. A short, human-readable, description of the TitleRecord as a future reminder.
* licenseDescription: A short, human-readable, description of the LicenseRecord as a future reminder.
* expiry: A LicenseRecord expiration date. Leave nil if the license never expires.
* - Returns: The created LicenseRecord
*/
static func license(_ ptr: String, _ uses: [LicenseUse], _ terms: String, tags: [TitleTag] = [], titleDescription: String? = nil, licenseDescription: String? = nil, expiry: Date? = nil, origin: String? = nil) async throws -> LicenseRecord {
let rspLicense: RspLicense = try await withCheckedThrowingContinuation{ continuation in
do{
let licenseReq = ReqLicense(
ptr: offer.ptr,
terms: offer.terms,
licenseDescription: offer.description,
uses: offer.uses,
tags: offer.tags,
expiry: offer.expiry
ptr: ptr,
terms: terms,
titleDescription: titleDescription,
licenseDescription: licenseDescription,
uses: uses,
tags: tags,
expiry: expiry
)
try instance.coreChannel.invokeMethod(
method: CoreMethod.license,
Expand Down
2 changes: 1 addition & 1 deletion Sources/TikiSdk/TitleRecord.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
public struct TitleRecord: Codable {
let id: String
let ptr: String
let hashedPtr: String
let tags: [TitleTag]
let description: String?
let origin: String?
Expand Down
6 changes: 5 additions & 1 deletion Sources/TikiSdk/Ui/OfferFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public struct OfferFlow: View{
Task{
loading = true
do{
let license: LicenseRecord = try await TikiSdk.license(offer: offer)
let license: LicenseRecord = try await license(offer: offer)
onAccept?(offer, license)
print(license)
loading = false
Expand All @@ -191,4 +191,8 @@ public struct OfferFlow: View{
}
}

func license(offer: Offer) async throws -> LicenseRecord {
return try await TikiSdk.license( offer.ptr!, offer.uses, offer.terms!, tags: offer.tags, licenseDescription: offer.description,expiry: offer.expiry)
}

}
11 changes: 8 additions & 3 deletions Sources/TikiSdk/Ui/Screens/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public struct Settings: View {
revokedOffer.permissions = offer.permissions
revokedOffer.expiry = offer.expiry
revokedOffer.uses = []
let _ = try await TikiSdk.license(offer: revokedOffer)
let _ = try await license(offer: revokedOffer)
accepted = try await self.guard()
isLoading = false
}catch{
Expand All @@ -169,8 +169,8 @@ public struct Settings: View {
Task{
do{
isLoading = true
let _ = try await TikiSdk.license(offer: offer)
accepted = await try self.guard()
let _ = try await license(offer: offer)
accepted = try await self.guard()
isLoading = false
}catch{
isLoading = false
Expand All @@ -193,4 +193,9 @@ public struct Settings: View {
}
return try await TikiSdk.guard(ptr: ptr, usecases: usecases, destinations: destinations)
}

func license(offer: Offer) async throws -> LicenseRecord {
return try await TikiSdk.license( offer.ptr!, offer.uses, offer.terms!, tags: offer.tags, licenseDescription: offer.description,expiry: offer.expiry)
}

}
151 changes: 74 additions & 77 deletions Tests/IntegrationTests/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,134 +8,131 @@ import XCTest
import SwiftUI

class IntegrationTests: XCTestCase {

let origin = "com.mytiki.iostest"
let publishingId = "e12f5b7b-6b48-4503-8b39-28e4995b5f88"
let id = UUID().uuidString


func testInitSdk() async throws {
do{
try await TikiSdk.config().initialize(publishingId: publishingId, id:id)
XCTAssert(TikiSdk.address != nil)
try TikiSdk.config().initialize(publishingId: publishingId, id:id, onComplete: {
XCTAssert(TikiSdk.address != nil)
})
}catch{
XCTFail(error.localizedDescription)
}
}

func testTikiSdkConfig() async throws{
do{
try await TikiSdk.config()
try TikiSdk.config()
.theme
.primaryTextColor(.white)
.primaryBackgroundColor(.white)
.secondaryBackgroundColor(.white)
.accentColor(.white)
.fontFamily("test")
.and()
.primaryTextColor(.white)
.primaryBackgroundColor(.white)
.secondaryBackgroundColor(.white)
.accentColor(.white)
.fontFamily("test")
.and()
.dark
.primaryTextColor(.white)
.primaryBackgroundColor(.white)
.secondaryBackgroundColor(.white)
.accentColor(.white)
.fontFamily("test")
.and()
.primaryTextColor(.white)
.primaryBackgroundColor(.white)
.secondaryBackgroundColor(.white)
.accentColor(.white)
.fontFamily("test")
.and()
.offer
.id("randomId")
.bullet(text: "test 1", isUsed: true)
.bullet(text: "test 2", isUsed: false)
.bullet(text: "test 3", isUsed: true)
.ptr("source")
.description("testing")
.terms("myTerms")
.use(usecases: [LicenseUsecase(LicenseUsecaseEnum.support)])
.tag(TitleTag(TitleTagEnum.advertisingData))
.duration(365 * 24 * 60 * 60)
.permission(Permission.camera)
.add()
.id("randomId")
.bullet(text: "test 1", isUsed: true)
.bullet(text: "test 2", isUsed: false)
.bullet(text: "test 3", isUsed: true)
.ptr("source")
.description("testing")
.use(usecases: [LicenseUsecase(LicenseUsecaseEnum.support)])
.tag(TitleTag(TitleTagEnum.advertisingData))
.duration(365 * 24 * 60 * 60)
.permission(Permission.camera)
.add()
.offer
.id("randomId2")
.bullet(text: "test 1", isUsed: true)
.bullet(text: "test 2", isUsed: true)
.bullet(text: "test 3", isUsed: true)
.ptr("source2")
.description("testing")
.terms("myTerms")
.use(usecases: [LicenseUsecase(LicenseUsecaseEnum.support)])
.tag(TitleTag(TitleTagEnum.advertisingData))
.duration(365 * 24 * 60 * 60)
.permission(Permission.camera)
.add()
.id("randomId2")
.bullet(text: "test 1", isUsed: true)
.bullet(text: "test 2", isUsed: true)
.bullet(text: "test 3", isUsed: true)
.ptr("source2")
.description("testing")
.use(usecases: [LicenseUsecase(LicenseUsecaseEnum.support)])
.tag(TitleTag(TitleTagEnum.advertisingData))
.duration(365 * 24 * 60 * 60)
.permission(Permission.camera)
.add()
.onAccept { _, __ in }
.onDecline { _, __ in }
.onSettings { }
.disableAcceptEnding(false)
.disableDeclineEnding(true)
.initialize(publishingId: publishingId, id:id)
XCTAssert(TikiSdk.address != nil)
}catch{
XCTFail(error.localizedDescription)
}
}


func testInitSdkWithAddress() async throws {
do{
try await TikiSdk.config().initialize(publishingId: publishingId, id:id)
let address = TikiSdk.address
try await TikiSdk.config().initialize(publishingId: publishingId, id:id)
let address2 = TikiSdk.address
XCTAssertEqual(address, address2)
.initialize(publishingId: publishingId, id:id, onComplete: {
XCTAssert(TikiSdk.address != nil)
})
}catch{
XCTFail(error.localizedDescription)
}
}

func testLicense() async throws{
do{
try await TikiSdk.config().initialize(publishingId: publishingId, id:id)
let offer = try Offer()
.id("randomId")
.bullet(text: "test 1", isUsed: true)
.bullet(text: "test 2", isUsed: false)
.bullet(text: "test 3", isUsed: true)
.ptr("source")
.description("testing")
.terms("path/terms.md")
.use(usecases: [LicenseUsecase(LicenseUsecaseEnum.support)])
.tag(TitleTag(TitleTagEnum.advertisingData))
.permission(Permission.camera)
let license = try await TikiSdk.license(offer: offer)
XCTAssertEqual(license.description, "testing")
XCTAssertEqual(license.uses[0].usecases[0].value, LicenseUsecase(LicenseUsecaseEnum.support).value)
XCTAssertEqual(license.title.tags[0].value, TitleTagEnum.advertisingData.rawValue)
try TikiSdk.config().initialize(publishingId: publishingId, id:id, onComplete: {
Task{
do{
let offer = try Offer()
.id("randomId")
.bullet(text: "test 1", isUsed: true)
.bullet(text: "test 2", isUsed: false)
.bullet(text: "test 3", isUsed: true)
.ptr("source")
.description("testing")
.terms("terms")
.use(usecases: [LicenseUsecase(LicenseUsecaseEnum.support)])
.tag(TitleTag(TitleTagEnum.advertisingData))
.permission(Permission.camera)
let license = try await TikiSdk.license(
offer.ptr!, offer.uses, offer.terms ?? "terms", tags: offer.tags, licenseDescription: offer.description, expiry: offer.expiry)
XCTAssertEqual(license.description, "testing")
XCTAssertEqual(license.uses[0].usecases[0].value, LicenseUsecase(LicenseUsecaseEnum.support).value)
XCTAssertEqual(license.title.tags[0].value, TitleTagEnum.advertisingData.rawValue)
}catch{
XCTFail()
}
}
})
}catch{
print(error)
XCTFail(error.localizedDescription)
XCTFail()
}
}

func testGuard() async throws{
do{
try await TikiSdk.config().initialize(publishingId: publishingId, id:id)
try TikiSdk.config().initialize(publishingId: publishingId, id:id)
let offer = try Offer()
.id("randomId")
.bullet(text: "test 1", isUsed: true)
.bullet(text: "test 2", isUsed: false)
.bullet(text: "test 3", isUsed: true)
.ptr("source")
.description("testing")
.terms("path/terms.md")
.terms("terms")
.use(usecases: [LicenseUsecase(LicenseUsecaseEnum.support)])
.tag(TitleTag(TitleTagEnum.advertisingData))
.permission(Permission.camera)
let license = try await TikiSdk.license(offer: offer)
let _ = try await license(offer: offer)
let guardResult = try await TikiSdk.guard(ptr: "source", usecases:[LicenseUsecase(LicenseUsecaseEnum.support)], destinations: [])
XCTAssert(guardResult)
}catch{
print(error)
XCTFail(error.localizedDescription)
}
}
}

func license(offer: Offer) async throws -> LicenseRecord {
return try await TikiSdk.license( offer.ptr!, offer.uses, offer.terms!, tags: offer.tags, licenseDescription: offer.description,expiry: offer.expiry)
}
Loading

0 comments on commit 0aff5b5

Please sign in to comment.