Class: Strutta::APIObject Abstract

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

Overview

This class is abstract.

APIObject contains all the HTTP request methods

Direct Known Subclasses

Entries, Flow, Judging, Moderation, Participants, Points, Rounds

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#gameObject

Returns the value of attribute game.


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

def game
  @game
end

Instance Method Details

#all(params = {}) ⇒ Hash

GET index request (Uses instance vars of child object to generate resource path)

Returns:

  • (Hash)

    Parsed body of the API response

[View source]

12
13
14
15
# File 'lib/strutta-api/api_object.rb', line 12

def all(params = {})
  @game.verify_no_id(@id)
  @game.all(params, "#{@game.id}/#{@root_path}")
end

#create(params = {}) ⇒ Hash

POST request (Uses instance vars of child object to generate resource path)

Returns:

  • (Hash)

    Parsed body of the API response

[View source]

21
22
23
24
# File 'lib/strutta-api/api_object.rb', line 21

def create(params = {})
  @game.verify_no_id(@id)
  @game.create(params, "#{@game.id}/#{@root_path}")
end

#deleteHash

DELETE request (Uses instance vars of child object to generate resource path)

Returns:

  • (Hash)

    Parsed body of the API response

[View source]

48
49
50
51
# File 'lib/strutta-api/api_object.rb', line 48

def delete
  @game.verify_id(@id, Errors::ROUND_ID_REQUIRED)
  @game.delete(@root_path)
end

#get(params = {}) ⇒ Hash

GET request (Uses instance vars of child object to generate resource path)

Returns:

  • (Hash)

    Parsed body of the API response

[View source]

30
31
32
33
# File 'lib/strutta-api/api_object.rb', line 30

def get(params = {})
  @game.verify_id(@id, Errors::ROUND_ID_REQUIRED)
  @game.get(params, @root_path)
end

#method_disabled(*_) ⇒ Object

Manually disable a method in child classed

[View source]

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

def method_disabled(*_)
  fail Errors::DisabledEndpointError, Errors::METHOD_DISABLED
end

#update(params = {}) ⇒ Hash

PATCH request (Uses instance vars of child object to generate resource path)

Returns:

  • (Hash)

    Parsed body of the API response

[View source]

39
40
41
42
# File 'lib/strutta-api/api_object.rb', line 39

def update(params = {})
  @game.verify_id(@id, Errors::ROUND_ID_REQUIRED)
  @game.update(params, @root_path)
end