class Api::V2::ProjectsController
Has to be authenticated with :user_email and :user_token
Information returns in <project_info>;
{:id=>91,
:slug=>"npq-npqt-comparison",
:name=>"NPQ NPQt comparison",
:description=>
"Developing parameter of NPQt (total or theoretical NPQ) that would allow estimates of NPQ without dark adaptation.",
:disclaimer=>nil,
:views=>nil,
:creator=>
{:name=>"Stefanie Tietz",
:id=>78,
:email=>"stietz@msu.edu",
:bio=>"",
:contributions=>221,
:projects=>2,
:collaborations=>0,
:institute=>"MSU DOE-Plant Research Laboratories",
:profile_url=>"http://localhost:5000/users/stefanie-tietz",
:avatar=>
{:original=>"/uploads/user/avatar/78/IMG_20140926_135621.jpg",
:thumb=>"/uploads/user/avatar/78/thumb_IMG_20140926_135621.jpg",
:medium=>"/uploads/user/avatar/78/medium_IMG_20140926_135621.jpg"},
:latest_activity=>Tue, 10 Mar 2015 19:10:17 UTC +00:00,
:badges=>[{:name=>"", :url=>""}]},
:location=>nil,
:latitude=>nil,
:longitude=>nil,
:radius=>"",
:start_date=>nil,
:end_date=>nil,
:start_time=>nil,
:end_time=>nil,
:is_open=>false,
:directions_to_collaborators=>"One hour dark adaption",
:beta=>true,
:created_at=>Tue, 09 Dec 2014 18:29:50 UTC +00:00,
:updated_at=>Tue, 09 Dec 2014 18:52:22 UTC +00:00,
:terms_accepted=>true,
:data_count=>34,
:tag_list=>[],
:project_url=>"http://localhost:5000/projects/npq-npqt-comparison",
:project_photo=>
{:original=>"/uploads/project/photo/91/IMG_20141121_134330_1.jpg",
:large=>"/uploads/project/photo/91/large_IMG_20141121_134330_1.jpg",
:medium=>"/uploads/project/photo/91/medium_IMG_20141121_134330_1.jpg",
:small=>"/uploads/project/photo/91/small_IMG_20141121_134330_1.jpg",
:thumb=>"/uploads/project/photo/91/thumb_IMG_20141121_134330_1.jpg"},
:protocols_ids=>[83],
:filters=>
[{:id=>207,
:value=>["Green", " Yellow", " Gray"],
:label=>"project defind question 1",
:created_at=>Sat, 11 Apr 2015 13:48:46 UTC +00:00,
:updated_at=>Sat, 11 Apr 2015 13:48:46 UTC +00:00,
:value_type=>1},
{:id=>208,
:value=>[],
:label=>"user defind question 1",
:created_at=>Sat, 11 Apr 2015 13:48:46 UTC +00:00,
:updated_at=>Sat, 11 Apr 2015 13:48:46 UTC +00:00,
:value_type=>2},
{:id=>209,
:value=>
[{:answer=>"image 1",
:image=>"/uploads/project_answer/image/208/avt1.gif"},
{:answer=>"image 2",
:image=>"/uploads/project_answer/image/209/avt1.gif"}],
:label=>"photo defined question 1",
:created_at=>Sat, 11 Apr 2015 13:48:46 UTC +00:00,
:updated_at=>Sat, 11 Apr 2015 13:48:46 UTC +00:00,
:value_type=>3}],
:is_contributed => false}
Public Instance Methods
index()
click to toggle source
Returns list of projects
GET /api/v2/projects(.:format)
Input params;
:all - 1, :page
If :all is set; returns all the projects pagingated according to the :page (if :page not passed 1st page is considered). page size is 10.
If :all is not set; returns all the projects the current user has access to (lead + collaborator).
Ex;
get :index, {:user_email => foo@bar.com, :user_token => "xxxxxxx", :all => 1, :page => 2}
Output;
# if :all - 1
On success - {:status => "success", :projects => [<project_info>, ...]}
# else
On success - {:status => "success", :projects => [<project_info>, ...], :page => xx, :total_pages => xx}
On failed - {:status => "failed", :notice => "..."}
# File app/controllers/api/v2/projects_controller.rb, line 108 def index #filter project by user id - own projects and collaborations, if all send a special flags filter and paging if params[:all].to_i.eql?(1) @projects = Project.all.page(params[:page]).per(10) render json: {status: "success", notice: "#{@projects.size} records found", projects: @projects.map{|p| p.info(current_user: current_user)}, page: @projects.current_page, total_pages: @projects.total_pages} else @projects = current_user.all_projects render json: {status: "success", notice: "#{@projects.size} records found", projects: @projects.map{|p| p.info(current_user: current_user)}} end end
show()
click to toggle source
Returns a individual project
GET /api/v2/projects/:id(.:format)
Input params;
:id - project id requested
Ex;
get :show, {:user_email => foo@bar.com, :user_token => "xxxxxxx", :id => 1}
Output;
On success - {:status => "success", :project => <project_info>}
On failed - {:status => "failed", :notice => "..."}
# File app/controllers/api/v2/projects_controller.rb, line 139 def show @project = Project.where(id: params[:id]).first if @project render json: {status: "success", notice: "Record found", project: @project.info(current_user: current_user)} else render json: {status: "failed", notice: "Error: Couldn't find a project with id #{params[:id]}"} end end