aboutsummaryrefslogtreecommitdiff
path: root/api_client.go
diff options
context:
space:
mode:
Diffstat (limited to 'api_client.go')
-rw-r--r--api_client.go25
1 files changed, 14 insertions, 11 deletions
diff --git a/api_client.go b/api_client.go
index d85f419..10e487a 100644
--- a/api_client.go
+++ b/api_client.go
@@ -1,15 +1,18 @@
-// Copyright 2020, Shulhan <m.shulhan@gmail.com>. All rights reserved.
+// Copyright 2020, Shulhan <ms@kilabit.info>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package kamusku
+package kamusd
import (
+ "encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strings"
+
+ "git.sr.ht/~shulhan/kamusku"
)
//
@@ -42,8 +45,8 @@ func newAPIClient(url string) (client *apiClient) {
//
// Lookup the definition of words through server API.
//
-func (client *apiClient) CariDefinisi(words []string) (
- res DefinisiResponse, err error,
+func (client *apiClient) Lookup(words []string) (
+ res kamusku.LookupResponse, err error,
) {
if len(words) == 0 {
return nil, nil
@@ -54,19 +57,19 @@ func (client *apiClient) CariDefinisi(words []string) (
req, err := http.NewRequest(http.MethodGet, client.url+pathAPIDefinisi, nil)
if err != nil {
- return nil, fmt.Errorf("CariDefinisi: %w", err)
+ return nil, fmt.Errorf("Lookup: %w", err)
}
req.URL.RawQuery = params.Encode()
httpRes, err := client.conn.Do(req)
if err != nil {
- return nil, fmt.Errorf("CariDefinisi: %w", err)
+ return nil, fmt.Errorf("Lookup: %w", err)
}
resBody, err := ioutil.ReadAll(httpRes.Body)
if err != nil {
- return nil, fmt.Errorf("CariDefinisi: %w", err)
+ return nil, fmt.Errorf("Lookup: %w", err)
}
defer httpRes.Body.Close()
@@ -75,18 +78,18 @@ func (client *apiClient) CariDefinisi(words []string) (
return res, nil
}
- err = res.unpack(resBody)
+ err = json.Unmarshal(resBody, &res)
if err != nil {
- return nil, fmt.Errorf("CariDefinisi: %w", err)
+ return nil, fmt.Errorf("Lookup: %w", err)
}
return res, nil
}
//
-// ListKataDasar list all of the root words in dictionary.
+// ListRootWords list all of the root words in dictionary.
//
-func (client *apiClient) ListKataDasar() (res DaftarKata, err error) {
+func (client *apiClient) ListRootWords() (res kamusku.Words, err error) {
//TODO: return cached list.
return res, nil
}