Permalink
Browse files

api call for players

  • Loading branch information...
1 parent 2ee30f2 commit dddf14ac0d5bd89bd5acbf338222634b5f3a7e3a @pairing pairing committed Feb 11, 2013
Showing with 139 additions and 126 deletions.
  1. +106 −113 Gemfile.lock
  2. +31 −13 app/controllers/players_controller.rb
  3. +1 −0 app/models/ranking.rb
  4. +1 −0 config/routes.rb
View
@@ -1,190 +1,183 @@
GEM
remote: http://rubygems.org/
specs:
- actionmailer (3.2.3)
- actionpack (= 3.2.3)
+ actionmailer (3.2.11)
+ actionpack (= 3.2.11)
mail (~> 2.4.4)
- actionpack (3.2.3)
- activemodel (= 3.2.3)
- activesupport (= 3.2.3)
+ actionpack (3.2.11)
+ activemodel (= 3.2.11)
+ activesupport (= 3.2.11)
builder (~> 3.0.0)
erubis (~> 2.7.0)
- journey (~> 1.0.1)
+ journey (~> 1.0.4)
rack (~> 1.4.0)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
- sprockets (~> 2.1.2)
- activemodel (3.2.3)
- activesupport (= 3.2.3)
+ sprockets (~> 2.2.1)
+ activemodel (3.2.11)
+ activesupport (= 3.2.11)
builder (~> 3.0.0)
- activerecord (3.2.3)
- activemodel (= 3.2.3)
- activesupport (= 3.2.3)
+ activerecord (3.2.11)
+ activemodel (= 3.2.11)
+ activesupport (= 3.2.11)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
- activeresource (3.2.3)
- activemodel (= 3.2.3)
- activesupport (= 3.2.3)
- activesupport (3.2.3)
+ activeresource (3.2.11)
+ activemodel (= 3.2.11)
+ activesupport (= 3.2.11)
+ activesupport (3.2.11)
i18n (~> 0.6)
multi_json (~> 1.0)
- addressable (2.2.7)
+ addressable (2.3.2)
arel (3.0.2)
- awesome_print (1.0.2)
+ awesome_print (1.1.0)
bcrypt-ruby (3.0.1)
- builder (3.0.0)
- coderay (1.0.6)
- commonjs (0.2.5)
- daemons (1.1.8)
- devise (2.0.4)
+ builder (3.0.4)
+ coderay (1.0.8)
+ daemons (1.1.9)
+ devise (2.2.2)
bcrypt-ruby (~> 3.0)
- orm_adapter (~> 0.0.3)
+ orm_adapter (~> 0.1)
railties (~> 3.1)
- warden (~> 1.1.1)
+ warden (~> 1.2.1)
diff-lcs (1.1.3)
elo (0.1.0)
erubis (2.7.0)
- eventmachine (0.12.10)
- execjs (1.3.0)
+ eventmachine (1.0.0)
+ excon (0.16.10)
+ execjs (1.4.0)
multi_json (~> 1.0)
- haml (3.1.4)
- haml-rails (0.3.4)
- actionpack (~> 3.0)
- activesupport (~> 3.0)
- haml (~> 3.0)
- railties (~> 3.0)
+ haml (3.1.7)
+ haml-rails (0.3.5)
+ actionpack (>= 3.1, < 4.1)
+ activesupport (>= 3.1, < 4.1)
+ haml (~> 3.1)
+ railties (>= 3.1, < 4.1)
hashie (1.2.0)
- heroku (2.24.1)
+ heroku (2.34.0)
+ heroku-api (~> 0.3.7)
launchy (>= 0.3.2)
- netrc (~> 0.7.1)
+ netrc (~> 0.7.7)
rest-client (~> 1.6.1)
rubyzip
+ heroku-api (0.3.7)
+ excon (~> 0.16.10)
hike (1.2.1)
- i18n (0.6.0)
- journey (1.0.3)
- jquery-rails (2.0.2)
- railties (>= 3.2.0, < 5.0)
- thor (~> 0.14)
- json (1.6.6)
- launchy (2.1.0)
- addressable (~> 2.2.6)
- less (2.1.0)
- commonjs (~> 0.2.0)
- therubyracer (~> 0.10.0)
- less-rails (2.2.0)
- actionpack (>= 3.1)
- less (~> 2.1.0)
- libv8 (3.3.10.4)
+ i18n (0.6.1)
+ journey (1.0.4)
+ jquery-rails (2.1.4)
+ railties (>= 3.0, < 5.0)
+ thor (>= 0.14, < 2.0)
+ json (1.7.6)
+ launchy (2.1.2)
+ addressable (~> 2.3)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
- method_source (0.7.1)
- mime-types (1.18)
- multi_json (1.2.0)
- netrc (0.7.1)
- newrelic_rpm (3.5.0.1)
- omniauth (1.1.0)
+ method_source (0.8.1)
+ mime-types (1.19)
+ multi_json (1.5.0)
+ netrc (0.7.7)
+ newrelic_rpm (3.5.5.38)
+ omniauth (1.1.1)
hashie (~> 1.2)
rack
omniauth-openid (1.0.1)
omniauth (~> 1.0)
rack-openid (~> 1.3.1)
- orm_adapter (0.0.7)
- pg (0.13.2)
+ orm_adapter (0.4.0)
+ pg (0.14.1)
polyglot (0.3.3)
- pry (0.9.8.4)
+ pry (0.9.11.3)
coderay (~> 1.0.5)
- method_source (~> 0.7.1)
- slop (>= 2.4.4, < 3)
- pry-doc (0.4.1)
- pry (>= 0.9.0)
- yard (~> 0.7.4)
- pry-nav (0.2.0)
- pry (~> 0.9.8.1)
- pry-rails (0.1.6)
- pry
- pry-remote (0.1.1)
- pry (~> 0.9.8)
- slop (~> 2.1)
- rack (1.4.1)
+ method_source (~> 0.8)
+ slop (~> 3.4)
+ pry-doc (0.4.4)
+ pry (>= 0.9.9.6)
+ yard (~> 0.8.1)
+ pry-nav (0.2.3)
+ pry (~> 0.9.10)
+ pry-rails (0.2.2)
+ pry (>= 0.9.10)
+ pry-remote (0.1.6)
+ pry (~> 0.9)
+ slop (~> 3.0)
+ rack (1.4.4)
rack-cache (1.2)
rack (>= 0.4)
rack-openid (1.3.1)
rack (>= 1.1.0)
ruby-openid (>= 2.1.8)
rack-ssl (1.3.2)
rack
- rack-test (0.6.1)
+ rack-test (0.6.2)
rack (>= 1.0)
- rails (3.2.3)
- actionmailer (= 3.2.3)
- actionpack (= 3.2.3)
- activerecord (= 3.2.3)
- activeresource (= 3.2.3)
- activesupport (= 3.2.3)
+ rails (3.2.11)
+ actionmailer (= 3.2.11)
+ actionpack (= 3.2.11)
+ activerecord (= 3.2.11)
+ activeresource (= 3.2.11)
+ activesupport (= 3.2.11)
bundler (~> 1.0)
- railties (= 3.2.3)
- railties (3.2.3)
- actionpack (= 3.2.3)
- activesupport (= 3.2.3)
+ railties (= 3.2.11)
+ railties (3.2.11)
+ actionpack (= 3.2.11)
+ activesupport (= 3.2.11)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
- thor (~> 0.14.6)
- rake (0.9.2.2)
+ thor (>= 0.14.6, < 2.0)
+ rake (10.0.3)
rdoc (3.12)
json (~> 1.4)
rest-client (1.6.7)
mime-types (>= 1.16)
- rspec (2.9.0)
- rspec-core (~> 2.9.0)
- rspec-expectations (~> 2.9.0)
- rspec-mocks (~> 2.9.0)
- rspec-core (2.9.0)
- rspec-expectations (2.9.1)
+ rspec-core (2.12.2)
+ rspec-expectations (2.12.1)
diff-lcs (~> 1.1.3)
- rspec-mocks (2.9.0)
- rspec-rails (2.9.0)
+ rspec-mocks (2.12.1)
+ rspec-rails (2.12.2)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
- rspec (~> 2.9.0)
- ruby-openid (2.1.8)
- rubyzip (0.9.7)
- sass (3.1.15)
- sass-rails (3.2.5)
+ rspec-core (~> 2.12.0)
+ rspec-expectations (~> 2.12.0)
+ rspec-mocks (~> 2.12.0)
+ ruby-openid (2.2.2)
+ rubyzip (0.9.9)
+ sass (3.2.5)
+ sass-rails (3.2.6)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
- slop (2.4.4)
- sprockets (2.1.2)
+ slop (3.4.3)
+ sprockets (2.2.2)
hike (~> 1.2)
+ multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
- sqlite3 (1.3.5)
- therubyracer (0.10.1)
- libv8 (~> 3.3.10)
- thin (1.3.1)
+ sqlite3 (1.3.7)
+ thin (1.5.0)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
- thor (0.14.6)
+ thor (0.16.0)
tilt (1.3.3)
- treetop (1.4.10)
+ treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
- twitter-bootstrap-rails (2.0.6)
+ twitter-bootstrap-rails (2.2.0)
actionpack (>= 3.1)
- less-rails (~> 2.2.0)
+ execjs
railties (>= 3.1)
- tzinfo (0.3.33)
- uglifier (1.2.4)
+ tzinfo (0.3.35)
+ uglifier (1.3.0)
execjs (>= 0.3.0)
- multi_json (>= 1.0.2)
- warden (1.1.1)
+ multi_json (~> 1.0, >= 1.0.2)
+ warden (1.2.1)
rack (>= 1.0)
- yard (0.7.5)
+ yard (0.8.3)
PLATFORMS
ruby
@@ -19,6 +19,37 @@ def api_index
end
def show
+ load_for_show
+ end
+
+ def api_show
+ load_for_show
+ render json: {
+ player: @player.as_json,
+ vs: @vs,
+ matches: @matches,
+ num_wins: @num_wins,
+ num_loses: @num_loses,
+ elo_player_rating: @elo_player.rating,
+ ratings_by_date: @ratings_by_date,
+ }
+ end
+
+ def rankings
+ @match = Match.new
+ @rankings = Ranking.all
+ respond_with(@rankings)
+ end
+
+ def distribution
+ @match = Match.new
+ @rankings = Ranking.recent
+ @top_n = params[:n] ? params[:n].to_i : @rankings.size
+ end
+
+ private
+
+ def load_for_show
@match = Match.new
@player = Player.find(params[:id])
@matches = @player.matches.order("occured_at desc")
@@ -36,19 +67,6 @@ def show
@ratings_by_date = EloRatings.ratings_by_date(@player.id)
end
- def rankings
- @match = Match.new
- @rankings = Ranking.all
- respond_with(@rankings)
- end
-
- def distribution
- @match = Match.new
- @rankings = Ranking.recent
- @top_n = params[:n] ? params[:n].to_i : @rankings.size
- end
-
- private
def format_names(names)
names.collect(&:downcase).sort.uniq.collect(&:titleize)
View
@@ -47,6 +47,7 @@ def rating
def as_json(options)
{
player_name: player.display_name,
+ player_id: player.id,
wins: wins,
losses: losses,
games_played: games_played,
View
@@ -14,6 +14,7 @@
scope "/api" do
match "players" => "players#api_index"
+ match "players/:id" => "players#api_show"
match "rankings" => "players#rankings"
end

0 comments on commit dddf14a

Please sign in to comment.