Skip to content

Commit

Permalink
makes Resource type conforming to Encodable protocol (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
matelo authored Mar 23, 2020
1 parent f0e581e commit 59402c4
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CONTENTFUL_SDK_VERSION=5.0.8
CONTENTFUL_SDK_VERSION=5.0.9
2 changes: 1 addition & 1 deletion Config.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CONTENTFUL_SDK_VERSION=5.0.8
CONTENTFUL_SDK_VERSION=5.0.9
33 changes: 21 additions & 12 deletions Contentful.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,7 @@
INFOPLIST_FILE = "$(SRCROOT)/Supporting Files/Info_tvOS.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 5.0.7;
MARKETING_VERSION = "${CONTENTFUL_SDK_VERSION}";
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.contentful.Contentful-tvOS";
Expand Down Expand Up @@ -1327,7 +1327,7 @@
INFOPLIST_FILE = "$(SRCROOT)/Supporting Files/Info_tvOS.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 5.0.7;
MARKETING_VERSION = "${CONTENTFUL_SDK_VERSION}";
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.contentful.Contentful-tvOS";
PRODUCT_NAME = Contentful;
Expand Down Expand Up @@ -1361,7 +1361,7 @@
INFOPLIST_FILE = "$(SRCROOT)/Supporting Files/Info_tvOS.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 5.0.7;
MARKETING_VERSION = "${CONTENTFUL_SDK_VERSION}";
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.contentful.Contentful-tvOS";
PRODUCT_NAME = Contentful;
Expand Down Expand Up @@ -1585,6 +1585,7 @@
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
CONTENTFUL_SDK_VERSION = "${CONTENTFUL_SDK_VERSION}";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -1595,7 +1596,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 5.0.7;
MARKETING_VERSION = "${CONTENTFUL_SDK_VERSION}";
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.contentful.Contentful;
PRODUCT_NAME = Contentful;
Expand All @@ -1614,6 +1615,7 @@
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
CONTENTFUL_SDK_VERSION = "${CONTENTFUL_SDK_VERSION}";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -1624,7 +1626,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 5.0.7;
MARKETING_VERSION = "${CONTENTFUL_SDK_VERSION}";
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = com.contentful.Contentful;
PRODUCT_NAME = Contentful;
Expand Down Expand Up @@ -1750,6 +1752,7 @@
CLANG_ANALYZER_NONNULL = YES;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CODE_SIGN_IDENTITY = "";
CONTENTFUL_SDK_VERSION = "${CONTENTFUL_SDK_VERSION}";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -1758,7 +1761,7 @@
INFOPLIST_FILE = "$(SRCROOT)/Supporting Files/Info_watchOS.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 5.0.7;
MARKETING_VERSION = "${CONTENTFUL_SDK_VERSION}";
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.contentful.Contentful-watchOS";
PRODUCT_NAME = Contentful;
Expand All @@ -1780,6 +1783,7 @@
CLANG_ANALYZER_NONNULL = YES;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CODE_SIGN_IDENTITY = "";
CONTENTFUL_SDK_VERSION = "${CONTENTFUL_SDK_VERSION}";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -1788,7 +1792,7 @@
INFOPLIST_FILE = "$(SRCROOT)/Supporting Files/Info_watchOS.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 5.0.7;
MARKETING_VERSION = "${CONTENTFUL_SDK_VERSION}";
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = "com.contentful.Contentful-watchOS";
PRODUCT_NAME = Contentful;
Expand All @@ -1811,6 +1815,7 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
CONTENTFUL_SDK_VERSION = "${CONTENTFUL_SDK_VERSION}";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -1821,7 +1826,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 5.0.7;
MARKETING_VERSION = "${CONTENTFUL_SDK_VERSION}";
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.contentful.Contentful-macOS";
PRODUCT_NAME = Contentful;
Expand All @@ -1842,6 +1847,7 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
CONTENTFUL_SDK_VERSION = "${CONTENTFUL_SDK_VERSION}";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -1852,7 +1858,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 5.0.7;
MARKETING_VERSION = "${CONTENTFUL_SDK_VERSION}";
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = "com.contentful.Contentful-macOS";
PRODUCT_NAME = Contentful;
Expand Down Expand Up @@ -1938,6 +1944,7 @@
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
CONTENTFUL_SDK_VERSION = "${CONTENTFUL_SDK_VERSION}";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -1951,7 +1958,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 5.0.7;
MARKETING_VERSION = "${CONTENTFUL_SDK_VERSION}";
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.contentful.Contentful;
PRODUCT_NAME = Contentful;
Expand Down Expand Up @@ -1992,6 +1999,7 @@
CLANG_ANALYZER_NONNULL = YES;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CODE_SIGN_IDENTITY = "";
CONTENTFUL_SDK_VERSION = "${CONTENTFUL_SDK_VERSION}";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -2003,7 +2011,7 @@
INFOPLIST_FILE = "$(SRCROOT)/Supporting Files/Info_watchOS.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 5.0.7;
MARKETING_VERSION = "${CONTENTFUL_SDK_VERSION}";
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.contentful.Contentful-watchOS";
PRODUCT_NAME = Contentful;
Expand All @@ -2026,6 +2034,7 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
CONTENTFUL_SDK_VERSION = "${CONTENTFUL_SDK_VERSION}";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -2039,7 +2048,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 5.0.7;
MARKETING_VERSION = "${CONTENTFUL_SDK_VERSION}";
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.contentful.Contentful-macOS";
PRODUCT_NAME = Contentful;
Expand Down
2 changes: 1 addition & 1 deletion Scripts/.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CONTENTFUL_SDK_VERSION=5.0.7
CONTENTFUL_SDK_VERSION=5.0.9
2 changes: 1 addition & 1 deletion Scripts/Config.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CONTENTFUL_SDK_VERSION=5.0.7
CONTENTFUL_SDK_VERSION=5.0.9
6 changes: 5 additions & 1 deletion Sources/Contentful/Resource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class DeletedResource: Resource, FlatResource, Decodable {
/// for the locale paramater (i.e "locale=*") during a fetch, the SDK will cache returned values for
/// all locales in moery. This class gives an interface to specify which locale should be used when
/// reading content from `Resource` instances that are in memory.
public class LocalizableResource: Resource, FlatResource, Decodable {
public class LocalizableResource: Resource, FlatResource, Codable {

/// System fields.
public let sys: Sys
Expand Down Expand Up @@ -154,6 +154,10 @@ public class LocalizableResource: Resource, FlatResource, Decodable {
selectedLocale: currentlySelectedLocale,
wasSelectedOnAPILevel: sys.locale != nil)
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(sys, forKey: .sys)
}

/// The keys used when representing a resource in JSON.
public enum CodingKeys: String, CodingKey {
Expand Down
27 changes: 19 additions & 8 deletions Sources/Contentful/Sys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Foundation
/// The system fields available on all resources in Contentful. At minimum,
/// all resources have an `id` and a `type` available. Entries and assets provide more information than
public struct Sys {

/// The unique identifier of the resource..
public let id: String

Expand Down Expand Up @@ -40,16 +39,15 @@ public struct Sys {
}

extension Sys: Decodable {

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

id = try container.decode(String.self, forKey: .id)
type = try container.decode(String.self, forKey: .type)
createdAt = try container.decodeIfPresent(Date.self, forKey: .createdAt)
updatedAt = try container.decodeIfPresent(Date.self, forKey: .updatedAt)
locale = try container.decodeIfPresent(String.self, forKey: .locale)
revision = try container.decodeIfPresent(Int.self, forKey: .revision)
id = try container.decode(String.self, forKey: .id)
type = try container.decode(String.self, forKey: .type)
createdAt = try container.decodeIfPresent(Date.self, forKey: .createdAt)
updatedAt = try container.decodeIfPresent(Date.self, forKey: .updatedAt)
locale = try container.decodeIfPresent(String.self, forKey: .locale)
revision = try container.decodeIfPresent(Int.self, forKey: .revision)
contentTypeInfo = try container.decodeIfPresent(Link.self, forKey: .contentType)
}

Expand All @@ -59,3 +57,16 @@ extension Sys: Decodable {
case id, type, createdAt, updatedAt, locale, revision, contentType
}
}

extension Sys: Encodable {
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
try container.encode(type, forKey: .type)
try container.encodeIfPresent(createdAt, forKey: .createdAt)
try container.encodeIfPresent(updatedAt, forKey: .updatedAt)
try container.encodeIfPresent(locale, forKey: .locale)
try container.encodeIfPresent(revision, forKey: .revision)
try container.encodeIfPresent(contentTypeInfo, forKey: .contentType)
}
}

0 comments on commit 59402c4

Please sign in to comment.