Skip to content

Commit 78c1732

Browse files
committed
chore: update endpoints
1 parent bc5d841 commit 78c1732

File tree

4 files changed

+111
-71
lines changed

4 files changed

+111
-71
lines changed

README.md

+39-31
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ Instantly locate email addresses from any company name or website.
5757
tomba search --target "tomba.io"
5858
```
5959

60+
### Email Finder
61+
62+
Retrieves the most likely email address from a domain name, a first name and a last name.
63+
64+
```bash
65+
tomba finder --target "tomba.io" --fist "mohamed" --last "ben rebia"
66+
```
67+
6068
### Enrichment
6169

6270
Locate and include data in your emails.
@@ -101,40 +109,40 @@ tomba http
101109

102110
## Endpoints
103111

104-
| Name | Route | Query | State | Authentication | Method |
105-
| --------------- | --------- | -------- | --------- | -------------- | ------ |
106-
| Home | / | No | Completed | No | Get |
107-
| author finder | /author | `url` | Completed | No | Get |
108-
| email counter | /count | `domain` | Completed | No | Get |
109-
| enrichment | /enrich | `email` | Completed | No | Get |
110-
| linkedin finder | /linkedin | `url` | Completed | No | Get |
111-
| logs | /logs | No | Completed | No | Get |
112-
| domain search | /search | `domain` | Completed | No | Get |
113-
| domain status | /status | `domain` | Completed | No | Get |
114-
| usage | /usage | No | Completed | No | Get |
115-
| email verifier | /verify | `email` | Completed | No | Get |
112+
| Name | Route | Body | State | Slack | Method |
113+
| --------------- | --------- | -------- | --------- | ----- | ------ |
114+
| author finder | /author | `url` | Completed | Yes | Post |
115+
| email counter | /count | `domain` | Completed | No | Post |
116+
| enrichment | /enrich | `email` | Completed | Yes | Post |
117+
| linkedin finder | /linkedin | `url` | Completed | Yes | Post |
118+
| domain search | /search | `domain` | Completed | Yes | Post |
119+
| domain status | /status | `domain` | Completed | No | Post |
120+
| email verifier | /verify | `email` | Completed | Yes | Post |
121+
| logs | /logs | No | Completed | No | Get |
122+
| usage | /usage | No | Completed | No | Get |
116123

117124
### Available Commands
118125

119-
| Command name | Description |
120-
| ------------ | ------------------------------------------------------------------ |
121-
| author | Instantly discover the email addresses of article authors. |
122-
| completion | Generate the autocompletion script for the specified shell |
123-
| count | Returns total email addresses we have for one domain. |
124-
| enrich | Locate and include data in your emails. |
125-
| help | Help about any command |
126-
| http | Runs a HTTP server (reverse proxy). |
127-
| linkedin | Instantly discover the email addresses of Linkedin URLs. |
128-
| login | Sign in to Tomba account |
129-
| logout | delete your current KEY & SECRET API session. |
130-
| logs | Check your last 1,000 requests you made during the last 3 months. |
131-
| search | Instantly locate email addresses from any company name or website. |
132-
| status | Returns domain status if is webmail or disposable. |
133-
| usage | Check your monthly requests. |
134-
| verify | Verify the deliverability of an email address. |
135-
| version | Print version number and build information. |
136-
137-
### Command Flags
126+
| Command name | Description |
127+
| ------------ | ----------------------------------------------------------------------------------------- |
128+
| author | Instantly discover the email addresses of article authors. |
129+
| completion | Generate the autocompletion script for the specified shell |
130+
| count | Returns total email addresses we have for one domain. |
131+
| enrich | Locate and include data in your emails. |
132+
| finder | Retrieves the most likely email address from a domain name, a first name and a last name. |
133+
| help | Help about any command |
134+
| http | Runs a HTTP server (reverse proxy). |
135+
| linkedin | Instantly discover the email addresses of Linkedin URLs. |
136+
| login | Sign in to Tomba account |
137+
| logout | delete your current KEY & SECRET API session. |
138+
| logs | Check your last 1,000 requests you made during the last 3 months. |
139+
| search | Instantly locate email addresses from any company name or website. |
140+
| status | Returns domain status if is webmail or disposable. |
141+
| usage | Check your monthly requests. |
142+
| verify | Verify the deliverability of an email address. |
143+
| version | Print version number and build information. |
144+
145+
### Command Global Flags
138146

139147
| shortopts | longopts | Description |
140148
| --------- | ---------- | ------------------------------------------------------------------ |

cmd/http.go

+18-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import (
44
"strconv"
55

66
"github.com/gofiber/fiber/v2"
7+
"github.com/gofiber/fiber/v2/middleware/cors"
78
"github.com/gofiber/fiber/v2/middleware/logger"
9+
"github.com/gofiber/fiber/v2/middleware/recover"
810
"github.com/spf13/cobra"
911
"github.com/tomba-io/tomba/pkg/start"
1012
)
@@ -25,21 +27,29 @@ func httpRun(cmd *cobra.Command, args []string) {
2527
AppName: "tomba",
2628
})
2729
app.Use(logger.New(logger.Config{
28-
Format: "[${time}] ${ip} ${status} - ${latency} ${method} ${path}\n",
30+
Format: "[${time}] ${ip} ${status} - ${latency} ${method} ${path} ${queryParams}\n",
2931
}))
32+
app.Use(cors.New(cors.Config{
33+
AllowOrigins: "*", //
34+
AllowHeaders: "Origin, Content-Type, Accept",
35+
AllowMethods: "GET,POST,HEAD,OPTIONS",
36+
Next: nil,
37+
}))
38+
// if you want to prevent crashes
39+
app.Use(recover.New())
3040
setUpRoutes(app, init)
3141
app.Listen(`:` + strconv.Itoa(init.Port))
3242
}
3343

3444
func setUpRoutes(app *fiber.App, conn *start.Conn) {
3545
app.Get("/", conn.Home)
36-
app.Get("author", conn.Author)
37-
app.Get("count", conn.Count)
38-
app.Get("enrich", conn.Enrich)
39-
app.Get("linkedin", conn.Linkedin)
46+
app.Post("author", conn.Author)
47+
app.Post("count", conn.Count)
48+
app.Post("enrich", conn.Enrich)
49+
app.Post("linkedin", conn.Linkedin)
4050
app.Get("logs", conn.Logs)
41-
app.Get("search", conn.Search)
42-
app.Get("status", conn.Status)
51+
app.Post("search", conn.Search)
52+
app.Post("status", conn.Status)
4353
app.Get("usage", conn.Usage)
44-
app.Get("verify", conn.Verify)
54+
app.Post("verify", conn.Verify)
4555
}

pkg/start/error.go

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ var (
99
ErrErrInvalidNoLogin = errors.New("Please Sign in to your account, not logged in.")
1010
ErrArgumentEmail = errors.New("Please enter a email, for example '[email protected]'.")
1111
ErrArgumentsDomain = errors.New("Please enter a domain name, for example 'tomba.io'.")
12+
ErrArgumentsDomainLimit = errors.New("The limit value is not a valid enum value of (10,20,50):")
1213
ErrArgumentsURL = errors.New("Please enter a valid article URL")
1314
ErrArgumentsLinkedinURL = errors.New("Please enter a valid linkedin URL")
15+
ErrArgumentsFinder = errors.New("Please enter the full name of the person you'd like to find the email address.")
1416
)

pkg/start/routes.go

+52-32
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,63 @@
11
package start
22

33
import (
4-
"strings"
5-
64
"github.com/gofiber/fiber/v2"
75
"github.com/gofiber/fiber/v2/log"
6+
"github.com/tomba-io/go/tomba"
7+
"github.com/tomba-io/tomba/pkg/slack"
88
_domain "github.com/tomba-io/tomba/pkg/validation/domain"
99
_email "github.com/tomba-io/tomba/pkg/validation/email"
1010
_url "github.com/tomba-io/tomba/pkg/validation/url"
1111
)
1212

13+
// Request structure
14+
type Request struct {
15+
URL string `json:"url" form:"url"`
16+
Domain string `json:"domain" form:"domain"`
17+
Email string `json:"email" form:"email"`
18+
Slack bool `json:"slack" form:"slack"`
19+
}
20+
21+
func request(c *fiber.Ctx) Request {
22+
req := Request{}
23+
c.BodyParser(&req)
24+
return req
25+
}
26+
1327
// Home redirect to tomba home page
1428
func (d *Conn) Home(c *fiber.Ctx) error {
1529
return c.Redirect("http://tomba.io?ref=tomba_cli", 301)
1630
}
1731

1832
// Author query author finder
1933
func (init *Conn) Author(c *fiber.Ctx) error {
20-
url := strings.ToLower(c.Query("url"))
21-
if !_url.IsValidURL(url) {
34+
req := request(c)
35+
if !_url.IsValidURL(req.URL) {
2236
log.Error(ErrArgumentsURL.Error())
2337
return c.Status(400).JSON(fiber.Map{"status": "error", "message": ErrArgumentsURL.Error()})
2438
}
25-
result, err := init.Tomba.AuthorFinder(url)
39+
result, err := init.Tomba.AuthorFinder(req.URL)
2640
if err != nil {
2741
log.Error(ErrErrInvalidLogin.Error())
2842
return c.Status(401).JSON(fiber.Map{"status": "error", "message": ErrErrInvalidLogin.Error()})
2943
}
3044
if result.Data.Email == "" {
3145
return c.Status(404).JSON(fiber.Map{"status": "error", "message": "Why doesn't the author finder return any result? https://help.tomba.io/en/questions/reasons-why-author-finder-don-t-find-any-result"})
3246
}
33-
47+
if req.Slack {
48+
return c.Status(200).JSON(slack.FinderResponse(result))
49+
}
3450
return c.Status(200).JSON(result)
35-
3651
}
3752

3853
// Count query email counter
3954
func (init *Conn) Count(c *fiber.Ctx) error {
40-
domain := strings.ToLower(c.Query("domain"))
41-
if !_domain.IsValidDomain(domain) {
55+
req := request(c)
56+
if !_domain.IsValidDomain(req.Domain) {
4257
log.Error(ErrArgumentsDomain.Error())
4358
return c.Status(400).JSON(fiber.Map{"status": "error", "message": ErrArgumentsDomain.Error()})
4459
}
45-
result, err := init.Tomba.Count(domain)
60+
result, err := init.Tomba.Count(req.Domain)
4661
if err != nil {
4762
log.Error(ErrErrInvalidLogin.Error())
4863
return c.Status(401).JSON(fiber.Map{"status": "error", "message": ErrErrInvalidLogin.Error()})
@@ -55,39 +70,43 @@ func (init *Conn) Count(c *fiber.Ctx) error {
5570

5671
// Enrich query enrichment
5772
func (init *Conn) Enrich(c *fiber.Ctx) error {
58-
email := strings.ToLower(c.Query("email"))
59-
60-
if !_email.IsValidEmail(email) {
73+
req := request(c)
74+
if !_email.IsValidEmail(req.Email) {
6175
log.Error(ErrArgumentEmail.Error())
6276
return c.Status(400).JSON(fiber.Map{"status": "error", "message": ErrArgumentEmail.Error()})
6377
}
64-
result, err := init.Tomba.Enrichment(email)
78+
result, err := init.Tomba.Enrichment(req.Email)
6579
if err != nil {
6680
log.Error(ErrErrInvalidLogin.Error())
6781
return c.Status(401).JSON(fiber.Map{"status": "error", "message": ErrErrInvalidLogin.Error()})
6882
}
6983
if result.Data.Email == "" {
7084
return c.Status(404).JSON(fiber.Map{"status": "error", "message": "Why doesn't the enrichment return any result? https://help.tomba.io/en/questions/reasons-why-enrichment-don-t-find-any-emails"})
7185
}
86+
if req.Slack {
87+
return c.Status(200).JSON(slack.FinderResponse(result))
88+
}
7289
return c.Status(200).JSON(result)
7390
}
7491

7592
// Linkedin query linkedin finder
7693
func (init *Conn) Linkedin(c *fiber.Ctx) error {
77-
url := strings.ToLower(c.Query("url"))
78-
79-
if !_url.IsValidURL(url) {
94+
req := request(c)
95+
if !_url.IsValidURL(req.URL) {
8096
log.Error(ErrArgumentsURL.Error())
8197
return c.Status(400).JSON(fiber.Map{"status": "error", "message": ErrArgumentsURL.Error()})
8298
}
83-
result, err := init.Tomba.LinkedinFinder(url)
99+
result, err := init.Tomba.LinkedinFinder(req.URL)
84100
if err != nil {
85101
log.Error(ErrErrInvalidLogin.Error())
86102
return c.Status(401).JSON(fiber.Map{"status": "error", "message": ErrErrInvalidLogin.Error()})
87103
}
88104
if result.Data.Email == "" {
89105
return c.Status(404).JSON(fiber.Map{"status": "error", "message": "Why doesn't the Linkedin return any result? https://help.tomba.io/en/questions/reasons-why-linkedin-don-t-find-any-emails"})
90106
}
107+
if req.Slack {
108+
return c.Status(200).JSON(slack.FinderResponse(result))
109+
}
91110
return c.Status(200).JSON(result)
92111
}
93112

@@ -103,33 +122,33 @@ func (init *Conn) Logs(c *fiber.Ctx) error {
103122

104123
// Search query domain search
105124
func (init *Conn) Search(c *fiber.Ctx) error {
106-
domain := strings.ToLower(c.Query("domain"))
107-
108-
if !_domain.IsValidDomain(domain) {
125+
req := request(c)
126+
if !_domain.IsValidDomain(req.Domain) {
109127
log.Error(ErrArgumentsDomain.Error())
110128
return c.Status(400).JSON(fiber.Map{"status": "error", "message": ErrArgumentsDomain.Error()})
111129
}
112-
result, err := init.Tomba.DomainSearch(domain, "10", "0")
130+
result, err := init.Tomba.DomainSearch(tomba.Params{"domain": req.Domain})
113131
if err != nil {
114132
log.Error(ErrErrInvalidLogin.Error())
115133
return c.Status(401).JSON(fiber.Map{"status": "error", "message": ErrErrInvalidLogin.Error()})
116134
}
117135
if result.Meta.Total == 0 {
118136
return c.Status(404).JSON(fiber.Map{"status": "error", "message": "TombaPublicWebCrawler is searching the internet for the best leads that relate to this company, but we don't have any for it yet. That said, we're working on it"})
119137
}
138+
if req.Slack {
139+
return c.Status(200).JSON(slack.SearchResponse(result))
140+
}
120141
return c.Status(200).JSON(result)
121-
122142
}
123143

124144
// Status query Domain status
125145
func (init *Conn) Status(c *fiber.Ctx) error {
126-
domain := strings.ToLower(c.Query("domain"))
127-
128-
if !_domain.IsValidDomain(domain) {
146+
req := request(c)
147+
if !_domain.IsValidDomain(req.Domain) {
129148
log.Error(ErrArgumentsDomain.Error())
130149
return c.Status(400).JSON(fiber.Map{"status": "error", "message": ErrArgumentsDomain.Error()})
131150
}
132-
result, err := init.Tomba.Status(domain)
151+
result, err := init.Tomba.Status(req.Domain)
133152
if err != nil {
134153
log.Error(ErrErrInvalidLogin.Error())
135154
return c.Status(401).JSON(fiber.Map{"status": "error", "message": ErrErrInvalidLogin.Error()})
@@ -149,14 +168,12 @@ func (init *Conn) Usage(c *fiber.Ctx) error {
149168

150169
// Verify query email verifier
151170
func (init *Conn) Verify(c *fiber.Ctx) error {
152-
email := strings.ToLower(c.Query("email"))
153-
154-
if !_email.IsValidEmail(email) {
171+
req := request(c)
172+
if !_email.IsValidEmail(req.Email) {
155173
log.Error(ErrArgumentEmail.Error())
156174
return c.Status(400).JSON(fiber.Map{"status": "error", "message": ErrArgumentEmail.Error()})
157175
}
158-
159-
result, err := init.Tomba.EmailVerifier(email)
176+
result, err := init.Tomba.EmailVerifier(req.Email)
160177
if err != nil {
161178
log.Error(ErrErrInvalidLogin.Error())
162179
return c.Status(401).JSON(fiber.Map{"status": "error", "message": ErrErrInvalidLogin.Error()})
@@ -168,6 +185,9 @@ func (init *Conn) Verify(c *fiber.Ctx) error {
168185
if result.Data.Email.Webmail {
169186
return c.Status(404).JSON(fiber.Map{"status": "error", "message": "The domain name is webmail provider."})
170187
}
188+
if req.Slack {
189+
return c.Status(200).JSON(slack.VerifyResponse(result))
190+
}
171191
return c.Status(200).JSON(result)
172192
}
173193
return c.Status(222).JSON(fiber.Map{"status": "error", "message": "The Email Verification failed because of an unexpected response from the remote SMTP server. This failure is outside of our control. We advise you to retry later."})

0 commit comments

Comments
 (0)