diff --git a/.idea/go-holidayapi.iml b/.idea/go-holidayapi.iml
new file mode 100644
index 0000000..c956989
--- /dev/null
+++ b/.idea/go-holidayapi.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..28a804d
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..f2ed0ed
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..0ca7010
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,242 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/holidayapi.go b/holidayapi.go
index 4230179..b13a065 100644
--- a/holidayapi.go
+++ b/holidayapi.go
@@ -2,6 +2,8 @@ package holidayapi
import (
"encoding/json"
+ "github.com/pkg/errors"
+ "github.com/simplereach/timeutils"
"io/ioutil"
"net/http"
"net/url"
@@ -21,8 +23,27 @@ func NewV1(key string) *V1 {
return v1
}
-func (v1 *V1) Holidays(args map[string]interface{}) (map[string]interface{}, error) {
- var data map[string]interface{}
+type Respone struct {
+ Status int32 `json:"status"`
+ Requests Request `json:"requests"`
+ Holidays []Holiday `json:"holidays"`
+}
+
+type Request struct {
+ Used int32 `json:"used"`
+ Available int32 `json:"available"`
+ Resets timeutils.Time `json:"resets"`
+}
+
+type Holiday struct {
+ Name string `json:"name"`
+ Date timeutils.Time `json:"date,omniempty"`
+ Observed timeutils.Time `json:"observed"`
+ Public bool `json:"public"`
+}
+
+func (v1 *V1) Holidays(args map[string]string) (Respone, error) {
+ var data Respone
if _, ok := args["key"]; !ok {
args["key"] = v1.Key
@@ -31,13 +52,13 @@ func (v1 *V1) Holidays(args map[string]interface{}) (map[string]interface{}, err
params := url.Values{}
for k, v := range args {
- params.Add(k, v.(string))
+ params.Add(k, v)
}
resp, err := http.Get(v1.Url + params.Encode())
if err != nil {
- return nil, err
+ return Respone{}, err
}
defer resp.Body.Close()
@@ -45,17 +66,16 @@ func (v1 *V1) Holidays(args map[string]interface{}) (map[string]interface{}, err
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
- return nil, err
+ return Respone{}, err
}
- json.Unmarshal([]byte(string(body)), &data)
+ err = json.Unmarshal(body, &data)
+ if err != nil {
+ return Respone{}, err
+ }
if resp.StatusCode != 200 {
- _, ok := data["error"]
-
- if !ok {
- data["error"] = "Unknown error."
- }
+ return Respone{}, errors.New("Unknown error!")
}
return data, nil
diff --git a/holidayapi_test.go b/holidayapi_test.go
new file mode 100644
index 0000000..2c2a2ea
--- /dev/null
+++ b/holidayapi_test.go
@@ -0,0 +1 @@
+package holidayapi
\ No newline at end of file
diff --git a/models.go b/models.go
new file mode 100644
index 0000000..fc14683
--- /dev/null
+++ b/models.go
@@ -0,0 +1 @@
+package holidayapi