Skip to content

Commit

Permalink
Extract method for default daily API limit
Browse files Browse the repository at this point in the history
  • Loading branch information
mlandauer committed Aug 8, 2024
1 parent fcea1d4 commit 968ffe4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions app/models/api_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ def self.find_valid(value)
ApiKey.find_by(value:, disabled: false)
end

# By default we allow up to 1000 API requests per day per API key
sig { returns(Integer) }
def self.default_daily_limit
1000
end

# Returns the daily limit for a given API key value. If no daily limit
# is set will return the default daily limit. Also, if an invalid key is given it
# will return the default daily limit as well.
# By default we allow up to 1000 API requests per day per API key
sig { params(value: String).returns(Integer) }
def self.daily_limit_with_default(value)
ApiKey.find_valid(value)&.daily_limit || 1000
ApiKey.find_valid(value)&.daily_limit || ApiKey.default_daily_limit
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/views/documentation/api_howto.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
Also, please
<%= pa_link_to "get in touch", documentation_contact_path(reason: "I want API access or commercial use") %>
if you intend to use the service on a large scale.
In order to maintain quality of service for our API users, this service is rate limited by default to approximately 1000 requests per day.
In order to maintain quality of service for our API users, this service is rate limited by default to approximately <%= ApiKey.default_daily_limit %> requests per day.
</p>
<p class="mt-8">
We offer a range of paid options, from rate&ndash;limited to unlimited use of this service.
Expand Down

0 comments on commit 968ffe4

Please sign in to comment.