class Api::V2::ProtocolsController
Has to be authenticated with :user_email and :user_token
Information returns in <protocol_info>;
{:id=>31, :name=>"PAR, Temp, RH, CO2 every 2 seconds for 3 hours", :slug=>"environmental-12-hours-every-2-seconds", :description=> "measures co2, temperature, relative humidity, and light intensity every 2 seconds for 3 hours. ", :macro_id=>53, :pre_selected=>true, :protocol_json=> "[\r\n {\r\n \"environmental\": [\r\n [\r\n \"co2\",\r\n 0\r\n ],\r\n [\r\n \"light_intensity\",\r\n 0\r\n ],\r\n [\r\n \"relative_humidity\",\r\n 0\r\n ],\r\n [\r\n \"temperature\",\r\n 0\r\n ]\r\n ],\r\n \"measurements_delay\": 2}\r\n]", :creator=> {:name=>"Greg Austic", :id=>3, :email=>"gbathree@gmail.com", :bio=>"Project lead at PhotosynQ!", :contributions=>2429, :projects=>31, :collaborations=>8, :institute=>"Michigan State University", :profile_url=>"http://localhost:5000/users/greg-austic", :avatar=> {:original=> "/uploads/user/avatar/3/012409_pbi_160_low_low_res_headshot.jpg", :thumb=> "/uploads/user/avatar/3/thumb_012409_pbi_160_low_low_res_headshot.jpg", :medium=> "/uploads/user/avatar/3/medium_012409_pbi_160_low_low_res_headshot.jpg"}, :latest_activity=>Fri, 06 Mar 2015 14:45:54 UTC +00:00, :badges=>[{:name=>"", :url=>""}]}, :created_at=>Mon, 26 May 2014 20:24:05 UTC +00:00, :updated_at=>Mon, 09 Mar 2015 03:04:36 UTC +00:00}
Public Instance Methods
Creates a protocol
POST /api/v2/protocols/(.:format)
Input params;
:protocol => { :name=>“???”, :description=>“???”, :protocol_json =>“???”, :macro_id =>“???”}
Ex;
post :create, {:user_email => foo@bar.com, :user_token => "xxxxxxx", :protocol => {:name=>"Protocol-1", :description=>"Protocol Description", :protocol_json =>"???", :macro_id =>"???"}}
Output;
On success - {:status => "success", :notice => "...", :protocol => <protocol_info>} On failed - {:status => "failed", :notice => "..."}
# File app/controllers/api/v2/protocols_controller.rb, line 123 def create @protocol = Protocol.new(params[:protocol]) @protocol.user_id = current_user.id if @protocol.save render json: {status: "success", notice: "You have successfully created the protocol!", protocol: @protocol.info} else render json: {status: "failed", notice: "Error: #{@protocol.errors.full_messages.join(',')}"} end end
Returns list of protocols
GET /api/v2/protocols(.:format)
Input params;
:user_id
If :user_id is set; returns all the protocols the current user has created.
If :user_id is not set; returns all the protocols.
Ex;
get :index, {:user_email => foo@bar.com, :user_token => "xxxxxxx", :user_id => "xx"}
Output;
On success - {:status => "success", :protocols => [<protocol_info>, ...]} On failed - {:status => "failed", :notice => "..."}
# File app/controllers/api/v2/protocols_controller.rb, line 63 def index if params[:user_id] @protocols = Protocol.where(user_id:params[:user_id]).all.map(&:info) render json: {status: "success", notice: "#{@protocols.size} records found", protocols: @protocols} else @protocols = Protocol.all.map(&:info) render json: {status: "success", notice: "#{@protocols.size} records found", protocols: @protocols} end end
Returns a individual protocol
GET /api/v2/protocols/:id(.:format)
Input params;
:id - protocol id requested
Ex;
get :show, {:user_email => foo@bar.com, :user_token => "xxxxxxx", :id => 1}
Output;
On success - {:status => "success", :protocol => <protocol_info>} On failed - {:status => "failed", :notice => "..."}
# File app/controllers/api/v2/protocols_controller.rb, line 91 def show @protocol = current_user.protocols.where(:id => params[:id]).first if @protocol render json: {status: "success", notice: "Record found", protocol: @protocol.info} else render json: {status: "failed", notice: "Error: Couldn't find a protocol with id #{params[:id]}"} end end
Updates a protocol
PUT /api/v2/protocols/:id(.:format)
Input params;
:id // requested protocol_id, :protocol => { :name=>“???”, :description=>“???”, :protocol_json =>“???”, :macro_id =>“???”}
Ex;
put :create, {:user_email => foo@bar.com, :user_token => "xxxxxxx", :id => "xxx", :protocol => {:name=>"Protocol-1", :description=>"Protocol Description", :protocol_json =>"???", :macro_id =>"???"}}
Output;
On success - {:status => "success", :notice => "...", :protocol => <protocol_info>} On failed - {:status => "failed", :notice => "..."}
# File app/controllers/api/v2/protocols_controller.rb, line 159 def update @protocol = Protocol.where(id: params[:id]).first if @protocol && @protocol.user_id.eql?(current_user.id) if @protocol.update_attributes(params[:protocol]) render json: {status: "success", notice: "Protocol updated successfully", protocol: @protocol.info} else render json: {status: "failed", notice: "Error: #{@protocol.errors.full_messages.join(',')}"} end else render json: {status: "failed", notice: "Error: Couldn't find a protocol with id #{params[:id]}"} end end