This PR contains all the work related to setting up this project as required to implement the [Assignment](https://repo.rock-n-code.com/rock-n-code/deep-linking-assignment/wiki/Assignment) on top, as intended. To summarise this work: - [x] created a new **Xcode** project; - [x] cloned the `Wikipedia` app and inserted it into the **Xcode** project; - [x] created the `Locations` app and also, its `Libraries` package; - [x] created the `Shared` package to share dependencies between the apps; - [x] added a `Makefile` file and implemented some **environment** and **help** commands. Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Reviewed-on: rock-n-code/deep-linking-assignment#1
56 lines
2.3 KiB
Objective-C
56 lines
2.3 KiB
Objective-C
#import "WMFOnThisDayEventsFetcher.h"
|
|
#import "WMFFeedOnThisDayEvent.h"
|
|
#import <WMF/WMF-Swift.h>
|
|
#import <WMF/WMFLegacySerializer.h>
|
|
|
|
@implementation WMFOnThisDayEventsFetcher
|
|
|
|
+ (NSSet<NSString *> *)supportedLanguages {
|
|
static dispatch_once_t onceToken;
|
|
static NSSet<NSString *> *supportedLanguages;
|
|
dispatch_once(&onceToken, ^{
|
|
supportedLanguages = [NSSet setWithObjects:@"en", @"de", @"sv", @"fr", @"es", @"ru", @"pt", @"ar", @"uk", nil];
|
|
});
|
|
return supportedLanguages;
|
|
}
|
|
|
|
+ (BOOL)isOnThisDaySupportedByLanguage:(NSString *)languageCode {
|
|
return [[WMFOnThisDayEventsFetcher supportedLanguages] containsObject:languageCode];
|
|
}
|
|
|
|
- (void)fetchOnThisDayEventsForURL:(NSURL *)siteURL month:(NSUInteger)month day:(NSUInteger)day failure:(WMFErrorHandler)failure success:(void (^)(NSArray<WMFFeedOnThisDayEvent *> *announcements))success {
|
|
NSParameterAssert(siteURL);
|
|
if (siteURL == nil || siteURL.wmf_languageCode == nil || ![WMFOnThisDayEventsFetcher isOnThisDaySupportedByLanguage:siteURL.wmf_languageCode] || month < 1 || day < 1) {
|
|
NSError *error = [WMFFetcher invalidParametersError];
|
|
failure(error);
|
|
return;
|
|
}
|
|
|
|
NSString *monthString = [NSString stringWithFormat:@"%lu", (unsigned long)month];
|
|
NSString *dayString = [NSString stringWithFormat:@"%lu", (unsigned long)day];
|
|
NSArray<NSString *> *path = @[@"feed", @"onthisday", @"events", monthString, dayString];
|
|
NSURL *url = [self.configuration feedContentAPIURLForURL:siteURL appendingPathComponents:path];
|
|
[self.session getJSONDictionaryFromURL:url ignoreCache:YES completionHandler:^(NSDictionary<NSString *,id> * _Nullable result, NSHTTPURLResponse * _Nullable response, NSError * _Nullable error) {
|
|
if (error) {
|
|
failure(error);
|
|
return;
|
|
}
|
|
|
|
if (response.statusCode == 304) {
|
|
failure([WMFFetcher noNewDataError]);
|
|
return;
|
|
}
|
|
|
|
NSError *serializerError = nil;
|
|
NSArray *events = [WMFLegacySerializer modelsOfClass:[WMFFeedOnThisDayEvent class] fromArrayForKeyPath:@"events" inJSONDictionary:result languageVariantCode: url.wmf_languageVariantCode error:&serializerError];
|
|
if (serializerError) {
|
|
failure(serializerError);
|
|
return;
|
|
}
|
|
|
|
success(events);
|
|
}];
|
|
}
|
|
|
|
@end
|