Skip to content

Instantly share code, notes, and snippets.

@lorenzosinisi
Last active August 29, 2015 14:22
Show Gist options
  • Save lorenzosinisi/403ae6467f01243cb6d1 to your computer and use it in GitHub Desktop.
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
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