Skip to content

Commit

Permalink
fixed GeneralAPIs
Browse files Browse the repository at this point in the history
  • Loading branch information
yamin8000 committed Feb 9, 2024
1 parent 8d9acb2 commit 670c1cd
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "gradle"
directory: "/"
schedule:
interval: "weekly"
23 changes: 23 additions & 0 deletions .github/workflows/dependency-submission.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Dependency Submission

on: [ push ]

permissions:
contents: write

jobs:
dependency-submission:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Generate and submit dependency graph
uses: gradle/actions/dependency-submission@v3
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ class GameClient(
block: HttpRequestBuilder.() -> Unit = {}
) = _client.request("$baseApiUrl$endpoint", block)

suspend fun rawRequest(
url: String,
block: HttpRequestBuilder.() -> Unit = {}
) = _client.request(url, block)

suspend fun authorizedGet(endpoint: String) = authorizedRequest(endpoint, HttpMethod.Get)

suspend inline fun <reified T> authorizedPost(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
package com.github.yamin8000.spacetraders_sdk.web.api

import com.github.yamin8000.spacetraders_sdk.model.status.Status
import com.github.yamin8000.spacetraders_sdk.model.general.RegisterRequest
import com.github.yamin8000.spacetraders_sdk.model.general.RegisterResponse
import com.github.yamin8000.spacetraders_sdk.model.status.Status
import com.github.yamin8000.spacetraders_sdk.web.Constants.BASE
import com.github.yamin8000.spacetraders_sdk.web.GameClient
import com.github.yamin8000.spacetraders_sdk.web.Utility.data
import com.github.yamin8000.spacetraders_sdk.web.Utility.div
import io.ktor.client.call.*
import io.ktor.client.request.*
import io.ktor.client.statement.*

object GeneralAPIs {
/**
* Returns a simple status of the game server.
*/
suspend fun GameClient.simpleStatus() = client.get(BASE / "game/status").bodyAsText()
suspend fun GameClient.simpleStatus() = rawRequest("$BASE/game/status").bodyAsText()

/**
* Returns the status of the game server.
*/
suspend fun GameClient.status(): Status = get("").body()
suspend fun GameClient.status(): Status = rawRequest("$BASE/v2").body()

/**
* Creates a new agent and ties it to a temporary Account.
Expand All @@ -34,5 +33,5 @@ object GeneralAPIs {
*/
suspend fun GameClient.register(
registerRequest: RegisterRequest
): RegisterResponse = client.post(BASE / "register") { setBody(registerRequest) }.data()
): RegisterResponse = post(BASE / "register", registerRequest).data()
}

0 comments on commit 670c1cd

Please sign in to comment.