Skip to content

Commit 6792b8f

Browse files
committed
Change getAccessFee endpoint to v2. Update models and create new ones.
1 parent 526d338 commit 6792b8f

17 files changed

+600
-91
lines changed

InPlayerSDK.xcodeproj/project.pbxproj

+24
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
A73211EB2240114C00452C15 /* countries.json in Resources */ = {isa = PBXBuildFile; fileRef = A73211EA2240114C00452C15 /* countries.json */; };
2121
A741EAA921F7799B00290AFD /* InPlayer+Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = A741EAA821F7799B00290AFD /* InPlayer+Configuration.swift */; };
2222
A741EAAB21F77A8700290AFD /* InPlayerEnvironmentType.swift in Sources */ = {isa = PBXBuildFile; fileRef = A741EAAA21F77A8700290AFD /* InPlayerEnvironmentType.swift */; };
23+
A75D20D62461F1D400910FCF /* InPlayerVoucher.swift in Sources */ = {isa = PBXBuildFile; fileRef = A75D20D12461F1D400910FCF /* InPlayerVoucher.swift */; };
24+
A75D20D72461F1D400910FCF /* InPlayerAgeRestriction.swift in Sources */ = {isa = PBXBuildFile; fileRef = A75D20D22461F1D400910FCF /* InPlayerAgeRestriction.swift */; };
25+
A75D20D82461F1D400910FCF /* InPlayerGeoRestriction.swift in Sources */ = {isa = PBXBuildFile; fileRef = A75D20D32461F1D400910FCF /* InPlayerGeoRestriction.swift */; };
26+
A75D20D92461F1D400910FCF /* InPlayerVoucherRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = A75D20D42461F1D400910FCF /* InPlayerVoucherRule.swift */; };
27+
A75D20DA2461F1D400910FCF /* InPlayerSeasonalFee.swift in Sources */ = {isa = PBXBuildFile; fileRef = A75D20D52461F1D400910FCF /* InPlayerSeasonalFee.swift */; };
28+
A75D20DC2461FBA000910FCF /* InPlayerExternalFee.swift in Sources */ = {isa = PBXBuildFile; fileRef = A75D20DB2461FBA000910FCF /* InPlayerExternalFee.swift */; };
2329
A75DE418227097B20057B2A7 /* InPlayerSocialUrlResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = A75DE417227097B20057B2A7 /* InPlayerSocialUrlResponse.swift */; };
2430
A76EA2932378916A00B13D41 /* AccedoAsset.swift in Sources */ = {isa = PBXBuildFile; fileRef = A76EA2922378916A00B13D41 /* AccedoAsset.swift */; };
2531
A76EA2952378917600B13D41 /* BrigthcoveAsset.swift in Sources */ = {isa = PBXBuildFile; fileRef = A76EA2942378917600B13D41 /* BrigthcoveAsset.swift */; };
@@ -123,6 +129,12 @@
123129
A73211EA2240114C00452C15 /* countries.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = countries.json; sourceTree = "<group>"; };
124130
A741EAA821F7799B00290AFD /* InPlayer+Configuration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "InPlayer+Configuration.swift"; sourceTree = "<group>"; };
125131
A741EAAA21F77A8700290AFD /* InPlayerEnvironmentType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InPlayerEnvironmentType.swift; sourceTree = "<group>"; };
132+
A75D20D12461F1D400910FCF /* InPlayerVoucher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InPlayerVoucher.swift; sourceTree = "<group>"; };
133+
A75D20D22461F1D400910FCF /* InPlayerAgeRestriction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InPlayerAgeRestriction.swift; sourceTree = "<group>"; };
134+
A75D20D32461F1D400910FCF /* InPlayerGeoRestriction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InPlayerGeoRestriction.swift; sourceTree = "<group>"; };
135+
A75D20D42461F1D400910FCF /* InPlayerVoucherRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InPlayerVoucherRule.swift; sourceTree = "<group>"; };
136+
A75D20D52461F1D400910FCF /* InPlayerSeasonalFee.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InPlayerSeasonalFee.swift; sourceTree = "<group>"; };
137+
A75D20DB2461FBA000910FCF /* InPlayerExternalFee.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InPlayerExternalFee.swift; sourceTree = "<group>"; };
126138
A75DE417227097B20057B2A7 /* InPlayerSocialUrlResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InPlayerSocialUrlResponse.swift; sourceTree = "<group>"; };
127139
A76EA2922378916A00B13D41 /* AccedoAsset.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccedoAsset.swift; sourceTree = "<group>"; };
128140
A76EA2942378917600B13D41 /* BrigthcoveAsset.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrigthcoveAsset.swift; sourceTree = "<group>"; };
@@ -416,6 +428,12 @@
416428
A7EA963A21F501F000CDA238 /* Asset */ = {
417429
isa = PBXGroup;
418430
children = (
431+
A75D20D22461F1D400910FCF /* InPlayerAgeRestriction.swift */,
432+
A75D20D32461F1D400910FCF /* InPlayerGeoRestriction.swift */,
433+
A75D20D52461F1D400910FCF /* InPlayerSeasonalFee.swift */,
434+
A75D20D12461F1D400910FCF /* InPlayerVoucher.swift */,
435+
A75D20D42461F1D400910FCF /* InPlayerVoucherRule.swift */,
436+
A75D20DB2461FBA000910FCF /* InPlayerExternalFee.swift */,
419437
A76EA2912378914B00B13D41 /* AssetTypes */,
420438
A7EA964421F501F000CDA238 /* InPlayerItem.swift */,
421439
A7EA963C21F501F000CDA238 /* InPlayerAccessControlType.swift */,
@@ -702,6 +720,7 @@
702720
A7EA967521F501F000CDA238 /* InPlayerTrialPeriod.swift in Sources */,
703721
A76EA2972378917F00B13D41 /* CloudfrontAsset.swift in Sources */,
704722
A73211DA223C0D7E00452C15 /* InPlayerRegisterField.swift in Sources */,
723+
A75D20D92461F1D400910FCF /* InPlayerVoucherRule.swift in Sources */,
705724
A7EA966B21F501F000CDA238 /* DataDecodeExt.swift in Sources */,
706725
A76EA2AD2378924100B13D41 /* StreamAMGAsset.swift in Sources */,
707726
A7EA966C21F501F000CDA238 /* DateExt.swift in Sources */,
@@ -723,19 +742,24 @@
723742
A73211E5223C1A8800452C15 /* InPlayerSubscription.swift in Sources */,
724743
A76EA2A1237891C200B13D41 /* LivestreamAsset.swift in Sources */,
725744
A741EAAB21F77A8700290AFD /* InPlayerEnvironmentType.swift in Sources */,
745+
A75D20D62461F1D400910FCF /* InPlayerVoucher.swift in Sources */,
726746
A73211DC223C11B500452C15 /* Subscription.swift in Sources */,
727747
A73211E7224006AC00452C15 /* InPlayerRegisterFieldsResponse.swift in Sources */,
728748
A741EAA921F7799B00290AFD /* InPlayer+Configuration.swift in Sources */,
729749
A7A690D4227C9CB20039AB59 /* InPlayerSocialUrl.swift in Sources */,
730750
A73211E3223C182200452C15 /* InPlayerSubscriptionList.swift in Sources */,
731751
A7EA968C21F501F000CDA238 /* InPlayerNotification.swift in Sources */,
732752
A73211D6223AD42300452C15 /* InPlayerPurchaseHistory.swift in Sources */,
753+
A75D20DC2461FBA000910FCF /* InPlayerExternalFee.swift in Sources */,
754+
A75D20D72461F1D400910FCF /* InPlayerAgeRestriction.swift in Sources */,
733755
A7EA967321F501F000CDA238 /* InPlayerAccessControlType.swift in Sources */,
734756
A76EA2952378917600B13D41 /* BrigthcoveAsset.swift in Sources */,
735757
A7EA967121F501F000CDA238 /* NetworkDataSource.swift in Sources */,
758+
A75D20D82461F1D400910FCF /* InPlayerGeoRestriction.swift in Sources */,
736759
A73211D0223AD06E00452C15 /* InPlayerCustomerAccessItem.swift in Sources */,
737760
A7EA968421F501F000CDA238 /* InPlayerInvalidResponseError.swift in Sources */,
738761
A76EA2AF2378925D00B13D41 /* WitsiaAsset.swift in Sources */,
762+
A75D20DA2461F1D400910FCF /* InPlayerSeasonalFee.swift in Sources */,
739763
A7EA968F21F501F000CDA238 /* INPNotificationService.swift in Sources */,
740764
A73211E922400B5700452C15 /* InPlayerFieldCountry.swift in Sources */,
741765
A7EA969021F501F000CDA238 /* InPlayerNotificationAPIManager.swift in Sources */,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

Source/Core/API/Asset/INPAssetService.swift

+34-26
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ class INPAssetService {
1414
}
1515

1616
static func getAssetAccessFees(id: Int,
17+
voucherId: Int?,
1718
completion: @escaping RequestCompletion<[InPlayerAccessFee]>) {
19+
var parameters: [String: Any] = [:]
20+
if let voucherId = voucherId {
21+
parameters[AssetParameters.voucherExpand] = voucherId
22+
}
1823
NetworkDataSource.performRequest(session: InPlayerSessionAPIManager.default.session,
19-
route: AssetAPIRouter.getItemAccessFees(id: id),
24+
route: AssetAPIRouter.getItemAccessFees(id: id, parameters: parameters),
2025
completion: completion)
2126
}
2227

@@ -51,62 +56,65 @@ class INPAssetService {
5156
private struct AssetParameters {
5257
static let merchantUUID = "merchant_uuid"
5358
static let entryId = "entry_id"
59+
static let voucherExpand = "voucher[expand]"
5460
}
5561

5662

5763
/// Enum of available asset api routes
5864
private enum AssetAPIRouter: INPAPIConfiguration {
5965
case getItemDetails(id: Int, merchantUUID: String)
60-
case getItemAccessFees(id: Int)
66+
case getItemAccessFees(id: Int, parameters: [String: Any])
6167
case getItemAccess(id: Int, parameters: [String: Any])
6268
case getExternalAsset(assetType: String, externalID: String, parameters: [String: Any])
6369

6470
var method: HTTPMethod {
6571
switch self {
66-
default:
67-
return .get
72+
default:
73+
return .get
6874
}
6975
}
7076

7177
var path: String {
7278
switch self {
73-
case .getItemDetails(let id, let merchantUUID):
74-
return String(format: NetworkConstants.Endpoints.Asset.itemDetails, merchantUUID, "\(id)")
75-
case .getItemAccessFees(let id):
76-
return String(format: NetworkConstants.Endpoints.Asset.itemAccessFees, "\(id)")
77-
case .getItemAccess(let id, _):
78-
return String(format: NetworkConstants.Endpoints.Asset.itemAccess, "\(id)")
79-
case .getExternalAsset(let assetType, let externalID, _):
80-
return String(format: NetworkConstants.Endpoints.Asset.externalItemDetails, assetType, externalID)
79+
case .getItemDetails(let id, let merchantUUID):
80+
return String(format: NetworkConstants.Endpoints.Asset.itemDetails, merchantUUID, "\(id)")
81+
case .getItemAccessFees(let id, _):
82+
return String(format: NetworkConstants.Endpoints.Asset.itemAccessFees, "\(id)")
83+
case .getItemAccess(let id, _):
84+
return String(format: NetworkConstants.Endpoints.Asset.itemAccess, "\(id)")
85+
case .getExternalAsset(let assetType, let externalID, _):
86+
return String(format: NetworkConstants.Endpoints.Asset.externalItemDetails, assetType, externalID)
8187
}
8288
}
8389

8490
var parameters: Parameters? {
8591
switch self {
86-
case .getItemAccess(_, let parameters):
87-
return parameters
88-
case .getExternalAsset(_,_, let parameters):
89-
return parameters
90-
default:
91-
return nil
92+
case .getItemAccessFees(_, let parameters):
93+
return parameters
94+
case .getItemAccess(_, let parameters):
95+
return parameters
96+
case .getExternalAsset(_,_, let parameters):
97+
return parameters
98+
default:
99+
return nil
92100
}
93101
}
94102

95103
var urlEncoding: Bool {
96104
switch self {
97-
default:
98-
return true
105+
default:
106+
return true
99107
}
100108
}
101109

102110
var requiresAuthorization: Bool {
103111
switch self {
104-
case .getItemAccessFees,
105-
.getItemDetails,
106-
.getExternalAsset:
107-
return false
108-
default:
109-
return true
112+
case .getItemAccessFees,
113+
.getItemDetails,
114+
.getExternalAsset:
115+
return false
116+
default:
117+
return true
110118
}
111119
}
112120
}

Source/Core/API/NetworkConstants.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ struct NetworkConstants {
3838

3939
struct Asset {
4040
static let itemDetails = "/items/%@/%@"
41-
static let itemAccessFees = "items/%@/access-fees"
42-
static let itemAccess = "items/%@/access"
41+
static let itemAccessFees = "/v2/items/%@/access-fees"
42+
static let itemAccess = "/items/%@/access"
4343
static let externalItemDetails = "/items/assets/external/%@/%@"
4444
}
4545

Source/Core/Asset.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,17 @@ public extension InPlayer {
3535
Returns a collection of fees for a specific asset
3636
- Parameters:
3737
- id: Asset ID.
38+
- voucherId: Voucher ID
3839
- success: A closure to be executed once the request has finished successfully.
3940
- accessFees: Collection of access fees for specific asset.
4041
- failure: A closure to be executed once the request has finished with error.
4142
- error: Containing information about the error that occurred.
4243
*/
4344
public static func getAssetAccessFees(id: Int,
45+
voucherId: Int?,
4446
success: @escaping ([InPlayerAccessFee]) -> Void,
4547
failure: @escaping (InPlayerError) -> Void) {
46-
INPAssetService.getAssetAccessFees(id: id, completion: { (accessFees, error) in
48+
INPAssetService.getAssetAccessFees(id: id, voucherId: voucherId, completion: { (accessFees, error) in
4749
if let error = error {
4850
failure(error)
4951
} else {

Source/Core/Models/Account/InPlayerRegisterField.swift

+16-16
Original file line numberDiff line numberDiff line change
@@ -114,31 +114,31 @@ public struct InPlayerRegisterField : Codable {
114114
/// Encoder method
115115
public func encode(to encoder: Encoder) throws {
116116
var values = encoder.container(keyedBy: CodingKeys.self)
117-
try values.encode(defaultValue, forKey: .defaultValue)
118-
try values.encode(id, forKey: .id)
119-
try values.encode(label, forKey: .label)
120-
try values.encode(name, forKey: .name)
121-
try values.encode(placeholder, forKey: .placeholder)
122-
try values.encode(required, forKey: .required)
117+
try values.encodeIfPresent(defaultValue, forKey: .defaultValue)
118+
try values.encodeIfPresent(id, forKey: .id)
119+
try values.encodeIfPresent(label, forKey: .label)
120+
try values.encodeIfPresent(name, forKey: .name)
121+
try values.encodeIfPresent(placeholder, forKey: .placeholder)
122+
try values.encodeIfPresent(required, forKey: .required)
123123

124124
switch type {
125125
case .dropdown(let options):
126-
try values.encode(options, forKey: .options)
127-
try values.encode(RegisterFieldTypeStrings.dropdown, forKey: .typeString)
126+
try values.encodeIfPresent(options, forKey: .options)
127+
try values.encodeIfPresent(RegisterFieldTypeStrings.dropdown, forKey: .typeString)
128128
case .radio(let options):
129-
try values.encode(options, forKey: .options)
130-
try values.encode(RegisterFieldTypeStrings.radio, forKey: .typeString)
129+
try values.encodeIfPresent(options, forKey: .options)
130+
try values.encodeIfPresent(RegisterFieldTypeStrings.radio, forKey: .typeString)
131131
case .country(let options):
132-
try values.encode(options, forKey: .options)
133-
try values.encode(RegisterFieldTypeStrings.country, forKey: .typeString)
132+
try values.encodeIfPresent(options, forKey: .options)
133+
try values.encodeIfPresent(RegisterFieldTypeStrings.country, forKey: .typeString)
134134
case .input:
135-
try values.encode(RegisterFieldTypeStrings.input, forKey: .typeString)
135+
try values.encodeIfPresent(RegisterFieldTypeStrings.input, forKey: .typeString)
136136
case .datepicker:
137-
try values.encode(RegisterFieldTypeStrings.datepicker, forKey: .typeString)
137+
try values.encodeIfPresent(RegisterFieldTypeStrings.datepicker, forKey: .typeString)
138138
case .checkbox:
139-
try values.encode(RegisterFieldTypeStrings.checkbox, forKey: .typeString)
139+
try values.encodeIfPresent(RegisterFieldTypeStrings.checkbox, forKey: .typeString)
140140
default:
141-
try values.encode(RegisterFieldTypeStrings.unknown, forKey: .typeString)
141+
try values.encodeIfPresent(RegisterFieldTypeStrings.unknown, forKey: .typeString)
142142
}
143143
}
144144
}

0 commit comments

Comments
 (0)