43 lines
906 B
GDScript
43 lines
906 B
GDScript
class_name DealApi
|
|
extends RefCounted
|
|
|
|
var _api_client: ApiClient
|
|
|
|
|
|
func _init(api_client: ApiClient = null) -> void:
|
|
_api_client = api_client
|
|
|
|
|
|
func set_api_client(api_client: ApiClient) -> void:
|
|
_api_client = api_client
|
|
|
|
|
|
func product_list(token: String) -> Dictionary:
|
|
if _api_client == null:
|
|
return _missing_client_result()
|
|
return await _api_client.get_query("deal/productlist", {"token": token})
|
|
|
|
|
|
func order(token: String, sid: int, price: int, count: int, state: String) -> Dictionary:
|
|
if _api_client == null:
|
|
return _missing_client_result()
|
|
var money := price * count
|
|
return await _api_client.post_form("deal/order", {
|
|
"token": token,
|
|
"sid": sid,
|
|
"price": price,
|
|
"num": count,
|
|
"money": money,
|
|
"state": state,
|
|
})
|
|
|
|
|
|
func _missing_client_result() -> Dictionary:
|
|
return {
|
|
"ok": false,
|
|
"offline": true,
|
|
"status": 0,
|
|
"body": {},
|
|
"text": "DealApi missing ApiClient."
|
|
}
|