Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, includin...
If you think the Android project pocket4android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright (c) 2012-2014 Yu AOKI//www.java2s.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/package com.aokyu.dev.pocket;
import com.aokyu.dev.pocket.error.PocketException;
import java.util.List;
import java.util.Map;
publicclass ClientLimit {
privatestaticfinal String CLIENT_LIMIT = "X-Limit-Key-Limit";
privatestaticfinal String CLIENT_REMAINING = "X-Limit-Key-Remaining";
privatestaticfinal String CLIENT_RESET = "X-Limit-Key-Reset";
private RateLimit mLimit;
public ClientLimit(Map<String, List<String>> headerFields) throws PocketException {
List<String> limitField = headerFields.get(CLIENT_LIMIT);
int limit = getValue(limitField);
List<String> remainingField = headerFields.get(CLIENT_REMAINING);
int remaining = getValue(remainingField);
List<String> resetField = headerFields.get(CLIENT_RESET);
int reset = getValue(resetField);
mLimit = new RateLimit(limit, remaining, reset);
}
privateint getValue(List<String> values) throws PocketException {
int size = values.size();
if (size > 0) {
String limit = values.get(0);
try {
return Integer.parseInt(limit);
} catch (NumberFormatException e) {
thrownew PocketException("cannot parse rate limit");
}
} else {
thrownew PocketException("cannot get rate limit");
}
}
publicint getLimit() {
return mLimit.getLimit();
}
publicint getRemainingCalls() {
return mLimit.getRemainingCalls();
}
publiclong getResetTime() {
return mLimit.getResetTime();
}
}