Added steam profile lookup API endpoint

This commit is contained in:
Luke Barratt 2014-08-28 21:43:11 +01:00
parent b97b3173bc
commit 4b9f2e6d84
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 'country_code_select', '~> 1.0.1'
gem 'active_link_to', '~> 1.0.2' gem 'active_link_to', '~> 1.0.2'
gem 'rmagick', '~> 2.13.2', require: false gem 'rmagick', '~> 2.13.2', require: false
gem 'steam-condenser', github: 'koraktor/steam-condenser-ruby'
# Please install nodejs locally. # Please install nodejs locally.
gem 'therubyracer', '~> 0.12.1' if RUBY_PLATFORM == 'x86_64-linux' 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 GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
@ -128,6 +136,7 @@ GEM
mime-types (1.25.1) mime-types (1.25.1)
mini_portile (0.5.3) mini_portile (0.5.3)
multi_json (1.10.1) multi_json (1.10.1)
multi_xml (0.5.5)
multipart-post (2.0.0) multipart-post (2.0.0)
mysql2 (0.3.15) mysql2 (0.3.15)
neat (1.6.0) neat (1.6.0)
@ -295,6 +304,7 @@ DEPENDENCIES
selenium-webdriver (~> 2.41.0) selenium-webdriver (~> 2.41.0)
simplecov (~> 0.7.1) simplecov (~> 0.7.1)
sprockets (~> 2.2.1) sprockets (~> 2.2.1)
steam-condenser!
timecop (~> 0.7.1) timecop (~> 0.7.1)
tinymce-rails (~> 3.5.9) tinymce-rails (~> 3.5.9)
uglifier (~> 2.5.0) uglifier (~> 2.5.0)

View file

@ -35,3 +35,14 @@ $ ->
$(this).closest('form').submit() $(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 class Api::V1::UsersController < Api::V1::BaseController
def index 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
end end

View file

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

View file

@ -3,6 +3,12 @@ Ensl::Application.routes.draw do
get code, to: 'errors#show', code: code get code, to: 'errors#show', code: code
end end
namespace :api do
namespace :v1 do
resources :users, only: [:show, :index]
end
end
root to: "articles#news_index" root to: "articles#news_index"
resources :articles do resources :articles do
@ -130,10 +136,4 @@ Ensl::Application.routes.draw do
match ':controller/:action/:id/:id2' match ':controller/:action/:id/:id2'
match 'teamers/replace', to: 'teamers#replace', as: 'teamers_replace' match 'teamers/replace', to: 'teamers#replace', as: 'teamers_replace'
namespace :api do
namespace :v1 do
resources :users
end
end
end end