Class: Believe::Resources::Matches

Inherits:
Object
  • Object
show all
Defined in:
lib/believe/resources/matches.rb,
lib/believe/resources/matches/commentary.rb

Defined Under Namespace

Classes: Commentary

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Matches

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Matches.

Parameters:



282
283
284
285
# File 'lib/believe/resources/matches.rb', line 282

def initialize(client:)
  @client = client
  @commentary = ::Believe::Resources::Matches::Commentary.new(client: client)
end

Instance Attribute Details

#commentary::Believe::Resources::Matches::Commentary (readonly)

Server-Sent Events (SSE) streaming endpoints



8
9
10
# File 'lib/believe/resources/matches.rb', line 8

def commentary
  @commentary
end

Instance Method Details

#create(away_team_id:, date:, home_team_id:, match_type:, attendance: nil, away_score: nil, episode_id: nil, home_score: nil, lesson_learned: nil, possession_percentage: nil, result: nil, ted_halftime_speech: nil, ticket_revenue_gbp: nil, turning_points: nil, weather_temp_celsius: nil, request_options: {}) ⇒ ::Believe::Models::Match

Schedule a new match.

Parameters:

  • away_team_id (String)

    Away team ID

  • date (Time)

    Match date and time

  • home_team_id (String)

    Home team ID

  • match_type (Symbol, ::Believe::Models::MatchType)

    Type of match

  • attendance (Integer, nil)

    Match attendance

  • away_score (Integer)

    Away team score

  • episode_id (String, nil)

    Episode ID where this match is featured

  • home_score (Integer)

    Home team score

  • lesson_learned (String, nil)

    The life lesson learned from this match

  • possession_percentage (Float, nil)

    Home team possession percentage

  • result (Symbol, ::Believe::Models::MatchResult)

    Match result from home team perspective

  • ted_halftime_speech (String, nil)

    Ted’s inspirational halftime speech

  • ticket_revenue_gbp (Float, String, nil)

    Total ticket revenue in GBP

  • turning_points (Array<::Believe::Models::TurningPoint>)

    Key moments that changed the match

  • weather_temp_celsius (Float, nil)

    Temperature at kickoff in Celsius

  • request_options (::Believe::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



49
50
51
52
53
54
55
56
57
58
# File 'lib/believe/resources/matches.rb', line 49

def create(params)
  parsed, options = ::Believe::MatchCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "matches",
    body: parsed,
    model: ::Believe::Match,
    options: options
  )
end

#delete(match_id, request_options: {}) ⇒ nil

Remove a match from the database.

Parameters:

Returns:

  • (nil)

See Also:



173
174
175
176
177
178
179
180
# File 'lib/believe/resources/matches.rb', line 173

def delete(match_id, params = {})
  @client.request(
    method: :delete,
    path: ["matches/%1$s", match_id],
    model: NilClass,
    options: params[:request_options]
  )
end

#get_lesson(match_id, request_options: {}) ⇒ Hash{Symbol=>Object}

Get the life lesson learned from a specific match.

Parameters:

Returns:

  • (Hash{Symbol=>Object})

See Also:



192
193
194
195
196
197
198
199
# File 'lib/believe/resources/matches.rb', line 192

def get_lesson(match_id, params = {})
  @client.request(
    method: :get,
    path: ["matches/%1$s/lesson", match_id],
    model: ::Believe::Internal::Type::HashOf[::Believe::Internal::Type::Unknown],
    options: params[:request_options]
  )
end

#get_turning_points(match_id, request_options: {}) ⇒ Array<Hash{Symbol=>Object}>

Get all turning points from a specific match.

Parameters:

Returns:

  • (Array<Hash{Symbol=>Object}>)

See Also:



211
212
213
214
215
216
217
218
# File 'lib/believe/resources/matches.rb', line 211

def get_turning_points(match_id, params = {})
  @client.request(
    method: :get,
    path: ["matches/%1$s/turning-points", match_id],
    model: ::Believe::Internal::Type::ArrayOf[::Believe::Internal::Type::HashOf[::Believe::Internal::Type::Unknown]],
    options: params[:request_options]
  )
end

#list(limit: nil, match_type: nil, result: nil, skip: nil, team_id: nil, request_options: {}) ⇒ ::Believe::Internal::SkipLimitPage<::Believe::Models::Match>

Get a paginated list of all matches with optional filtering.

Parameters:

Returns:

See Also:



150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/believe/resources/matches.rb', line 150

def list(params = {})
  parsed, options = ::Believe::MatchListParams.dump_request(params)
  query = ::Believe::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "matches",
    query: query,
    page: ::Believe::Internal::SkipLimitPage,
    model: ::Believe::Match,
    options: options
  )
end

#retrieve(match_id, request_options: {}) ⇒ ::Believe::Models::Match

Retrieve detailed information about a specific match.

Parameters:

Returns:

See Also:



70
71
72
73
74
75
76
77
# File 'lib/believe/resources/matches.rb', line 70

def retrieve(match_id, params = {})
  @client.request(
    method: :get,
    path: ["matches/%1$s", match_id],
    model: ::Believe::Match,
    options: params[:request_options]
  )
end

#stream_live(away_team: nil, excitement_level: nil, home_team: nil, speed: nil, request_options: {}) ⇒ nil

WebSocket endpoint for real-time live match simulation.

Connect to receive a stream of match events as they happen in a simulated football match.

## Connection

Connect via WebSocket with optional query parameters to customize the simulation.

## Example WebSocket URL

“‘ ws://localhost:8000/matches/live “`

Append query parameters from the list above to customize the simulation.

## Server Messages

The server sends JSON messages with these types:

  • ‘match_start` - When the match begins

  • ‘match_event` - For each match event (goals, fouls, cards, etc.)

  • ‘match_end` - When the match concludes

  • ‘error` - If an error occurs

  • ‘pong` - Response to client ping

## Client Messages

Send JSON to control the simulation:

  • ‘“ping”` - Keep-alive, server responds with `“pong”`

  • ‘“pause”` - Pause the simulation

  • ‘“resume”` - Resume a paused simulation

  • ‘“set_speed”, “speed”: 2.0` - Change playback speed (0.1-10.0)

  • ‘“get_status”` - Request current match status

Parameters:

  • away_team (String)

    Away team name

  • excitement_level (Integer)

    How eventful the match should be (1=boring, 10=chaos)

  • home_team (String)

    Home team name

  • speed (Float)

    Simulation speed multiplier (1.0 = real-time)

  • request_options (::Believe::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



273
274
275
276
277
# File 'lib/believe/resources/matches.rb', line 273

def stream_live(params = {})
  parsed, options = ::Believe::MatchStreamLiveParams.dump_request(params)
  query = ::Believe::Internal::Util.encode_query_params(parsed)
  @client.request(method: :get, path: "matches/live", query: query, model: NilClass, options: options)
end

#update(match_id, attendance: nil, away_score: nil, away_team_id: nil, date: nil, episode_id: nil, home_score: nil, home_team_id: nil, lesson_learned: nil, match_type: nil, possession_percentage: nil, result: nil, ted_halftime_speech: nil, ticket_revenue_gbp: nil, turning_points: nil, weather_temp_celsius: nil, request_options: {}) ⇒ ::Believe::Models::Match

Update specific fields of an existing match (e.g., update score).

Parameters:

  • match_id (String)
  • attendance (Integer, nil)
  • away_score (Integer, nil)
  • away_team_id (String, nil)
  • date (Time, nil)
  • episode_id (String, nil)
  • home_score (Integer, nil)
  • home_team_id (String, nil)
  • lesson_learned (String, nil)
  • match_type (Symbol, ::Believe::Models::MatchType, nil)

    Types of matches.

  • possession_percentage (Float, nil)
  • result (Symbol, ::Believe::Models::MatchResult, nil)

    Match result types.

  • ted_halftime_speech (String, nil)
  • ticket_revenue_gbp (Float, String, nil)
  • turning_points (Array<::Believe::Models::TurningPoint>, nil)
  • weather_temp_celsius (Float, nil)
  • request_options (::Believe::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



120
121
122
123
124
125
126
127
128
129
# File 'lib/believe/resources/matches.rb', line 120

def update(match_id, params = {})
  parsed, options = ::Believe::MatchUpdateParams.dump_request(params)
  @client.request(
    method: :patch,
    path: ["matches/%1$s", match_id],
    body: parsed,
    model: ::Believe::Match,
    options: options
  )
end