-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
26 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Provides API usage for a given month. | ||
export class Usage | ||
|
||
# Creates a new usage. | ||
constructor: (options = {}) -> | ||
|
||
# The number of monthly API calls your plan entitles you to. | ||
@limit = options.limit ? (-1) | ||
|
||
# The percentage of the limit used since the beginning of the month. | ||
@percentage = options.percentage ? 0 | ||
|
||
# Value indicating whether the requests are being throttled for having consistently gone over the limit. | ||
@throttled = options.throttled ? no | ||
|
||
# The number of calls (spam + ham) since the beginning of the month. | ||
@usage = options.usage ? 0 | ||
|
||
# Creates a new usage from the specified JSON object. | ||
@fromJson: (json) -> new @ | ||
limit: if Number.isInteger(json.limit) then json.limit else -1 | ||
percentage: if typeof json.percentage == "number" then json.percentage else 0 | ||
throttled: if typeof json.throttled == "boolean" then json.throttled else no | ||
usage: if Number.isInteger(json.usage) then json.usage else 0 |