search.go
author Mikael Berthe <mikael@lilotux.net>
Mon, 17 Apr 2017 10:28:10 +0200
changeset 130 c450bb73f59a
parent 120 579912e9d0ef
child 138 23d3a518d0ad
permissions -rw-r--r--
Update credits
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
130
c450bb73f59a Update credits
Mikael Berthe <mikael@lilotux.net>
parents: 120
diff changeset
     1
/*
c450bb73f59a Update credits
Mikael Berthe <mikael@lilotux.net>
parents: 120
diff changeset
     2
Copyright 2017 Mikael Berthe
c450bb73f59a Update credits
Mikael Berthe <mikael@lilotux.net>
parents: 120
diff changeset
     3
c450bb73f59a Update credits
Mikael Berthe <mikael@lilotux.net>
parents: 120
diff changeset
     4
Licensed under the MIT license.  Please see the LICENSE file is this directory.
c450bb73f59a Update credits
Mikael Berthe <mikael@lilotux.net>
parents: 120
diff changeset
     5
*/
c450bb73f59a Update credits
Mikael Berthe <mikael@lilotux.net>
parents: 120
diff changeset
     6
113
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     7
package gondole
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     8
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     9
import (
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    10
	"github.com/sendgrid/rest"
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    11
)
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    12
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    13
// Search search for contents (accounts or statuses) and returns a Results
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    14
func (g *Client) Search(query string, resolve bool) (*Results, error) {
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    15
	if query == "" {
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    16
		return nil, ErrInvalidParameter
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    17
	}
120
579912e9d0ef Refactor API calls
Mikael Berthe <mikael@lilotux.net>
parents: 113
diff changeset
    18
579912e9d0ef Refactor API calls
Mikael Berthe <mikael@lilotux.net>
parents: 113
diff changeset
    19
	params := make(apiCallParams)
579912e9d0ef Refactor API calls
Mikael Berthe <mikael@lilotux.net>
parents: 113
diff changeset
    20
	params["q"] = query
113
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    21
	if resolve {
120
579912e9d0ef Refactor API calls
Mikael Berthe <mikael@lilotux.net>
parents: 113
diff changeset
    22
		params["resolve"] = "true"
113
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    23
	}
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    24
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    25
	var results Results
120
579912e9d0ef Refactor API calls
Mikael Berthe <mikael@lilotux.net>
parents: 113
diff changeset
    26
	if err := g.apiCall("search", rest.Get, params, &results); err != nil {
579912e9d0ef Refactor API calls
Mikael Berthe <mikael@lilotux.net>
parents: 113
diff changeset
    27
		return nil, err
113
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    28
	}
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    29
	return &results, nil
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    30
}