mirror of
https://github.com/ENSL/ensl.org.git
synced 2025-01-13 21:31:28 +00:00
Added server api
This commit is contained in:
parent
ed3bf229c0
commit
03ef45225c
4 changed files with 104 additions and 54 deletions
21
app/controllers/api/v1/servers_controller.rb
Normal file
21
app/controllers/api/v1/servers_controller.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
class Api::V1::ServersController < Api::V1::BaseController
|
||||
def index
|
||||
render json: { servers: active_servers }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def active_servers
|
||||
Server.active.map do |s|
|
||||
{
|
||||
id: s.id,
|
||||
description: s.description,
|
||||
dns: s.dns,
|
||||
ip: s.ip,
|
||||
port: s.port,
|
||||
password: s.password,
|
||||
category_id: s.category_id
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
|
@ -6,76 +6,77 @@ Ensl::Application.routes.draw do
|
|||
namespace :api do
|
||||
namespace :v1 do
|
||||
resources :users, only: [:show, :index]
|
||||
resources :servers, only: [:index]
|
||||
end
|
||||
end
|
||||
|
||||
root to: "articles#news_index"
|
||||
root to: "articles#news_index"
|
||||
|
||||
resources :articles do
|
||||
resources :versions
|
||||
end
|
||||
resources :articles do
|
||||
resources :versions
|
||||
end
|
||||
|
||||
match 'contests/del_map'
|
||||
match 'contests/scores'
|
||||
match 'contests/historical', to: "contests#historical"
|
||||
|
||||
resources :contests do
|
||||
get 'current', on: :collection
|
||||
end
|
||||
resources :contests do
|
||||
get 'current', on: :collection
|
||||
end
|
||||
|
||||
resources :log_events
|
||||
resources :categories
|
||||
resources :options
|
||||
resources :polls
|
||||
resources :categories
|
||||
resources :options
|
||||
resources :polls
|
||||
|
||||
match 'comments/quote'
|
||||
|
||||
resources :comments
|
||||
resources :shoutmsgs
|
||||
resources :teamers
|
||||
resources :teams
|
||||
resources :gathers
|
||||
resources :gatherers
|
||||
resources :groups
|
||||
resources :groupers
|
||||
resources :forumers
|
||||
resources :topics
|
||||
resources :comments
|
||||
resources :shoutmsgs
|
||||
resources :teamers
|
||||
resources :teams
|
||||
resources :gathers
|
||||
resources :gatherers
|
||||
resources :groups
|
||||
resources :groupers
|
||||
resources :forumers
|
||||
resources :topics
|
||||
|
||||
match 'forums/up'
|
||||
match 'forums/down'
|
||||
|
||||
resources :forums
|
||||
resources :users
|
||||
resources :locks
|
||||
resources :contesters
|
||||
resources :contests
|
||||
resources :challenges
|
||||
resources :servers
|
||||
resources :predictions
|
||||
resources :rounds
|
||||
resources :matches do |m|
|
||||
resources :forums
|
||||
resources :users
|
||||
resources :locks
|
||||
resources :contesters
|
||||
resources :contests
|
||||
resources :challenges
|
||||
resources :servers
|
||||
resources :predictions
|
||||
resources :rounds
|
||||
resources :matches do |m|
|
||||
get :admin, to: "matches#admin", on: :collection
|
||||
get :ref, to: "matches#ref"
|
||||
end
|
||||
|
||||
resources :maps
|
||||
resources :logs
|
||||
resources :log_files
|
||||
resources :directories
|
||||
resources :maps
|
||||
resources :logs
|
||||
resources :log_files
|
||||
resources :directories
|
||||
resources :data_files
|
||||
resources :predictions
|
||||
resources :weeks
|
||||
resources :movies
|
||||
resources :messages
|
||||
resources :sites
|
||||
resources :bans
|
||||
resources :tweets
|
||||
resources :issues
|
||||
resources :predictions
|
||||
resources :weeks
|
||||
resources :movies
|
||||
resources :messages
|
||||
resources :sites
|
||||
resources :bans
|
||||
resources :tweets
|
||||
resources :issues
|
||||
|
||||
match 'posts/quote'
|
||||
|
||||
resources :posts
|
||||
resources :brackets
|
||||
resources :posts
|
||||
resources :brackets
|
||||
|
||||
match 'about/action'
|
||||
match 'about/staff'
|
||||
|
@ -127,10 +128,10 @@ Ensl::Application.routes.draw do
|
|||
|
||||
match 'votes/create'
|
||||
|
||||
match ':controller/:action', requirements: { action: /A-Za-z/ }
|
||||
match ':controller/:action/:id'
|
||||
match ':controller/:action/:id.:format'
|
||||
match ':controller/:action/:id/:id2'
|
||||
match ':controller/:action', requirements: { action: /A-Za-z/ }
|
||||
match ':controller/:action/:id'
|
||||
match ':controller/:action/:id.:format'
|
||||
match ':controller/:action/:id/:id2'
|
||||
|
||||
match 'teamers/replace', to: 'teamers#replace', as: 'teamers_replace'
|
||||
end
|
||||
|
|
20
spec/controllers/api/v1/servers_controller_spec.rb
Normal file
20
spec/controllers/api/v1/servers_controller_spec.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Api::V1::ServersController do
|
||||
before do
|
||||
request.accept = 'application/json'
|
||||
end
|
||||
|
||||
describe '#index' do
|
||||
let!(:server) { create :server, :active }
|
||||
let!(:inactive_server) { create :server, :inactive }
|
||||
|
||||
it 'returns a list of servers' do
|
||||
get :index
|
||||
expect(response).to be_success
|
||||
expect(json['servers'].length).to eq(1)
|
||||
json_server = json['servers'][0]
|
||||
expect(json_server['id']).to eq(server.id)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,8 +1,16 @@
|
|||
FactoryGirl.define do
|
||||
factory :server do
|
||||
sequence(:name) { |n| "ServerName#{n}" }
|
||||
sequence(:dns) { |n| "DNS#{n}" }
|
||||
sequence(:ip) { |n| "192.168.#{n % 255}.#{n}" }
|
||||
sequence(:port) { |n| "#{1000 + n}" }
|
||||
end
|
||||
factory :server do
|
||||
sequence(:name) { |n| "ServerName#{n}" }
|
||||
sequence(:dns) { |n| "DNS#{n}" }
|
||||
sequence(:ip) { |n| "192.168.#{n % 255}.#{n}" }
|
||||
sequence(:port) { |n| "#{1000 + n}" }
|
||||
|
||||
trait :active do
|
||||
active true
|
||||
end
|
||||
|
||||
trait :inactive do
|
||||
active false
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue