Skip to content

Initial Release v0.1.0

Latest
Compare
Choose a tag to compare
@h-alice h-alice released this 03 Jul 06:51
· 2 commits to main since this release
96d6200

Initial Release: Taipei City Government API Management Platform Client

This is the first release of our Go client for interacting with the Taipei City Government API management platform.

Features

  • Request access tokens / sign blocks in simple way.
  • Send signed requests to the Taipei City Government API.

Usage

Please refer to the README for detailed information and example usages.

Installation

Install the package using the following command:

go get github.com/h-alice/tcg-api-platform-client

Getting Started

Below is a sample code demonstrating how to use the client to interact with the "TaipeiON Chat" service via the API management platform.

Make sure to replace all secret credentials with your actual credentials and adjust the API endpoint and format to fit your requirements.

package main

import (
	"fmt"
	"io"

	api_client "github.com/h-alice/tcg-api-platform-client"
)

func main() {
	// Example usage
	client := api_client.NewApiPlatformClient("https://apimtest.gov.taipei", "your_client_id", "your_client_token_block")

	// Request Access Token
	accessToken, err := client.RequestAccessToken()
	if err != nil {
		fmt.Println("Error requesting access token:", err)
		return
	}

	fmt.Println("Access Token:", accessToken)

	// Request Sign Block
	signBlock, err := client.RequestSignBlock()
	if err != nil {
		fmt.Println("Error requesting sign block:", err)
		return
	}
	fmt.Println("Sign Block:", signBlock)

	header := map[string]string{
		"Content-Type": "application/json",
		"backAuth":     "your_back_auth_token",
	}

	payload := map[string]interface{}{
		"ask": "broadcastMessage",
		"message": map[string]interface{}{
			"type": "text",
			"text": " Hello World from API platform! (SEQ=4, LANG=GO)",
		},
	}
	resp, err := client.SendRequest("https://apimtest.gov.taipei/tsmpc/m-taipeion/MessageFeedService", "POST", header, payload, nil)
	if err != nil {
		fmt.Println("Error sending request:", err)
		return
	}
	defer resp.Body.Close()

	body, _ := io.ReadAll(resp.Body)
	fmt.Println("Response:", string(body))
}

For more details and example usages, please check the README file included in the repository.

Contributing

Feel free to open an issue or submit a pull request on our GitHub repository.

License

This project is licensed under the Apache License 2.0