Last active
August 29, 2015 14:22
-
-
Save lorenzosinisi/403ae6467f01243cb6d1 to your computer and use it in GitHub Desktop.
Check if an API is valid and present into the db and update the number of request made by the client
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
def self.valid_api?(api_key) | |
if api_key and Apikey.where(:api_key => api_key).present? | |
api = Apikey.where(:api_key => api_key).first | |
if !api.requests.nil? | |
api.requests = api.requests + 1 | |
else | |
api.requests = 1 | |
end | |
api.save | |
true | |
else | |
false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment