Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added rate limits for API calls #399

Merged
merged 13 commits into from
Sep 19, 2023
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ let sources: [String] = ["Qonversion/Automations/Constants",
"Qonversion/Qonversion/Utils",
"Qonversion/Qonversion/Utils/QNDevice",
"Qonversion/Qonversion/Utils/QNProperties",
"Qonversion/Qonversion/Utils/QNRateLimiter",
"Qonversion/Qonversion/Utils/QNUserInfo",
"Qonversion/Qonversion/Utils/QNUtils"]

Expand Down
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: cd1911d751c59f56b7f0243af0b5eba4ce54bf26

COCOAPODS: 1.11.3
COCOAPODS: 1.12.0
27 changes: 27 additions & 0 deletions Qonversion.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
45FFA2EB24BEEA9A007EFB8F /* ProductCenterManagerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 45FFA2EA24BEEA9A007EFB8F /* ProductCenterManagerTests.m */; };
45FFA2ED24BEF379007EFB8F /* full_init.json in Resources */ = {isa = PBXBuildFile; fileRef = 45FFA2EC24BEF379007EFB8F /* full_init.json */; };
4CADC5602759181A004FDC10 /* AuthViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CADC55F2759181A004FDC10 /* AuthViewController.swift */; };
6A21BF4C2AB201A7005BDA7C /* QONRateLimiter.h in Headers */ = {isa = PBXBuildFile; fileRef = 6A21BF4B2AB201A7005BDA7C /* QONRateLimiter.h */; };
6A21BF4E2AB20483005BDA7C /* QONRateLimiter.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A21BF4D2AB20483005BDA7C /* QONRateLimiter.m */; };
6A21BF532AB2059F005BDA7C /* QONRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 6A21BF522AB2059F005BDA7C /* QONRequest.h */; };
6A21BF552AB205AC005BDA7C /* QONRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A21BF542AB205AC005BDA7C /* QONRequest.m */; };
6A8A604329DAD363008EC7D8 /* Qonversion.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 459DAB69243E329F0011ECF3 /* Qonversion.framework */; };
6A8A604929DAD36E008EC7D8 /* QNAPIClientIntegrationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A8A603929D48B1A008EC7D8 /* QNAPIClientIntegrationTests.m */; };
6A95DE9929E007A600350BD6 /* init_request_main_data.json in Resources */ = {isa = PBXBuildFile; fileRef = 6A95DE9829E007A600350BD6 /* init_request_main_data.json */; };
Expand Down Expand Up @@ -328,6 +332,10 @@
45FFA2EA24BEEA9A007EFB8F /* ProductCenterManagerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ProductCenterManagerTests.m; sourceTree = "<group>"; };
45FFA2EC24BEF379007EFB8F /* full_init.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = full_init.json; sourceTree = "<group>"; };
4CADC55F2759181A004FDC10 /* AuthViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthViewController.swift; sourceTree = "<group>"; };
6A21BF4B2AB201A7005BDA7C /* QONRateLimiter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QONRateLimiter.h; sourceTree = "<group>"; };
6A21BF4D2AB20483005BDA7C /* QONRateLimiter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QONRateLimiter.m; sourceTree = "<group>"; };
6A21BF522AB2059F005BDA7C /* QONRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QONRequest.h; sourceTree = "<group>"; };
6A21BF542AB205AC005BDA7C /* QONRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QONRequest.m; sourceTree = "<group>"; };
6A8A603929D48B1A008EC7D8 /* QNAPIClientIntegrationTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNAPIClientIntegrationTests.m; sourceTree = "<group>"; };
6A8A603F29DAD363008EC7D8 /* IntegrationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = IntegrationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
6A95DE9829E007A600350BD6 /* init_request_main_data.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = init_request_main_data.json; sourceTree = "<group>"; };
Expand Down Expand Up @@ -764,6 +772,17 @@
path = workflows;
sourceTree = "<group>";
};
6A21BF4A2AB2018C005BDA7C /* QNRateLimiter */ = {
isa = PBXGroup;
children = (
6A21BF4B2AB201A7005BDA7C /* QONRateLimiter.h */,
6A21BF4D2AB20483005BDA7C /* QONRateLimiter.m */,
6A21BF522AB2059F005BDA7C /* QONRequest.h */,
6A21BF542AB205AC005BDA7C /* QONRequest.m */,
);
path = QNRateLimiter;
sourceTree = "<group>";
};
6A8A604029DAD363008EC7D8 /* IntegrationTests */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1220,6 +1239,7 @@
8957322526DD03A3009507A6 /* Utils */ = {
isa = PBXGroup;
children = (
6A21BF4A2AB2018C005BDA7C /* QNRateLimiter */,
8957322626DD03A3009507A6 /* QNUtils */,
8957322926DD03A3009507A6 /* QNDevice */,
8957322C26DD03A3009507A6 /* QNProperties */,
Expand Down Expand Up @@ -1541,6 +1561,7 @@
895732AD26DD03A3009507A6 /* QONAutomationsFlowCoordinator.h in Headers */,
8957328626DD03A3009507A6 /* QONAutomationsEvent.h in Headers */,
8957329826DD03A3009507A6 /* QONAutomationsEventType.h in Headers */,
6A21BF4C2AB201A7005BDA7C /* QONRateLimiter.h in Headers */,
895732B426DD03A3009507A6 /* QONAutomationsService.h in Headers */,
895732CA26DD03A3009507A6 /* QNUtils.h in Headers */,
8957328126DD03A3009507A6 /* QONEntitlement.h in Headers */,
Expand Down Expand Up @@ -1568,6 +1589,7 @@
70D0E2BB291AA21C004E8DE8 /* QONLaunchMode.h in Headers */,
895732D026DD03A3009507A6 /* QNUserInfo.h in Headers */,
895732B126DD03A3009507A6 /* QONAutomationsFlowAssembly.h in Headers */,
6A21BF532AB2059F005BDA7C /* QONRequest.h in Headers */,
8957329026DD03A3009507A6 /* QONEntitlementsUpdateListener.h in Headers */,
8957329326DD03A3009507A6 /* QONExperimentGroup.h in Headers */,
895732A126DD03A3009507A6 /* QONMacrosProcess.h in Headers */,
Expand Down Expand Up @@ -1720,6 +1742,7 @@
TargetAttributes = {
454EF63B24E5CC580070581E = {
CreatedOnToolsVersion = 11.5;
LastSwiftMigration = 1430;
};
459DAB68243E329F0011ECF3 = {
CreatedOnToolsVersion = 11.3.1;
Expand Down Expand Up @@ -1916,6 +1939,7 @@
895732CE26DD03A3009507A6 /* QNProperties.m in Sources */,
8957327A26DD03A3009507A6 /* QNDevice+Advertising.m in Sources */,
895732C626DD03A3009507A6 /* QNAPIConstants.m in Sources */,
6A21BF552AB205AC005BDA7C /* QONRequest.m in Sources */,
70D05A8F29C9FC1600EA5DDF /* QONRemoteConfigManager.m in Sources */,
895732C426DD03A3009507A6 /* QNRequestBuilder.m in Sources */,
8957329726DD03A3009507A6 /* QONStoreKitSugare.m in Sources */,
Expand All @@ -1933,6 +1957,7 @@
895732CB26DD03A3009507A6 /* QNUtils.m in Sources */,
70ADE7102951CC7200CB4D2E /* QONScreenPresentationConfiguration.m in Sources */,
707734F52A9F607700CFF742 /* QONRemoteConfigurationSource.m in Sources */,
6A21BF4E2AB20483005BDA7C /* QONRateLimiter.m in Sources */,
895732A626DD03A3009507A6 /* QONAutomationsScreen.m in Sources */,
70ED951129FAAF31005F5D00 /* QONStoreKit2PurchaseModel.m in Sources */,
70EC019D29EEE94300E686E2 /* StoreKit2Service.swift in Sources */,
Expand Down Expand Up @@ -2073,6 +2098,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Sample/Sample.entitlements;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = MTVL2X9L7N;
Expand Down Expand Up @@ -2112,6 +2138,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Sample/Sample.entitlements;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = MTVL2X9L7N;
Expand Down
5 changes: 4 additions & 1 deletion Sources/Qonversion/Public/QONErrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ typedef NS_ERROR_ENUM(QONErrorDomain, QONAPIError) {
QONAPIErrorInvalidStoreCredentials = 13,

// Receipt validation error
QONAPIErrorReceiptValidation = 14
QONAPIErrorReceiptValidation = 14,

// Rate limit exceeded
QONAPIErrorRateLimitExceeded = 15,
} NS_SWIFT_NAME(Qonversion.APIError);

@interface QONErrors: NSObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ extern NSString *const kEventEndpoint;

extern NSString *const kAccessDeniedError;
extern NSString *const kInternalServerError;

extern NSUInteger const kMaxSimilarRequestsPerSecond;
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@

NSString * const kAccessDeniedError = @"Access denied";
NSString * const kInternalServerError = @"Internal server error";

NSUInteger const kMaxSimilarRequestsPerSecond = 5;
Loading
Loading