Class: Barker::Api::Base

Inherits:
Object
  • Object
show all
Includes:
Errors
Defined in:
lib/barker/api/base.rb

Constant Summary

Constants included from Errors

Errors::AlreadyAnsweredError, Errors::AlreadyStartedError, Errors::AnswerNotFoundError, Errors::BarkerError, Errors::FileNotExistError, Errors::HasToRespondToIdError, Errors::HasToRespondToLocaleError, Errors::JokerAlreadyUsedError, Errors::NoCurrentStageError, Errors::NotStartedError, Errors::RecordNotFound, Errors::UnknownJokerError

Instance Method Summary collapse

Instance Method Details

#abort(game_show_id) ⇒ Object



62
63
64
65
66
# File 'lib/barker/api/base.rb', line 62

def abort(game_show_id)
  catch_error do
    build_game_show repo.around(game_show_id) { |game_show| game_show.abort }
  end
end

#answer(game_show_id, candidate_id, answer_id) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/barker/api/base.rb', line 89

def answer(game_show_id, candidate_id, answer_id)
  catch_error do
    game_show = repo.get game_show_id
    given_answer = game_show.answer(candidate_id, answer_id)
    repo.update game_show
    build_candidate_answer(given_answer)
  end
end

#ask(game_show_id, candidate_id, options = {}) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/barker/api/base.rb', line 80

def ask(game_show_id, candidate_id, options = {})
  catch_error do
    game_show = repo.get game_show_id
    candidate_question = game_show.ask(candidate_id, options)
    repo.update game_show
    build_candidate_question(candidate_question)
  end
end

#create(options = {}) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/barker/api/base.rb', line 7

def create(options = {})
  catch_error do
    game_show = Barker::GameShow.new([], [], :guideline => options[:guideline])
    repo.add game_show
    build_game_show(game_show)
  end
end

#finish(game_show_id) ⇒ Object



56
57
58
59
60
# File 'lib/barker/api/base.rb', line 56

def finish(game_show_id)
  catch_error do
    build_game_show repo.around(game_show_id) { |game_show| game_show.finish }
  end
end

#get(game_show_id) ⇒ Object



15
16
17
18
19
# File 'lib/barker/api/base.rb', line 15

def get(game_show_id)
  catch_error do
    build_game_show repo.get(game_show_id)
  end
end

#join(game_show_id, candidate_id, candidate_locale) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/barker/api/base.rb', line 27

def join(game_show_id, candidate_id, candidate_locale)
  catch_error do
    candidate = Barker::Candidate.new(OpenStruct.new(:id => candidate_id, :locale => candidate_locale))
    repo.around(game_show_id) { |game_show| game_show.join(candidate) }
    build_candidate(candidate)
  end
end

#joker(game_show_id, candidate_id, joker_id) ⇒ Object



98
99
100
101
102
103
104
105
106
# File 'lib/barker/api/base.rb', line 98

def joker(game_show_id, candidate_id, joker_id)
  catch_error do
    game_show = repo.get game_show_id
    candidate_question = game_show.ask(candidate_id)
    candidate_joker = game_show.joker(candidate_id, joker_id)
    repo.update game_show
    build_candidate_joker(candidate_joker)
  end
end

#leave(game_show_id, candidate_id) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/barker/api/base.rb', line 35

def leave(game_show_id, candidate_id)
  catch_error do
    game_show = repo.get game_show_id
    candidate = game_show.leave(candidate_id)
    repo.update game_show
    build_candidate(candidate)
  end
end

#next_round(game_show_id) ⇒ Object



74
75
76
77
78
# File 'lib/barker/api/base.rb', line 74

def next_round(game_show_id)
  catch_error do
    build_game_show repo.around(game_show_id) { |game_show| game_show.next_round }
  end
end

#next_stage(game_show_id) ⇒ Object



68
69
70
71
72
# File 'lib/barker/api/base.rb', line 68

def next_stage(game_show_id)
  catch_error do
    build_game_show repo.around(game_show_id) { |game_show| game_show.next_stage }
  end
end

#raw(game_show_id) ⇒ Object



50
51
52
53
54
# File 'lib/barker/api/base.rb', line 50

def raw(game_show_id)
  catch_error do
    repo.get(game_show_id)
  end
end

#remove(game_show_id) ⇒ Object



21
22
23
24
25
# File 'lib/barker/api/base.rb', line 21

def remove(game_show_id)
  catch_error do
    build_game_show repo.remove(repo.get(game_show_id))
  end
end

#start(game_show_id) ⇒ Object



44
45
46
47
48
# File 'lib/barker/api/base.rb', line 44

def start(game_show_id)
  catch_error do
    build_game_show repo.around(game_show_id) { |game_show| game_show.start }
  end
end