Added steam profile lookup API endpoint

This commit is contained in:
Luke Barratt 2014-08-28 21:43:11 +01:00
parent 68b6c15b4f
commit a676d4c423
6 changed files with 47 additions and 11 deletions

View file

@ -23,6 +23,7 @@ gem 'dynamic_form', '~> 1.1.4'
gem 'country_code_select', '~> 1.0.1'
gem 'active_link_to', '~> 1.0.2'
gem 'rmagick', '~> 2.13.2', require: false
gem 'steam-condenser', github: 'koraktor/steam-condenser-ruby'
# Please install nodejs locally.
gem 'therubyracer', '~> 0.12.1' if RUBY_PLATFORM == 'x86_64-linux'

View file

@ -1,3 +1,11 @@
GIT
remote: git://github.com/koraktor/steam-condenser-ruby.git
revision: c8a7b69d3dc73d56c1de6b6653ec45491d047db1
specs:
steam-condenser (1.3.9)
multi_json (~> 1.6)
multi_xml (~> 0.5)
GEM
remote: http://rubygems.org/
specs:
@ -128,6 +136,7 @@ GEM
mime-types (1.25.1)
mini_portile (0.5.3)
multi_json (1.10.1)
multi_xml (0.5.5)
multipart-post (2.0.0)
mysql2 (0.3.15)
neat (1.6.0)
@ -295,6 +304,7 @@ DEPENDENCIES
selenium-webdriver (~> 2.41.0)
simplecov (~> 0.7.1)
sprockets (~> 2.2.1)
steam-condenser!
timecop (~> 0.7.1)
tinymce-rails (~> 3.5.9)
uglifier (~> 2.5.0)

View file

@ -34,4 +34,15 @@ $ ->
$('select.autosubmit').change ->
$(this).closest('form').submit()
$('#notification').delay(3000).fadeOut()
$('#notification').delay(3000).fadeOut()
$('#steam-search a').click (event) ->
event.preventDefault()
$search = $('#steam-search')
id = $search.data 'user-id'
$search.html "<p>Searching...</p>"
$.get "/api/v1/users/#{id}", (data) ->
$search.html "<a href='#{data.steam.url}'>Steam Profile: #{data.steam.nickname}</a>"

View file

@ -1,5 +1,17 @@
class Api::V1::UsersController < Api::V1::BaseController
def index
respond_with Api::V1::UsersCollection.as_json
render json: Api::V1::UsersCollection.as_json
end
def show
@user = User.find(params[:id])
@steam = SteamCondenser::Community::SteamId.from_steam_id("STEAM_#{@user.steamid}")
render json: {
steam: {
url: @steam.base_url,
nickname: @steam.nickname
}
}
end
end

View file

@ -10,8 +10,10 @@
<dd><%= @user.profile.town %></dd>
<dt>SteamID</dt>
<dd>
<%= @user.steamid %>
<%= link_to "Search for Steam Account", "http://steamidfinder.com/?STEAM_#{@user.steamid}" %>
<p><%= @user.steamid %></p>
<div id="steam-search" data-user-id="<%= @user.id %>">
<%= link_to "Search for Steam Account" %>
</div>
</dd>
</dl>

View file

@ -1,8 +1,14 @@
Ensl::Application.routes.draw do
Ensl::Application.routes.draw do
%w(403 404 422 500).each do |code|
get code, to: 'errors#show', code: code
end
namespace :api do
namespace :v1 do
resources :users, only: [:show, :index]
end
end
root to: "articles#news_index"
resources :articles do
@ -130,10 +136,4 @@ Ensl::Application.routes.draw do
match ':controller/:action/:id/:id2'
match 'teamers/replace', to: 'teamers#replace', as: 'teamers_replace'
namespace :api do
namespace :v1 do
resources :users
end
end
end