Skip to content

Commit

Permalink
Merge branch 'release/6.3.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
defagos committed Dec 4, 2018
2 parents 071798e + da8d393 commit 0f3506b
Show file tree
Hide file tree
Showing 15 changed files with 354 additions and 6 deletions.
38 changes: 38 additions & 0 deletions Framework/Sources/Model/SRGBroadcastInformation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// Copyright (c) SRG SSR. All rights reserved.
//
// License information is available from the LICENSE file.
//

#import "SRGModel.h"

NS_ASSUME_NONNULL_BEGIN

/**
* Broadcast information.
*/
@interface SRGBroadcastInformation : SRGModel

/**
* An information message.
*/
@property (nonatomic, readonly, copy) NSString *message;

/**
* The date at which the information has been made available.
*/
@property (nonatomic, readonly) NSDate *startDate;

/**
* The date at which the information will be removed.
*/
@property (nonatomic, readonly) NSDate *endDate;

/**
* A URL to an associated web page.
*/
@property (nonatomic, readonly, nullable) NSURL *URL;

@end

NS_ASSUME_NONNULL_END
56 changes: 56 additions & 0 deletions Framework/Sources/Model/SRGBroadcastInformation.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// Copyright (c) SRG SSR. All rights reserved.
//
// License information is available from the LICENSE file.
//

#import "SRGBroadcastInformation.h"

#import "SRGJSONTransformers.h"

#import <libextobjc/libextobjc.h>

@interface SRGBroadcastInformation ()

@property (nonatomic, copy) NSString *message;
@property (nonatomic) NSDate *startDate;
@property (nonatomic) NSDate *endDate;
@property (nonatomic, nullable) NSURL *URL;

@end

@implementation SRGBroadcastInformation

#pragma mark MTLJSONSerializing protocol

+ (NSDictionary *)JSONKeyPathsByPropertyKey
{
static NSDictionary *s_mapping;
static dispatch_once_t s_onceToken;
dispatch_once(&s_onceToken, ^{
s_mapping = @{ @keypath(SRGBroadcastInformation.new, message) : @"hintText",
@keypath(SRGBroadcastInformation.new, startDate) : @"startDate",
@keypath(SRGBroadcastInformation.new, endDate) : @"endDate",
@keypath(SRGBroadcastInformation.new, URL) : @"url" };
});
return s_mapping;
}

#pragma mark Transformers

+ (NSValueTransformer *)startDateJSONTransformer
{
return SRGISO8601DateJSONTransformer();
}

+ (NSValueTransformer *)endDateJSONTransformer
{
return SRGISO8601DateJSONTransformer();
}

+ (NSValueTransformer *)URLJSONTransformer
{
return [NSValueTransformer valueTransformerForName:MTLURLValueTransformerName];
}

@end
38 changes: 38 additions & 0 deletions Framework/Sources/Model/SRGServiceMessage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// Copyright (c) SRG SSR. All rights reserved.
//
// License information is available from the LICENSE file.
//

#import "SRGModel.h"

NS_ASSUME_NONNULL_BEGIN

/**
* A service status message.
*/
@interface SRGServiceMessage : SRGModel

/**
* The message unique identifier.
*/
@property (nonatomic, readonly, copy) NSString *uid;

/**
* The message text.
*/
@property (nonatomic, readonly, copy) NSString *text;

/**
* The message date.
*/
@property (nonatomic, readonly) NSDate *date;

/**
* A URL where additional information can be accessed.
*/
@property (nonatomic, readonly, nullable) NSURL *URL;

@end

NS_ASSUME_NONNULL_END
68 changes: 68 additions & 0 deletions Framework/Sources/Model/SRGServiceMessage.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// Copyright (c) SRG SSR. All rights reserved.
//
// License information is available from the LICENSE file.
//

#import "SRGServiceMessage.h"

#import "SRGJSONTransformers.h"

#import <libextobjc/libextobjc.h>

@interface SRGServiceMessage ()

@property (nonatomic, copy) NSString *uid;
@property (nonatomic, copy) NSString *text;
@property (nonatomic) NSDate *date;
@property (nonatomic) NSURL *URL;

@end

@implementation SRGServiceMessage

#pragma mark MTLJSONSerializing protocol

+ (NSDictionary *)JSONKeyPathsByPropertyKey
{
static NSDictionary *s_mapping;
static dispatch_once_t s_onceToken;
dispatch_once(&s_onceToken, ^{
s_mapping = @{ @keypath(SRGServiceMessage.new, uid) : @"id",
@keypath(SRGServiceMessage.new, text) : @"text",
@keypath(SRGServiceMessage.new, date) : @"modifyDate",
@keypath(SRGServiceMessage.new, URL) : @"url" };
});
return s_mapping;
}

#pragma mark Transformers

+ (NSValueTransformer *)dateJSONTransformer
{
return SRGISO8601DateJSONTransformer();
}

+ (NSValueTransformer *)URLJSONTransformer
{
return [NSValueTransformer valueTransformerForName:MTLURLValueTransformerName];
}

#pragma mark Equality

- (BOOL)isEqual:(id)object
{
if (! [object isKindOfClass:self.class]) {
return NO;
}

SRGServiceMessage *otherServiceMessage = object;
return [self.uid isEqualToString:otherServiceMessage.uid];
}

- (NSUInteger)hash
{
return self.uid.hash;
}

@end
10 changes: 8 additions & 2 deletions Framework/Sources/Model/SRGShow.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// License information is available from the LICENSE file.
//

#import "SRGBroadcastInformation.h"
#import "SRGImageMetadata.h"
#import "SRGMetadata.h"
#import "SRGModel.h"
Expand Down Expand Up @@ -44,12 +45,12 @@ OBJC_EXPORT SRGImageType const SRGImageTypeShowBanner; // Show banner i
@property (nonatomic, readonly, nullable) NSURL *podcastHighDefinitionURL;

/**
* The URL for podcast on Deezer.
* The Deezer podcast URL.
*/
@property (nonatomic, readonly, nullable) NSURL *podcastDeezerURL;

/**
* The URL for podcast on Spotify.
* The Spotify podcast URL.
*/
@property (nonatomic, readonly, nullable) NSURL *podcastSpotifyURL;

Expand All @@ -63,6 +64,11 @@ OBJC_EXPORT SRGImageType const SRGImageTypeShowBanner; // Show banner i
*/
@property (nonatomic, readonly) NSInteger numberOfEpisodes;

/**
* Broadcast information associated with the show.
*/
@property (nonatomic, readonly, nullable) SRGBroadcastInformation *broadcastInformation;

@end

NS_ASSUME_NONNULL_END
7 changes: 7 additions & 0 deletions Framework/Sources/Model/SRGShow.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ @interface SRGShow ()
@property (nonatomic, copy) NSString *primaryChannelUid;
@property (nonatomic) NSURL *bannerImageURL;
@property (nonatomic) NSInteger numberOfEpisodes;
@property (nonatomic) SRGBroadcastInformation *broadcastInformation;

@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *lead;
Expand Down Expand Up @@ -58,6 +59,7 @@ + (NSDictionary *)JSONKeyPathsByPropertyKey
@keypath(SRGShow.new, primaryChannelUid) : @"primaryChannelId",
@keypath(SRGShow.new, numberOfEpisodes) : @"numberOfEpisodes",
@keypath(SRGShow.new, bannerImageURL) : @"bannerImageUrl",
@keypath(SRGShow.new, broadcastInformation) : @"broadcastInformation",

@keypath(SRGShow.new, title) : @"title",
@keypath(SRGShow.new, lead) : @"lead",
Expand Down Expand Up @@ -117,6 +119,11 @@ + (NSValueTransformer *)bannerImageURLJSONTransformer
return [NSValueTransformer valueTransformerForName:MTLURLValueTransformerName];
}

+ (NSValueTransformer *)broadcastInformationJSONTransformer
{
return [MTLJSONAdapter dictionaryTransformerWithModelClass:SRGBroadcastInformation.class];
}

+ (NSValueTransformer *)transmissionJSONTransformer
{
return SRGTransmissionJSONTransformer();
Expand Down
17 changes: 17 additions & 0 deletions Framework/Sources/SRGDataProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "SRGAlbum.h"
#import "SRGArtist.h"
#import "SRGBaseTopic.h"
#import "SRGBroadcastInformation.h"
#import "SRGChannel.h"
#import "SRGChapter.h"
#import "SRGDataProvider.h"
Expand Down Expand Up @@ -42,6 +43,7 @@
#import "SRGSearchResultShow.h"
#import "SRGSection.h"
#import "SRGSegment.h"
#import "SRGServiceMessage.h"
#import "SRGShow.h"
#import "SRGShowIdentifierMetadata.h"
#import "SRGSocialCount.h"
Expand Down Expand Up @@ -71,6 +73,7 @@ typedef void (^SRGMediaCompletionBlock)(SRGMedia * _Nullable media, NSHTTPURLRes
typedef void (^SRGMediaCompositionCompletionBlock)(SRGMediaComposition * _Nullable mediaComposition, NSHTTPURLResponse * _Nullable HTTPResponse, NSError * _Nullable error);
typedef void (^SRGMediaListCompletionBlock)(NSArray<SRGMedia *> * _Nullable medias, NSHTTPURLResponse * _Nullable HTTPResponse, NSError * _Nullable error);
typedef void (^SRGModuleListCompletionBlock)(NSArray<SRGModule *> * _Nullable modules, NSHTTPURLResponse * _Nullable HTTPResponse, NSError * _Nullable error);
typedef void (^SRGServiceMessageCompletionBlock)(SRGServiceMessage * _Nullable serviceMessage, NSHTTPURLResponse * _Nullable HTTPResponse, NSError * _Nullable error);
typedef void (^SRGShowCompletionBlock)(SRGShow * _Nullable show, NSHTTPURLResponse * _Nullable HTTPResponse, NSError * _Nullable error);
typedef void (^SRGShowListCompletionBlock)(NSArray<SRGShow *> * _Nullable shows, NSHTTPURLResponse * _Nullable HTTPResponse, NSError * _Nullable error);
typedef void (^SRGSocialCountOverviewCompletionBlock)(SRGSocialCountOverview * _Nullable socialCountOverview, NSHTTPURLResponse * _Nullable HTTPResponse, NSError * _Nullable error);
Expand Down Expand Up @@ -556,6 +559,20 @@ typedef void (^SRGPaginatedSongListCompletionBlock)(NSArray<SRGSong *> * _Nullab

@end

/**
* General services supported by the data provider.
*/
@interface SRGDataProvider (GeneralServices)

/**
* Retrieve a message from the service about its status, if there is currently one. If none is available, the
* call ends with an HTTP error.
*/
- (SRGRequest *)serviceMessageForVendor:(SRGVendor)vendor
withCompletionBlock:(SRGServiceMessageCompletionBlock)completionBlock;

@end

/**
* List of services for popularity measurements supported by the data provider.
*/
Expand Down
11 changes: 11 additions & 0 deletions Framework/Sources/SRGDataProvider.m
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,17 @@ - (SRGRequest *)modulesForVendor:(SRGVendor)vendor
}];
}

#pragma mark General services

- (SRGRequest *)serviceMessageForVendor:(SRGVendor)vendor withCompletionBlock:(SRGServiceMessageCompletionBlock)completionBlock
{
NSString *resourcePath = [NSString stringWithFormat:@"2.0/%@/general/information.json", SRGPathComponentForVendor(vendor)];
NSURLRequest *URLRequest = [self URLRequestForResourcePath:resourcePath withQueryItems:nil];
return [self fetchObjectWithURLRequest:URLRequest modelClass:SRGServiceMessage.class completionBlock:^(id _Nullable object, SRGPage *page, SRGPage * _Nullable nextPage, NSHTTPURLResponse * _Nullable HTTPResponse, NSError * _Nullable error) {
completionBlock(object, HTTPResponse, error);
}];
}

#pragma mark Popularity services

- (SRGRequest *)increaseSocialCountForType:(SRGSocialCountType)type
Expand Down
Loading

0 comments on commit 0f3506b

Please sign in to comment.