Skip to content

Commit 6dcc205

Browse files
authored
Merge pull request #3 from contentstack/development
Publish content fallback
2 parents 39efc15 + 2f0af6c commit 6dcc205

11 files changed

Lines changed: 242 additions & 17 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
DEVELOPER_DIR: /Applications/Xcode_11.4.app/Contents/Developer
3131
strategy:
3232
matrix:
33-
destination: ["OS=13.4,name=iPhone 11 Pro"]
33+
destination: ["OS=13.4.1,name=iPhone 11 Pro"]
3434
steps:
3535
- uses: actions/checkout@v1
3636
with:

Config.xcconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
CONTENTSTACK_SDK_VERSION = 1.0.0
1+
CONTENTSTACK_SDK_VERSION = 1.1.0

Contentstack.xcodeproj/project.pbxproj

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@
5757
0F2DB7E82451D353007B9815 /* ImageOperations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F2DB7E62451D353007B9815 /* ImageOperations.swift */; };
5858
0F2DB7E92451D353007B9815 /* ImageOperations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F2DB7E62451D353007B9815 /* ImageOperations.swift */; };
5959
0F2DB7EA2451D353007B9815 /* ImageOperations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F2DB7E62451D353007B9815 /* ImageOperations.swift */; };
60+
0F359991257BE29B00B3DB89 /* Asset.json in Resources */ = {isa = PBXBuildFile; fileRef = 0FFBB4462446F9A4000D2795 /* Asset.json */; };
61+
0F359992257BE2A700B3DB89 /* ContentType.json in Resources */ = {isa = PBXBuildFile; fileRef = 0F244F9C244062B4003C3F26 /* ContentType.json */; };
62+
0F359993257BE2D100B3DB89 /* Entry.json in Resources */ = {isa = PBXBuildFile; fileRef = 0F796C512449EA8700EA04D5 /* Entry.json */; };
63+
0F359994257BE2EE00B3DB89 /* QueryOn.json in Resources */ = {isa = PBXBuildFile; fileRef = 0F50EA15244ED7F500E5D705 /* QueryOn.json */; };
64+
0F359995257BE30A00B3DB89 /* SyncTest.json in Resources */ = {isa = PBXBuildFile; fileRef = 0F1DCC77243D9BBF00EED404 /* SyncTest.json */; };
6065
0F38D7E0242C7C9E00232D7F /* Product.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F38D7DF242C7C9E00232D7F /* Product.swift */; };
6166
0F38D7E1242C7C9E00232D7F /* Product.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F38D7DF242C7C9E00232D7F /* Product.swift */; };
6267
0F38D7E2242C7C9E00232D7F /* Product.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F38D7DF242C7C9E00232D7F /* Product.swift */; };
@@ -158,11 +163,6 @@
158163
0F796C502449EA6000EA04D5 /* EntryAPITest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F6D3A84243F064900FCFEBC /* EntryAPITest.swift */; };
159164
0F796C532449EA8700EA04D5 /* Entry.json in Resources */ = {isa = PBXBuildFile; fileRef = 0F796C512449EA8700EA04D5 /* Entry.json */; };
160165
0F796C542449EA8700EA04D5 /* Entry.json in Resources */ = {isa = PBXBuildFile; fileRef = 0F796C512449EA8700EA04D5 /* Entry.json */; };
161-
0FB118B024596D16007662E7 /* Entry.json in Resources */ = {isa = PBXBuildFile; fileRef = 0F796C512449EA8700EA04D5 /* Entry.json */; };
162-
0FB118B124596D16007662E7 /* QueryOn.json in Resources */ = {isa = PBXBuildFile; fileRef = 0F50EA15244ED7F500E5D705 /* QueryOn.json */; };
163-
0FB118B224596D16007662E7 /* Asset.json in Resources */ = {isa = PBXBuildFile; fileRef = 0FFBB4462446F9A4000D2795 /* Asset.json */; };
164-
0FB118B324596D16007662E7 /* ContentType.json in Resources */ = {isa = PBXBuildFile; fileRef = 0F244F9C244062B4003C3F26 /* ContentType.json */; };
165-
0FB118B424596D16007662E7 /* SyncTest.json in Resources */ = {isa = PBXBuildFile; fileRef = 0F1DCC77243D9BBF00EED404 /* SyncTest.json */; };
166166
0FB4CAC924332C5200A385B1 /* ImageOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0FB4CAC824332C5200A385B1 /* ImageOperation.swift */; };
167167
0FB4CACA24332C5200A385B1 /* ImageOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0FB4CAC824332C5200A385B1 /* ImageOperation.swift */; };
168168
0FB4CACB24332C5200A385B1 /* ImageOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0FB4CAC824332C5200A385B1 /* ImageOperation.swift */; };
@@ -939,11 +939,11 @@
939939
isa = PBXResourcesBuildPhase;
940940
buildActionMask = 2147483647;
941941
files = (
942-
0FB118B424596D16007662E7 /* SyncTest.json in Resources */,
943-
0FB118B124596D16007662E7 /* QueryOn.json in Resources */,
944-
0FB118B324596D16007662E7 /* ContentType.json in Resources */,
945-
0FB118B024596D16007662E7 /* Entry.json in Resources */,
946-
0FB118B224596D16007662E7 /* Asset.json in Resources */,
942+
0F359995257BE30A00B3DB89 /* SyncTest.json in Resources */,
943+
0F359993257BE2D100B3DB89 /* Entry.json in Resources */,
944+
0F359994257BE2EE00B3DB89 /* QueryOn.json in Resources */,
945+
0F359991257BE29B00B3DB89 /* Asset.json in Resources */,
946+
0F359992257BE2A700B3DB89 /* ContentType.json in Resources */,
947947
0F4C0A87243C6990006604B7 /* config.json in Resources */,
948948
);
949949
runOnlyForDeploymentPostprocessing = 0;

Sources/Asset.swift

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,33 @@ public class Asset: CachePolicyAccessible {
2323
self.stack = stack
2424
}
2525

26+
/// Instance method to fetch `Asset` for specific locale.
27+
/// - Parameter locale: The code for fetching entry for locale.
28+
///
29+
/// - Returns: A `Asset` to enable chaining.
30+
///
31+
/// Example usage:
32+
/// ```
33+
/// let stack = Contentstack.stack(apiKey: apiKey,
34+
/// deliveryToken: deliveryToken,
35+
/// environment: environment)
36+
///
37+
/// // To retrive single asset with specific locale
38+
/// stack.asset(uid: assetUID).locale("en-us")
39+
/// .fetch { (result: Result<AssetModel, Error>, response: ResponseType) in
40+
/// switch result {
41+
/// case .success(let model):
42+
/// //Model retrive from API
43+
/// case .failure(let error):
44+
/// //Error Message
45+
/// }
46+
/// }
47+
/// ```
48+
public func locale(_ locale: String) -> Self {
49+
self.parameters["locale"] = locale
50+
return self
51+
}
52+
2653
/// To include the relative URLs of the assets in the response.
2754
/// - Returns: A `Asset` to enable chaining.
2855
///
@@ -48,6 +75,31 @@ public class Asset: CachePolicyAccessible {
4875
return self
4976
}
5077

78+
/// To include the fallback published content if specified locale content is not publish.
79+
/// - Returns: A `Asset` to enable chaining.
80+
///
81+
/// Example usage:
82+
/// ```
83+
/// let stack = Contentstack.stack(apiKey: apiKey,
84+
/// deliveryToken: deliveryToken,
85+
/// environment: environment)
86+
///
87+
/// // To retrive single asset with relative URL
88+
/// let asset = stack.asset(uid: assetUID).includeFallback()
89+
/// .fetch { (result: Result<AssetModel, Error>, response: ResponseType) in
90+
/// switch result {
91+
/// case .success(let model):
92+
/// //Model retrive from API
93+
/// case .failure(let error):
94+
/// //Error Message
95+
/// }
96+
/// }
97+
/// ```
98+
public func includeFallback() -> Asset {
99+
self.parameters[QueryParameter.includeFallback] = true
100+
return self
101+
}
102+
51103
/// To include the dimensions (height and width) of the image in the response.
52104
/// - Precondition: Supported image types: `JPG`, `GIF`, `PNG`, `WebP`, `BMP`, `TIFF`, `SVG`, and `PSD`.
53105
/// - Returns: A `Asset` to enable chaining.

Sources/AssetModel.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public final class AssetModel: AssetDecodable {
2929

3030
public var url: String
3131

32+
public var fields: [String: Any]?
33+
3234
public enum FieldKeys: String, CodingKey {
3335
case title, uid, url, dimension
3436
case fileName = "filename"
@@ -77,6 +79,9 @@ public final class AssetModel: AssetDecodable {
7779
createdBy = try container.decode(String.self, forKey: .createdBy)
7880
updatedAt = try container.decode(Date.self, forKey: .updatedAt)
7981
updatedBy = try container.decode(String.self, forKey: .updatedBy)
82+
83+
let containerFields = try decoder.container(keyedBy: JSONCodingKeys.self)
84+
fields = try containerFields.decode(Dictionary<String, Any>.self)
8085
}
8186

8287
public enum QueryableCodingKey: String, CodingKey {

Sources/ContentType.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class ContentType: CachePolicyAccessible {
5151

5252
/// To include Global Fields schema in ContentType response.
5353
/// - Returns: A `ContentType` to enable chaining.
54+
///
5455
/// Example usage:
5556
/// ```
5657
/// let stack = Contentstack.stack(apiKey: apiKey,

Sources/EntryModel.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
import Foundation
99

10-
public protocol EntryDecodable: EntryFields, FieldKeysQueryable, EndpointAccessible, Decodable {}
11-
1210
public protocol ContentTypeIncludable {
1311
var contentType: ContentTypeModel? { get set}
1412
}

Sources/EntryQuaryable.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ extension EntryQueryable {
141141
/// }
142142
/// }
143143
/// ```
144-
144+
145145
public func include(params: Query.Include) -> Self {
146146
if params.contains(Query.Include.count) {
147147
self.parameters[QueryParameter.includeCount] = true
@@ -157,6 +157,9 @@ extension EntryQueryable {
157157
if params.contains(Query.Include.refContentTypeUID) {
158158
self.parameters[QueryParameter.includeRefContentTypeUID] = true
159159
}
160+
if params.contains(Query.Include.fallback) {
161+
self.parameters[QueryParameter.includeFallback] = true
162+
}
160163
return self
161164
}
162165

Sources/Query.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,33 @@ public final class AssetQuery: BaseQuery {
445445
self.cachePolicy = stack.cachePolicy
446446
}
447447

448+
/// Instance method to fetch `Assets` for specific locale.
449+
/// - Parameter locale: The code for fetching entry for locale.
450+
///
451+
/// - Returns: A `AssetQuery` to enable chaining.
452+
///
453+
/// Example usage:
454+
/// ```
455+
/// let stack = Contentstack.stack(apiKey: apiKey,
456+
/// deliveryToken: deliveryToken,
457+
/// environment: environment)
458+
///
459+
/// // To retrive single asset with specific locale
460+
/// stack.asset().query().locale("en-us")
461+
/// .fetch { (result: Result<AssetModel, Error>, response: ResponseType) in
462+
/// switch result {
463+
/// case .success(let model):
464+
/// //Model retrive from API
465+
/// case .failure(let error):
466+
/// //Error Message
467+
/// }
468+
/// }
469+
/// ```
470+
public func locale(_ locale: String) -> Self {
471+
self.parameters["locale"] = locale
472+
return self
473+
}
474+
448475
/// Use this method to do a search on `Assets` which enables
449476
/// searching for entries based on value's for members of referenced entries.
450477
///
@@ -506,6 +533,9 @@ public final class AssetQuery: BaseQuery {
506533
if params.contains(.dimension) {
507534
self.parameters[QueryParameter.includeDimension] = true
508535
}
536+
if params.contains(.fallback) {
537+
self.parameters[QueryParameter.includeFallback] = true
538+
}
509539
return self
510540
}
511541
}

Sources/QueryParameter.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ internal enum QueryParameter {
6060
internal static let includeContentType = "include_content_type"
6161

6262
internal static let includeRefContentTypeUID = "include_reference_content_type_uid"
63+
64+
internal static let includeFallback = "include_fallback"
6365
}
6466

6567
extension Query {
@@ -88,12 +90,15 @@ extension Query {
8890
public static let globalField: Include = Include(rawValue: 1 << 3)
8991
/// To include Reference ContentType Uid in reference field in Entry response,
9092
public static let refContentTypeUID: Include = Include(rawValue: 1 << 4)
93+
/// Retrieve the published content of the fallback locale if an entry is not localized in specified locale.
94+
public static let fallback: Include = Include(rawValue: 1 << 5)
9195
/// To inclide all `Query.Include` values.
9296
public static let all: Include = [.count,
9397
.unpublished,
9498
.contentType,
9599
.globalField,
96-
.refContentTypeUID]
100+
.refContentTypeUID,
101+
.fallback]
97102
}
98103
}
99104

@@ -143,9 +148,12 @@ extension AssetQuery {
143148
/// To include the dimensions (height and width) of the image in the response.
144149
/// Supported image types: JPG, GIF, PNG, WebP, BMP, TIFF, SVG, and PSD.
145150
public static let dimension: Include = Include(rawValue: 1 << 2)
151+
/// Retrieve the published content of the fallback locale if an entry is not localized in specified locale.
152+
public static let fallback: Include = Include(rawValue: 1 << 3)
146153
/// To inclide all `AssetQuery.Include` values.
147154
public static let all: Include = [.count,
148155
.relativeURL,
149-
.dimension]
156+
.dimension,
157+
.fallback]
150158
}
151159
}

0 commit comments

Comments
 (0)