README ¶
Module/Method DATA:GET_ORG (data.get_org)
Module "Get Origination" (DATA:GET_ORG) is a service method to retreive list of origination (departure location) information from KAI Train (RailTicket) Web Service [1].
The following are the sections available in this guide.
Use Case
Let’s retrieve origination departure location from KAI Train Web Service Endpoint.
Prerequisites
go get github.com/ClientSDK/kai-train-ws-client-go/kaiwsdkv2
- A Text Editor or an IDE
KAI Agent requirements
- KAI Train (RailTicket) Agent Credential Account (RQID)
- KAI Train (RailTicket) Web Service Access (IP Whitelist) ( Production Server, Demo Server)
Implementation
If you want to skip the basics, you can download the git repo and directly move to the "Build and Running" section by skipping "Implementation" section.
Example structure
Go is a complete programming language that supports custom project structures. Let's use the following package structure for this example.
get-org
├── build_and_run.sh
└── main.go
- Create the above directories in your local machine and also create empty
main.go
andbuild_and_run.sh
files.
Developing the application
Let's make a simple application for getting list of origination (departure location) information using kaiwsdkv2
package.
package main
import (
"crypto/tls"
"encoding/json"
"fmt"
"log"
"net/http"
"net/url"
"github.com/ClientSDK/kai-train-ws-client-go/kaiwsdkv2"
)
const (
kaiServer = "https://railticket.kereta-api.co.id/" // Production Server
// kaiServer = "http://ws.demo.kai.sqiva.com/" // Demo Server
kaiRQID = "YOUR-KAI-AGENT-CREDENTIAL-RQID"
)
func makeHTTPClient() *http.Client {
// Access via proxy if needed
proxyURL, _ := url.Parse("http://proxy-ip-address:proxy-port")
//proxyURL, _ := url.Parse("http://proxy-user:proxy-password@proxy-ip-address:proxy-port")
// Initiate transport with proxy and skip TLS
tr := &http.Transport{
Proxy: http.ProxyURL(proxyURL),
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
// Initiate transport without proxy and skip TLS
// tr := &http.Transport{
// TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
// }
// Using Transport
httpClient := &http.Client{Transport: tr}
return httpClient
}
func main() {
// init http client
httpClient := makeHTTPClient()
// Initiate NewKAIHttpClient version 2
kaiClient, err := kaiwsdkv2.NewKAIHttpClient(httpClient, kaiServer, kaiRQID)
if err != nil {
log.Fatal(err)
}
// call KAI web service method
callGetOrigination(kaiClient)
}
func callGetOrigination(kaiClient *kaiwsdkv2.KAIHttpClient) {
// params := make(map[string]string)
vRS, err := kaiClient.CallGetOrigination(false)
if err != nil {
log.Fatal(err)
}
// sample how to Access Response
// fmt.Println(vRS.ErrCode)
// fmt.Println(vRS.ErrMsg)
// fmt.Println(vRS.Return[0].OriginCode)
// fmt.Println(vRS.Return[0].OriginName)
// if you want to retreive KAI Origin Response
// fmt.Println(string(kaiClient.KAIRealResponseBody))
json, _ := json.Marshal(vRS)
fmt.Println(string(json))
}
echo "Clean..."
rm ./data.get_org
echo "Build..."
go build -o data.get_org main.go
echo "Build Done..."
echo "Run..."
./data.get_org > data.get_org-rs.json
echo "Done."
Build and Running
You can build and running by execute the "build_and_run.sh" bash files.
$ sh build_and_run.sh
After the application is running, you will get the json response in data.get_org-rs.json
files.
Sample Response
Sample KAI Response:
// Get KAI Response Raw from KAIHttpClient Struct
KAIHttpClient.KAIRealResponseBody
{
"err_code": 0,
"origination": [
[
"AK",
"ANGKE"
],
[
"YK",
"YOGYAKARTA"
]
]
}
Sample Internal Response:
// Get Internal Response Raw from KAIHttpClient Struct
KAIHttpClient.KAIResponseBody
{
"errCode": "0",
"errMsg": null,
"return": [
{
"OriginCode": "AK",
"OriginName": "ANGKE"
},
{
"OriginCode": "YK",
"OriginName": "YOGYAKARTA"
}
]
}
Documentation ¶
There is no documentation for this package.