Skip to content

Commit 84b9800

Browse files
Vikram KaltaVikram Kalta
authored andcommitted
feat: added taxonomy initial support
1 parent 6b3f509 commit 84b9800

File tree

15 files changed

+208
-12
lines changed

15 files changed

+208
-12
lines changed

Contentstack.xcodeproj/project.pbxproj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
23A53F5A1E277CD3001DBE35 /* Contentstack.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 230B38C01C16E98B00444A14 /* Contentstack.framework */; };
9797
23B6F12A1B5662EE00A9E983 /* ISO8601DateFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 23B6F1281B5662EE00A9E983 /* ISO8601DateFormatter.m */; };
9898
4714B7D42C5EAFCC004E941E /* Taxonomy.m in Sources */ = {isa = PBXBuildFile; fileRef = 4714B7D32C5EAFCC004E941E /* Taxonomy.m */; };
99+
479EC6642C5FCBDC00C5630B /* Taxonomy.h in Headers */ = {isa = PBXBuildFile; fileRef = 4714B7D52C5EAFF5004E941E /* Taxonomy.h */; settings = {ATTRIBUTES = (Public, ); }; };
99100
565E11BB1BD76654005AD47F /* MMDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = 565E11AA1BD76654005AD47F /* MMDocument.m */; };
100101
565E11BC1BD76654005AD47F /* MMElement.m in Sources */ = {isa = PBXBuildFile; fileRef = 565E11AD1BD76654005AD47F /* MMElement.m */; };
101102
565E11BD1BD76654005AD47F /* MMGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 565E11AF1BD76654005AD47F /* MMGenerator.m */; };
@@ -497,6 +498,7 @@
497498
isa = PBXHeadersBuildPhase;
498499
buildActionMask = 2147483647;
499500
files = (
501+
479EC6642C5FCBDC00C5630B /* Taxonomy.h in Headers */,
500502
0F9C0FC8221ADAC90091205A /* NamespacedDependencies.h in Headers */,
501503
23A53F3C1E276C83001DBE35 /* CSIOAPIURLs.h in Headers */,
502504
23A53F3E1E276C83001DBE35 /* CSIOCoreHTTPNetworking.h in Headers */,
@@ -845,7 +847,7 @@
845847
ENABLE_TESTABILITY = YES;
846848
FRAMEWORK_SEARCH_PATHS = (
847849
"$(inherited)",
848-
"$(PROJECT_DIR)/ThirdPartyExtension",
850+
"$(PROJECT_DIR)/ThirdPartyExtension/**",
849851
);
850852
GCC_PREFIX_HEADER = ./Contentstack/ThirdPartyNamespaceHeader/NamespacedDependencies.h;
851853
INFOPLIST_FILE = Contentstack/Info.plist;
@@ -874,7 +876,7 @@
874876
DYLIB_INSTALL_NAME_BASE = "@rpath";
875877
FRAMEWORK_SEARCH_PATHS = (
876878
"$(inherited)",
877-
"$(PROJECT_DIR)/ThirdPartyExtension",
879+
"$(PROJECT_DIR)/ThirdPartyExtension/**",
878880
);
879881
GCC_PREFIX_HEADER = ./Contentstack/ThirdPartyNamespaceHeader/NamespacedDependencies.h;
880882
INFOPLIST_FILE = Contentstack/Info.plist;
@@ -923,7 +925,7 @@
923925
23A0F86A1B3801D1003334E9 /* Debug */ = {
924926
isa = XCBuildConfiguration;
925927
buildSettings = {
926-
ALWAYS_SEARCH_USER_PATHS = NO;
928+
ALWAYS_SEARCH_USER_PATHS = YES;
927929
BITCODE_GENERATION_MODE = marker;
928930
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
929931
CLANG_CXX_LIBRARY = "libc++";
@@ -978,7 +980,7 @@
978980
23A0F86B1B3801D1003334E9 /* Release */ = {
979981
isa = XCBuildConfiguration;
980982
buildSettings = {
981-
ALWAYS_SEARCH_USER_PATHS = NO;
983+
ALWAYS_SEARCH_USER_PATHS = YES;
982984
BITCODE_GENERATION_MODE = bitcode;
983985
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
984986
CLANG_CXX_LIBRARY = "libc++";
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

Contentstack/Contentstack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#import <Contentstack/Config.h>
1313
#import <Contentstack/Stack.h>
1414
#import <Contentstack/ContentType.h>
15+
#import <Contentstack/Taxonomy.h>
1516
#import <Contentstack/Entry.h>
1617
#import <Contentstack/Query.h>
1718
#import <Contentstack/Asset.h>

Contentstack/Entry.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ - (instancetype)initWithContentType:(ContentType*)contentType withEntryUID:(NSSt
4949
return self;
5050
}
5151

52+
- (instancetype)initWithTaxonomy:(Taxonomy *)taxonomy {
53+
if (self = [super init]) {
54+
_taxonomy = taxonomy;
55+
_localHeaders = [NSMutableDictionary dictionary];
56+
_objectProperties = [NSMutableDictionary dictionary];
57+
_postParamDictionary = [NSMutableDictionary dictionary];
58+
}
59+
return self;
60+
}
61+
5262
-(void)setLanguage:(Language)language {
5363
_language = language;
5464
[self setLocale:[self localeCode:language]];
@@ -63,6 +73,9 @@ - (instancetype)initWithContentType:(ContentType*)contentType {
6373
return [self initWithContentType:contentType withEntryUID:nil];
6474
}
6575

76+
//- (instancetype)initWithTaxonomy:(Taxonomy*)taxonomy {
77+
// return [self initWithTaxonomy:taxonomy];
78+
//}
6679
//MARK: - Headers -
6780

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

Contentstack/Query.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ This method provides all the entries for the specified language in the response.
130130
*/
131131
- (void)search:(NSString *)searchString;
132132

133+
- (void)query:(NSDictionary *)queryString;
134+
133135
//MARK: - Tags -
134136
/**---------------------------------------------------------------------------------------
135137
* @name Tags
@@ -759,6 +761,9 @@ This method provides all the entries from a specified contenttype.
759761
*/
760762
- (void)find:(void (^) (ResponseType type,QueryResult * BUILT_NULLABLE_P result,NSError * BUILT_NULLABLE_P error))completionBlock;
761763

764+
765+
- (void)findTaxonomy:(void (^) (ResponseType type,QueryResult * BUILT_NULLABLE_P result,NSError * BUILT_NULLABLE_P error))completionBlock;
766+
762767
/**
763768
This method provides the first entry from a specified contenttype.
764769

Contentstack/Query.m

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ - (instancetype)initWithContentType:(ContentType*)contentType {
4242

4343
- (instancetype)initWithTaxonomy:(Taxonomy*)taxonomy {
4444
if (self = [super init]) {
45+
_taxonomy = taxonomy;
4546
_localHeaders = [NSMutableDictionary dictionary];
4647
_queryDictionary = [NSMutableDictionary dictionary];
4748
_requestOperationSet = [NSMutableSet set];
@@ -94,6 +95,11 @@ - (void)tags:(NSArray*)tagsArray {
9495
[self.queryDictionary setObject:[tagsArray componentsJoinedByString:@","] forKey:kCSIO_Tags];
9596
}
9697

98+
//MARK: - Query -
99+
- (void)query:(NSDictionary *)query {
100+
[self.queryDictionary setObject:query forKey:kCSIO_Queryable];
101+
}
102+
97103
////MARK: - Before/After UID -
98104
//- (void)beforeUID:(NSString *)uid {
99105
// [self.queryDictionary setObject:uid forKey:kCSIO_BeforeUID];
@@ -511,6 +517,35 @@ - (void)find:(void (^) (ResponseType type,QueryResult * BUILT_NULLABLE_P result,
511517
}
512518
}
513519

520+
//MARK: Execute Query -
521+
522+
- (void)findTaxonomy:(void (^) (ResponseType type,QueryResult * BUILT_NULLABLE_P result,NSError * BUILT_NULLABLE_P error))completionBlock {
523+
524+
[self.queryDictionary setObject:self.taxonomy.stack.environment forKey:kCSIO_Environment];
525+
526+
NSMutableDictionary *paramDictionary = [NSMutableDictionary dictionaryWithDictionary:self.queryDictionary];
527+
528+
NSMutableDictionary *headers = [NSMutableDictionary dictionaryWithDictionary:self.taxonomy.headers];
529+
530+
[headers addEntriesFromDictionary:self.localHeaders];
531+
532+
NSString *path = [CSIOAPIURLs fetchTaxonomyWithVersion:self.taxonomy.stack.version];
533+
534+
NSURLSessionDataTask *op = [self.taxonomy.stack.network requestForStack:self.taxonomy.stack withURLPath:path requestType:CSIOCoreNetworkingRequestTypeGET params:paramDictionary additionalHeaders:headers cachePolicy:self.cachePolicy completion:^(ResponseType responseType, id responseJSON, NSError *error) {
535+
536+
if (error) {
537+
completionBlock(responseType, nil, error);
538+
}else {
539+
QueryResult *queryResult = [[QueryResult alloc] initWithTaxonomy:self.taxonomy objectDictionary:responseJSON];
540+
541+
completionBlock(responseType, queryResult, nil);
542+
}
543+
}];
544+
if (op && ![op isKindOfClass:[NSNull class]]) {
545+
[self.requestOperationSet addObject:op];
546+
}
547+
}
548+
514549
- (void)findOne:(void (^) (ResponseType type,Entry * BUILT_NULLABLE_P entry,NSError * BUILT_NULLABLE_P error))completionBlock {
515550
[self.queryDictionary setObject:@(1) forKey:kCSIO_Limit];
516551

Contentstack/QueryResult.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@
1212
BUILT_ASSUME_NONNULL_BEGIN
1313

1414
@class ContentType;
15+
@class Taxonomy;
1516
@class Entry;
1617
@interface QueryResult : NSObject
1718

1819

1920
- (instancetype)init UNAVAILABLE_ATTRIBUTE;
2021

22+
//- (BUILT_NULLABLE NSArray<Entry *> *)getResult;
23+
- (instancetype)initWithTaxonomy:(Taxonomy*)taxonomy objectDictionary:(NSDictionary*)dictionary;
24+
2125
//MARK: Result -
2226
/**---------------------------------------------------------------------------------------
2327
* @name Result

Contentstack/QueryResult.m

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import "CSIOInternalHeaders.h"
1111
#import "CSIOConstants.h"
1212
#import "ContentType.h"
13+
#import "Taxonomy.h"
1314
#import "Entry.h"
1415

1516
@interface QueryResult ()
@@ -30,6 +31,17 @@ - (instancetype)initWithContentType:(ContentType*)contentType objectDictionary:(
3031
return self;
3132
}
3233

34+
- (instancetype)initWithTaxonomy:(Taxonomy*)taxonomy objectDictionary:(NSDictionary*)dictionary{
35+
if (self = [super init]) {
36+
self.taxonomy = taxonomy;
37+
self.resultsDictionary = [NSMutableDictionary dictionary];
38+
if (dictionary) {
39+
[self.resultsDictionary addEntriesFromDictionary:dictionary];
40+
}
41+
}
42+
return self;
43+
}
44+
3345
- (NSInteger)totalCount {
3446

3547
if ([self.resultsDictionary objectForKey:kCSIO_Count]) {
@@ -55,7 +67,13 @@ - (NSInteger)totalCount {
5567
NSArray *objectsArray = (NSArray*)[self.resultsDictionary objectForKey:kCSIO_Entries];
5668
NSMutableArray *entryObjects = [NSMutableArray array];
5769
// if condition is fix for value of "entries" key ie.array inside array in response JSON
58-
if (objectsArray.firstObject && [objectsArray.firstObject isKindOfClass:[NSArray class]]) {
70+
if (objectsArray.firstObject && [objectsArray.firstObject isKindOfClass:[NSDictionary class]]) {
71+
[objectsArray enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL * _Nonnull stop) {
72+
Entry *formEntry = [self.taxonomy entry];
73+
[formEntry configureWithDictionary:obj];
74+
[entryObjects addObject:formEntry];
75+
}];
76+
} else if (objectsArray.firstObject && [objectsArray.firstObject isKindOfClass:[NSArray class]]) {
5977
[objectsArray enumerateObjectsUsingBlock:^(NSArray *obj, NSUInteger idx, BOOL * _Nonnull stop) {
6078
[obj enumerateObjectsUsingBlock:^(NSDictionary *objDict, NSUInteger idx, BOOL * _Nonnull stop) {
6179
Entry *formEntry = [self.contentType entry];

Contentstack/Stack.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
@class Config;
1313
@class ContentType;
14+
@class Taxonomy;
1415
@class AssetLibrary;
1516
@class Asset;
1617
@class SyncStack;
@@ -65,6 +66,8 @@ BUILT_ASSUME_NONNULL_BEGIN
6566
*/
6667
- (ContentType *)contentTypeWithName:(NSString *)contentTypeName;
6768

69+
- (Taxonomy *)taxonomy;
70+
6871
//MARK: - Manually set headers
6972
/**---------------------------------------------------------------------------------------
7073
* @name Manually set headers

Contentstack/Stack.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#import "CSIOConstants.h"
1212
#import "CSIOCoreHTTPNetworking.h"
1313
#import "ContentType.h"
14+
#import "Taxonomy.h"
1415
#import "CSIOAPIURLs.h"
1516
#import "NSObject+Extensions.h"
1617

@@ -86,6 +87,12 @@ -(ContentType*)contentTypeWithName:(NSString*)contentTypeName; {
8687
return contentType;
8788
}
8889

90+
//MARK: - Taxonomy
91+
-(Taxonomy*)taxonomy {
92+
Taxonomy *taxonomy = [[Taxonomy alloc] initWithStack:self];
93+
return taxonomy;
94+
}
95+
8996
//MARK: - Asset
9097

9198
-(Asset *)asset {

0 commit comments

Comments
 (0)