mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 17:24:26 +08:00
update API tools script
This commit is contained in:
+74
-36
@@ -78,9 +78,9 @@ $API_CONFIGS = @(
|
|||||||
" `"category`": `"integer (Account category, 1: Cash, 2: Checking Account, 3: Credit Card, 4: Virtual Account, 5: Debt Account, 6: Receivables, 7: Investment Account, 8: Savings Account, 9: Certificate of Deposit)`","
|
" `"category`": `"integer (Account category, 1: Cash, 2: Checking Account, 3: Credit Card, 4: Virtual Account, 5: Debt Account, 6: Receivables, 7: Investment Account, 8: Savings Account, 9: Certificate of Deposit)`","
|
||||||
" `"type`": `"integer (Account type, 1: Single Account, 2: Multiple Sub-accounts)`","
|
" `"type`": `"integer (Account type, 1: Single Account, 2: Multiple Sub-accounts)`","
|
||||||
" `"icon`": `"string (Account icon ID)`","
|
" `"icon`": `"string (Account icon ID)`","
|
||||||
" `"color`": `"string (Account icon color, Hex color code RRGGBB)`","
|
" `"color`": `"string (Account icon color, hex color code RRGGBB)`","
|
||||||
" `"currency`": `"string (Account currency code)`","
|
" `"currency`": `"string (Account currency code)`","
|
||||||
" `"balance`": `"integer (Account balance, supports up to two decimals. For example, a value of `"1234`" represents an amount of `"12.34`")`","
|
" `"balance`": `"integer (Account balance, supports up to two decimals. For example, a value of '1234' represents an amount of '12.34')`","
|
||||||
" `"comment`": `"string (Account description)`","
|
" `"comment`": `"string (Account description)`","
|
||||||
" `"creditCardStatementDate`": `"integer (The statement date of the credit card account)`","
|
" `"creditCardStatementDate`": `"integer (The statement date of the credit card account)`","
|
||||||
" `"displayOrder`": `"integer (The display order of the account)`","
|
" `"displayOrder`": `"integer (The display order of the account)`","
|
||||||
@@ -254,8 +254,10 @@ $API_CONFIGS = @(
|
|||||||
ResponseStructure = @(
|
ResponseStructure = @(
|
||||||
"{"
|
"{"
|
||||||
" `"id`": `"string (Transaction tag ID)`","
|
" `"id`": `"string (Transaction tag ID)`","
|
||||||
" `"name`": `"string`","
|
" `"name`": `"string (Transaction tag name)`","
|
||||||
" ..."
|
" `"groupId`": `"string (Transaction tag group ID)`","
|
||||||
|
" `"displayOrder`": `"integer (The display order of the transaction tag)`","
|
||||||
|
" `"hidden`": `"boolean (Whether the transaction tag is hidden)`""
|
||||||
"}"
|
"}"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -316,8 +318,8 @@ $API_CONFIGS = @(
|
|||||||
" `"sourceAccount`": `"object (Source account object)`","
|
" `"sourceAccount`": `"object (Source account object)`","
|
||||||
" `"destinationAccountId`": `"string (Destination account ID)`","
|
" `"destinationAccountId`": `"string (Destination account ID)`","
|
||||||
" `"destinationAccount`": `"object (Destination account object)`","
|
" `"destinationAccount`": `"object (Destination account object)`","
|
||||||
" `"sourceAmount`": `"integer (Source amount, supports up to two decimals. For example, a value of 1234 represents an amount of 12.34)`","
|
" `"sourceAmount`": `"integer (Source amount, supports up to two decimals. For example, a value of '1234' represents an amount of '12.34')`","
|
||||||
" `"destinationAmount`": `"integer (Destination amount, supports up to two decimals. For example, a value of 1234 represents an amount of 12.34)`","
|
" `"destinationAmount`": `"integer (Destination amount, supports up to two decimals. For example, a value of '1234' represents an amount of '12.34')`","
|
||||||
" `"hideAmount`": `"boolean (Whether to hide the amount)`","
|
" `"hideAmount`": `"boolean (Whether to hide the amount)`","
|
||||||
" `"tagIds`": [`"each string representing a transaction tag ID`"],"
|
" `"tagIds`": [`"each string representing a transaction tag ID`"],"
|
||||||
" `"tags`": [`"each object representing a transaction tag object`"],"
|
" `"tags`": [`"each object representing a transaction tag object`"],"
|
||||||
@@ -327,7 +329,7 @@ $API_CONFIGS = @(
|
|||||||
" `"editable`": `"boolean (Whether the transaction is editable)`""
|
" `"editable`": `"boolean (Whether the transaction is editable)`""
|
||||||
" }"
|
" }"
|
||||||
" ],"
|
" ],"
|
||||||
" `"nextTimeSequenceId`": `"integer (The next cursor ``max_time`` parameter when requesting older data)`","
|
" `"nextTimeSequenceId`": `"integer (The next cursor 'max_time' parameter when requesting older data)`","
|
||||||
" `"totalCount`": `"integer (The total count of transactions)`""
|
" `"totalCount`": `"integer (The total count of transactions)`""
|
||||||
"}"
|
"}"
|
||||||
)
|
)
|
||||||
@@ -382,8 +384,8 @@ $API_CONFIGS = @(
|
|||||||
" `"sourceAccount`": `"object (Source account object)`","
|
" `"sourceAccount`": `"object (Source account object)`","
|
||||||
" `"destinationAccountId`": `"string (Destination account ID)`","
|
" `"destinationAccountId`": `"string (Destination account ID)`","
|
||||||
" `"destinationAccount`": `"object (Destination account object)`","
|
" `"destinationAccount`": `"object (Destination account object)`","
|
||||||
" `"sourceAmount`": `"integer (Source amount, supports up to two decimals. For example, a value of 1234 represents an amount of 12.34)`","
|
" `"sourceAmount`": `"integer (Source amount, supports up to two decimals. For example, a value of '1234' represents an amount of '12.34')`","
|
||||||
" `"destinationAmount`": `"integer (Destination amount, supports up to two decimals. For example, a value of 1234 represents an amount of 12.34)`","
|
" `"destinationAmount`": `"integer (Destination amount, supports up to two decimals. For example, a value of '1234' represents an amount of '12.34')`","
|
||||||
" `"hideAmount`": `"boolean (Whether to hide the amount)`","
|
" `"hideAmount`": `"boolean (Whether to hide the amount)`","
|
||||||
" `"tagIds`": [`"each string representing a transaction tag ID`"],"
|
" `"tagIds`": [`"each string representing a transaction tag ID`"],"
|
||||||
" `"tags`": [`"each object representing a transaction tag object`"],"
|
" `"tags`": [`"each object representing a transaction tag object`"],"
|
||||||
@@ -460,7 +462,7 @@ $API_CONFIGS = @(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Reference: https://raw.githubusercontent.com/unicode-org/cldr/main/common/supplemental/windowsZones.xml
|
# Reference: https://github.com/unicode-org/cldr/blob/main/common/supplemental/windowsZones.xml
|
||||||
$TIMEZONE_IANA_NAMES = @{
|
$TIMEZONE_IANA_NAMES = @{
|
||||||
"Dateline Standard Time" = "Etc/GMT+12"
|
"Dateline Standard Time" = "Etc/GMT+12"
|
||||||
"UTC-11" = "Etc/GMT+11"
|
"UTC-11" = "Etc/GMT+11"
|
||||||
@@ -473,7 +475,7 @@ $TIMEZONE_IANA_NAMES = @{
|
|||||||
"UTC-08" = "Etc/GMT+8"
|
"UTC-08" = "Etc/GMT+8"
|
||||||
"Pacific Standard Time" = "America/Los_Angeles"
|
"Pacific Standard Time" = "America/Los_Angeles"
|
||||||
"US Mountain Standard Time" = "America/Phoenix"
|
"US Mountain Standard Time" = "America/Phoenix"
|
||||||
"Mountain Standard Time (Mexico)" = "America/Chihuahua"
|
"Mountain Standard Time (Mexico)" = "America/Mazatlan"
|
||||||
"Mountain Standard Time" = "America/Denver"
|
"Mountain Standard Time" = "America/Denver"
|
||||||
"Yukon Standard Time" = "America/Whitehorse"
|
"Yukon Standard Time" = "America/Whitehorse"
|
||||||
"Central America Standard Time" = "America/Guatemala"
|
"Central America Standard Time" = "America/Guatemala"
|
||||||
@@ -732,17 +734,37 @@ function Get-SystemTimezoneName {
|
|||||||
} catch {
|
} catch {
|
||||||
# Do Nothing
|
# Do Nothing
|
||||||
}
|
}
|
||||||
return "Asia/Shanghai"
|
return $null
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-ExampleTimezoneName {
|
||||||
|
$name = Get-SystemTimezoneName
|
||||||
|
|
||||||
|
if ($null -ne $name) {
|
||||||
|
return "$name"
|
||||||
|
} else {
|
||||||
|
return "Asia/Shanghai"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-SystemTimezoneOffset {
|
function Get-SystemTimezoneOffset {
|
||||||
try {
|
try {
|
||||||
$offset = [System.TimeZoneInfo]::Local.BaseUtcOffset
|
$offset = [System.TimeZoneInfo]::Local.BaseUtcOffset
|
||||||
return [int]$offset.TotalMinutes
|
return [string]$offset.TotalMinutes.ToString()
|
||||||
} catch {
|
} catch {
|
||||||
# Do Nothing
|
# Do Nothing
|
||||||
}
|
}
|
||||||
return 480
|
return $null
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-ExampleTimezoneOffset {
|
||||||
|
$offset = Get-SystemTimezoneOffset
|
||||||
|
|
||||||
|
if ($null -ne $offset) {
|
||||||
|
return "$offset"
|
||||||
|
} else {
|
||||||
|
return "480"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-ApiConfig {
|
function Get-ApiConfig {
|
||||||
@@ -758,8 +780,8 @@ function Get-ApiConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Show-Help {
|
function Show-Help {
|
||||||
$tzName = Get-SystemTimezoneName
|
$exampleTimezoneName = Get-ExampleTimezoneName
|
||||||
$tzOffset = Get-SystemTimezoneOffset
|
$exampleTimezoneOffset = Get-ExampleTimezoneOffset
|
||||||
|
|
||||||
Write-Host "ezBookkeeping API Tools"
|
Write-Host "ezBookkeeping API Tools"
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
@@ -768,14 +790,14 @@ function Show-Help {
|
|||||||
Write-Host "Usage:"
|
Write-Host "Usage:"
|
||||||
Write-Host " ebktools.ps1 [-tzName <name>] [-tzOffset <offset>] <command> [command-options]"
|
Write-Host " ebktools.ps1 [-tzName <name>] [-tzOffset <offset>] <command> [command-options]"
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
Write-Host "Global Options:"
|
|
||||||
Write-Host " -tzName <name> The IANA timezone name, for example, for Beijing Time it is 'Asia/Shanghai'."
|
|
||||||
Write-Host " -tzOffset <offset> The offset in minutes of the current timezone from UTC. For example, for Beijing Time which is UTC+8, the value is '480'. If both are provided, '-tzName' takes precedence."
|
|
||||||
Write-Host ""
|
|
||||||
Write-Host "Environment Variables (Required):"
|
Write-Host "Environment Variables (Required):"
|
||||||
Write-Host " EBKTOOL_SERVER_BASEURL ezBookkeeping server base URL (e.g., http://localhost:8080)"
|
Write-Host " EBKTOOL_SERVER_BASEURL ezBookkeeping server base URL (e.g., http://localhost:8080)"
|
||||||
Write-Host " EBKTOOL_TOKEN ezBookkeeping API token"
|
Write-Host " EBKTOOL_TOKEN ezBookkeeping API token"
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
|
Write-Host "Global Options:"
|
||||||
|
Write-Host " -tzName <name> The IANA timezone name of current timezone. For example, for Beijing Time it is 'Asia/Shanghai'."
|
||||||
|
Write-Host " -tzOffset <offset> The offset in minutes of the current timezone from UTC. For example, for Beijing Time which is UTC+8, the value is '480'. If both '-tzName' and '-tzOffset' are set, '-tzName' takes priority. If neither is set, the current system time zone is used by default."
|
||||||
|
Write-Host ""
|
||||||
Write-Host "Commands:"
|
Write-Host "Commands:"
|
||||||
Write-Host " list List all available API commands"
|
Write-Host " list List all available API commands"
|
||||||
Write-Host " help <api-command> Show help for a specific API command"
|
Write-Host " help <api-command> Show help for a specific API command"
|
||||||
@@ -796,10 +818,10 @@ function Show-Help {
|
|||||||
Write-Host " ebktools.ps1 accounts-list"
|
Write-Host " ebktools.ps1 accounts-list"
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
Write-Host " # Call API with timezone name"
|
Write-Host " # Call API with timezone name"
|
||||||
Write-Host " ebktools.ps1 -tzName $tzName transactions-list -count 10"
|
Write-Host " ebktools.ps1 -tzName $exampleTimezoneName transactions-list -count 10"
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
Write-Host " # Call API with timezone offset"
|
Write-Host " # Call API with timezone offset"
|
||||||
Write-Host " ebktools.ps1 -tzOffset $tzOffset transactions-list -count 10"
|
Write-Host " ebktools.ps1 -tzOffset $exampleTimezoneOffset transactions-list -count 10"
|
||||||
}
|
}
|
||||||
|
|
||||||
function Show-CommandList {
|
function Show-CommandList {
|
||||||
@@ -831,6 +853,7 @@ function Show-CommandHelp {
|
|||||||
Write-Host "Description: $($config.Description)"
|
Write-Host "Description: $($config.Description)"
|
||||||
Write-Host "Method: $($config.Method)"
|
Write-Host "Method: $($config.Method)"
|
||||||
Write-Host "Path: $($config.Path)"
|
Write-Host "Path: $($config.Path)"
|
||||||
|
Write-Host ("Require current time zone: " + ($(if ($config.RequiresTimezone) { 'Yes' } else { 'No' })))
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
|
|
||||||
if ($config.RequiredParams.Count -gt 0) {
|
if ($config.RequiredParams.Count -gt 0) {
|
||||||
@@ -860,9 +883,14 @@ function Show-CommandHelp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Example:"
|
Write-Host "Example:"
|
||||||
if ($config.RequiresTimezone) {
|
$currentTzName = Get-SystemTimezoneName
|
||||||
$tzName = Get-SystemTimezoneName
|
$currentTzOffset = Get-SystemTimezoneOffset
|
||||||
Write-Host " ebktools.ps1 -tzName $tzName $($config.Name)"
|
if ($config.RequiresTimezone -and $null -ne $currentTzName) {
|
||||||
|
Write-Host " ebktools.ps1 -tzName $currentTzName $($config.Name)"
|
||||||
|
} elseif ($config.RequiresTimezone -and $null -ne $currentTzOffset) {
|
||||||
|
Write-Host " ebktools.ps1 -tzOffset $currentTzOffset $($config.Name)"
|
||||||
|
} elseif ($config.RequiresTimezone) {
|
||||||
|
Write-Host " ebktools.ps1 -tzName <name> $($config.Name)"
|
||||||
} else {
|
} else {
|
||||||
Write-Host " ebktools.ps1 $($config.Name)"
|
Write-Host " ebktools.ps1 $($config.Name)"
|
||||||
}
|
}
|
||||||
@@ -969,25 +997,35 @@ function Invoke-Api {
|
|||||||
|
|
||||||
if (-not $serverBaseUrl) {
|
if (-not $serverBaseUrl) {
|
||||||
Write-Red "Error: Environment variable 'EBKTOOL_SERVER_BASEURL' is not set."
|
Write-Red "Error: Environment variable 'EBKTOOL_SERVER_BASEURL' is not set."
|
||||||
Write-Host "Please set it to your API server base URL (e.g., http://localhost:8080)"
|
Write-Host "Please set it to your ezBookkeeping server base URL (e.g., http://localhost:8080)"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-not $authToken) {
|
if (-not $authToken) {
|
||||||
Write-Red "Error: Environment variable 'EBKTOOL_TOKEN' is not set."
|
Write-Red "Error: Environment variable 'EBKTOOL_TOKEN' is not set."
|
||||||
Write-Host "Please set it to your authentication token."
|
Write-Host "Please set it to your API token."
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($config.RequiresTimezone -and -not $script:tzName -and -not $script:tzOffset) {
|
$currentTimezoneName = Get-SystemTimezoneName
|
||||||
$tzName = Get-SystemTimezoneName
|
$currentTimezoneOffset = Get-SystemTimezoneOffset
|
||||||
$tzOffset = Get-SystemTimezoneOffset
|
|
||||||
|
if ($script:tzName -ne $null -and $script:tzName -ne "") {
|
||||||
|
$currentTimezoneName = $script:tzName
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($script:tzOffset -ne $null -and $script:tzOffset -ne "") {
|
||||||
|
$currentTimezoneName = ""
|
||||||
|
$currentTimezoneOffset = $script:tzOffset
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($config.RequiresTimezone -and -not $currentTimezoneName -and -not $currentTimezoneOffset) {
|
||||||
Write-Red "Error: Command '$commandName' requires timezone information."
|
Write-Red "Error: Command '$commandName' requires timezone information."
|
||||||
Write-Host "Please provide either '-tzName' or '-tzOffset' parameter."
|
Write-Host "Please provide either '-tzName' or '-tzOffset' parameter."
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
Write-Host "Examples:"
|
Write-Host "Examples:"
|
||||||
Write-Host " ebktools.ps1 -tzName $tzName $commandName ..."
|
Write-Host " ebktools.ps1 -tzName <name> $commandName ..."
|
||||||
Write-Host " ebktools.ps1 -tzOffset $tzOffset $commandName ..."
|
Write-Host " ebktools.ps1 -tzOffset <offset> $commandName ..."
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1016,10 +1054,10 @@ function Invoke-Api {
|
|||||||
"Authorization" = "Bearer $authToken"
|
"Authorization" = "Bearer $authToken"
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($script:tzName) {
|
if ($currentTimezoneName) {
|
||||||
$headers["X-Timezone-Name"] = $script:tzName
|
$headers["X-Timezone-Name"] = $currentTimezoneName
|
||||||
} elseif ($script:tzOffset) {
|
} elseif ($currentTimezoneOffset) {
|
||||||
$headers["X-Timezone-Offset"] = $script:tzOffset
|
$headers["X-Timezone-Offset"] = $currentTimezoneOffset
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($config.Method -eq "POST") {
|
if ($config.Method -eq "POST") {
|
||||||
|
|||||||
+90
-49
@@ -66,7 +66,7 @@ API_CONFIGS='[
|
|||||||
" \"icon\": \"string (Account icon ID)\",",
|
" \"icon\": \"string (Account icon ID)\",",
|
||||||
" \"color\": \"string (Account icon color, hex color code RRGGBB)\",",
|
" \"color\": \"string (Account icon color, hex color code RRGGBB)\",",
|
||||||
" \"currency\": \"string (Account currency code)\",",
|
" \"currency\": \"string (Account currency code)\",",
|
||||||
" \"balance\": \"integer (Account balance, supports up to two decimals. For example, a value of \\"1234\\" represents an amount of \\"12.34\\")\",",
|
" \"balance\": \"integer (Account balance, supports up to two decimals. For example, a value of '"'"'1234'"'"' represents an amount of '"'"'12.34'"'"')\",",
|
||||||
" \"comment\": \"string (Account description)\",",
|
" \"comment\": \"string (Account description)\",",
|
||||||
" \"creditCardStatementDate\": \"integer (The statement date of the credit card account)\",",
|
" \"creditCardStatementDate\": \"integer (The statement date of the credit card account)\",",
|
||||||
" \"displayOrder\": \"integer (The display order of the account)\",",
|
" \"displayOrder\": \"integer (The display order of the account)\",",
|
||||||
@@ -240,8 +240,10 @@ API_CONFIGS='[
|
|||||||
"ResponseStructure": [
|
"ResponseStructure": [
|
||||||
"{",
|
"{",
|
||||||
" \"id\": \"string (Transaction tag ID)\",",
|
" \"id\": \"string (Transaction tag ID)\",",
|
||||||
" \"name\": \"string\",",
|
" \"name\": \"string (Transaction tag name)\",",
|
||||||
" ...",
|
" \"groupId\": \"string (Transaction tag group ID)\",",
|
||||||
|
" \"displayOrder\": \"integer (The display order of the transaction tag)\",",
|
||||||
|
" \"hidden\": \"boolean (Whether the transaction tag is hidden)\"",
|
||||||
"}"
|
"}"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -302,8 +304,8 @@ API_CONFIGS='[
|
|||||||
" \"sourceAccount\": \"object (Source account object)\",",
|
" \"sourceAccount\": \"object (Source account object)\",",
|
||||||
" \"destinationAccountId\": \"string (Destination account ID)\",",
|
" \"destinationAccountId\": \"string (Destination account ID)\",",
|
||||||
" \"destinationAccount\": \"object (Destination account object)\",",
|
" \"destinationAccount\": \"object (Destination account object)\",",
|
||||||
" \"sourceAmount\": \"integer (Source amount, supports up to two decimals. For example, a value of 1234 represents an amount of 12.34)\",",
|
" \"sourceAmount\": \"integer (Source amount, supports up to two decimals. For example, a value of '"'"'1234'"'"' represents an amount of '"'"'12.34'"'"')\",",
|
||||||
" \"destinationAmount\": \"integer (Destination amount, supports up to two decimals. For example, a value of 1234 represents an amount of 12.34)\",",
|
" \"destinationAmount\": \"integer (Destination amount, supports up to two decimals. For example, a value of '"'"'1234'"'"' represents an amount of '"'"'12.34'"'"')\",",
|
||||||
" \"hideAmount\": \"boolean (Whether to hide the amount)\",",
|
" \"hideAmount\": \"boolean (Whether to hide the amount)\",",
|
||||||
" \"tagIds\": [\"each string representing a transaction tag ID\"],",
|
" \"tagIds\": [\"each string representing a transaction tag ID\"],",
|
||||||
" \"tags\": [\"each object representing a transaction tag object\"],",
|
" \"tags\": [\"each object representing a transaction tag object\"],",
|
||||||
@@ -313,7 +315,7 @@ API_CONFIGS='[
|
|||||||
" \"editable\": \"boolean (Whether the transaction is editable)\"",
|
" \"editable\": \"boolean (Whether the transaction is editable)\"",
|
||||||
" }",
|
" }",
|
||||||
" ],",
|
" ],",
|
||||||
" \"nextTimeSequenceId\": \"integer (The next cursor `max_time` parameter when requesting older data)\",",
|
" \"nextTimeSequenceId\": \"integer (The next cursor '"'"'max_time'"'"' parameter when requesting older data)\",",
|
||||||
" \"totalCount\": \"integer (The total count of transactions)\"",
|
" \"totalCount\": \"integer (The total count of transactions)\"",
|
||||||
"}"
|
"}"
|
||||||
]
|
]
|
||||||
@@ -368,8 +370,8 @@ API_CONFIGS='[
|
|||||||
" \"sourceAccount\": \"object (Source account object)\",",
|
" \"sourceAccount\": \"object (Source account object)\",",
|
||||||
" \"destinationAccountId\": \"string (Destination account ID)\",",
|
" \"destinationAccountId\": \"string (Destination account ID)\",",
|
||||||
" \"destinationAccount\": \"object (Destination account object)\",",
|
" \"destinationAccount\": \"object (Destination account object)\",",
|
||||||
" \"sourceAmount\": \"integer (Source amount, supports up to two decimals. For example, a value of 1234 represents an amount of 12.34)\",",
|
" \"sourceAmount\": \"integer (Source amount, supports up to two decimals. For example, a value of '"'"'1234'"'"' represents an amount of '"'"'12.34'"'"')\",",
|
||||||
" \"destinationAmount\": \"integer (Destination amount, supports up to two decimals. For example, a value of 1234 represents an amount of 12.34)\",",
|
" \"destinationAmount\": \"integer (Destination amount, supports up to two decimals. For example, a value of '"'"'1234'"'"' represents an amount of '"'"'12.34'"'"')\",",
|
||||||
" \"hideAmount\": \"boolean (Whether to hide the amount)\",",
|
" \"hideAmount\": \"boolean (Whether to hide the amount)\",",
|
||||||
" \"tagIds\": [\"each string representing a transaction tag ID\"],",
|
" \"tagIds\": [\"each string representing a transaction tag ID\"],",
|
||||||
" \"tags\": [\"each object representing a transaction tag object\"],",
|
" \"tags\": [\"each object representing a transaction tag object\"],",
|
||||||
@@ -479,13 +481,26 @@ get_system_timezone_name() {
|
|||||||
readlink /etc/localtime | sed 's|.*/zoneinfo/||'
|
readlink /etc/localtime | sed 's|.*/zoneinfo/||'
|
||||||
elif command -v timedatectl > /dev/null 2>&1; then
|
elif command -v timedatectl > /dev/null 2>&1; then
|
||||||
timedatectl | grep "Time zone" | awk '{print $3}'
|
timedatectl | grep "Time zone" | awk '{print $3}'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
get_example_timezone_name() {
|
||||||
|
tz_name="$(get_system_timezone_name)"
|
||||||
|
|
||||||
|
if [ -n "$tz_name" ]; then
|
||||||
|
echo "$tz_name"
|
||||||
else
|
else
|
||||||
echo "Asia/Shanghai"
|
echo "Asia/Shanghai"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
get_system_timezone_offset() {
|
get_system_timezone_offset() {
|
||||||
offset_str="$(date +%z 2>/dev/null || echo "+0800")"
|
offset_str="$(date +%z 2>/dev/null)"
|
||||||
|
|
||||||
|
if [ -z "$offset_str" ]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
sign="${offset_str%????}"
|
sign="${offset_str%????}"
|
||||||
hours="${offset_str#?}"
|
hours="${offset_str#?}"
|
||||||
hours="${hours%??}"
|
hours="${hours%??}"
|
||||||
@@ -504,14 +519,24 @@ get_system_timezone_offset() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get_example_timezone_offset() {
|
||||||
|
tz_offset="$(get_system_timezone_offset)"
|
||||||
|
|
||||||
|
if [ -n "$tz_offset" ]; then
|
||||||
|
echo "$tz_offset"
|
||||||
|
else
|
||||||
|
echo "480"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
parse_api_config() {
|
parse_api_config() {
|
||||||
api_name="$1"
|
api_name="$1"
|
||||||
echo "$API_CONFIGS" | jq -r --arg name "$api_name" '.[] | select(.Name == $name)'
|
echo "$API_CONFIGS" | jq -r --arg name "$api_name" '.[] | select(.Name == $name)'
|
||||||
}
|
}
|
||||||
|
|
||||||
show_help() {
|
show_help() {
|
||||||
tz_name="$(get_system_timezone_name)"
|
example_timezone_name="$(get_example_timezone_name)"
|
||||||
tz_offset="$(get_system_timezone_offset)"
|
example_timezone_offset="$(get_example_timezone_offset)"
|
||||||
|
|
||||||
cat <<-EOF
|
cat <<-EOF
|
||||||
ezBookkeeping API Tools
|
ezBookkeeping API Tools
|
||||||
@@ -521,14 +546,14 @@ A command-line tool for calling ezBookkeeping APIs
|
|||||||
Usage:
|
Usage:
|
||||||
ebktools.sh [--tz-name <name>] [--tz-offset <offset>] <command> [command-options]
|
ebktools.sh [--tz-name <name>] [--tz-offset <offset>] <command> [command-options]
|
||||||
|
|
||||||
Global Options:
|
|
||||||
--tz-name <name> The IANA timezone name, for example, for Beijing Time it is 'Asia/Shanghai'.
|
|
||||||
--tz-offset <offset> The offset in minutes of the current timezone from UTC. For example, for Beijing Time which is UTC+8, the value is '480'. If both are provided, '--tz-name' takes precedence.
|
|
||||||
|
|
||||||
Environment Variables (Required):
|
Environment Variables (Required):
|
||||||
EBKTOOL_SERVER_BASEURL ezBookkeeping server base URL (e.g., http://localhost:8080)
|
EBKTOOL_SERVER_BASEURL ezBookkeeping server base URL (e.g., http://localhost:8080)
|
||||||
EBKTOOL_TOKEN ezBookkeeping API token
|
EBKTOOL_TOKEN ezBookkeeping API token
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--tz-name <name> The IANA timezone name of current timezone. For example, for Beijing Time it is 'Asia/Shanghai'.
|
||||||
|
--tz-offset <offset> The offset in minutes of the current timezone from UTC. For example, for Beijing Time which is UTC+8, the value is '480'. If both '--tz-name' and '--tz-offset' are set, '--tz-name' takes priority. If neither is set, the current system time zone is used by default.
|
||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
list List all available API commands
|
list List all available API commands
|
||||||
help <api-command> Show help for a specific API command
|
help <api-command> Show help for a specific API command
|
||||||
@@ -549,10 +574,10 @@ Examples:
|
|||||||
ebktools.sh accounts-list
|
ebktools.sh accounts-list
|
||||||
|
|
||||||
# Call API with timezone name
|
# Call API with timezone name
|
||||||
ebktools.sh --tz-name ${tz_name} transactions-list --count 10
|
ebktools.sh --tz-name ${example_timezone_name} transactions-list --count 10
|
||||||
|
|
||||||
# Call API with timezone offset
|
# Call API with timezone offset
|
||||||
ebktools.sh --tz-offset ${tz_offset} transactions-list --count 10
|
ebktools.sh --tz-offset ${example_timezone_offset} transactions-list --count 10
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -583,12 +608,14 @@ show_command_help() {
|
|||||||
desc="$(echo "$config" | jq -r '.Description')"
|
desc="$(echo "$config" | jq -r '.Description')"
|
||||||
method="$(echo "$config" | jq -r '.Method')"
|
method="$(echo "$config" | jq -r '.Method')"
|
||||||
path="$(echo "$config" | jq -r '.Path')"
|
path="$(echo "$config" | jq -r '.Path')"
|
||||||
|
requires_timezone="$(echo "$config" | jq -r '.RequiresTimezone // false')"
|
||||||
response_struct="$(echo "$config" | jq -r '.ResponseStructure')"
|
response_struct="$(echo "$config" | jq -r '.ResponseStructure')"
|
||||||
|
|
||||||
echo "Command: $name"
|
echo "Command: $name"
|
||||||
echo "Description: $desc"
|
echo "Description: $desc"
|
||||||
echo "Method: $method"
|
echo "Method: $method"
|
||||||
echo "Path: $path"
|
echo "Path: $path"
|
||||||
|
echo "Require current time zone: $([ "$requires_timezone" = "true" ] && echo Yes || echo No)"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
required_count="$(echo "$config" | jq '.RequiredParams | length')"
|
required_count="$(echo "$config" | jq '.RequiredParams | length')"
|
||||||
@@ -622,10 +649,14 @@ show_command_help() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Example:"
|
echo "Example:"
|
||||||
requires_timezone="$(echo "$config" | jq -r '.RequiresTimezone // false')"
|
current_tz_name="$(get_system_timezone_name)"
|
||||||
if [ "$requires_timezone" = "true" ]; then
|
current_tz_offset="$(get_system_timezone_offset)"
|
||||||
tz_name="$(get_system_timezone_name)"
|
if [ "$requires_timezone" = "true" ] && [ -n "$current_tz_name" ]; then
|
||||||
echo " ebktools.sh --tz-name ${tz_name} $name"
|
echo " ebktools.sh --tz-name ${current_tz_name} $name"
|
||||||
|
elif [ "$requires_timezone" = "true" ] && [ -n "$current_tz_offset" ]; then
|
||||||
|
echo " ebktools.sh --tz-offset ${current_tz_offset} $name"
|
||||||
|
elif [ "$requires_timezone" = "true" ]; then
|
||||||
|
echo " ebktools.sh --tz-name <name> $name"
|
||||||
else
|
else
|
||||||
echo " ebktools.sh $name"
|
echo " ebktools.sh $name"
|
||||||
fi
|
fi
|
||||||
@@ -649,26 +680,36 @@ call_api() {
|
|||||||
|
|
||||||
if [ -z "$serverBaseUrl" ]; then
|
if [ -z "$serverBaseUrl" ]; then
|
||||||
echo_red "Error: Environment variable 'EBKTOOL_SERVER_BASEURL' is not set."
|
echo_red "Error: Environment variable 'EBKTOOL_SERVER_BASEURL' is not set."
|
||||||
echo "Please set it to your API server base URL (e.g., http://localhost:8080)"
|
echo "Please set it to your ezBookkeeping server base URL (e.g., http://localhost:8080)"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$authToken" ]; then
|
if [ -z "$authToken" ]; then
|
||||||
echo_red "Error: Environment variable 'EBKTOOL_TOKEN' is not set."
|
echo_red "Error: Environment variable 'EBKTOOL_TOKEN' is not set."
|
||||||
echo "Please set it to your authentication token."
|
echo "Please set it to your API token."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
requires_timezone="$(echo "$config" | jq -r '.RequiresTimezone // false')"
|
requires_timezone="$(echo "$config" | jq -r '.RequiresTimezone // false')"
|
||||||
if [ "$requires_timezone" = "true" ] && [ -z "$TIMEZONE_NAME" ] && [ -z "$TIMEZONE_OFFSET" ]; then
|
current_tz_name="$(get_system_timezone_name)"
|
||||||
tz_name="$(get_system_timezone_name)"
|
current_tz_offset="$(get_system_timezone_offset)"
|
||||||
tz_offset="$(get_system_timezone_offset)"
|
|
||||||
|
if [ -n "$TIMEZONE_NAME" ]; then
|
||||||
|
current_tz_name="$TIMEZONE_NAME"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$TIMEZONE_OFFSET" ]; then
|
||||||
|
current_tz_name=""
|
||||||
|
current_tz_offset="$TIMEZONE_OFFSET"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$requires_timezone" = "true" ] && [ -z "$current_tz_name" ] && [ -z "$current_tz_offset" ]; then
|
||||||
echo_red "Error: Command '$command_name' requires timezone information."
|
echo_red "Error: Command '$command_name' requires timezone information."
|
||||||
echo "Please provide either '--tz-name' or '--tz-offset' parameter."
|
echo "Please provide either '--tz-name' or '--tz-offset' parameter."
|
||||||
echo ""
|
echo ""
|
||||||
echo "Examples:"
|
echo "Examples:"
|
||||||
echo " ebktools.sh --tz-name ${tz_name} $command_name ..."
|
echo " ebktools.sh --tz-name <name> $command_name ..."
|
||||||
echo " ebktools.sh --tz-offset ${tz_offset} $command_name ..."
|
echo " ebktools.sh --tz-offset <offset> $command_name ..."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -800,10 +841,10 @@ call_api() {
|
|||||||
url="${serverBaseUrl}/api/v1/${path}"
|
url="${serverBaseUrl}/api/v1/${path}"
|
||||||
timezone_headers=""
|
timezone_headers=""
|
||||||
|
|
||||||
if [ -n "$TIMEZONE_NAME" ]; then
|
if [ -n "$current_tz_name" ]; then
|
||||||
timezone_headers="X-Timezone-Name: $TIMEZONE_NAME"
|
timezone_headers="X-Timezone-Name: $current_tz_name"
|
||||||
elif [ -n "$TIMEZONE_OFFSET" ]; then
|
elif [ -n "$current_tz_offset" ]; then
|
||||||
timezone_headers="X-Timezone-Offset: $TIMEZONE_OFFSET"
|
timezone_headers="X-Timezone-Offset: $current_tz_offset"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$method" = "POST" ]; then
|
if [ "$method" = "POST" ]; then
|
||||||
@@ -812,32 +853,32 @@ call_api() {
|
|||||||
|
|
||||||
if [ "$json_params" != "{}" ]; then
|
if [ "$json_params" != "{}" ]; then
|
||||||
if [ -n "$timezone_headers" ]; then
|
if [ -n "$timezone_headers" ]; then
|
||||||
response=$(curl -s -X "POST" \
|
response="$(curl -s -X "POST" \
|
||||||
-H "Authorization: Bearer $EBKTOOL_TOKEN" \
|
-H "Authorization: Bearer $EBKTOOL_TOKEN" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-H "$timezone_headers" \
|
-H "$timezone_headers" \
|
||||||
-d "$json_params" \
|
-d "$json_params" \
|
||||||
"$url")
|
"$url")"
|
||||||
curl_exit_code=$?
|
curl_exit_code=$?
|
||||||
else
|
else
|
||||||
response=$(curl -s -X "POST" \
|
response="$(curl -s -X "POST" \
|
||||||
-H "Authorization: Bearer $EBKTOOL_TOKEN" \
|
-H "Authorization: Bearer $EBKTOOL_TOKEN" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "$json_params" \
|
-d "$json_params" \
|
||||||
"$url")
|
"$url")"
|
||||||
curl_exit_code=$?
|
curl_exit_code=$?
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ -n "$timezone_headers" ]; then
|
if [ -n "$timezone_headers" ]; then
|
||||||
response=$(curl -s -X "POST" \
|
response="$(curl -s -X "POST" \
|
||||||
-H "Authorization: Bearer $EBKTOOL_TOKEN" \
|
-H "Authorization: Bearer $EBKTOOL_TOKEN" \
|
||||||
-H "$timezone_headers" \
|
-H "$timezone_headers" \
|
||||||
"$url")
|
"$url")"
|
||||||
curl_exit_code=$?
|
curl_exit_code=$?
|
||||||
else
|
else
|
||||||
response=$(curl -s -X "POST" \
|
response="$(curl -s -X "POST" \
|
||||||
-H "Authorization: Bearer $EBKTOOL_TOKEN" \
|
-H "Authorization: Bearer $EBKTOOL_TOKEN" \
|
||||||
"$url")
|
"$url")"
|
||||||
curl_exit_code=$?
|
curl_exit_code=$?
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -850,14 +891,14 @@ call_api() {
|
|||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
if [ -n "$timezone_headers" ]; then
|
if [ -n "$timezone_headers" ]; then
|
||||||
response=$(curl -s -X "$method" \
|
response="$(curl -s -X "$method" \
|
||||||
-H "Authorization: Bearer $EBKTOOL_TOKEN" \
|
-H "Authorization: Bearer $EBKTOOL_TOKEN" \
|
||||||
-H "$timezone_headers" \
|
-H "$timezone_headers" \
|
||||||
"$url")
|
"$url")"
|
||||||
else
|
else
|
||||||
response=$(curl -s -X "$method" \
|
response="$(curl -s -X "$method" \
|
||||||
-H "Authorization: Bearer $EBKTOOL_TOKEN" \
|
-H "Authorization: Bearer $EBKTOOL_TOKEN" \
|
||||||
"$url")
|
"$url")"
|
||||||
fi
|
fi
|
||||||
curl_exit_code=$?
|
curl_exit_code=$?
|
||||||
fi
|
fi
|
||||||
@@ -867,22 +908,22 @@ call_api() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
success=$(echo "$response" | jq -r '.success // "null"')
|
success=$(printf "%s\n" "$response" | jq -r '.success // "null"')
|
||||||
|
|
||||||
if [ "$success" = "true" ]; then
|
if [ "$success" = "true" ]; then
|
||||||
echo "Response Result:"
|
echo "Response Result:"
|
||||||
result=$(echo "$response" | jq '.result // "null"')
|
result=$(printf "%s\n" "$response" | jq '.result // "null"')
|
||||||
if [ "$result" != "null" ]; then
|
if [ "$result" != "null" ]; then
|
||||||
echo "$response" | jq '.result'
|
printf "%s\n" "$response" | jq '.result'
|
||||||
else
|
else
|
||||||
echo "Success: true (No result data)"
|
echo "Success: true (No result data)"
|
||||||
fi
|
fi
|
||||||
elif [ "$success" = "false" ]; then
|
elif [ "$success" = "false" ]; then
|
||||||
echo "Raw Response:"
|
echo "Raw Response:"
|
||||||
echo "$response" | jq '.'
|
printf "%s\n" "$response" | jq '.'
|
||||||
else
|
else
|
||||||
echo "Raw Response:"
|
echo "Raw Response:"
|
||||||
echo "$response" | jq '.'
|
printf "%s\n" "$response" | jq '.'
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user