Class: Strutta::Games

Inherits:
Object
  • Object
show all
Defined in:
lib/strutta-api/games.rb

Overview

The Strutta Games object is the master of all other API objects (Rounds, Flow, Entries, Participants) The above objects are instantiated in association with a Games object, as each belong to a Game in the Strutta API The above objects also have all their API requests forwarded through this object to Strutta::API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id = nil, master) ⇒ Strutta::Games

Initializes the Strutta::Games object



13
14
15
16
17
# File 'lib/strutta-api/games.rb', line 13

def initialize(id = nil, master)
  @id = id
  @root_path = 'games'
  @master = master
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/strutta-api/games.rb', line 6

def id
  @id
end

#masterObject

Returns the value of attribute master.



6
7
8
# File 'lib/strutta-api/games.rb', line 6

def master
  @master
end

Instance Method Details

#all(params = {}, resource_path = nil) ⇒ Hash

Polymorphic GET Index request



34
35
36
37
# File 'lib/strutta-api/games.rb', line 34

def all(params = {}, resource_path = nil)
  verify_no_id(@id) unless resource_path
  call('get', "#{@root_path}/#{resource_path}", params)
end

#call(method, url, params = {}) ⇒ Hash

Forwards an API call to @master



25
26
27
# File 'lib/strutta-api/games.rb', line 25

def call(method, url, params = {})
  @master.call(method, url, params)
end

#create(params = {}, resource_path = nil) ⇒ Hash

Polymorphic POST request



54
55
56
57
# File 'lib/strutta-api/games.rb', line 54

def create(params = {}, resource_path = nil)
  verify_no_id(@id) unless resource_path
  call('post', "#{@root_path}/#{resource_path}", params)
end

#delete(resource_path = nil) ⇒ Hash

Polymorphic DELETE request



74
75
76
77
# File 'lib/strutta-api/games.rb', line 74

def delete(resource_path = nil)
  verify_id(@id, Errors::GAME_ID_REQUIRED)
  call('delete', "#{@root_path}/#{@id}/#{resource_path}", {})
end

#entries(id = nil) ⇒ Strutta::Entries

Instantiates a Strutta::Entries object with reference to this Game



110
111
112
113
# File 'lib/strutta-api/games.rb', line 110

def entries(id = nil)
  verify_id(@id, Errors::GAME_ID_REQUIRED)
  Entries.new id, self
end

#flow(id = nil) ⇒ Strutta::Flow

Instantiates a Strutta::Flow object with reference to this Game



101
102
103
104
# File 'lib/strutta-api/games.rb', line 101

def flow(id = nil)
  verify_id(@id, Errors::GAME_ID_REQUIRED)
  Flow.new id, self
end

#get(params = {}, resource_path = '') ⇒ Hash

Polymorphic GET single object request



44
45
46
47
# File 'lib/strutta-api/games.rb', line 44

def get(params = {}, resource_path = '')
  verify_id(@id, Errors::GAME_ID_REQUIRED)
  call('get', "#{@root_path}/#{@id}/#{resource_path}", params)
end

#judging(id = nil) ⇒ Strutta::Entries

Instantiates a Strutta::Judging object with reference to this Game



137
138
139
140
# File 'lib/strutta-api/games.rb', line 137

def judging(id = nil)
  verify_id(@id, Errors::GAME_ID_REQUIRED)
  Judging.new id, self
end

#moderation(id = nil) ⇒ Strutta::Entries

Instantiates a Strutta::Moderation object with reference to this Game



128
129
130
131
# File 'lib/strutta-api/games.rb', line 128

def moderation(id = nil)
  verify_id(@id, Errors::GAME_ID_REQUIRED)
  Moderation.new id, self
end

#participants(id = nil) ⇒ Strutta::Participants

Instantiates a Strutta::Participants object with reference to this Game



92
93
94
95
# File 'lib/strutta-api/games.rb', line 92

def participants(id = nil)
  verify_id(@id, Errors::GAME_ID_REQUIRED)
  Participants.new id, self
end

#points(id = nil) ⇒ Strutta::Entries

Instantiates a Strutta::Points object with reference to this Game



119
120
121
122
# File 'lib/strutta-api/games.rb', line 119

def points(id = nil)
  verify_id(@id, Errors::GAME_ID_REQUIRED)
  Points.new id, self
end

#rounds(id = nil) ⇒ Strutta::Rounds

Instantiates a Strutta::Rounds object with reference to this Game



83
84
85
86
# File 'lib/strutta-api/games.rb', line 83

def rounds(id = nil)
  verify_id(@id, Errors::GAME_ID_REQUIRED)
  Rounds.new id, self
end

#update(params, resource_path = nil) ⇒ Hash

Polymorphic PATCH request



64
65
66
67
# File 'lib/strutta-api/games.rb', line 64

def update(params, resource_path = nil)
  verify_id(@id, Errors::GAME_ID_REQUIRED)
  call('patch', "#{@root_path}/#{@id}/#{resource_path}", params)
end

#verify_id(id, message) ⇒ nil

Confirm that an id exists for a request



147
148
149
# File 'lib/strutta-api/games.rb', line 147

def verify_id(id, message)
  fail Errors::ObjectIDRequired, message unless id
end

#verify_no_id(id) ⇒ nil

Confirm that no id exists for a request



155
156
157
# File 'lib/strutta-api/games.rb', line 155

def verify_no_id(id)
  fail Errors::ObjectIDNotAllowed, Errors::OBJECT_NOT_ALLOWED if id
end