Skip to content

Commit 4a0f857

Browse files
authored
Merge pull request contentful#52 from contentful/develop
Develop
2 parents be98aa7 + 1a7c10b commit 4a0f857

37 files changed

+5196
-1397
lines changed

CHANGELOG.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
This project adheres to [Semantic Versioning](http://semver.org/) starting from 1.x releases.
5+
6+
## Unreleased
7+
8+
#### Planned
9+
- Further iteration on `ContentModellable` protocol.
10+
11+
#### Added
12+
- Swift'ier API for [Contentful Delivery API Search Parameters](https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters)
13+
- Mechanism for mapping responses to user-defined Swift types when using `QueryOn` queries.
14+
- Improved link resolving via the new `Link` type
15+
- Swift 3.1, Xcode 8.3 support.
16+
17+
#### Changed
18+
- **BREAKING:** `Contentful.Array` is now called `ArrayResponse` to avoid clashing with native Swift arrays.
19+
20+
#### Planned
21+
- Better support and Swift'ier API for [Images API](https://www.contentful.com/developers/docs/references/images-api/).
22+
23+
#### Changed
24+
- `fetch` methods no longer return tuples of `(URLSessionTask?, Observable)` and now simply return the observable.
25+
26+
---
27+
28+
## Table of contents
29+
30+
#### 0.x Releases
31+
- `0.3.x` Releases - [0.3.0](#030) | [0.3.1](#031)
32+
33+
---
34+
35+
## [`0.3.1`](https://github.com/contentful/contentful.swift/releases/tag/0.3.1)
36+
Released on 2017-02-03.
37+
38+
#### Added
39+
- Support for installation via Carthage on all of iOS, macOS, tvOS, & watchOS.
40+
41+
---
42+
43+
## [`0.3.0`](https://github.com/contentful/contentful.swift/releases/tag/0.3.0)
44+
Released 2017-01-08.
45+
46+
#### Changed
47+
- **BREAKING:** Upgrade to Swift 3 and Xcode 8. Versions of Swift < 3 and Xcode < 8 no longer supported.
48+

Cartfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
github "anviking/Decodable" ~> 0.5
21
github "JensRavens/Interstellar" ~> 2.0.0
2+
github "Hearst-DD/ObjectMapper" ~> 2.2
33

Cartfile.private

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
github "krzyzanowskim/CryptoSwift.git" ~> 0.6.7
2-
github "Quick/Nimble" ~> 5.1.1
1+
github "krzyzanowskim/CryptoSwift.git" ~> 0.6.8
2+
github "Quick/Nimble" ~> 6.1.0
33
github "venmo/DVR" ~> 1.0.0
44

Cartfile.resolved

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
github "Hearst-DD/ObjectMapper" "2.2.5"
12
github "JensRavens/Interstellar" "2.0.0"
2-
github "Quick/Nimble" "v5.1.1"
3-
github "anviking/Decodable" "v0.5.1"
4-
github "krzyzanowskim/CryptoSwift" "0.6.7"
3+
github "Quick/Nimble" "v6.1.0"
4+
github "krzyzanowskim/CryptoSwift" "0.6.8"
55
github "venmo/DVR" "v1.0.0"

Contentful.podspec

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Pod::Spec.new do |spec|
44
spec.name = "Contentful"
5-
spec.version = "0.3.1"
5+
spec.version = "0.4.0-beta1"
66
spec.summary = "Swift SDK for Contentful's Content Delivery API."
77
spec.homepage = "https://github.com/contentful/contentful.swift/"
88
spec.social_media_url = 'https://twitter.com/contentful'
@@ -18,13 +18,15 @@ Pod::Spec.new do |spec|
1818
spec.requires_arc = true
1919

2020
spec.source_files = 'Sources/*.swift'
21+
22+
spec.frameworks = 'CoreLocation'
2123

2224
spec.ios.deployment_target = '8.0'
2325
spec.osx.deployment_target = '10.10'
2426
spec.watchos.deployment_target = '2.0'
2527
spec.tvos.deployment_target = '9.0'
2628

27-
spec.dependency 'Decodable', '~> 0.5'
29+
spec.dependency 'ObjectMapper', '~> 2.2'
2830
spec.dependency 'Interstellar', '~> 2.0.0'
2931
end
3032

Contentful.xcodeproj/project.pbxproj

Lines changed: 107 additions & 71 deletions
Large diffs are not rendered by default.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PackageDescription
33
let package = Package(
44
name: "Contentful",
55
dependencies: [
6-
.Package(url: "https://github.com/anviking/Decodable", majorVersion: 0),
6+
.Package(url: "https://github.com/Hearst-DD/ObjectMapper", majorVersion: 2, minorVersion: 2),
77
.Package(url: "https://github.com/jensravens/Interstellar", majorVersion: 2)
88
],
99
exclude: ["Tests/"]

Sources/Array.swift

Lines changed: 0 additions & 33 deletions
This file was deleted.

Sources/ArrayResponse.swift

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
//
2+
// ArrayResponse.swift
3+
// Contentful
4+
//
5+
// Created by Boris Bügling on 18/08/15.
6+
// Copyright © 2015 Contentful GmbH. All rights reserved.
7+
//
8+
9+
import ObjectMapper
10+
11+
12+
internal protocol Array {
13+
14+
associatedtype ItemType
15+
16+
var items: [ItemType] { get }
17+
18+
var limit: UInt { get }
19+
20+
var skip: UInt { get }
21+
22+
var total: UInt { get }
23+
}
24+
25+
/**
26+
A list of resources in Contentful
27+
28+
This is the result type for any request of a collection of resources.
29+
See: <https://www.contentful.com/developers/docs/references/content-delivery-api/#/introduction/collection-resources-and-pagination>
30+
**/
31+
public struct ArrayResponse<ItemType>: Array, ImmutableMappable where ItemType: Resource {
32+
33+
/// The resources which are part of the given array
34+
public let items: [ItemType]
35+
36+
/// The maximum number of resources originally requested
37+
public let limit: UInt
38+
39+
/// The number of elements skipped when performing the request
40+
public let skip: UInt
41+
42+
/// The total number of resources which matched the original request
43+
public let total: UInt
44+
45+
internal let includedAssets: [Asset]?
46+
internal let includedEntries: [Entry]?
47+
48+
// MARK: <ImmutableMappable>
49+
50+
public init(map: Map) throws {
51+
52+
items = try map.value("items")
53+
limit = try map.value("limit")
54+
skip = try map.value("skip")
55+
total = try map.value("total")
56+
57+
includedAssets = try? map.value("includes.Asset")
58+
includedEntries = try? map.value("includes.Entry")
59+
60+
// Annoying workaround for type system not allowing cast of items to [Entry]
61+
let entries: [Entry] = items.flatMap { $0 as? Entry }
62+
63+
let allIncludedEntries = entries + (includedEntries ?? [])
64+
65+
// Rememember `Entry`s are classes (passed by reference) so we can change them in place
66+
for entry in allIncludedEntries {
67+
entry.resolveLinks(against: allIncludedEntries, and: (includedAssets ?? []))
68+
}
69+
}
70+
71+
}
72+
73+
/**
74+
A list of Contentful entries that have been mapped to types conforming to `EntryModellable`
75+
76+
See: <https://www.contentful.com/developers/docs/references/content-delivery-api/#/introduction/collection-resources-and-pagination>
77+
*/
78+
public struct MappedArrayResponse<ItemType>: Array where ItemType: EntryModellable {
79+
80+
/// The resources which are part of the given array
81+
public let items: [ItemType]
82+
83+
/// The maximum number of resources originally requested
84+
public let limit: UInt
85+
86+
/// The number of elements skipped when performing the request
87+
public let skip: UInt
88+
89+
/// The total number of resources which matched the original request
90+
public let total: UInt
91+
}
92+
93+
internal extension ArrayResponse where ItemType: Entry {
94+
95+
internal func toMappedArrayResponse<EntryType: EntryModellable>() -> MappedArrayResponse<EntryType> {
96+
let mappedItems = items.flatMap { entry in
97+
return EntryType(sys: entry.sys, fields: entry.fields, linkDepth: 20)
98+
}
99+
return MappedArrayResponse<EntryType>(items: mappedItems, limit: limit, skip: skip, total: total)
100+
}
101+
}

Sources/Asset.swift

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,19 @@
77
//
88

99
import Foundation
10+
import ObjectMapper
1011

1112
/// An asset represents a media file in Contentful
12-
public struct Asset: Resource, LocalizedResource {
13-
/// System fields
14-
public let sys: [String: Any]
13+
public class Asset: Resource, LocalizedResource {
14+
1515
/// Content fields
16-
public var fields: [String:Any] {
16+
public var fields: [String:Any]! {
1717
return Contentful.fields(localizedFields, forLocale: locale, defaultLocale: defaultLocale)
1818
}
1919

20-
let localizedFields: [String:[String:Any]]
21-
let defaultLocale: String
22-
23-
/// The unique identifier of this Asset
24-
public let identifier: String
20+
var localizedFields: [String: [String: Any]]
2521

26-
/// Resource type ("Asset")
27-
public let type: String
22+
let defaultLocale: String
2823

2924
/// Currently selected locale
3025
public var locale: String
@@ -41,4 +36,15 @@ public struct Asset: Resource, LocalizedResource {
4136

4237
throw SDKError.invalidURL(string: "")
4338
}
39+
40+
// MARK: - <ImmutableMappable>
41+
42+
public required init(map: Map) throws {
43+
let (locale, localizedFields) = try parseLocalizedFields(map.JSON)
44+
self.locale = locale
45+
self.defaultLocale = determineDefaultLocale(map.JSON)
46+
self.localizedFields = localizedFields
47+
48+
try super.init(map: map)
49+
}
4450
}

0 commit comments

Comments
 (0)