module Articlesclass ArticleData < Grape::APIinclude ActionController::HttpAuthentication::Token::ControllerMethods# http_basic do |email, password|# user = User.find_by_email(email)# user && user.valid_password?(password)# endbefore doerror!("401 Unauthorized", 401) unless authenticatedendhelpers dodef authenticatedauthenticate_or_request_with_http_token do |token, options|apiKey = ApiKey.where(auth_token: token).first#ApiKey.exists?(access_token: token)endendendresource :article_data dodesc "Return all article data"get doArticle.allenddesc "create a new article"## This takes care of parameter validationparams dorequires :title, type: Stringrequires :author, type: String#requires :content, type: Textend#This takes care of creating articlepost doArticle.create!({title:params[:title],content:params[:content],author:params[:author],user_id:params[:user_id],image_url:params[:image_url]})enddesc "update article"# this takes care of parameter validationparams dorequires :image_url, type: Stringendput ':id' doArticle.find(params[:id]).update({content:params[:content],image_url:params[:image_url]})enddesc "delete article by id"# this takes care of parameter validationparams dorequires :id, type: Stringenddelete ':id' doArticle.find(params[:id]).destroy!endendendend
--
You received this message because you are subscribed to the Google Groups "Grape Framework Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-grape+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.