Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Functions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# v7.1.0
- [added] Added a constructor to set a custom domain. (#6787)

# v2.9.0
- [changed] Weak dependency on Instance ID replaced by Firebase Messaging. (#6395)

Expand Down
2 changes: 2 additions & 0 deletions Functions/Example/IntegrationTests/FIRIntegrationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ - (void)setUp {
_functions = [[FIRFunctions alloc]
initWithProjectID:_projectID
region:@"us-central1"
customDomain:nil
auth:[[FIRAuthInteropFake alloc] initWithToken:nil userID:nil error:nil]
messaging:_messagingFake];
if (_useLocalhost) {
Expand Down Expand Up @@ -105,6 +106,7 @@ - (void)testToken {
FIRFunctions *functions = [[FIRFunctions alloc]
initWithProjectID:_projectID
region:@"us-central1"
customDomain:nil
auth:[[FIRAuthInteropFake alloc] initWithToken:@"token" userID:nil error:nil]
messaging:_messagingFake];
if (_useLocalhost) {
Expand Down
40 changes: 34 additions & 6 deletions Functions/Example/Tests/FIRFunctionsTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,54 @@
#import "Functions/FirebaseFunctions/FIRFunctions+Internal.h"
#import "Functions/FirebaseFunctions/Public/FirebaseFunctions/FIRFunctions.h"

@interface FIRFunctionsTests : XCTestCase
@interface FIRFunctionsTests : XCTestCase {
FIRFunctions *_functions;
FIRFunctions *_functionsCustomDomain;
}
@end

@implementation FIRFunctionsTests

- (void)setUp {
[super setUp];

_functions = [[FIRFunctions alloc] initWithProjectID:@"my-project"
region:@"my-region"
customDomain:nil
auth:nil
messaging:nil];

_functionsCustomDomain = [[FIRFunctions alloc] initWithProjectID:@"my-project"
region:@"my-region"
customDomain:@"https://mydomain.com"
auth:nil
messaging:nil];
}

- (void)tearDown {
[super tearDown];
}

- (void)testURLWithName {
FIRFunctions *functions = [[FIRFunctions alloc] initWithProjectID:@"my-project"
region:@"my-region"
auth:nil
messaging:nil];
NSString *url = [functions URLWithName:@"my-endpoint"];
NSString *url = [_functions URLWithName:@"my-endpoint"];
XCTAssertEqualObjects(@"https://my-region-my-project.cloudfunctions.net/my-endpoint", url);
}

- (void)testRegionWithEmulator {
[_functions useFunctionsEmulatorOrigin:@"http://localhost:5005"];
NSString *url = [_functions URLWithName:@"my-endpoint"];
XCTAssertEqualObjects(@"http://localhost:5005/my-project/my-region/my-endpoint", url);
}

- (void)testCustomDomain {
NSString *url = [_functionsCustomDomain URLWithName:@"my-endpoint"];
XCTAssertEqualObjects(@"https://mydomain.com/my-endpoint", url);
}

- (void)testCustomDomainWithEmulator {
[_functionsCustomDomain useFunctionsEmulatorOrigin:@"http://localhost:5005"];
NSString *url = [_functionsCustomDomain URLWithName:@"my-endpoint"];
XCTAssertEqualObjects(@"http://localhost:5005/my-project/my-region/my-endpoint", url);
}

@end
2 changes: 2 additions & 0 deletions Functions/FirebaseFunctions/FIRFunctions+Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ NS_ASSUME_NONNULL_BEGIN
* Internal initializer for the Cloud Functions client.
* @param projectID The project ID for the Firebase project.
* @param region The region for the http trigger, such as "us-central1".
* @param customDomain A custom domain for the http trigger, such as "https://mydomain.com".
* @param auth The auth provider to use (optional).
* @param messaging The messaging interop to use (optional).
*/
- (id)initWithProjectID:(NSString *)projectID
region:(NSString *)region
customDomain:(nullable NSString *)customDomain
auth:(nullable id<FIRAuthInterop>)auth
messaging:(nullable id<FIRMessagingInterop>)messaging;

Expand Down
31 changes: 26 additions & 5 deletions Functions/FirebaseFunctions/FIRFunctions.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ @interface FIRFunctions () <FIRLibrary, FIRFunctionsInstanceProvider> {
NSString *_projectID;
// The region to use for all function references.
NSString *_region;
// The custom domain to use for all functions references (optional).
NSString *_customDomain;
// A serializer to encode/decode data and return values.
FUNSerializer *_serializer;
// A factory for getting the metadata to include with function calls.
Expand All @@ -60,6 +62,7 @@ @interface FIRFunctions () <FIRLibrary, FIRFunctionsInstanceProvider> {
// Re-declare this initializer here in order to attribute it as the designated initializer.
- (instancetype)initWithProjectID:(NSString *)projectID
region:(NSString *)region
customDomain:(nullable NSString *)customDomain
auth:(nullable id<FIRAuthInterop>)auth
messaging:(nullable id<FIRMessagingInterop>)messaging
NS_DESIGNATED_INITIALIZER;
Expand Down Expand Up @@ -89,30 +92,44 @@ + (void)load {
}

+ (instancetype)functions {
return [[self alloc] initWithApp:[FIRApp defaultApp] region:kFUNDefaultRegion];
return [[self alloc] initWithApp:[FIRApp defaultApp] region:kFUNDefaultRegion customDomain:nil];
}

+ (instancetype)functionsForApp:(FIRApp *)app {
return [[self alloc] initWithApp:app region:kFUNDefaultRegion];
return [[self alloc] initWithApp:app region:kFUNDefaultRegion customDomain:nil];
}

+ (instancetype)functionsForRegion:(NSString *)region {
return [[self alloc] initWithApp:[FIRApp defaultApp] region:region];
return [[self alloc] initWithApp:[FIRApp defaultApp] region:region customDomain:nil];
}

+ (instancetype)functionsForCustomDomain:(NSString *)customDomain {
return [[self alloc] initWithApp:[FIRApp defaultApp]
region:kFUNDefaultRegion
customDomain:customDomain];
}

+ (instancetype)functionsForApp:(FIRApp *)app region:(NSString *)region {
return [[self alloc] initWithApp:app region:region];
return [[self alloc] initWithApp:app region:region customDomain:nil];
}

- (instancetype)initWithApp:(FIRApp *)app region:(NSString *)region {
+ (instancetype)functionsForApp:(FIRApp *)app customDomain:(NSString *)customDomain {
return [[self alloc] initWithApp:app region:kFUNDefaultRegion customDomain:customDomain];
}

- (instancetype)initWithApp:(FIRApp *)app
region:(NSString *)region
customDomain:(nullable NSString *)customDomain {
return [self initWithProjectID:app.options.projectID
region:region
customDomain:customDomain
auth:FIR_COMPONENT(FIRAuthInterop, app.container)
messaging:FIR_COMPONENT(FIRMessagingInterop, app.container)];
}

- (instancetype)initWithProjectID:(NSString *)projectID
region:(NSString *)region
customDomain:(nullable NSString *)customDomain
auth:(nullable id<FIRAuthInterop>)auth
messaging:(nullable id<FIRMessagingInterop>)messaging {
self = [super init];
Expand All @@ -123,6 +140,7 @@ - (instancetype)initWithProjectID:(NSString *)projectID
_fetcherService = [[GTMSessionFetcherService alloc] init];
_projectID = [projectID copy];
_region = [region copy];
_customDomain = [customDomain copy];
_serializer = [[FUNSerializer alloc] init];
_contextProvider = [[FUNContextProvider alloc] initWithAuth:auth messaging:messaging];
_emulatorOrigin = nil;
Expand All @@ -148,6 +166,9 @@ - (NSString *)URLWithName:(NSString *)name {
if (_emulatorOrigin) {
return [NSString stringWithFormat:@"%@/%@/%@/%@", _emulatorOrigin, _projectID, _region, name];
}
if (_customDomain) {
return [NSString stringWithFormat:@"%@/%@", _customDomain, name];
}
return
[NSString stringWithFormat:@"https://%@-%@.cloudfunctions.net/%@", _region, _projectID, name];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,29 @@ NS_SWIFT_NAME(Functions)
*/
+ (instancetype)functionsForRegion:(NSString *)region NS_SWIFT_NAME(functions(region:));

/**
* Creates a Cloud Functions client with the default app and given custom domain.
* @param customDomain A custom domain for the http trigger, such as "https://mydomain.com".
*/
+ (instancetype)functionsForCustomDomain:(NSString *)customDomain
NS_SWIFT_NAME(functions(customDomain:));

/**
* Creates a Cloud Functions client with the given app and region.
* @param app The app for the Firebase project.
* @param region The region for the http trigger, such as "us-central1".
*/
// clang-format off
// because it incorrectly breaks this NS_SWIFT_NAME.
+ (instancetype)functionsForApp:(FIRApp *)app
region:(NSString *)region NS_SWIFT_NAME(functions(app:region:));
// clang-format on

/**
* Creates a Cloud Functions client with the given app and region.
* @param app The app for the Firebase project.
* @param customDomain A custom domain for the http trigger, such as "https://mydomain.com".
*/
+ (instancetype)functionsForApp:(FIRApp *)app
customDomain:(NSString *)customDomain
NS_SWIFT_NAME(functions(app:customDomain:));

/**
* Creates a reference to the Callable HTTPS trigger with the given name.
Expand Down
2 changes: 1 addition & 1 deletion Functions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ integration test FirebaseFunctions:

### To Develop

- Run `pod gen FirebaseFunctions.podspec`
- Run `pod gen FirebaseFunctions.podspec --local-sources=./`
- `open gen/FirebaseFunctions/FirebaseFunctions.xcworkspace`

OR these two commands can be combined with
Expand Down