mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-12-25 03:50:53 +00:00
commit
de62098c0a
4 changed files with 67 additions and 3 deletions
23
app/controllers/api/v1/teams_controller.rb
Normal file
23
app/controllers/api/v1/teams_controller.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
class Api::V1::TeamsController < Api::V1::BaseController
|
||||
def index
|
||||
render json: Api::V1::UsersCollection.as_json
|
||||
end
|
||||
|
||||
def show
|
||||
@team = Team.find params[:id]
|
||||
render json: {
|
||||
id: @team.id,
|
||||
name: @team.name,
|
||||
logo: @team.logo,
|
||||
members: @team.teamers.active.map do |m|
|
||||
{
|
||||
id: m.user.id,
|
||||
username: m.user.username,
|
||||
steamid: m.user.steamid
|
||||
}
|
||||
end
|
||||
}
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
raise ActionController::RoutingError.new("User Not Found")
|
||||
end
|
||||
end
|
|
@ -39,7 +39,7 @@ end
|
|||
|
||||
class GoogleCalendar
|
||||
class Request
|
||||
BASE_URL = "https://www.googleapis.com/calendar/v3/calendars"
|
||||
BASE_URL = "https://www.googleapis.com/"
|
||||
EVENTS_ENDPOINT = "events"
|
||||
|
||||
def self.events_list(id, timezone_offset)
|
||||
|
@ -61,7 +61,12 @@ class GoogleCalendar
|
|||
|
||||
def get_data
|
||||
Rails.cache.fetch(cache_key, expires_in: 5.minutes) do
|
||||
Faraday.get(request_url)
|
||||
if Rails.env.development?
|
||||
conn = Faraday.new(BASE_URL, ssl: {verify: false})
|
||||
else
|
||||
conn = Faraday.new(BASE_URL)
|
||||
end
|
||||
conn.get(request_url)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -76,7 +81,7 @@ class GoogleCalendar
|
|||
#that is longer ago then 7 days.
|
||||
#Alternative: maxResults=2500
|
||||
time_min = (Time.now - 7.days).utc.iso8601
|
||||
"#{BASE_URL}/#{@id}/#{@endpoint}/?key=#{ENV['GOOGLE_API_KEY']}&timeMin=#{time_min}"
|
||||
"calendar/v3/calendars/#{@id}/#{@endpoint}/?key=#{ENV['GOOGLE_API_KEY']}&timeMin=#{time_min}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ Ensl::Application.routes.draw do
|
|||
namespace :api do
|
||||
namespace :v1 do
|
||||
resources :users, only: [:show, :index]
|
||||
resources :teams, only: [:show]
|
||||
resources :servers, only: [:index]
|
||||
resources :maps, only: [:index]
|
||||
end
|
||||
|
|
35
spec/controllers/api/v1/teams_controller_spec.rb
Normal file
35
spec/controllers/api/v1/teams_controller_spec.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
require "spec_helper"
|
||||
|
||||
describe Api::V1::TeamsController do
|
||||
before do
|
||||
request.accept = "application/json"
|
||||
end
|
||||
|
||||
describe "#show" do
|
||||
before(:each) do
|
||||
@founder = create :user
|
||||
@team_member = create :user
|
||||
@ex_team_member = create :user
|
||||
@team = create :team, founder: @founder
|
||||
Teamer.create user: @team_member, team: @team, rank: Teamer::RANK_MEMBER
|
||||
Teamer.create user: @ex_team_member, team: @team, rank: Teamer::RANK_REMOVED
|
||||
end
|
||||
|
||||
it "returns team data" do
|
||||
get :show, id: @team.id
|
||||
expect(response).to be_success
|
||||
expect(json["id"]).to eq(@team.id)
|
||||
expect(json["name"]).to eq(@team.name)
|
||||
|
||||
json["members"].each do |member|
|
||||
expect(@team.teamers.active.map(&:user_id)).to include(member["id"])
|
||||
end
|
||||
end
|
||||
|
||||
it "returns 404 if team not found" do
|
||||
expect {
|
||||
get :show, id: Team.last.id + 1
|
||||
}.to raise_error(ActionController::RoutingError)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue