aboutsummaryrefslogtreecommitdiff
path: root/api.go
diff options
context:
space:
mode:
authorAlexander Kiryukhin <alexander@kiryukhin.su>2019-03-30 22:12:37 +0300
committerAlexander Kiryukhin <alexander@kiryukhin.su>2019-03-30 22:12:37 +0300
commit9ce24ee41c5649ca5a03edf60bef1606dca6a8d3 (patch)
tree2e23c6c4301bc8b715de390e4f606f7d569ad8b8 /api.go
parent49c90f986bc8ba1abe7cedc24bd42522df4c3a2e (diff)
Keyboard builder
Logger
Diffstat (limited to 'api.go')
-rw-r--r--api.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/api.go b/api.go
index 3d727fd..ec45e73 100644
--- a/api.go
+++ b/api.go
@@ -10,6 +10,7 @@ import (
"fmt"
"io"
"io/ioutil"
+ "log"
"net/http"
"net/url"
"strconv"
@@ -22,6 +23,7 @@ type Api struct {
url *url.URL
timeout int
pause int
+ logging bool
}
// New TamTam Api object
@@ -33,9 +35,14 @@ func New(key string) *Api {
version: "1.0.3",
timeout: 30,
pause: 1,
+ logging: false,
}
}
+func (a *Api) EnableLogging() {
+ a.logging = true
+}
+
// region Misc methods
func (a *Api) GetMe() (*UserWithPhoto, error) {
@@ -464,7 +471,11 @@ func (a *Api) getUpdates(limit int, timeout int, marker int64, types []string) (
return result, err
}
defer body.Close()
- return result, json.NewDecoder(body).Decode(result)
+ jb, _ := ioutil.ReadAll(body)
+ if a.logging {
+ log.Printf("Received: %s", string(jb))
+ }
+ return result, json.Unmarshal(jb, result)
}
func (a *Api) request(method, path string, query url.Values, body interface{}) (io.ReadCloser, error) {
@@ -478,6 +489,9 @@ func (a *Api) request(method, path string, query url.Values, body interface{}) (
if err != nil {
return nil, err
}
+ if a.logging {
+ log.Printf("Sent: [%s %s] Query: %#v Body: %s", method, path, query, string(j))
+ }
req, err := http.NewRequest(method, u.String(), bytes.NewReader(j))
if err != nil {
return nil, err