Skip to content

Commit

Permalink
Switch to api.onesignal.com for all requests
Browse files Browse the repository at this point in the history
* Switching from using onesignal.com directly
  • Loading branch information
jkasten2 committed Mar 24, 2020
1 parent 70cea7e commit a673945
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion iOS_SDK/OneSignalSDK/Source/OSInAppMessageViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ - (OSResultSuccessBlock)messageContentOnSuccess {
let message = [NSString stringWithFormat:@"In App Messaging htmlContent.html: %@", data[@"hmtl"]];
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:message];

let baseUrl = [NSURL URLWithString:SERVER_URL];
let baseUrl = [NSURL URLWithString:OS_IAM_WEBVIEW_BASE_URL];
NSString* htmlContent = data[@"html"];
[self.messageView loadedHtmlContent:htmlContent withBaseURL:baseUrl];

Expand Down
7 changes: 5 additions & 2 deletions iOS_SDK/OneSignalSDK/Source/OneSignalCommonDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@
#import <Foundation/Foundation.h>

// Networking
#define API_VERSION @"api/v1/"
#define SERVER_URL @"https://onesignal.com/"
#define OS_API_VERSION @"1"
#define OS_API_ACCEPT_HEADER @"application/vnd.onesignal.v" OS_API_VERSION @"+json"
#define OS_API_SERVER_URL @"https://api.onesignal.com/"

#define OS_IAM_WEBVIEW_BASE_URL @"https://onesignal.com/"

// OneSignalUserDefault keys
// String values start with "OSUD_" to maintain a level of uniqueness from other libs and app code
Expand Down
1 change: 0 additions & 1 deletion iOS_SDK/OneSignalSDK/Source/OneSignalRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
@property (strong, nonatomic, nullable) NSDictionary *parameters;
@property (nonatomic) int reattemptCount;
@property (nonatomic) BOOL dataRequest; //false for JSON based requests
@property (strong, nonatomic, nonnull) NSString *requestContentType; //ie. application/json
-(BOOL)missingAppId; //for requests that don't require an appId parameter, the subclass should override this method and return false
-(NSMutableURLRequest * _Nonnull )urlRequest;

Expand Down
6 changes: 2 additions & 4 deletions iOS_SDK/OneSignalSDK/Source/OneSignalRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,21 @@ - (id)init {
// However some requests want to load non-JSON data like HTML
// In those cases, `dataRequest` should be true
self.dataRequest = false;
self.requestContentType = @"application/json";
}

return self;
}

-(NSMutableURLRequest *)urlRequest {
//build URL
let urlString = [[SERVER_URL stringByAppendingString:API_VERSION] stringByAppendingString:self.path];
let urlString = [OS_API_SERVER_URL stringByAppendingString:self.path];

let request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];

if (!self.dataRequest)
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

// usually just application/json
[request setValue:self.requestContentType forHTTPHeaderField:@"Accept"];
[request setValue:OS_API_ACCEPT_HEADER forHTTPHeaderField:@"Accept"];

let versionString = [NSString stringWithFormat:@"%@%@", HTTP_HEADER_PREFIX_OS_VERSION, ONESIGNAL_VERSION];
[request setValue:versionString forHTTPHeaderField:HTTP_HEADER_KEY_OS_VERSION];
Expand Down
4 changes: 2 additions & 2 deletions iOS_SDK/OneSignalSDK/UnitTests/RequestTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ - (void)setUp {
}

NSString *correctUrlWithPath(NSString *path) {
return [[SERVER_URL stringByAppendingString:API_VERSION] stringByAppendingString:path];
return [OS_API_SERVER_URL stringByAppendingString:path];
}

// only works for dictionaries with values that are strings, numbers, or sub-dictionaries/arrays of strings and numbers
Expand Down Expand Up @@ -397,7 +397,7 @@ - (void)testLoadMessageContent {

XCTAssertEqualObjects(request.urlRequest.URL.absoluteString, correctUrlWithPath(iamUrlPath));
XCTAssertEqualObjects(request.urlRequest.HTTPMethod, @"GET");
XCTAssertEqualObjects(request.urlRequest.allHTTPHeaderFields[@"Accept"], @"application/json");
XCTAssertEqualObjects(request.urlRequest.allHTTPHeaderFields[@"Accept"], @"application/vnd.onesignal.v1+json");
XCTAssertFalse(request.dataRequest);
}

Expand Down
2 changes: 1 addition & 1 deletion iOS_SDK/OneSignalSDK/UnitTests/UnitTestCommonMethods.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#import "OneSignalTrackFirebaseAnalytics.h"

NSString * serverUrlWithPath(NSString *path) {
return [NSString stringWithFormat:@"%@%@%@", SERVER_URL, API_VERSION, path];
return [OS_API_SERVER_URL stringByAppendingString:path];
}

@interface OneSignal ()
Expand Down

0 comments on commit a673945

Please sign in to comment.