search.go
author Mikael Berthe <mikael@lilotux.net>
Sat, 15 Apr 2017 21:08:34 +0200
changeset 125 2bbb72b9ebf6
parent 120 579912e9d0ef
child 130 c450bb73f59a
permissions -rw-r--r--
Rework the API wrappers to handle arrays of parameters This make some API calls work better (reports with several statuses, statuses with several attachments, relationships for multiple accounts...).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
113
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     1
package gondole
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     2
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     3
import (
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     4
	"github.com/sendgrid/rest"
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     5
)
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     6
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     7
// 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
     8
func (g *Client) Search(query string, resolve bool) (*Results, error) {
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     9
	if query == "" {
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    10
		return nil, ErrInvalidParameter
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    11
	}
120
579912e9d0ef Refactor API calls
Mikael Berthe <mikael@lilotux.net>
parents: 113
diff changeset
    12
579912e9d0ef Refactor API calls
Mikael Berthe <mikael@lilotux.net>
parents: 113
diff changeset
    13
	params := make(apiCallParams)
579912e9d0ef Refactor API calls
Mikael Berthe <mikael@lilotux.net>
parents: 113
diff changeset
    14
	params["q"] = query
113
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    15
	if resolve {
120
579912e9d0ef Refactor API calls
Mikael Berthe <mikael@lilotux.net>
parents: 113
diff changeset
    16
		params["resolve"] = "true"
113
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    17
	}
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    18
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    19
	var results Results
120
579912e9d0ef Refactor API calls
Mikael Berthe <mikael@lilotux.net>
parents: 113
diff changeset
    20
	if err := g.apiCall("search", rest.Get, params, &results); err != nil {
579912e9d0ef Refactor API calls
Mikael Berthe <mikael@lilotux.net>
parents: 113
diff changeset
    21
		return nil, err
113
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    22
	}
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    23
	return &results, nil
bb9aaa5440c1 Add Search() (using endpoint /search)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    24
}