Merge pull request #16 from sundowndev/refactor/api

Rename API methods to camel case
pull/17/head
Raphaël 2020-09-06 17:26:44 +02:00 committed by GitHub
commit 1bb19f42ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 137 additions and 137 deletions

View File

@ -44,7 +44,7 @@ go get github.com/sundowndev/dorkgen
## Usage ## Usage
**[Try it in the Go playground](https://play.golang.org/p/EoaiowZTr0i)** **[Try it in the Go playground](https://play.golang.org/p/H_sCs_CB10A)**
#### Get started #### Get started
@ -59,7 +59,7 @@ func main() {
// dork := dorkgen.NewBingSearch() // dork := dorkgen.NewBingSearch()
// dork := dorkgen.NewYahooSearch() // dork := dorkgen.NewYahooSearch()
dork.Site("example.com").Intext("text").String() dork.Site("example.com").InText("text").String()
// returns: site:example.com intext:"text" // returns: site:example.com intext:"text"
} }
``` ```
@ -71,7 +71,7 @@ func main() {
dork.Site("facebook.com").Or().Site("twitter.com").String() dork.Site("facebook.com").Or().Site("twitter.com").String()
// returns: site:facebook.com | site:twitter.com // returns: site:facebook.com | site:twitter.com
dork.Intext("facebook").And().Intext("twitter").String() dork.InText("facebook").And().InText("twitter").String()
// returns: intext:"facebook" + intext:"twitter" // returns: intext:"facebook" + intext:"twitter"
} }
``` ```
@ -86,7 +86,7 @@ func main() {
String()). String()).
Site("example.*"). Site("example.*").
Or(). Or().
Intext("text") InText("text")
// returns: -site:example.com site:example.* | "text" // returns: -site:example.com site:example.* | "text"
} }
``` ```
@ -100,7 +100,7 @@ func main() {
Site("facebook.com"). Site("facebook.com").
Or(). Or().
Site("twitter.com")). Site("twitter.com")).
Intext("wtf"). InText("wtf").
String() String()
// returns: (site:facebook.com | site:twitter.com) "wtf" // returns: (site:facebook.com | site:twitter.com) "wtf"
} }

View File

@ -34,7 +34,7 @@ func New() *DuckDuckGo {
return &DuckDuckGo{} return &DuckDuckGo{}
} }
func (d *DuckDuckGo) concat(tag string, value string, quotes bool) string { func (e *DuckDuckGo) join(tag string, value string, quotes bool) string {
if quotes { if quotes {
return tag + "\"" + value + "\"" return tag + "\"" + value + "\""
} }
@ -43,13 +43,13 @@ func (d *DuckDuckGo) concat(tag string, value string, quotes bool) string {
} }
// String converts all tags to a single request // String converts all tags to a single request
func (d *DuckDuckGo) String() string { func (e *DuckDuckGo) String() string {
return strings.Join(d.tags, " ") return strings.Join(e.tags, " ")
} }
// QueryValues returns search request as URL values // QueryValues returns search request as URL values
func (d *DuckDuckGo) QueryValues() url.Values { func (e *DuckDuckGo) QueryValues() url.Values {
tags := strings.Join(d.tags, " ") tags := strings.Join(e.tags, " ")
params := url.Values{} params := url.Values{}
params.Add("q", tags) params.Add("q", tags)
@ -58,115 +58,115 @@ func (d *DuckDuckGo) QueryValues() url.Values {
} }
// URL converts tags to an encoded Google Search URL // URL converts tags to an encoded Google Search URL
func (d *DuckDuckGo) URL() string { func (e *DuckDuckGo) URL() string {
baseURL, _ := url.Parse(searchURL) baseURL, _ := url.Parse(searchURL)
baseURL.RawQuery = d.QueryValues().Encode() baseURL.RawQuery = e.QueryValues().Encode()
return baseURL.String() return baseURL.String()
} }
// Site specifically searches that particular site and lists all the results for that site. // Site specifically searches that particular site and lists all the results for that site.
func (d *DuckDuckGo) Site(site string) *DuckDuckGo { func (e *DuckDuckGo) Site(site string) *DuckDuckGo {
d.tags = append(d.tags, d.concat(siteTag, site, false)) e.tags = append(e.tags, e.join(siteTag, site, false))
return d return e
} }
// Or puts an OR operator in the request // Or puts an OR operator in the request
func (d *DuckDuckGo) Or() *DuckDuckGo { func (e *DuckDuckGo) Or() *DuckDuckGo {
d.tags = append(d.tags, operatorOr) e.tags = append(e.tags, operatorOr)
return d return e
} }
// And puts an AND operator in the request // And puts an AND operator in the request
func (d *DuckDuckGo) And() *DuckDuckGo { func (e *DuckDuckGo) And() *DuckDuckGo {
d.tags = append(d.tags, operatorAnd) e.tags = append(e.tags, operatorAnd)
return d return e
} }
// Intext searches for the occurrences of keywords all at once or one at a time. // InText searches for the occurrences of keywords all at once or one at a time.
func (d *DuckDuckGo) Intext(text string) *DuckDuckGo { func (e *DuckDuckGo) InText(text string) *DuckDuckGo {
d.tags = append(d.tags, d.concat(intextTag, text, true)) e.tags = append(e.tags, e.join(intextTag, text, true))
return d return e
} }
// Inurl searches for a URL matching one of the keywords. // InURL searches for a URL matching one of the keywords.
func (d *DuckDuckGo) Inurl(url string) *DuckDuckGo { func (e *DuckDuckGo) InURL(url string) *DuckDuckGo {
d.tags = append(d.tags, d.concat(urlTag, url, true)) e.tags = append(e.tags, e.join(urlTag, url, true))
return d return e
} }
// Filetype searches for a particular filetype mentioned in the query. // FileType searches for a particular filetype mentioned in the query.
func (d *DuckDuckGo) Filetype(filetype string) *DuckDuckGo { func (e *DuckDuckGo) FileType(filetype string) *DuckDuckGo {
d.tags = append(d.tags, d.concat(filetypeTag, filetype, true)) e.tags = append(e.tags, e.join(filetypeTag, filetype, true))
return d return e
} }
// Ext searches for a particular file extension mentioned in the query. // Ext searches for a particular file extension mentioned in the query.
func (d *DuckDuckGo) Ext(ext string) *DuckDuckGo { func (e *DuckDuckGo) Ext(ext string) *DuckDuckGo {
d.tags = append(d.tags, d.concat(extTag, ext, false)) e.tags = append(e.tags, e.join(extTag, ext, false))
return d return e
} }
// Exclude excludes some results. // Exclude excludes some results.
func (d *DuckDuckGo) Exclude(tags *DuckDuckGo) *DuckDuckGo { func (e *DuckDuckGo) Exclude(tags *DuckDuckGo) *DuckDuckGo {
d.tags = append(d.tags, d.concat(excludeTag, tags.String(), false)) e.tags = append(e.tags, e.join(excludeTag, tags.String(), false))
return d return e
} }
// Group isolate tags between parentheses // Group isolate tags between parentheses
func (d *DuckDuckGo) Group(tags *DuckDuckGo) *DuckDuckGo { func (e *DuckDuckGo) Group(tags *DuckDuckGo) *DuckDuckGo {
d.tags = append(d.tags, "("+tags.String()+")") e.tags = append(e.tags, "("+tags.String()+")")
return d return e
} }
// Intitle searches for occurrences of keywords in title all or one. // InTitle searches for occurrences of keywords in title all or one.
func (d *DuckDuckGo) Intitle(value string) *DuckDuckGo { func (e *DuckDuckGo) InTitle(value string) *DuckDuckGo {
d.tags = append(d.tags, d.concat(intitleTag, value, true)) e.tags = append(e.tags, e.join(intitleTag, value, true))
return d return e
} }
// Plain allows you to add additional values as string without any kind of formatting. // Plain allows you to add additional values as string without any kind of formatting.
func (d *DuckDuckGo) Plain(value string) *DuckDuckGo { func (e *DuckDuckGo) Plain(value string) *DuckDuckGo {
d.tags = append(d.tags, value) e.tags = append(e.tags, value)
return d return e
} }
// AllInURL finds pages that include a specific keyword as part of their indexed URLs. // AllInURL finds pages that include a specific keyword as part of their indexed URLs.
func (d *DuckDuckGo) AllInURL(value string) *DuckDuckGo { func (e *DuckDuckGo) AllInURL(value string) *DuckDuckGo {
d.tags = append(d.tags, d.concat(allInURLTag, value, true)) e.tags = append(e.tags, e.join(allInURLTag, value, true))
return d return e
} }
// Location searches for specific region. // Location searches for specific region.
// An iso location code is a short code for a country for example, Egypt is eg and USA is us. // An iso location code is a short code for a country for example, Egypt is eg and USA is us.
// https://en.wikipedia.org/wiki/ISO_3166-1 // https://en.wikipedia.org/wiki/ISO_3166-1
func (d *DuckDuckGo) Location(isoCode string) *DuckDuckGo { func (e *DuckDuckGo) Location(isoCode string) *DuckDuckGo {
d.tags = append(d.tags, d.concat(locationTag, isoCode, true)) e.tags = append(e.tags, e.join(locationTag, isoCode, true))
return d return e
} }
// Feed finds RSS feed related to search term (i.e. rss). // Feed finds RSS feed related to search term (i.e. rss).
func (d *DuckDuckGo) Feed(feed string) *DuckDuckGo { func (e *DuckDuckGo) Feed(feed string) *DuckDuckGo {
d.tags = append(d.tags, d.concat(feedTag, feed, false)) e.tags = append(e.tags, e.join(feedTag, feed, false))
return d return e
} }
// HasFeed finds webpages that contain both the term or terms for which you are querying and one or more RSS or Atom feeds. // HasFeed finds webpages that contain both the term or terms for which you are querying and one or more RSS or Atom feeds.
func (d *DuckDuckGo) HasFeed(url string) *DuckDuckGo { func (e *DuckDuckGo) HasFeed(url string) *DuckDuckGo {
d.tags = append(d.tags, d.concat(hasfeedTag, url, true)) e.tags = append(e.tags, e.join(hasfeedTag, url, true))
return d return e
} }
// Language returns websites that match the search term in a specified language. // Language returns websites that match the search term in a specified language.
// See https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes for a complete list of ISO 639-1 codes you can use. // See https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes for a complete list of ISO 639-1 codes you can use.
func (d *DuckDuckGo) Language(lang string) *DuckDuckGo { func (e *DuckDuckGo) Language(lang string) *DuckDuckGo {
d.tags = append(d.tags, d.concat(languageTag, lang, false)) e.tags = append(e.tags, e.join(languageTag, lang, false))
return d return e
} }
// AllInTitle finds pages that include a specific keyword as part of the indexed title tag. // AllInTitle finds pages that include a specific keyword as part of the indexed title tag.
func (d *DuckDuckGo) AllInTitle(value string) *DuckDuckGo { func (e *DuckDuckGo) AllInTitle(value string) *DuckDuckGo {
d.tags = append(d.tags, d.concat(allintitleTag, value, true)) e.tags = append(e.tags, e.join(allintitleTag, value, true))
return d return e
} }

View File

@ -46,7 +46,7 @@ func TestInit(t *testing.T) {
dork = duckduckgo.New() dork = duckduckgo.New()
result := dork. result := dork.
Intext("text"). InText("text").
String() String()
assert.Equal(result, "intext:\"text\"", "they should be equal") assert.Equal(result, "intext:\"text\"", "they should be equal")
@ -56,7 +56,7 @@ func TestInit(t *testing.T) {
dork = duckduckgo.New() dork = duckduckgo.New()
result := dork. result := dork.
Inurl("index.php"). InURL("index.php").
String() String()
assert.Equal(result, "inurl:\"index.php\"", "they should be equal") assert.Equal(result, "inurl:\"index.php\"", "they should be equal")
@ -66,7 +66,7 @@ func TestInit(t *testing.T) {
dork = duckduckgo.New() dork = duckduckgo.New()
result := dork. result := dork.
Filetype("pdf"). FileType("pdf").
String() String()
assert.Equal(result, "filetype:\"pdf\"", "they should be equal") assert.Equal(result, "filetype:\"pdf\"", "they should be equal")
@ -171,9 +171,9 @@ func TestInit(t *testing.T) {
dork = duckduckgo.New() dork = duckduckgo.New()
result := dork. result := dork.
Intitle("facebook"). InTitle("facebook").
And(). And().
Intitle("twitter"). InTitle("twitter").
String() String()
assert.Equal(result, "intitle:\"facebook\" + intitle:\"twitter\"", "they should be equal") assert.Equal(result, "intitle:\"facebook\" + intitle:\"twitter\"", "they should be equal")
@ -184,7 +184,7 @@ func TestInit(t *testing.T) {
result := dork. result := dork.
Site("linkedin.com"). Site("linkedin.com").
Group(duckduckgo.New().Intext("1").Or().Intext("2")). Group(duckduckgo.New().InText("1").Or().InText("2")).
String() String()
assert.Equal(result, "site:linkedin.com (intext:\"1\" | intext:\"2\")", "they should be equal") assert.Equal(result, "site:linkedin.com (intext:\"1\" | intext:\"2\")", "they should be equal")
@ -195,8 +195,8 @@ func TestInit(t *testing.T) {
result := dork. result := dork.
Site("linkedin.com"). Site("linkedin.com").
Group(duckduckgo.New().Intext("1").Or().Intext("2")). Group(duckduckgo.New().InText("1").Or().InText("2")).
Intitle("jordan"). InTitle("jordan").
String() String()
assert.Equal(result, "site:linkedin.com (intext:\"1\" | intext:\"2\") intitle:\"jordan\"", "they should be equal") assert.Equal(result, "site:linkedin.com (intext:\"1\" | intext:\"2\") intitle:\"jordan\"", "they should be equal")
@ -207,8 +207,8 @@ func TestInit(t *testing.T) {
result := dork. result := dork.
Site("linkedin.com"). Site("linkedin.com").
Group(duckduckgo.New().Intext("1").Or().Intext("2")). Group(duckduckgo.New().InText("1").Or().InText("2")).
Intitle("jordan"). InTitle("jordan").
QueryValues() QueryValues()
assert.Equal(url.Values{ assert.Equal(url.Values{

View File

@ -30,7 +30,7 @@ func New() *GoogleSearch {
return &GoogleSearch{} return &GoogleSearch{}
} }
func (_ *GoogleSearch) concat(tag string, value string, quotes bool) string { func (e *GoogleSearch) join(tag string, value string, quotes bool) string {
if quotes { if quotes {
return tag + "\"" + value + "\"" return tag + "\"" + value + "\""
} }
@ -39,13 +39,13 @@ func (_ *GoogleSearch) concat(tag string, value string, quotes bool) string {
} }
// String converts all tags to a single request // String converts all tags to a single request
func (g *GoogleSearch) String() string { func (e *GoogleSearch) String() string {
return strings.Join(g.tags, " ") return strings.Join(e.tags, " ")
} }
// QueryValues returns search request as URL values // QueryValues returns search request as URL values
func (g *GoogleSearch) QueryValues() url.Values { func (e *GoogleSearch) QueryValues() url.Values {
tags := strings.Join(g.tags, " ") tags := strings.Join(e.tags, " ")
params := url.Values{} params := url.Values{}
params.Add("q", tags) params.Add("q", tags)
@ -54,88 +54,88 @@ func (g *GoogleSearch) QueryValues() url.Values {
} }
// URL converts tags to an encoded Google Search URL // URL converts tags to an encoded Google Search URL
func (g *GoogleSearch) URL() string { func (e *GoogleSearch) URL() string {
baseURL, _ := url.Parse(searchURL) baseURL, _ := url.Parse(searchURL)
baseURL.RawQuery = g.QueryValues().Encode() baseURL.RawQuery = e.QueryValues().Encode()
return baseURL.String() return baseURL.String()
} }
// Site specifically searches that particular site and lists all the results for that site. // Site specifically searches that particular site and lists all the results for that site.
func (g *GoogleSearch) Site(site string) *GoogleSearch { func (e *GoogleSearch) Site(site string) *GoogleSearch {
g.tags = append(g.tags, g.concat(siteTag, site, false)) e.tags = append(e.tags, e.join(siteTag, site, false))
return g return e
} }
// Or puts an OR operator in the request // Or puts an OR operator in the request
func (g *GoogleSearch) Or() *GoogleSearch { func (e *GoogleSearch) Or() *GoogleSearch {
g.tags = append(g.tags, operatorOr) e.tags = append(e.tags, operatorOr)
return g return e
} }
// And puts an AND operator in the request // And puts an AND operator in the request
func (g *GoogleSearch) And() *GoogleSearch { func (e *GoogleSearch) And() *GoogleSearch {
g.tags = append(g.tags, operatorAnd) e.tags = append(e.tags, operatorAnd)
return g return e
} }
// Intext searches for the occurrences of keywords all at once or one at a time. // InText searches for the occurrences of keywords all at once or one at a time.
func (g *GoogleSearch) Intext(text string) *GoogleSearch { func (e *GoogleSearch) InText(text string) *GoogleSearch {
g.tags = append(g.tags, g.concat(intextTag, text, true)) e.tags = append(e.tags, e.join(intextTag, text, true))
return g return e
} }
// Inurl searches for a URL matching one of the keywords. // InURL searches for a URL matching one of the keywords.
func (g *GoogleSearch) Inurl(url string) *GoogleSearch { func (e *GoogleSearch) InURL(url string) *GoogleSearch {
g.tags = append(g.tags, g.concat(urlTag, url, true)) e.tags = append(e.tags, e.join(urlTag, url, true))
return g return e
} }
// Filetype searches for a particular filetype mentioned in the query. // FileType searches for a particular filetype mentioned in the query.
func (g *GoogleSearch) Filetype(filetype string) *GoogleSearch { func (e *GoogleSearch) FileType(filetype string) *GoogleSearch {
g.tags = append(g.tags, g.concat(filetypeTag, filetype, true)) e.tags = append(e.tags, e.join(filetypeTag, filetype, true))
return g return e
} }
// Cache shows the version of the web page that Google has in its cache. // Cache shows the version of the web page that Google has in its cache.
func (g *GoogleSearch) Cache(url string) *GoogleSearch { func (e *GoogleSearch) Cache(url string) *GoogleSearch {
g.tags = append(g.tags, g.concat(cacheTag, url, true)) e.tags = append(e.tags, e.join(cacheTag, url, true))
return g return e
} }
// Related list web pages that are “similar” to a specified web page. // Related list web pages that are “similar” to a specified web page.
func (g *GoogleSearch) Related(url string) *GoogleSearch { func (e *GoogleSearch) Related(url string) *GoogleSearch {
g.tags = append(g.tags, g.concat(relatedTag, url, true)) e.tags = append(e.tags, e.join(relatedTag, url, true))
return g return e
} }
// Ext searches for a particular file extension mentioned in the query. // Ext searches for a particular file extension mentioned in the query.
func (g *GoogleSearch) Ext(ext string) *GoogleSearch { func (e *GoogleSearch) Ext(ext string) *GoogleSearch {
g.tags = append(g.tags, g.concat(extTag, ext, false)) e.tags = append(e.tags, e.join(extTag, ext, false))
return g return e
} }
// Exclude excludes some results. // Exclude excludes some results.
func (g *GoogleSearch) Exclude(tags *GoogleSearch) *GoogleSearch { func (e *GoogleSearch) Exclude(tags *GoogleSearch) *GoogleSearch {
g.tags = append(g.tags, g.concat(excludeTag, tags.String(), false)) e.tags = append(e.tags, e.join(excludeTag, tags.String(), false))
return g return e
} }
// Group isolate tags between parentheses // Group isolate tags between parentheses
func (g *GoogleSearch) Group(tags *GoogleSearch) *GoogleSearch { func (e *GoogleSearch) Group(tags *GoogleSearch) *GoogleSearch {
g.tags = append(g.tags, "("+tags.String()+")") e.tags = append(e.tags, "("+tags.String()+")")
return g return e
} }
// Intitle searches for occurrences of keywords in title all or one. // InTitle searches for occurrences of keywords in title all or one.
func (g *GoogleSearch) Intitle(value string) *GoogleSearch { func (e *GoogleSearch) InTitle(value string) *GoogleSearch {
g.tags = append(g.tags, g.concat(intitleTag, value, true)) e.tags = append(e.tags, e.join(intitleTag, value, true))
return g return e
} }
// Plain allows you to add additional values as string without any kind of formatting. // Plain allows you to add additional values as string without any kind of formatting.
func (g *GoogleSearch) Plain(value string) *GoogleSearch { func (e *GoogleSearch) Plain(value string) *GoogleSearch {
g.tags = append(g.tags, value) e.tags = append(e.tags, value)
return g return e
} }

View File

@ -46,7 +46,7 @@ func TestInit(t *testing.T) {
dork = googlesearch.New() dork = googlesearch.New()
result := dork. result := dork.
Intext("text"). InText("text").
String() String()
assert.Equal(result, "intext:\"text\"", "they should be equal") assert.Equal(result, "intext:\"text\"", "they should be equal")
@ -56,7 +56,7 @@ func TestInit(t *testing.T) {
dork = googlesearch.New() dork = googlesearch.New()
result := dork. result := dork.
Inurl("index.php"). InURL("index.php").
String() String()
assert.Equal(result, "inurl:\"index.php\"", "they should be equal") assert.Equal(result, "inurl:\"index.php\"", "they should be equal")
@ -66,7 +66,7 @@ func TestInit(t *testing.T) {
dork = googlesearch.New() dork = googlesearch.New()
result := dork. result := dork.
Filetype("pdf"). FileType("pdf").
String() String()
assert.Equal(result, "filetype:\"pdf\"", "they should be equal") assert.Equal(result, "filetype:\"pdf\"", "they should be equal")
@ -131,9 +131,9 @@ func TestInit(t *testing.T) {
dork = googlesearch.New() dork = googlesearch.New()
result := dork. result := dork.
Intitle("facebook"). InTitle("facebook").
And(). And().
Intitle("twitter"). InTitle("twitter").
String() String()
assert.Equal(result, "intitle:\"facebook\" + intitle:\"twitter\"", "they should be equal") assert.Equal(result, "intitle:\"facebook\" + intitle:\"twitter\"", "they should be equal")
@ -144,7 +144,7 @@ func TestInit(t *testing.T) {
result := dork. result := dork.
Site("linkedin.com"). Site("linkedin.com").
Group(googlesearch.New().Intext("1").Or().Intext("2")). Group(googlesearch.New().InText("1").Or().InText("2")).
String() String()
assert.Equal(result, "site:linkedin.com (intext:\"1\" | intext:\"2\")", "they should be equal") assert.Equal(result, "site:linkedin.com (intext:\"1\" | intext:\"2\")", "they should be equal")
@ -155,8 +155,8 @@ func TestInit(t *testing.T) {
result := dork. result := dork.
Site("linkedin.com"). Site("linkedin.com").
Group(googlesearch.New().Intext("1").Or().Intext("2")). Group(googlesearch.New().InText("1").Or().InText("2")).
Intitle("jordan"). InTitle("jordan").
String() String()
assert.Equal(result, "site:linkedin.com (intext:\"1\" | intext:\"2\") intitle:\"jordan\"", "they should be equal") assert.Equal(result, "site:linkedin.com (intext:\"1\" | intext:\"2\") intitle:\"jordan\"", "they should be equal")
@ -167,8 +167,8 @@ func TestInit(t *testing.T) {
result := dork. result := dork.
Site("linkedin.com"). Site("linkedin.com").
Group(googlesearch.New().Intext("1").Or().Intext("2")). Group(googlesearch.New().InText("1").Or().InText("2")).
Intitle("jordan"). InTitle("jordan").
QueryValues() QueryValues()
assert.Equal(url.Values{ assert.Equal(url.Values{