Class: Lishogi::ChallengesApi

Inherits:
Object
  • Object
show all
Defined in:
lib/lishogi/api/challenges_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client = ApiClient.default) ⇒ ChallengesApi

Returns a new instance of ChallengesApi.



19
20
21
# File 'lib/lishogi/api/challenges_api.rb', line 19

def initialize(api_client = ApiClient.default)
  @api_client = api_client
end

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



17
18
19
# File 'lib/lishogi/api/challenges_api.rb', line 17

def api_client
  @api_client
end

Instance Method Details

#challenge_accept(challenge_id, opts = {}) ⇒ Ok

Accept a challenge Accept an incoming challenge. You should receive a ‘gameStart` event on the [incoming events stream](#operation/apiStreamEvent).

Parameters:

  • challenge_id (String)
  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



27
28
29
30
# File 'lib/lishogi/api/challenges_api.rb', line 27

def challenge_accept(challenge_id, opts = {})
  data, _status_code, _headers = challenge_accept_with_http_info(challenge_id, opts)
  data
end

#challenge_accept_with_http_info(challenge_id, opts = {}) ⇒ Array<(Ok, Integer, Hash)>

Accept a challenge Accept an incoming challenge. You should receive a &#x60;gameStart&#x60; event on the [incoming events stream](#operation/apiStreamEvent).

Parameters:

  • challenge_id (String)
  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(Ok, Integer, Hash)>)

    Ok data, response status code and response headers



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/lishogi/api/challenges_api.rb', line 37

def challenge_accept_with_http_info(challenge_id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: ChallengesApi.challenge_accept ...'
  end
  # verify the required parameter 'challenge_id' is set
  if @api_client.config.client_side_validation && challenge_id.nil?
    fail ArgumentError, "Missing the required parameter 'challenge_id' when calling ChallengesApi.challenge_accept"
  end
  # resource path
  local_var_path = '/api/challenge/{challengeId}/accept'.sub('{' + 'challengeId' + '}', CGI.escape(challenge_id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Ok'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['OAuth2']

  new_options = opts.merge(
    :operation => :"ChallengesApi.challenge_accept",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: ChallengesApi#challenge_accept\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#challenge_ai(opts = {}) ⇒ GameJson

Challenge the AI Start a game with Lishogi AI. You will be notified on the [event stream](#operation/apiStreamEvent) that a new game has started.

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :level (Float)

    AI strength

  • :clock_limit (Float)

    Clock initial time in seconds. If empty, a correspondence game is created.

  • :clock_increment (Integer)

    Clock increment in seconds. If empty, a correspondence game is created.

  • :clock_byoyomi (Integer)

    Clock byoyomi in seconds. If empty, a correspondence game is created.

  • :clock_periods (Integer)

    Clock periods for byoyomi in seconds. If empty, a correspondence game is created.

  • :days (Integer)

    Days per move, for correspondence games. Clock settings must be omitted.

  • :color (String)

    Which color you get to play (default to ‘random’)

  • :variant (VariantKey) — default: default to 'standard'
  • :sfen (String)

    Custom initial position (in SFEN). Variant must be standard, and the game cannot be rated. (default to ‘rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1’)

Returns:



98
99
100
101
# File 'lib/lishogi/api/challenges_api.rb', line 98

def challenge_ai(opts = {})
  data, _status_code, _headers = challenge_ai_with_http_info(opts)
  data
end

#challenge_ai_with_http_info(opts = {}) ⇒ Array<(GameJson, Integer, Hash)>

Challenge the AI Start a game with Lishogi AI. You will be notified on the [event stream](#operation/apiStreamEvent) that a new game has started.

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :level (Float)

    AI strength

  • :clock_limit (Float)

    Clock initial time in seconds. If empty, a correspondence game is created.

  • :clock_increment (Integer)

    Clock increment in seconds. If empty, a correspondence game is created.

  • :clock_byoyomi (Integer)

    Clock byoyomi in seconds. If empty, a correspondence game is created.

  • :clock_periods (Integer)

    Clock periods for byoyomi in seconds. If empty, a correspondence game is created.

  • :days (Integer)

    Days per move, for correspondence games. Clock settings must be omitted.

  • :color (String)

    Which color you get to play (default to ‘random’)

  • :variant (VariantKey) — default: default to 'standard'
  • :sfen (String)

    Custom initial position (in SFEN). Variant must be standard, and the game cannot be rated. (default to ‘rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1’)

Returns:

  • (Array<(GameJson, Integer, Hash)>)

    GameJson data, response status code and response headers



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/lishogi/api/challenges_api.rb', line 116

def challenge_ai_with_http_info(opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: ChallengesApi.challenge_ai ...'
  end
  if @api_client.config.client_side_validation && !opts[:'level'].nil? && opts[:'level'] > 8
    fail ArgumentError, 'invalid value for "opts[:"level"]" when calling ChallengesApi.challenge_ai, must be smaller than or equal to 8.'
  end

  if @api_client.config.client_side_validation && !opts[:'level'].nil? && opts[:'level'] < 1
    fail ArgumentError, 'invalid value for "opts[:"level"]" when calling ChallengesApi.challenge_ai, must be greater than or equal to 1.'
  end

  if @api_client.config.client_side_validation && !opts[:'clock_limit'].nil? && opts[:'clock_limit'] > 10800
    fail ArgumentError, 'invalid value for "opts[:"clock_limit"]" when calling ChallengesApi.challenge_ai, must be smaller than or equal to 10800.'
  end

  if @api_client.config.client_side_validation && !opts[:'clock_limit'].nil? && opts[:'clock_limit'] < 0
    fail ArgumentError, 'invalid value for "opts[:"clock_limit"]" when calling ChallengesApi.challenge_ai, must be greater than or equal to 0.'
  end

  if @api_client.config.client_side_validation && !opts[:'clock_increment'].nil? && opts[:'clock_increment'] > 60
    fail ArgumentError, 'invalid value for "opts[:"clock_increment"]" when calling ChallengesApi.challenge_ai, must be smaller than or equal to 60.'
  end

  if @api_client.config.client_side_validation && !opts[:'clock_increment'].nil? && opts[:'clock_increment'] < 0
    fail ArgumentError, 'invalid value for "opts[:"clock_increment"]" when calling ChallengesApi.challenge_ai, must be greater than or equal to 0.'
  end

  if @api_client.config.client_side_validation && !opts[:'clock_byoyomi'].nil? && opts[:'clock_byoyomi'] > 60
    fail ArgumentError, 'invalid value for "opts[:"clock_byoyomi"]" when calling ChallengesApi.challenge_ai, must be smaller than or equal to 60.'
  end

  if @api_client.config.client_side_validation && !opts[:'clock_byoyomi'].nil? && opts[:'clock_byoyomi'] < 0
    fail ArgumentError, 'invalid value for "opts[:"clock_byoyomi"]" when calling ChallengesApi.challenge_ai, must be greater than or equal to 0.'
  end

  if @api_client.config.client_side_validation && !opts[:'clock_periods'].nil? && opts[:'clock_periods'] > 5
    fail ArgumentError, 'invalid value for "opts[:"clock_periods"]" when calling ChallengesApi.challenge_ai, must be smaller than or equal to 5.'
  end

  if @api_client.config.client_side_validation && !opts[:'clock_periods'].nil? && opts[:'clock_periods'] < 1
    fail ArgumentError, 'invalid value for "opts[:"clock_periods"]" when calling ChallengesApi.challenge_ai, must be greater than or equal to 1.'
  end

  allowable_values = [1, 2, 3, 5, 7, 10, 14]
  if @api_client.config.client_side_validation && opts[:'days'] && !allowable_values.include?(opts[:'days'])
    fail ArgumentError, "invalid value for \"days\", must be one of #{allowable_values}"
  end
  allowable_values = ["random", "sente", "gote"]
  if @api_client.config.client_side_validation && opts[:'color'] && !allowable_values.include?(opts[:'color'])
    fail ArgumentError, "invalid value for \"color\", must be one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/api/challenge/ai'

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['application/x-www-form-urlencoded'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end

  # form parameters
  form_params = opts[:form_params] || {}
  form_params['level'] = opts[:'level'] if !opts[:'level'].nil?
  form_params['clock.limit'] = opts[:'clock_limit'] if !opts[:'clock_limit'].nil?
  form_params['clock.increment'] = opts[:'clock_increment'] if !opts[:'clock_increment'].nil?
  form_params['clock.byoyomi'] = opts[:'clock_byoyomi'] if !opts[:'clock_byoyomi'].nil?
  form_params['clock.periods'] = opts[:'clock_periods'] if !opts[:'clock_periods'].nil?
  form_params['days'] = opts[:'days'] if !opts[:'days'].nil?
  form_params['color'] = opts[:'color'] if !opts[:'color'].nil?
  form_params['variant'] = opts[:'variant'] if !opts[:'variant'].nil?
  form_params['sfen'] = opts[:'sfen'] if !opts[:'sfen'].nil?

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'GameJson'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['OAuth2']

  new_options = opts.merge(
    :operation => :"ChallengesApi.challenge_ai",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: ChallengesApi#challenge_ai\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#challenge_create(username, opts = {}) ⇒ ChallengeJson

Create a challenge Challenge someone to play. The targeted player can choose to accept or decline. If the challenge is accepted, you will be notified on the [event stream](#operation/apiStreamEvent) that a new game has started. The game ID will be the same as the challenge ID. If you also have an OAuth token with ‘challenge:write` scope for the receiving user, you can make them accept the challenge immediately by setting the `acceptByToken` field. Challenges for realtime games (not correspondence) expire after 20s if not accepted. To prevent that, use the `keepAliveStream` flag described below.

Parameters:

  • username (String)
  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :rated (Boolean)

    Game is rated and impacts players ratings

  • :clock_limit (Float)

    Clock initial time in seconds. If empty, a correspondence game is created.

  • :clock_increment (Integer)

    Clock increment in seconds. If empty, a correspondence game is created.

  • :clock_byoyomi (Integer)

    Clock byoyomi in seconds. If empty, a correspondence game is created.

  • :clock_periods (Integer)

    Clock periods for byoyomi in seconds. If empty, a correspondence game is created.

  • :days (Integer)

    Days per move, for correspondence games. Clock settings must be omitted.

  • :color (String)

    Which color you get to play (default to ‘random’)

  • :variant (VariantKey) — default: default to 'standard'
  • :sfen (String)

    Custom initial position (in SFEN). Variant must be standard, and the game cannot be rated. (default to ‘rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1’)

  • :keep_alive_stream (Boolean)

    If set, the response is streamed as [ndjson](#section/Introduction/Streaming-with-ND-JSON). The challenge is kept alive until the connection is closed by the client. When the challenge is accepted or declined, a message of the form &#x60;\&quot;done\&quot;:\&quot;accepted\&quot;&#x60; is sent, then the connection is closed by the server. If not set, the response is not streamed, and the challenge expires after 20s if not accepted.

  • :accept_by_token (String)

    Immediately accept the challenge and create the game. Pass in an OAuth token (with the &#x60;challenge:write&#x60; scope) for the receiving user. On success, the response will contain a &#x60;game&#x60; field instead of a &#x60;challenge&#x60; field.

  • :message (String)

    **Only if &#x60;acceptByToken&#x60; is set.** Message that is sent to each player, when the game is created. It is sent from your user account. &#x60;opponent&#x60;, &#x60;player&#x60; and &#x60;game&#x60; are placeholders that will be replaced with the opponent name, player name, and the game URLs. You can omit this field to send the default message, but if you set your own message, it must at least contain the &#x60;game&#x60; placeholder. (default to ‘Your game with opponent is ready: game.’)

Returns:



239
240
241
242
# File 'lib/lishogi/api/challenges_api.rb', line 239

def challenge_create(username, opts = {})
  data, _status_code, _headers = challenge_create_with_http_info(username, opts)
  data
end

#challenge_create_with_http_info(username, opts = {}) ⇒ Array<(ChallengeJson, Integer, Hash)>

Create a challenge Challenge someone to play. The targeted player can choose to accept or decline. If the challenge is accepted, you will be notified on the [event stream](#operation/apiStreamEvent) that a new game has started. The game ID will be the same as the challenge ID. If you also have an OAuth token with &#x60;challenge:write&#x60; scope for the receiving user, you can make them accept the challenge immediately by setting the &#x60;acceptByToken&#x60; field. Challenges for realtime games (not correspondence) expire after 20s if not accepted. To prevent that, use the &#x60;keepAliveStream&#x60; flag described below.

Parameters:

  • username (String)
  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :rated (Boolean)

    Game is rated and impacts players ratings

  • :clock_limit (Float)

    Clock initial time in seconds. If empty, a correspondence game is created.

  • :clock_increment (Integer)

    Clock increment in seconds. If empty, a correspondence game is created.

  • :clock_byoyomi (Integer)

    Clock byoyomi in seconds. If empty, a correspondence game is created.

  • :clock_periods (Integer)

    Clock periods for byoyomi in seconds. If empty, a correspondence game is created.

  • :days (Integer)

    Days per move, for correspondence games. Clock settings must be omitted.

  • :color (String)

    Which color you get to play (default to ‘random’)

  • :variant (VariantKey) — default: default to 'standard'
  • :sfen (String)

    Custom initial position (in SFEN). Variant must be standard, and the game cannot be rated. (default to ‘rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1’)

  • :keep_alive_stream (Boolean)

    If set, the response is streamed as [ndjson](#section/Introduction/Streaming-with-ND-JSON). The challenge is kept alive until the connection is closed by the client. When the challenge is accepted or declined, a message of the form &#x60;\&quot;done\&quot;:\&quot;accepted\&quot;&#x60; is sent, then the connection is closed by the server. If not set, the response is not streamed, and the challenge expires after 20s if not accepted.

  • :accept_by_token (String)

    Immediately accept the challenge and create the game. Pass in an OAuth token (with the &#x60;challenge:write&#x60; scope) for the receiving user. On success, the response will contain a &#x60;game&#x60; field instead of a &#x60;challenge&#x60; field.

  • :message (String)

    **Only if &#x60;acceptByToken&#x60; is set.** Message that is sent to each player, when the game is created. It is sent from your user account. &#x60;opponent&#x60;, &#x60;player&#x60; and &#x60;game&#x60; are placeholders that will be replaced with the opponent name, player name, and the game URLs. You can omit this field to send the default message, but if you set your own message, it must at least contain the &#x60;game&#x60; placeholder. (default to ‘Your game with opponent is ready: game.’)

Returns:

  • (Array<(ChallengeJson, Integer, Hash)>)

    ChallengeJson data, response status code and response headers



261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/lishogi/api/challenges_api.rb', line 261

def challenge_create_with_http_info(username, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: ChallengesApi.challenge_create ...'
  end
  # verify the required parameter 'username' is set
  if @api_client.config.client_side_validation && username.nil?
    fail ArgumentError, "Missing the required parameter 'username' when calling ChallengesApi.challenge_create"
  end
  if @api_client.config.client_side_validation && !opts[:'clock_limit'].nil? && opts[:'clock_limit'] > 10800
    fail ArgumentError, 'invalid value for "opts[:"clock_limit"]" when calling ChallengesApi.challenge_create, must be smaller than or equal to 10800.'
  end

  if @api_client.config.client_side_validation && !opts[:'clock_limit'].nil? && opts[:'clock_limit'] < 0
    fail ArgumentError, 'invalid value for "opts[:"clock_limit"]" when calling ChallengesApi.challenge_create, must be greater than or equal to 0.'
  end

  if @api_client.config.client_side_validation && !opts[:'clock_increment'].nil? && opts[:'clock_increment'] > 60
    fail ArgumentError, 'invalid value for "opts[:"clock_increment"]" when calling ChallengesApi.challenge_create, must be smaller than or equal to 60.'
  end

  if @api_client.config.client_side_validation && !opts[:'clock_increment'].nil? && opts[:'clock_increment'] < 0
    fail ArgumentError, 'invalid value for "opts[:"clock_increment"]" when calling ChallengesApi.challenge_create, must be greater than or equal to 0.'
  end

  if @api_client.config.client_side_validation && !opts[:'clock_byoyomi'].nil? && opts[:'clock_byoyomi'] > 60
    fail ArgumentError, 'invalid value for "opts[:"clock_byoyomi"]" when calling ChallengesApi.challenge_create, must be smaller than or equal to 60.'
  end

  if @api_client.config.client_side_validation && !opts[:'clock_byoyomi'].nil? && opts[:'clock_byoyomi'] < 0
    fail ArgumentError, 'invalid value for "opts[:"clock_byoyomi"]" when calling ChallengesApi.challenge_create, must be greater than or equal to 0.'
  end

  if @api_client.config.client_side_validation && !opts[:'clock_periods'].nil? && opts[:'clock_periods'] > 5
    fail ArgumentError, 'invalid value for "opts[:"clock_periods"]" when calling ChallengesApi.challenge_create, must be smaller than or equal to 5.'
  end

  if @api_client.config.client_side_validation && !opts[:'clock_periods'].nil? && opts[:'clock_periods'] < 1
    fail ArgumentError, 'invalid value for "opts[:"clock_periods"]" when calling ChallengesApi.challenge_create, must be greater than or equal to 1.'
  end

  allowable_values = [1, 2, 3, 5, 7, 10, 14]
  if @api_client.config.client_side_validation && opts[:'days'] && !allowable_values.include?(opts[:'days'])
    fail ArgumentError, "invalid value for \"days\", must be one of #{allowable_values}"
  end
  allowable_values = ["random", "sente", "gote"]
  if @api_client.config.client_side_validation && opts[:'color'] && !allowable_values.include?(opts[:'color'])
    fail ArgumentError, "invalid value for \"color\", must be one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/api/challenge/{username}'.sub('{' + 'username' + '}', CGI.escape(username.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['application/x-www-form-urlencoded'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end

  # form parameters
  form_params = opts[:form_params] || {}
  form_params['rated'] = opts[:'rated'] if !opts[:'rated'].nil?
  form_params['clock.limit'] = opts[:'clock_limit'] if !opts[:'clock_limit'].nil?
  form_params['clock.increment'] = opts[:'clock_increment'] if !opts[:'clock_increment'].nil?
  form_params['clock.byoyomi'] = opts[:'clock_byoyomi'] if !opts[:'clock_byoyomi'].nil?
  form_params['clock.periods'] = opts[:'clock_periods'] if !opts[:'clock_periods'].nil?
  form_params['days'] = opts[:'days'] if !opts[:'days'].nil?
  form_params['color'] = opts[:'color'] if !opts[:'color'].nil?
  form_params['variant'] = opts[:'variant'] if !opts[:'variant'].nil?
  form_params['sfen'] = opts[:'sfen'] if !opts[:'sfen'].nil?
  form_params['keepAliveStream'] = opts[:'keep_alive_stream'] if !opts[:'keep_alive_stream'].nil?
  form_params['acceptByToken'] = opts[:'accept_by_token'] if !opts[:'accept_by_token'].nil?
  form_params['message'] = opts[:'message'] if !opts[:'message'].nil?

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'ChallengeJson'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['OAuth2']

  new_options = opts.merge(
    :operation => :"ChallengesApi.challenge_create",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: ChallengesApi#challenge_create\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#challenge_decline(challenge_id, opts = {}) ⇒ Ok

Decline a challenge Decline an incoming challenge.

Parameters:

  • challenge_id (String)
  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



371
372
373
374
# File 'lib/lishogi/api/challenges_api.rb', line 371

def challenge_decline(challenge_id, opts = {})
  data, _status_code, _headers = challenge_decline_with_http_info(challenge_id, opts)
  data
end

#challenge_decline_with_http_info(challenge_id, opts = {}) ⇒ Array<(Ok, Integer, Hash)>

Decline a challenge Decline an incoming challenge.

Parameters:

  • challenge_id (String)
  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(Ok, Integer, Hash)>)

    Ok data, response status code and response headers



381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
# File 'lib/lishogi/api/challenges_api.rb', line 381

def challenge_decline_with_http_info(challenge_id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: ChallengesApi.challenge_decline ...'
  end
  # verify the required parameter 'challenge_id' is set
  if @api_client.config.client_side_validation && challenge_id.nil?
    fail ArgumentError, "Missing the required parameter 'challenge_id' when calling ChallengesApi.challenge_decline"
  end
  # resource path
  local_var_path = '/api/challenge/{challengeId}/decline'.sub('{' + 'challengeId' + '}', CGI.escape(challenge_id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Ok'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['OAuth2']

  new_options = opts.merge(
    :operation => :"ChallengesApi.challenge_decline",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: ChallengesApi#challenge_decline\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#challenge_open(opts = {}) ⇒ Object

Open-ended challenge Create a challenge that any 2 players can join. Share the URL of the challenge. the first 2 players to click it will be paired for a game. The response body also contains ‘senteUrl` and `goteUrl`. You can control which color each player gets by giving them these URLs, instead of the main challenge URL. Open challenges expire after 24h. To directly pair 2 known players, use [this endpoint](#operation/challengeCreate) instead, with the `acceptByToken` parameter.

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :rated (Boolean)

    Game is rated and impacts players ratings

  • :clock_limit (Float)

    Clock initial time in seconds. If empty, a correspondence game is created.

  • :clock_increment (Integer)

    Clock increment in seconds. If empty, a correspondence game is created.

  • :clock_byoyomi (Integer)

    Clock byoyomi in seconds. If empty, a correspondence game is created.

  • :clock_periods (Integer)

    Clock periods for byoyomi in seconds. If empty, a correspondence game is created.

  • :days (Integer)

    Days per turn. For correspondence challenges.

  • :variant (VariantKey) — default: default to 'standard'
  • :sfen (String)

    Custom initial position (in SFEN). Variant must be standard, and the game cannot be rated. (default to ‘rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1’)

  • :name (String)

    Optional name for the challenge, that players will see on the challenge page.

Returns:

  • (Object)


442
443
444
445
# File 'lib/lishogi/api/challenges_api.rb', line 442

def challenge_open(opts = {})
  data, _status_code, _headers = challenge_open_with_http_info(opts)
  data
end

#challenge_open_with_http_info(opts = {}) ⇒ Array<(Object, Integer, Hash)>

Open-ended challenge Create a challenge that any 2 players can join. Share the URL of the challenge. the first 2 players to click it will be paired for a game. The response body also contains &#x60;senteUrl&#x60; and &#x60;goteUrl&#x60;. You can control which color each player gets by giving them these URLs, instead of the main challenge URL. Open challenges expire after 24h. To directly pair 2 known players, use [this endpoint](#operation/challengeCreate) instead, with the &#x60;acceptByToken&#x60; parameter.

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :rated (Boolean)

    Game is rated and impacts players ratings

  • :clock_limit (Float)

    Clock initial time in seconds. If empty, a correspondence game is created.

  • :clock_increment (Integer)

    Clock increment in seconds. If empty, a correspondence game is created.

  • :clock_byoyomi (Integer)

    Clock byoyomi in seconds. If empty, a correspondence game is created.

  • :clock_periods (Integer)

    Clock periods for byoyomi in seconds. If empty, a correspondence game is created.

  • :days (Integer)

    Days per turn. For correspondence challenges.

  • :variant (VariantKey) — default: default to 'standard'
  • :sfen (String)

    Custom initial position (in SFEN). Variant must be standard, and the game cannot be rated. (default to ‘rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1’)

  • :name (String)

    Optional name for the challenge, that players will see on the challenge page.

Returns:

  • (Array<(Object, Integer, Hash)>)

    Object data, response status code and response headers



460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
# File 'lib/lishogi/api/challenges_api.rb', line 460

def challenge_open_with_http_info(opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: ChallengesApi.challenge_open ...'
  end
  if @api_client.config.client_side_validation && !opts[:'clock_limit'].nil? && opts[:'clock_limit'] > 10800
    fail ArgumentError, 'invalid value for "opts[:"clock_limit"]" when calling ChallengesApi.challenge_open, must be smaller than or equal to 10800.'
  end

  if @api_client.config.client_side_validation && !opts[:'clock_limit'].nil? && opts[:'clock_limit'] < 0
    fail ArgumentError, 'invalid value for "opts[:"clock_limit"]" when calling ChallengesApi.challenge_open, must be greater than or equal to 0.'
  end

  if @api_client.config.client_side_validation && !opts[:'clock_increment'].nil? && opts[:'clock_increment'] > 60
    fail ArgumentError, 'invalid value for "opts[:"clock_increment"]" when calling ChallengesApi.challenge_open, must be smaller than or equal to 60.'
  end

  if @api_client.config.client_side_validation && !opts[:'clock_increment'].nil? && opts[:'clock_increment'] < 0
    fail ArgumentError, 'invalid value for "opts[:"clock_increment"]" when calling ChallengesApi.challenge_open, must be greater than or equal to 0.'
  end

  if @api_client.config.client_side_validation && !opts[:'clock_byoyomi'].nil? && opts[:'clock_byoyomi'] > 60
    fail ArgumentError, 'invalid value for "opts[:"clock_byoyomi"]" when calling ChallengesApi.challenge_open, must be smaller than or equal to 60.'
  end

  if @api_client.config.client_side_validation && !opts[:'clock_byoyomi'].nil? && opts[:'clock_byoyomi'] < 0
    fail ArgumentError, 'invalid value for "opts[:"clock_byoyomi"]" when calling ChallengesApi.challenge_open, must be greater than or equal to 0.'
  end

  if @api_client.config.client_side_validation && !opts[:'clock_periods'].nil? && opts[:'clock_periods'] > 5
    fail ArgumentError, 'invalid value for "opts[:"clock_periods"]" when calling ChallengesApi.challenge_open, must be smaller than or equal to 5.'
  end

  if @api_client.config.client_side_validation && !opts[:'clock_periods'].nil? && opts[:'clock_periods'] < 1
    fail ArgumentError, 'invalid value for "opts[:"clock_periods"]" when calling ChallengesApi.challenge_open, must be greater than or equal to 1.'
  end

  allowable_values = [1, 2, 3, 5, 7, 10, 14]
  if @api_client.config.client_side_validation && opts[:'days'] && !allowable_values.include?(opts[:'days'])
    fail ArgumentError, "invalid value for \"days\", must be one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/api/challenge/open'

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['application/x-www-form-urlencoded'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end

  # form parameters
  form_params = opts[:form_params] || {}
  form_params['rated'] = opts[:'rated'] if !opts[:'rated'].nil?
  form_params['clock.limit'] = opts[:'clock_limit'] if !opts[:'clock_limit'].nil?
  form_params['clock.increment'] = opts[:'clock_increment'] if !opts[:'clock_increment'].nil?
  form_params['clock.byoyomi'] = opts[:'clock_byoyomi'] if !opts[:'clock_byoyomi'].nil?
  form_params['clock.periods'] = opts[:'clock_periods'] if !opts[:'clock_periods'].nil?
  form_params['days'] = opts[:'days'] if !opts[:'days'].nil?
  form_params['variant'] = opts[:'variant'] if !opts[:'variant'].nil?
  form_params['sfen'] = opts[:'sfen'] if !opts[:'sfen'].nil?
  form_params['name'] = opts[:'name'] if !opts[:'name'].nil?

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Object'

  # auth_names
  auth_names = opts[:debug_auth_names] || []

  new_options = opts.merge(
    :operation => :"ChallengesApi.challenge_open",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: ChallengesApi#challenge_open\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end