Skip to content

Commit

Permalink
Merge pull request capcom6#46 from capcom6/feature/device-info-api
Browse files Browse the repository at this point in the history
Device information endpoint
  • Loading branch information
capcom6 authored Mar 5, 2024
2 parents ede8f03 + dd1808e commit 94a9a16
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ import me.capcom.smsgateway.R
import me.capcom.smsgateway.data.entities.Message
import me.capcom.smsgateway.domain.MessageState
import me.capcom.smsgateway.helpers.SettingsHelper
import me.capcom.smsgateway.modules.localserver.domain.Device
import me.capcom.smsgateway.modules.localserver.domain.PostMessageRequest
import me.capcom.smsgateway.modules.localserver.domain.PostMessageResponse
import me.capcom.smsgateway.modules.messages.MessagesService
import me.capcom.smsgateway.modules.messages.data.MessageSource
import me.capcom.smsgateway.modules.messages.data.SendRequest
import me.capcom.smsgateway.modules.notifications.NotificationsService
import org.koin.android.ext.android.inject
import java.util.Date
import kotlin.concurrent.thread

class WebService : Service() {
Expand Down Expand Up @@ -74,6 +76,10 @@ class WebService : Service() {
if (me.capcom.smsgateway.BuildConfig.DEBUG) {
setPrettyPrinting()
}
// ISO_8601
this.setDateFormat(
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"
)
}
}
install(StatusPages) {
Expand All @@ -99,6 +105,28 @@ class WebService : Service() {
get("/") {
call.respond(mapOf("status" to "ok", "model" to Build.MODEL))
}
route("/device") {
get {
val firstInstallTime = packageManager.getPackageInfo(
packageName,
0
).firstInstallTime
val deviceName = "${Build.MANUFACTURER}/${Build.PRODUCT}"
val deviceId =
deviceName.hashCode().toULong()
.toString(16).padStart(16, '0') + firstInstallTime.toULong()
.toString(16).padStart(16, '0')
val device = Device(
deviceId,
deviceName,
Date(firstInstallTime),
Date(),
Date()
)

call.respond(listOf(device))
}
}
route("/message") {
post {
val request = call.receive<PostMessageRequest>()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package me.capcom.smsgateway.modules.localserver.domain

import java.util.Date

data class Device(
val id: String,
val name: String,
val createdAt: Date,
val updatedAt: Date,
val lastSeen: Date
)
68 changes: 67 additions & 1 deletion docs/api/swagger.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"openapi": "3.0.0",
"info": {
"version": "1.5.0",
"version": "1.8.0",
"title": "Android SMS Gateway - Integration API",
"description": "Provides the ability to send SMS by sending requests directly to the device or through a cloud server.",
"contact": {
Expand Down Expand Up @@ -121,6 +121,43 @@
}
]
}
},
"/device": {
"get": {
"summary": "Get devices",
"description": "Returns a list of registered devices in the account",
"operationId": "get-device",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Device"
}
}
}
}
}
},
"security": [
{
"BasicAuth": []
}
],
"servers": [
{
"url": "http://device-ip:8080",
"description": "Device"
},
{
"url": "https://sms.capcom.me/api/3rdparty/v1",
"description": "Cloud"
}
]
}
}
},
"tags": [
Expand Down Expand Up @@ -180,6 +217,35 @@
}
},
"schemas": {
"Device": {
"type": "object",
"title": "Device",
"properties": {
"id": {
"type": "string",
"description": "ID"
},
"name": {
"type": "string",
"description": "Name"
},
"createdAt": {
"type": "string",
"description": "Created at",
"format": "date-time"
},
"updatedAt": {
"type": "string",
"description": "Updated at",
"format": "date-time"
},
"lastSeen": {
"type": "string",
"description": "Last seen date",
"format": "date-time"
}
}
},
"Message": {
"type": "object",
"title": "Message",
Expand Down

0 comments on commit 94a9a16

Please sign in to comment.