Latest 1.0.1
Homepage https://github.com/questbeat/QBRateLimit
License MIT
Platforms ios 6.0, osx 10.7, requires ARC
Authors

Rate limit controller.

Installation

Install with CocoaPods.

pod 'QBRateLimit'

Then import the header file.

#import "QBRateLimit.h"

Example

Basic usage is setting interval and limit property and using performRequest to decrease the remaining count.

QBRateLimit *rateLimit = [[QBRateLimit alloc] init];
rateLimit.interval = 10.0;
rateLimit.limit = 2;

NSLog(@"Remaining: %lu", rateLimit.remaining); // 2
NSLog(@"Exceeded: %@", [rateLimit isExceeded] ? @"YES" : @"NO"); // NO

[rateLimit performReqeust];

NSLog(@"Remaining: %lu", rateLimit.remaining); // 1
NSLog(@"Exceeded: %@", [rateLimit isExceeded] ? @"YES" : @"NO"); // NO

[rateLimit performReqeust];

NSLog(@"Remaining: %lu", rateLimit.remaining); // 0
NSLog(@"Exceeded: %@", [rateLimit isExceeded] ? @"YES" : @"NO"); // YES

You can use convenience setter.

QBRateLimit *rateLimit = [[QBRateLimit alloc] init];
rateLimit.perHour = 60;

perHour sets interval to 3600.0 and limit to 60.

You can get noticed when the rate limit is reset.

- (void)somewhere
{
    ...

    self.rateLimit.delegate = self;
}

...

// QBRateLimitDelegage
- (void)rateLimitDidReset:(QBRateLimit *)rateLimit
{
    // Rate limit was reset
}

License

QBRateLimit is available under the MIT license.
See the LICENSE file for more info.

Latest podspec

{
    "name": "QBRateLimit",
    "version": "1.0.1",
    "summary": "Rate limit controller.",
    "description": "A rate limit controller for avoiding excess HTTP requests or preventing UI from being tapped repeatedly.",
    "homepage": "https://github.com/questbeat/QBRateLimit",
    "license": "MIT",
    "authors": {
        "questbeat": "[email protected]"
    },
    "source": {
        "git": "https://github.com/questbeat/QBRateLimit.git",
        "tag": "1.0.1"
    },
    "social_media_url": "https://twitter.com/questbeat",
    "requires_arc": true,
    "source_files": "Classes",
    "platforms": {
        "ios": "6.0",
        "osx": "10.7"
    }
}

Pin It on Pinterest

Share This