aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorShulhan <m.shulhan@gmail.com>2020-03-31 01:11:26 +0700
committerShulhan <m.shulhan@gmail.com>2020-04-01 06:28:03 +0700
commit8a141995aabdee289d2b096bd77a10b52b08a1bf (patch)
tree98af569d4c3e2620809ce591c2733184cd77db8f /client.go
parent84fdfdb6ae4175a125fc67a6aed377476d31ee0e (diff)
downloadkamusku-8a141995aabdee289d2b096bd77a10b52b08a1bf.tar.xz
all: implement server and client for dictionary API
Currently the server and client can onyl handle API for looking up definitions of the words through "/api/definisi" URL.
Diffstat (limited to 'client.go')
-rw-r--r--client.go42
1 files changed, 24 insertions, 18 deletions
diff --git a/client.go b/client.go
index fabe600..c23100f 100644
--- a/client.go
+++ b/client.go
@@ -4,13 +4,16 @@
package kbbi
-import "net/http"
+import (
+ "net/http"
+)
//
-// Client for dictionary API and official KBBI servers.
+// Client for dictionary API and official KBBI server.
//
type Client struct {
active activeClient
+ api *apiClient
direct *directClient
}
@@ -21,13 +24,17 @@ type Client struct {
func NewClient(cookies []*http.Cookie) (cl *Client, err error) {
cl = &Client{}
+ cl.direct, err = newDirectClient(cookies)
+ if err != nil {
+ return nil, err
+ }
+
+ cl.api = newAPIClient("")
+
if cookies != nil {
- cl.direct, err = newDirectClient(cookies)
- if err != nil {
- return nil, err
- }
cl.active = cl.direct
- return cl, nil
+ } else {
+ cl.active = cl.api
}
return cl, nil
@@ -43,29 +50,28 @@ func (cl *Client) CariDefinisi(words []string) (
return cl.active.CariDefinisi(words)
}
- // TODO: start with api client first ...
-
- cl.direct, err = newDirectClient(nil)
+ res, err = cl.api.CariDefinisi(words)
if err != nil {
- return nil, err
+ return cl.direct.CariDefinisi(words)
}
- return cl.direct.CariDefinisi(words)
+ return res, nil
}
-func (cl *Client) ListKataDasar() (kataDasar daftarKata, err error) {
+//
+// ListKataDasar list all of the root words in dictionary.
+//
+func (cl *Client) ListKataDasar() (res DaftarKata, err error) {
if cl.active != nil {
return cl.active.ListKataDasar()
}
- // TODO: start with api client first ...
-
- cl.direct, err = newDirectClient(nil)
+ res, err = cl.api.ListKataDasar()
if err != nil {
- return nil, err
+ return cl.direct.ListKataDasar()
}
- return cl.direct.ListKataDasar()
+ return res, nil
}
//