Skip to content

Commit

Permalink
adding api to init SQRLi to init in CDN mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Moenicke authored and MarshallOfSound committed Jan 10, 2018
1 parent 3f398df commit db58a91
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
21 changes: 20 additions & 1 deletion Squirrel/SQRLUpdater.h
Expand Up @@ -67,6 +67,12 @@ extern NSString * const SQRLUpdaterJSONObjectErrorKey;
@class RACDisposable;
@class RACSignal;

/// Type of mode used to download the release
typedef enum {
JSONFILE=1,
RELEASESERVER
} SQRLUpdaterMode;

// Checks for, downloads, and installs updates.
@interface SQRLUpdater : NSObject

Expand Down Expand Up @@ -123,6 +129,19 @@ extern NSString * const SQRLUpdaterJSONObjectErrorKey;
// Returns the initialized `SQRLUpdater`.
- (id)initWithUpdateRequest:(NSURLRequest *)updateRequest;

// Initializes an updater that will send the given request to check for updates
// on a CDN reading a release file in json format.
//
// updateRequest - A request to send to check for updates. This request can be
// customized as desired, like by including an `Authorization`
// header to authenticate with a private update server, or
// pointing to a local URL for testing. This must not be nil.
// forVersion - the currently installed version
//
// Returns the initialized `SQRLUpdater`.
- (id)initWithUpdateRequest:(NSURLRequest *)updateRequest
forVersion:(NSString*)version;

// Initializes an updater that will send the given request to check for updates
// and passes a block to provide requests for the update downloads.
//
Expand All @@ -133,7 +152,7 @@ extern NSString * const SQRLUpdaterJSONObjectErrorKey;
// updateRequest param.
//
// Returns the initialized `SQRLUpdater`.
- (id)initWithUpdateRequest:(NSURLRequest *)updateRequest requestForDownload:(SQRLRequestForDownload)requestForDownload;
- (id)initWithUpdateRequest:(NSURLRequest *)updateRequest requestForDownload:(SQRLRequestForDownload)requestForDownload forVersion:(NSString*) version useMode:(SQRLUpdaterMode) mode;

// Executes `checkForUpdatesCommand` (if enabled) every `interval` seconds.
//
Expand Down
27 changes: 12 additions & 15 deletions Squirrel/SQRLUpdater.m
Expand Up @@ -40,12 +40,6 @@
// followed by a random string of characters.
static NSString * const SQRLUpdaterUniqueTemporaryDirectoryPrefix = @"update.";

/// Type of mode used to download the release
typedef enum {
JSONFILE=1,
RELEASESERVER
} Mode;

@interface SQRLUpdater ()

@property (atomic, readwrite) SQRLUpdaterState state;
Expand Down Expand Up @@ -152,24 +146,27 @@ - (id)init {
- (id)initWithUpdateRequest:(NSURLRequest *)updateRequest {
return [self initWithUpdateRequest:updateRequest requestForDownload:^(NSURL *downloadURL) {
return [NSURLRequest requestWithURL:downloadURL];
}];
} forVersion:@"" useMode:RELEASESERVER];
}

- (id)initWithUpdateRequest:(NSURLRequest *)updateRequest requestForDownload:(SQRLRequestForDownload)requestForDownload {
//! foo.bar/releases.json?version=1.0

NSString* version = getenv("VERSION") ? @(getenv("VERSION")) : @"";
- (id)initWithUpdateRequest:(NSURLRequest *)updateRequest forVersion: (NSString*) version {
return [self initWithUpdateRequest:updateRequest requestForDownload:^(NSURL *downloadURL) {
return [NSURLRequest requestWithURL:downloadURL];
} forVersion:version useMode:JSONFILE];
}

Mode mode = RELEASESERVER;
if(getenv("MODE")) {
mode = [@(getenv("MODE")) isEqualToString:@"JSONFILE"] ? JSONFILE : RELEASESERVER;
}
- (id)initWithUpdateRequest:(NSURLRequest *)updateRequest requestForDownload:(SQRLRequestForDownload)requestForDownload
forVersion:(NSString*) version useMode:(SQRLUpdaterMode) mode {

//! download simple file

NSParameterAssert(updateRequest != nil);
NSParameterAssert(requestForDownload != nil);

if(mode == JSONFILE) {
NSParameterAssert(version != nil);
}

self = [super init];
if (self == nil) return nil;

Expand Down
4 changes: 2 additions & 2 deletions SquirrelTests/SQRLUpdaterSpec.m
Expand Up @@ -99,7 +99,7 @@ bool isRunningOnReadOnlyVolumeImp(id self, SEL _cmd)
@"name": @"my-stub-release",
@"notes": @"mock release for automated tests, json",
@"pub_date": @"2017-03-09T15:24:55-05:00",
@"url": @"http://localhost/hipchatng-0.0.145.zip"
@"url": @"http://localhost/myapp-0.0.145.zip"
};

NSError * err;
Expand All @@ -116,7 +116,7 @@ bool isRunningOnReadOnlyVolumeImp(id self, SEL _cmd)
@"name": @"my-stub-release",
@"notes": @"mock release for automated tests, release server",
@"pub_date": @"2017-03-09T15:24:55-05:00",
@"url": @"http://localhost/hipchatng-0.0.145.zip"
@"url": @"http://localmyappng-0.0.145.zip"
};

NSError * err;
Expand Down

0 comments on commit db58a91

Please sign in to comment.