Class: CodersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/coders_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#conditions

Instance Method Details

#indexObject

returns coders in json based upon certain paramters

Examples:

/coders.json /coders/sferik.json /codeforamerica/shortstack/coders.json

Parameters:

  • :org_login

    Organization name

  • :name

    Project name

  • :login

    Code Login

  • created_at (>)

    reated_at>

  • created_at<
  • followers_count ()

    ollowers_count<

  • followers_count (>)

    ollowers_count>

  • following_count ()

    ollowing_count<

  • following_count (>)

    ollowing_count>

  • public_repo_count ()

    ublic_repo_count<

  • public_repo_count (>)

    ublic_repo_count>

  • public_gist_count ()

    ublic_gist_count<

  • public_gist_count (>)

    ublic_gist_count>

Returns:

  • Coders.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/coders_controller.rb', line 24

def index
  
  conditions(Coder)
  
  if params[:org_login]
    org = Org.where(:name => params[:organization]).first
  end
  
  if params[:project_name]
    project = Project.where(:name => params[:project_name]).first
  end
  
  @conditions << "commits.org_id = '#{org.id}'" unless org.nil?     
  @conditions << "commits.project_id = '#{project.id}'" unless project.nil?         
  
  @coders = Coder.includes(:commits).where(@conditions.join(" and "))
    
  @items = [:results => @coders.size, :page => (params[:page].nil? ? 1 : params[:page]), :total_items => @coders.size]    
  
  respond_to do |format|
    format.json { render :json => [@items, @coders].to_json}    
    format.html  
  end
end

#projectsObject



49
50
51
52
53
54
55
# File 'app/controllers/coders_controller.rb', line 49

def projects
  @coder = Coder.where(:login => params[:login]).first
  
  respond_to do |format|
    format.json { render :json => [@coder, :projects => [@coder.projects]].to_json}      
  end  
end