class Api::V3::ProtocolsController

Has to be authenticated with :user_email and :user_token

Information returns in <protocol_info>;

{
    id: 144,
    name: "ePBR Phi2 (revised2)",
    slug: "epbr-phi2-revised2",
    description: "Testing Stirring with ePBR measuring Phi2",
    pre_selected: null,
    macro_id: 7,
    protocol_json: {
        pulses: [20,20,50,20],
        averages: 3,
        averages_delay: 5,
        get_ir_baseline: [15,14],
        pulsesize: 75,
        pulsedistance: 10000,
        act1_lights: [0,0,16,0],
        act2_lights: [0,0,15,0],
        act_intensities: [250,250,250,250],
        cal_intensities: [4095,0,0,0],
        meas_intensities: [4000,4000,4000,4000],
        detectors: [
            [34],[34],[34],[34]
        ],
        meas_lights: [
      [20],[20],[20],[20]
  ],
        measurements: 1,
        measurements_delay: 0,
        get_offset: 1,
        protocol_id: 144
    },
    created_at: "2015-03-19T19:52:11.283Z",
    updated_at: "2015-03-19T21:32:23.905Z",
    is_deleted: false,
    macro: {
        id: 7,
        name: "Chlorophyll Fluorescence",
        slug: "integrated-fluorescence",
        description: "This calculates baseline, fv/fm..... Note that Fv/Fm and Phi2 are equal under dark conditions!",
        default_y_axis: "",
        default_x_axis: "",
        javascript_code: "var data = json.data_raw;.....; return output;",
        json_data: "{....}",
        created_at: "2014-07-15T13:07:54.167Z",
        updated_at: "2015-02-03T20:07:20.360Z",
        is_deleted: false,
        creator: {
            name: "Greg Austic",
            id: 3,
            email: "gbathree@gmail.com",
            bio: "Project lead at PhotosynQ!",
            institute: "Michigan State University",
            profile_url: "http://localhost:3000/users/greg-austic",
            contributions: 2480,
            projects: 37,
            collaborations: 21,
            avatar: {
                original: "http://localhost:3000/uploads/user/avatar/3/012409_pbi_160_low_low_res_headshot.jpg",
                thumb: "http://localhost:3000/uploads/user/avatar/3/thumb_012409_pbi_160_low_low_res_headshot.jpg",
                medium: "http://localhost:3000/uploads/user/avatar/3/medium_012409_pbi_160_low_low_res_headshot.jpg"
            },
            latest_activity: "2015-04-01T19:57:23.649Z",
            badges: [{
                name: "",
                url: ""
            }]
        }
    },
    creator: {
        name: "Christopher",
        id: 25,
        email: "czatzke@gmail.com",
        bio: "<i>I LOVE PHOTOSYNQ!!!</i>",
        institute: "Zatzke",
        profile_url: "http://localhost:3000/users/christopher",
        contributions: 158,
        projects: 1,
        collaborations: 0,
        avatar: {
            original: "http://localhost:3000/assets/avatar.png",
            thumb: "http://localhost:3000/assets/thumb_avatar.png",
            medium: "http://localhost:3000/assets/medium_avatar.png"
        },
        latest_activity: "2015-03-18T17:34:43.026Z",
        badges: [{
            name: "",
            url: ""
        }]
    }
}

Public Instance Methods

create() click to toggle source

Creates a protocol

POST /api/v3/protocols.json

Input params:

:protocol => { :name=>“???”, :description=>“???”, :protocol_catgegory_id=>“???”, :protocol_json =>“???”, :macro_id =>“???”}

Ex:

post :create, {:user_email => foo@bar.com, :user_token => "xxxxxxx", :protocol => {:name=>"Protocol-1", :description=>"Protocol Description", :protocol_catgegory_id=> "???" , :protocol_json =>"???", :macro_id =>"???"}, :format => :json}

Output:

On success - {:status => "success", :notice => "...", :protocol => <protocol_info>}
On failed - {:status => "failed", :notice => "..."}
# File app/controllers/api/v3/protocols_controller.rb, line 225
def create
  @protocol = Protocol.new(params[:protocol])
  @protocol.user_id = current_user.id
  @protocol.save
end
index() click to toggle source

Returns list of protocols

GET /api/v3/protocols.json

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, {:include_deleted => true, :user_email => foo@bar.com, :user_token => "xxxxxxx", :user_id => "xx", :format => :json}

Output:

On success - {:status => "success", :protocols => [<protocol_info>, ...]}
On failed - {:status => "failed", :notice => "..."}

Note: To list all protocols (including deleted), need to pass 'include_deleted=true'

GET /api/v3/protocols.json?include_deleted=true

To list the protocols for only given ids, need to pass 'ids' parameter with comma separated protocol ids

GET /api/v3/protocols.json?ids=72,57,44

To filter only the preselected protocols, need to pass 'preselected=true'

GET /api/v3/protocols.json?preselected=true

# File app/controllers/api/v3/protocols_controller.rb, line 138
def index
  if params[:include_deleted] == "true"
    @protocols = Protocol.unscoped.all
  else
    @protocols = Protocol.all
  end

  if params[:ids].present?
    protocol_ids = params[:ids].to_s.split(",").compact.uniq
    @protocols = @protocols.where(id: protocol_ids).order("id")
    return
  end

  if params[:user_id]
    @protocols = @protocols.where(user_id:params[:user_id])
  end

  if params[:preselected] == "true"
    @protocols = @protocols.where(pre_selected: true)
  end

  @protocols
end
protocols_hashes() click to toggle source

Returns list of protocols with id & hash

GET /api/v3/protocols_hashes.json

Ex:

get :protocols_hashes, {:user_email => foo@bar.com, :user_token => "xxxxxxx", :format => :json}

Output:

On success - {:status => "success", :protocols => [{id: xx, md5hash: "1c..835"}, ...]}
On failed - {:status => "failed", :notice => "..."}
# File app/controllers/api/v3/protocols_controller.rb, line 175
def protocols_hashes
  @protocols = Protocol.order("id").page(params[:page].to_i).per(1000)
end
show() click to toggle source

Returns an individual protocol

GET /api/v3/protocols/:id.json

Input params:

:id - protocol id requested

Ex:

get :show, {:user_email => foo@bar.com, :user_token => "xxxxxxx", :id => 1, :format => :json}

Output:

On success - {:status => "success", :protocol => <protocol_info>}
On failed - {:status => "failed", :notice => "..."}
# File app/controllers/api/v3/protocols_controller.rb, line 198
def show
  @protocol = Protocol.unscoped.where(:id => params[:id]).first
end
update() click to toggle source

Updates a protocol

PUT /api/v3/protocols/:id.json

Input params:

:id // requested protocol_id, :protocol => { :name=>“???”, :description=>“???”, :protocol_catgegory_id=>“???”, :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_catgegory_id=>"???", :protocol_json =>"???", :macro_id =>"???"}, :format => :json}

Output:

On success - {:status => "success", :notice => "...", :protocol => <protocol_info>}
On failed - {:status => "failed", :notice => "..."}
# File app/controllers/api/v3/protocols_controller.rb, line 255
def update
  @protocol = Protocol.where(id: params[:id]).first

  if @protocol && @protocol.user_id.eql?(current_user.id)
    @protocol.update_attributes(params[:protocol])
  end
end