Skip to content

Commit 3c87b78

Browse files
Vikram KaltaVikram Kalta
authored andcommitted
feat: added support for taxonomy
1 parent 9154ab2 commit 3c87b78

9 files changed

Lines changed: 239 additions & 18 deletions

File tree

Contentstack.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
23A53F501E277BBE001DBE35 /* NSObject+Extensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 23A53F331E276BA5001DBE35 /* NSObject+Extensions.m */; };
9696
23A53F5A1E277CD3001DBE35 /* Contentstack.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 230B38C01C16E98B00444A14 /* Contentstack.framework */; };
9797
23B6F12A1B5662EE00A9E983 /* ISO8601DateFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 23B6F1281B5662EE00A9E983 /* ISO8601DateFormatter.m */; };
98+
4714B7D42C5EAFCC004E941E /* Taxonomy.m in Sources */ = {isa = PBXBuildFile; fileRef = 4714B7D32C5EAFCC004E941E /* Taxonomy.m */; };
9899
565E11BB1BD76654005AD47F /* MMDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = 565E11AA1BD76654005AD47F /* MMDocument.m */; };
99100
565E11BC1BD76654005AD47F /* MMElement.m in Sources */ = {isa = PBXBuildFile; fileRef = 565E11AD1BD76654005AD47F /* MMElement.m */; };
100101
565E11BD1BD76654005AD47F /* MMGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 565E11AF1BD76654005AD47F /* MMGenerator.m */; };
@@ -207,6 +208,8 @@
207208
23B6F1281B5662EE00A9E983 /* ISO8601DateFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ISO8601DateFormatter.m; sourceTree = "<group>"; };
208209
23C545FB1C1976FE007BBD27 /* ios-build-framework-script.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = "ios-build-framework-script.sh"; sourceTree = "<group>"; };
209210
3CF581B9F7526EDA48ED5C6F /* Pods-ContentstackTest.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ContentstackTest.debug.xcconfig"; path = "Target Support Files/Pods-ContentstackTest/Pods-ContentstackTest.debug.xcconfig"; sourceTree = "<group>"; };
211+
4714B7D32C5EAFCC004E941E /* Taxonomy.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Taxonomy.m; sourceTree = "<group>"; };
212+
4714B7D52C5EAFF5004E941E /* Taxonomy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Taxonomy.h; sourceTree = "<group>"; };
210213
565E11A91BD76654005AD47F /* MMDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MMDocument.h; sourceTree = "<group>"; };
211214
565E11AA1BD76654005AD47F /* MMDocument.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MMDocument.m; sourceTree = "<group>"; };
212215
565E11AB1BD76654005AD47F /* MMDocument_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MMDocument_Private.h; sourceTree = "<group>"; };
@@ -315,6 +318,8 @@
315318
0FD6BAEE29CD6E73001A0930 /* CSURLSessionDelegate.h */,
316319
0F9C0FAF221ADAC90091205A /* ThirdPartyNamespaceHeader */,
317320
230B38C41C16E98B00444A14 /* Info.plist */,
321+
4714B7D32C5EAFCC004E941E /* Taxonomy.m */,
322+
4714B7D52C5EAFF5004E941E /* Taxonomy.h */,
318323
);
319324
path = Contentstack;
320325
sourceTree = "<group>";
@@ -769,6 +774,7 @@
769774
230B38EA1C16EB4400444A14 /* MMScanner.m in Sources */,
770775
230B38E81C16EB4400444A14 /* MMMarkdown.m in Sources */,
771776
230B38E91C16EB4400444A14 /* MMParser.m in Sources */,
777+
4714B7D42C5EAFCC004E941E /* Taxonomy.m in Sources */,
772778
230B38E51C16EB4400444A14 /* MMElement.m in Sources */,
773779
230B39021C16EB8F00444A14 /* ISO8601DateFormatter.m in Sources */,
774780
230B38E61C16EB4400444A14 /* MMGenerator.m in Sources */,

Contentstack.xcodeproj/xcshareddata/xcschemes/Contentstack.xcscheme

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
2929
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<MacroExpansion>
31+
<BuildableReference
32+
BuildableIdentifier = "primary"
33+
BlueprintIdentifier = "230B38BF1C16E98B00444A14"
34+
BuildableName = "Contentstack.framework"
35+
BlueprintName = "Contentstack"
36+
ReferencedContainer = "container:Contentstack.xcodeproj">
37+
</BuildableReference>
38+
</MacroExpansion>
3039
<Testables>
3140
<TestableReference
3241
skipped = "NO">
@@ -39,20 +48,9 @@
3948
</BuildableReference>
4049
</TestableReference>
4150
</Testables>
42-
<MacroExpansion>
43-
<BuildableReference
44-
BuildableIdentifier = "primary"
45-
BlueprintIdentifier = "230B38BF1C16E98B00444A14"
46-
BuildableName = "Contentstack.framework"
47-
BlueprintName = "Contentstack"
48-
ReferencedContainer = "container:Contentstack.xcodeproj">
49-
</BuildableReference>
50-
</MacroExpansion>
51-
<AdditionalOptions>
52-
</AdditionalOptions>
5351
</TestAction>
5452
<LaunchAction
55-
buildConfiguration = "Release"
53+
buildConfiguration = "Debug"
5654
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
5755
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
5856
launchStyle = "0"
@@ -70,11 +68,9 @@
7068
ReferencedContainer = "container:Contentstack.xcodeproj">
7169
</BuildableReference>
7270
</MacroExpansion>
73-
<AdditionalOptions>
74-
</AdditionalOptions>
7571
</LaunchAction>
7672
<ProfileAction
77-
buildConfiguration = "Release"
73+
buildConfiguration = "Debug"
7874
shouldUseLaunchSchemeArgsEnv = "YES"
7975
savedToolIdentifier = ""
8076
useCustomWorkingDirectory = "NO"
@@ -93,7 +89,7 @@
9389
buildConfiguration = "Debug">
9490
</AnalyzeAction>
9591
<ArchiveAction
96-
buildConfiguration = "Release"
92+
buildConfiguration = "Debug"
9793
revealArchiveInOrganizer = "YES">
9894
</ArchiveAction>
9995
</Scheme>

Contentstack/Query.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#import "CSIOAPIURLs.h"
1313
#import "QueryResult.h"
1414
#import "ContentType.h"
15+
#import "Taxonomy.h"
1516
#import "CSIOInternalHeaders.h"
1617
#import "NSObject+Extensions.h"
1718

@@ -39,6 +40,15 @@ - (instancetype)initWithContentType:(ContentType*)contentType {
3940
return self;
4041
}
4142

43+
- (instancetype)initWithTaxonomy:(Taxonomy*)taxonomy {
44+
if (self = [super init]) {
45+
_localHeaders = [NSMutableDictionary dictionary];
46+
_queryDictionary = [NSMutableDictionary dictionary];
47+
_requestOperationSet = [NSMutableSet set];
48+
}
49+
return self;
50+
}
51+
4252
//MARK: - Headers
4353

4454
- (void)setHeader:(NSString *)headerValue forKey:(NSString *)headerKey {

Contentstack/Taxonomy.h

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
//
2+
// Taxonomy.h
3+
// Contentstack
4+
//
5+
// Created by Vikram Kalta on 27/07/2024.
6+
// Copyright © 2024 Contentstack. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "ContentstackDefinitions.h"
11+
12+
@class Query;
13+
14+
BUILT_ASSUME_NONNULL_BEGIN
15+
16+
@interface Taxonomy : NSObject
17+
18+
- (instancetype)init UNAVAILABLE_ATTRIBUTE;
19+
20+
//MARK: - Manually set headers
21+
/**---------------------------------------------------------------------------------------
22+
* @name Manually set headers
23+
* ---------------------------------------------------------------------------------------
24+
*/
25+
26+
/**
27+
Set a header for ContentType
28+
29+
//Obj-C
30+
[contentTypeObj setHeader:@"MyValue" forKey:@"My-Custom-Header"];
31+
//Swift
32+
contentTypeObj.setHeader("MyValue", forKey: "My-Custom-Header")
33+
@param headerValue The header key
34+
@param headerKey The header value
35+
*/
36+
- (void)setHeader:(NSString *)headerValue forKey:(NSString *)headerKey;
37+
/**
38+
Set a header for ContentType
39+
40+
//Obj-C
41+
[contentTypeObj addHeadersWithDictionary:@{@"My-Custom-Header": @"MyValue"}];
42+
43+
//Swift
44+
contentTypeObj.addHeadersWithDictionary(["My-Custom-Header":"MyValue"])
45+
46+
47+
@param headers The headers as dictionary which needs to be added to the application
48+
*/
49+
- (void)addHeadersWithDictionary:(NSDictionary<NSString *, NSString *> *)headers;
50+
/**
51+
Removes a header from this ContentType.
52+
53+
//Obj-C
54+
[contentTypeObj removeHeaderForKey:@"My-Custom-Header"];
55+
56+
//Swift
57+
contentTypeObj.removeHeaderForKey("My-Custom-Header")
58+
59+
@param headerKey The header key that needs to be removed
60+
*/
61+
- (void)removeHeaderForKey:(NSString *)headerKey;
62+
//MARK: - Query
63+
/**---------------------------------------------------------------------------------------
64+
* @name Query
65+
* ---------------------------------------------------------------------------------------
66+
*/
67+
68+
/**
69+
Represents a Query on 'ContentType' which can be executed to retrieve entries that pass the query condition
70+
//Obj-C
71+
Query *queryObj = [contentTypeObj query];
72+
73+
//Swift
74+
var queryObj:Query = contentTypeObj.query()
75+
76+
@return Returns new Query instance
77+
*/
78+
- (Query*)query;
79+
80+
//MARK: - Content-Type Schema
81+
/**---------------------------------------------------------------------------------------
82+
* @name ContentType Schema
83+
* ---------------------------------------------------------------------------------------
84+
*/
85+
/**
86+
Gets ContentType Schema defination.
87+
88+
//Obj-C
89+
90+
ContentType * contentType = [stack contentTypeWithName:@"<content_type_id>"]
91+
[contentType fetch:params completion:^(NSDictionary * _Nullable contentType, NSError * _Nullable error) {
92+
93+
}];
94+
95+
//Swift
96+
97+
let contentType = stack.contentTypeWithName("<content_type_id>")
98+
contentType.fetch(params, { (contentType, error) in
99+
100+
})
101+
@param completionBlock block to be called once operation is done.
102+
*/
103+
- (void)fetch:(NSDictionary<NSString *, id> * _Nullable)params completion:(void (^)(NSDictionary<NSString *, NSString *> *
104+
BUILT_NULLABLE_P contentType,
105+
NSError * BUILT_NULLABLE_P error))completionBlock;
106+
@end
107+
108+
BUILT_ASSUME_NONNULL_END

Contentstack/Taxonomy.m

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//
2+
// Taxonomy.m
3+
// Contentstack
4+
//
5+
// Created by Vikram Kalta on 27/07/2024.
6+
// Copyright © 2024 Contentstack. All rights reserved.
7+
//
8+
9+
#import "Taxonomy.h"
10+
#import "CSIOInternalHeaders.h"
11+
#import "CSIOConstants.h"
12+
#import "CSIOCoreHTTPNetworking.h"
13+
#import "CSIOAPIURLs.h"
14+
#import "NSObject+Extensions.h"
15+
#import "Stack.h"
16+
#import "Query.h"
17+
18+
@interface Taxonomy ()
19+
@property (nonatomic, strong, getter=stack) Stack *csStack;
20+
@end
21+
22+
@implementation Taxonomy
23+
24+
-(instancetype)initWithStack:(Stack*)stack {
25+
if (self = [super init]) {
26+
_csStack = stack;
27+
_postParamDictionary = [NSMutableDictionary dictionary];
28+
_headers = [NSMutableDictionary dictionary];
29+
}
30+
return self;
31+
}
32+
33+
-(Query*)query {
34+
Query *query = [[Query alloc] initWithTaxonomy:self];
35+
return query;
36+
}
37+
38+
//MARK: - Headers
39+
- (void)setHeader:(NSString *)headerValue forKey:(NSString *)headerKey {
40+
[self.headers setObject:headerValue forKey:headerKey];
41+
}
42+
43+
- (void)addHeadersWithDictionary:(NSDictionary<NSString *,NSString *> *)headers {
44+
[headers enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
45+
[self.headers setObject:obj forKey:key];
46+
}];
47+
}
48+
49+
- (void)removeHeaderForKey:(NSString *)headerKey {
50+
if (self.headers[headerKey]) {
51+
[self.headers removeObjectForKey:headerKey];
52+
}
53+
}
54+
//MARK: - Get entries
55+
- (void)fetch:(NSDictionary<NSString *, id> * _Nullable)params completion:(void (^)(NSDictionary<NSString *,NSString *> * _Nullable,
56+
NSError * _Nullable))completionBlock {
57+
NSString *path = [CSIOAPIURLs fetchTaxonomyWithVersion:self.stack.version];
58+
[self.postParamDictionary setObject:_csStack.environment forKey:kCSIO_Environment];
59+
60+
NSMutableDictionary *paramDictionary = [NSMutableDictionary dictionaryWithDictionary:self.postParamDictionary];
61+
for (NSString* key in params) {
62+
[paramDictionary setValue:[params valueForKey:key] forKey:key];
63+
}
64+
65+
NSURLSessionDataTask *op = [self.stack.network requestForStack:self.stack withURLPath:path requestType:CSIOCoreNetworkingRequestTypeGET params:paramDictionary additionalHeaders:self.stack.stackHeaders completion:^(ResponseType responseType, id responseJSON, NSError *error) {
66+
if (completionBlock) {
67+
if (error) {
68+
completionBlock(nil, error);
69+
} else {
70+
NSDictionary *responseData = responseJSON;
71+
if ([[responseData allKeys] containsObject:@"entries"] && [responseData objectForKey:@"entries"] != nil && [[responseData objectForKey:@"entries"] isKindOfClass:[NSDictionary class]]) {
72+
completionBlock([responseData objectForKey:@"entries"], nil);
73+
} else {
74+
NSError *error = [NSError errorWithDomain:@"Error" code:-4001 userInfo:@{@"error": @"Failed to retrieve data"}];
75+
completionBlock(nil, error);
76+
}
77+
}
78+
}
79+
}];
80+
81+
if (op && ![op isKindOfClass:[NSNull class]]) {
82+
[self.stack.requestOperationSet addObject:op];
83+
}
84+
}
85+
@end

ContentstackInternal/CSIOAPIURLs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
//Content Type
2121
+(NSString *)fetchContenTypeSchema:(NSString*)contentTypeUID withVersion:(NSString*)version;
2222

23+
//Taxonomy
24+
+(NSString *)fetchTaxonomyWithVersion:(NSString*)version;
25+
2326
//Entry
2427
+ (NSString *)fetchEntryURLWithContentTypeUID:(NSString *)contentTypeUID entryUID:(NSString*)entryUID withVersion:(NSString*)version;
2528

ContentstackInternal/CSIOAPIURLs.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ @implementation CSIOAPIURLs
3030
// sync
3131
static NSString *syncData = @"/%@/stacks/sync";
3232

33+
// Taxonomy
34+
static NSString *fetchTaxonomyWithVersion = @"/%@/taxonomies/%@/entries";
35+
3336
//MARK: Methods -
3437

3538
//stack

ContentstackInternal/CSIOInternalHeaders.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#import <Contentstack/Stack.h>
1313
#import "Query.h"
1414
#import "ContentType.h"
15+
#import "Taxonomy.h"
1516
#import "Entry.h"
1617
#import "Asset.h"
1718
#import "QueryResult.h"
@@ -47,7 +48,7 @@
4748
@property (nonatomic, strong) ContentType *contentType;
4849
- (instancetype)initWithContentType:(ContentType *)contentType;
4950
@property (nonatomic, strong) NSMutableDictionary *queryDictionary;
50-
51+
- (instancetype)initWithTaxonomy:(Taxonomy *)taxonomy;
5152
@end
5253

5354
@interface QueryResult ()
@@ -73,6 +74,15 @@
7374
- (instancetype)initWithContentType:(ContentType *)contentType withEntryUID:(NSString*)uid;
7475

7576
@end
77+
78+
@interface Taxonomy ()
79+
@property (nonatomic, strong) NSMutableDictionary *headers;
80+
@property (nonatomic, strong) NSMutableDictionary *postParamDictionary;
81+
82+
-(instancetype)initWithStack:(Stack *)stack;
83+
-(Stack *)stack;
84+
@end
85+
7686
@interface Asset ()
7787
- (instancetype)initWithStack:(Stack *)stack;
7888
- (instancetype)initWithStack:(Stack *)stack withAssetUID:(NSString*)assetUID;

Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
PODFILE CHECKSUM: e70b33906e829ccd2b052bc0e0cff91ee8ee49e6
22

3-
COCOAPODS: 1.15.0
3+
COCOAPODS: 1.14.3

0 commit comments

Comments
 (0)