-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Api | ||
module Endpoints | ||
class StatusEndpoint < Grape::API | ||
format :json | ||
|
||
namespace :status do | ||
desc 'Get system status.' | ||
get do | ||
present self, with: Api::Presenters::StatusPresenter | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module Api | ||
module Presenters | ||
module StatusPresenter | ||
include Roar::JSON::HAL | ||
include Roar::Hypermedia | ||
include Grape::Roar::Representer | ||
|
||
link :self do |opts| | ||
"#{base_url(opts)}/status" | ||
end | ||
|
||
property :teams_count | ||
property :active_teams_count | ||
property :users_count | ||
property :challenges_count | ||
property :matches_count | ||
property :seasons_count | ||
property :ping | ||
|
||
private | ||
|
||
def teams_count | ||
Team.count | ||
end | ||
|
||
def users_count | ||
User.count | ||
end | ||
|
||
def challenges_count | ||
Challenge.count | ||
end | ||
|
||
def matches_count | ||
Match.count | ||
end | ||
|
||
def seasons_count | ||
Season.count | ||
end | ||
|
||
def active_teams_count | ||
Team.active.count | ||
end | ||
|
||
def ping | ||
team = Team.asc(:_id).first | ||
team.ping! if team | ||
end | ||
|
||
def base_url(opts) | ||
request = Grape::Request.new(opts[:env]) | ||
request.base_url | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'spec_helper' | ||
|
||
describe Api::Endpoints::StatusEndpoint do | ||
include Api::Test::EndpointTest | ||
|
||
before do | ||
allow_any_instance_of(Team).to receive(:ping!).and_return(ok: 1) | ||
end | ||
|
||
context 'status' do | ||
it 'returns a status' do | ||
status = client.status | ||
expect(status.teams_count).to eq 0 | ||
expect(status.active_teams_count).to eq 0 | ||
end | ||
|
||
context 'with a team' do | ||
let!(:team) { Fabricate(:team, active: false) } | ||
it 'returns a status' do | ||
status = client.status | ||
expect(status.teams_count).to eq 1 | ||
expect(status.active_teams_count).to eq 0 | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters