Skip to content

Commit 3db06a2

Browse files
committed
Email to post
Signed-off-by: Vishal Rana <[email protected]>
1 parent e9d5824 commit 3db06a2

File tree

7 files changed

+65
-32
lines changed

7 files changed

+65
-32
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ import (
2222
)
2323

2424
func main() {
25-
client := labstack.NewClient("<API_KEY>")
26-
res, err := client.GeocodeAddress(&labstack.GeocodeAddressRequest{
27-
Location: "eiffel tower",
28-
})
29-
if err != nil {
30-
fmt.Println(err)
31-
} else {
32-
fmt.Printf("%+v", res)
33-
}
25+
client := labstack.NewClient("<API_KEY>")
26+
geocode := client.Geocode()
27+
res, err := geocode.Address(&labstack.GeocodeAddressRequest{
28+
Location: "eiffel tower",
29+
})
30+
if err != nil {
31+
fmt.Println(err)
32+
} else {
33+
fmt.Printf("%+v", res)
34+
}
3435
}
3536
```
3637

client.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ func (c *Client) error(r *resty.Response) bool {
4343
return r.StatusCode() < 200 || r.StatusCode() >= 300
4444
}
4545

46+
func (c *Client) Currency() *Currency {
47+
return &Currency{c}
48+
}
49+
50+
func (c *Client) Geocode() *Geocode {
51+
return &Geocode{c}
52+
}
53+
54+
func (c *Client) Post() *Post {
55+
return &Post{c}
56+
}
57+
4658
func (c *Client) Download(id string, path string) (err *APIError) {
4759
_, e := c.resty.R().
4860
SetOutput(path).

currency.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import (
66
)
77

88
type (
9+
Currency struct {
10+
*Client
11+
}
12+
913
CurrencyConvertRequest struct {
1014
From string
1115
To string
@@ -27,7 +31,7 @@ type (
2731
}
2832
)
2933

30-
func (c *Client) CurrencyConvert(req *CurrencyConvertRequest) (*CurrencyConvertResponse, *APIError) {
34+
func (c *Currency) Convert(req *CurrencyConvertRequest) (*CurrencyConvertResponse, *APIError) {
3135
res := new(CurrencyConvertResponse)
3236
err := new(APIError)
3337
r, e := c.resty.R().
@@ -50,7 +54,7 @@ func (c *Client) CurrencyConvert(req *CurrencyConvertRequest) (*CurrencyConvertR
5054
return res, nil
5155
}
5256

53-
func (c *Client) CurrencyRates(req *CurrencyRatesRequest) (*CurrencyRatesResponse, *APIError) {
57+
func (c *Currency) Rates(req *CurrencyRatesRequest) (*CurrencyRatesResponse, *APIError) {
5458
res := new(CurrencyRatesResponse)
5559
err := new(APIError)
5660
r, e := c.resty.R().

geocode.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ package labstack
33
import "strconv"
44

55
type (
6+
Geocode struct {
7+
*Client
8+
}
9+
610
GeocodeAddressRequest struct {
711
Location string
812
Longitude float64
@@ -40,10 +44,10 @@ type (
4044
}
4145
)
4246

43-
func (c *Client) GeocodeAddress(req *GeocodeAddressRequest) (*GeocodeResponse, *APIError) {
47+
func (g *Geocode) Address(req *GeocodeAddressRequest) (*GeocodeResponse, *APIError) {
4448
res := new(GeocodeResponse)
4549
err := new(APIError)
46-
r, e := c.resty.R().
50+
r, e := g.resty.R().
4751
SetQueryParams(map[string]string{
4852
"location": req.Location,
4953
"longitude": strconv.FormatFloat(req.Longitude, 'f', -1, 64),
@@ -60,16 +64,16 @@ func (c *Client) GeocodeAddress(req *GeocodeAddressRequest) (*GeocodeResponse, *
6064
Message: e.Error(),
6165
}
6266
}
63-
if c.error(r) {
67+
if g.error(r) {
6468
return nil, err
6569
}
6670
return res, nil
6771
}
6872

69-
func (c *Client) GeocodeIP(req *GeocodeIPRequest) (*GeocodeResponse, *APIError) {
73+
func (g *Geocode) IP(req *GeocodeIPRequest) (*GeocodeResponse, *APIError) {
7074
res := new(GeocodeResponse)
7175
err := new(APIError)
72-
r, e := c.resty.R().
76+
r, e := g.resty.R().
7377
SetQueryParams(map[string]string{
7478
"ip": req.IP,
7579
}).
@@ -81,16 +85,16 @@ func (c *Client) GeocodeIP(req *GeocodeIPRequest) (*GeocodeResponse, *APIError)
8185
Message: e.Error(),
8286
}
8387
}
84-
if c.error(r) {
88+
if g.error(r) {
8589
return nil, err
8690
}
8791
return res, nil
8892
}
8993

90-
func (c *Client) GeocodeReverse(req *GeocodeReverseRequest) (*GeocodeResponse, *APIError) {
94+
func (g *Geocode) Reverse(req *GeocodeReverseRequest) (*GeocodeResponse, *APIError) {
9195
res := new(GeocodeResponse)
9296
err := new(APIError)
93-
r, e := c.resty.R().
97+
r, e := g.resty.R().
9498
SetQueryParams(map[string]string{
9599
"longitude": strconv.FormatFloat(req.Longitude, 'f', -1, 64),
96100
"latitude": strconv.FormatFloat(req.Latitude, 'f', -1, 64),
@@ -105,7 +109,7 @@ func (c *Client) GeocodeReverse(req *GeocodeReverseRequest) (*GeocodeResponse, *
105109
Message: e.Error(),
106110
}
107111
}
108-
if c.error(r) {
112+
if g.error(r) {
109113
return nil, err
110114
}
111115
return res, nil

email.go renamed to post.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package labstack
22

33
type (
4-
EmailVerifyRequest struct {
4+
Post struct {
5+
*Client
6+
}
7+
8+
PostVerifyRequest struct {
59
Email string
610
}
711

8-
EmailVerifyResponse struct {
12+
PostVerifyResponse struct {
913
Syntax bool `json:"syntax"`
1014
Disposable bool `json:"disposable"`
1115
Domain bool `json:"domain"`
@@ -14,10 +18,10 @@ type (
1418
}
1519
)
1620

17-
func (c *Client) EmailVerify(req *EmailVerifyRequest) (*EmailVerifyResponse, *APIError) {
18-
res := new(EmailVerifyResponse)
21+
func (p *Post) Verify(req *PostVerifyRequest) (*PostVerifyResponse, *APIError) {
22+
res := new(PostVerifyResponse)
1923
err := new(APIError)
20-
r, e := c.resty.R().
24+
r, e := p.resty.R().
2125
SetQueryParams(map[string]string{
2226
"email": req.Email,
2327
}).
@@ -29,7 +33,7 @@ func (c *Client) EmailVerify(req *EmailVerifyRequest) (*EmailVerifyResponse, *AP
2933
Message: e.Error(),
3034
}
3135
}
32-
if c.error(r) {
36+
if p.error(r) {
3337
return nil, err
3438
}
3539
return res, nil

watermark.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ package labstack
33
import "strconv"
44

55
type (
6+
Watermark struct {
7+
*Client
8+
}
9+
610
WatermarkImageRequest struct {
711
File string
812
Text string
@@ -19,10 +23,10 @@ type (
1923
}
2024
)
2125

22-
func (c *Client) WatermarkImage(req *WatermarkImageRequest) (*WatermarkImageResponse, *APIError) {
26+
func (w *Watermark) Image(req *WatermarkImageRequest) (*WatermarkImageResponse, *APIError) {
2327
res := new(WatermarkImageResponse)
2428
err := new(APIError)
25-
r, e := c.resty.R().
29+
r, e := w.resty.R().
2630
SetFile("file", req.File).
2731
SetFormData(map[string]string{
2832
"text": req.Text,
@@ -41,7 +45,7 @@ func (c *Client) WatermarkImage(req *WatermarkImageRequest) (*WatermarkImageResp
4145
Message: e.Error(),
4246
}
4347
}
44-
if c.error(r) {
48+
if w.error(r) {
4549
return nil, err
4650
}
4751
return res, nil

webpage.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package labstack
22

33
type (
4+
Webpage struct {
5+
*Client
6+
}
7+
48
WebpagePDFRequest struct {
59
URL string
610
Layout string
@@ -12,10 +16,10 @@ type (
1216
}
1317
)
1418

15-
func (c *Client) WebpagePDF(req *WebpagePDFRequest) (*WebpagePDFResponse, *APIError) {
19+
func (w *Webpage) PDF(req *WebpagePDFRequest) (*WebpagePDFResponse, *APIError) {
1620
res := new(WebpagePDFResponse)
1721
err := new(APIError)
18-
r, e := c.resty.R().
22+
r, e := w.resty.R().
1923
SetQueryParams(map[string]string{
2024
"url": req.URL,
2125
"layout": req.Layout,
@@ -29,7 +33,7 @@ func (c *Client) WebpagePDF(req *WebpagePDFRequest) (*WebpagePDFResponse, *APIEr
2933
Message: e.Error(),
3034
}
3135
}
32-
if c.error(r) {
36+
if w.error(r) {
3337
return nil, err
3438
}
3539
return res, nil

0 commit comments

Comments
 (0)