Skip to content

Commit 36c92e3

Browse files
authored
Merge pull request #12 from contentstack/enhancement/add-header
Add header support added [CS-35612]
2 parents a5dd6f8 + c17e180 commit 36c92e3

23 files changed

+231
-39
lines changed

.env

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

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
name: Test macOS
1212
runs-on: macos-latest
1313
env:
14-
DEVELOPER_DIR: /Applications/Xcode_12.4.app/Contents/Developer
14+
DEVELOPER_DIR: /Applications/Xcode_14.2.app/Contents/Developer
1515
steps:
1616
- uses: actions/checkout@v1
1717
with:
@@ -29,7 +29,7 @@ jobs:
2929
name: Test iOS
3030
runs-on: macos-latest
3131
env:
32-
DEVELOPER_DIR: /Applications/Xcode_12.4.app/Contents/Developer
32+
DEVELOPER_DIR: /Applications/Xcode_14.2.app/Contents/Developer
3333
strategy:
3434
matrix:
3535
destination: ["OS=14.4,name=iPhone 13 Pro"]
@@ -49,7 +49,7 @@ jobs:
4949
name: Test tvOS
5050
runs-on: macos-latest
5151
env:
52-
DEVELOPER_DIR: /Applications/Xcode_12.4.app/Contents/Developer
52+
DEVELOPER_DIR: /Applications/Xcode_14.2.app/Contents/Developer
5353
strategy:
5454
matrix:
5555
destination: ["OS=14.3,name=Apple TV 4K"]
@@ -69,7 +69,7 @@ jobs:
6969
name: Test watchOS
7070
runs-on: macos-latest
7171
env:
72-
DEVELOPER_DIR: /Applications/Xcode_12.4.app/Contents/Developer
72+
DEVELOPER_DIR: /Applications/Xcode_14.2.app/Contents/Developer
7373
strategy:
7474
matrix:
7575
destination: ["OS=7.2,name=Apple Watch Series 6 - 44mm"]

.github/workflows/sca-scan.yml

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

Config.xcconfig

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

Contentstack.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,7 +2268,7 @@
22682268
TVOS_DEPLOYMENT_TARGET = 9.0;
22692269
VERSIONING_SYSTEM = "apple-generic";
22702270
VERSION_INFO_PREFIX = "";
2271-
WATCHOS_DEPLOYMENT_TARGET = 3.0;
2271+
WATCHOS_DEPLOYMENT_TARGET = 4.0;
22722272
};
22732273
name = Debug;
22742274
};
@@ -2344,7 +2344,7 @@
23442344
VALIDATE_PRODUCT = YES;
23452345
VERSIONING_SYSTEM = "apple-generic";
23462346
VERSION_INFO_PREFIX = "";
2347-
WATCHOS_DEPLOYMENT_TARGET = 3.0;
2347+
WATCHOS_DEPLOYMENT_TARGET = 4.0;
23482348
};
23492349
name = Release;
23502350
};

Contentstack.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2012-2022 Contentstack
3+
Copyright (c) 2012-2023 Contentstack
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Scripts/.env

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.4.0

Sources/Asset.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Foundation
1313
public class Asset: CachePolicyAccessible {
1414
public var cachePolicy: CachePolicy = .networkOnly
1515
internal var parameters: Parameters = [:]
16+
internal var headers: [String: String] = [:]
1617
internal var stack: Stack
1718

1819
/// Unique ID of the asset of which you wish to retrieve the details.
@@ -151,6 +152,33 @@ public class Asset: CachePolicyAccessible {
151152
}
152153
return query
153154
}
155+
156+
/// The Query parameters dictionary that are converted to `URLComponents`.
157+
/// - Parameters:
158+
/// - key: The key for header parameter,
159+
/// - value: The value for header parameter.
160+
///
161+
/// Example usage:
162+
/// ```
163+
/// let stack = Contentstack.stack(apiKey: apiKey,
164+
/// deliveryToken: deliveryToken,
165+
/// environment: environment)
166+
///
167+
/// // To fetch Assets
168+
/// stack.asset().addValue("value", forHTTPHeaderField: "header")
169+
/// .fetch { (result: Result<AssetModel, Error>, response: ResponseType) in
170+
/// switch result {
171+
/// case .success(let model):
172+
/// //Model retrive from API
173+
/// case .failure(let error):
174+
/// //Error Message
175+
/// }
176+
/// }
177+
/// ```
178+
public func addValue(_ value: String, forHTTPHeaderField field: String) -> Self {
179+
self.headers[field] = value
180+
return self
181+
}
154182
}
155183

156184
extension Asset: ResourceQueryable {
@@ -180,6 +208,7 @@ extension Asset: ResourceQueryable {
180208
self.stack.fetch(endpoint: ResourceType.endpoint,
181209
cachePolicy: self.cachePolicy,
182210
parameters: parameters + [QueryParameter.uid: uid],
211+
headers: headers,
183212
then: { (result: Result<ContentstackResponse<ResourceType>, Error>, response: ResponseType) in
184213
switch result {
185214
case .success(let contentStackResponse):

Sources/ContentType.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class ContentType: CachePolicyAccessible {
1818
var uid: String?
1919
internal var stack: Stack
2020
internal var parameters: Parameters = [:]
21+
internal var headers: [String: String] = [:]
2122
public var cachePolicy: CachePolicy = .networkOnly
2223

2324
internal required init(_ uid: String?, stack: Stack) {
@@ -98,6 +99,42 @@ public class ContentType: CachePolicyAccessible {
9899
}
99100
return query
100101
}
102+
103+
/// The Query parameters dictionary that are converted to `URLComponents`.
104+
/// - Parameters:
105+
/// - key: The key for header parameter,
106+
/// - value: The value for header parameter.
107+
///
108+
/// Example usage:
109+
/// ```
110+
/// let stack = Contentstack.stack(apiKey: apiKey,
111+
/// deliveryToken: deliveryToken,
112+
///
113+
/// // To fetch allContentTypes
114+
/// stack.contentType().addValue("value", forHTTPHeaderField: "header")
115+
/// .fetch { (result: Result<ContentstackResponse<ContentTypeModel>, Error>, response: ResponseType) in
116+
/// switch result {
117+
/// case .success(let contentstackResponse):
118+
/// // Contentstack response with ContentTypeModel array in items.
119+
/// case .failure(let error):
120+
/// //Error Message
121+
/// }
122+
/// }
123+
/// // To fetch Assets
124+
/// stack.asset().query().addValue("value", forHTTPHeaderField: "header")
125+
/// .fetch { (result: Result<ContentTypeModel, Error>, response: ResponseType) in
126+
/// switch result {
127+
/// case .success(let model):
128+
/// //Model retrive from API
129+
/// case .failure(let error):
130+
/// //Error Message
131+
/// }
132+
/// }
133+
/// ```
134+
public func addValue(_ value: String, forHTTPHeaderField field: String) -> Self {
135+
self.headers[field] = value
136+
return self
137+
}
101138
}
102139

103140
extension ContentType: ResourceQueryable {
@@ -127,6 +164,7 @@ extension ContentType: ResourceQueryable {
127164
self.stack.fetch(endpoint: ResourceType.endpoint,
128165
cachePolicy: self.cachePolicy,
129166
parameters: parameters + [QueryParameter.uid: uid],
167+
headers: headers,
130168
then: { (result: Result<ContentstackResponse<ResourceType>, Error>, response: ResponseType) in
131169
switch result {
132170
case .success(let contentStackResponse):

0 commit comments

Comments
 (0)