From 4eeb46d6b9bd9d6c588cb1934695002fe39e2221 Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Mon, 13 Feb 2017 17:16:31 +0000 Subject: [PATCH 1/3] Search for large images only. Fix httpClient reference. Fix logging when no error and no results --- .../matrix-org/go-neb/services/google/google.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/github.com/matrix-org/go-neb/services/google/google.go b/src/github.com/matrix-org/go-neb/services/google/google.go index 030a861..630722c 100644 --- a/src/github.com/matrix-org/go-neb/services/google/google.go +++ b/src/github.com/matrix-org/go-neb/services/google/google.go @@ -145,7 +145,7 @@ func (s *Service) text2imgGoogle(query string) (*googleSearchResult, error) { q.Set("q", query) // String to search for q.Set("num", "1") // Just return 1 image result q.Set("start", "1") // No search result offset - q.Set("imgSize", "medium") // Just search for medium size images + q.Set("imgSize", "large") // Just search for medium size images q.Set("searchType", "image") // Search for images q.Set("key", s.APIKey) // Set the API key for the request @@ -154,7 +154,7 @@ func (s *Service) text2imgGoogle(query string) (*googleSearchResult, error) { u.RawQuery = q.Encode() // log.Info("Request URL: ", u) - res, err := http.Get(u.String()) + res, err := httpClient.Get(u.String()) if res != nil { defer res.Body.Close() } @@ -167,8 +167,10 @@ func (s *Service) text2imgGoogle(query string) (*googleSearchResult, error) { var searchResults googleSearchResults // log.Info(response2String(res)) - if err := json.NewDecoder(res.Body).Decode(&searchResults); err != nil || len(searchResults.Items) < 1 { - return nil, fmt.Errorf("No images found - %s", err.Error()) + if err := json.NewDecoder(res.Body).Decode(&searchResults); err != nil { + return nil, fmt.Errorf("ERROR - %s", err.Error()) + } else if len(searchResults.Items) < 1 { + return nil, fmt.Errorf("No images found") } // Return only the first search result From 445c277bd30cdd2e84b1933da4c3f9ea1761fe76 Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Mon, 13 Feb 2017 17:22:14 +0000 Subject: [PATCH 2/3] Add default command route handler --- src/github.com/matrix-org/go-neb/services/google/google.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/github.com/matrix-org/go-neb/services/google/google.go b/src/github.com/matrix-org/go-neb/services/google/google.go index 630722c..728bfe1 100644 --- a/src/github.com/matrix-org/go-neb/services/google/google.go +++ b/src/github.com/matrix-org/go-neb/services/google/google.go @@ -82,6 +82,12 @@ func (s *Service) Commands(client *gomatrix.Client) []types.Command { return usageMessage(), nil }, }, + types.Command{ + Path: []string{"google"}, + Command: func(roomID, userID string, args []string) (interface{}, error) { + return usageMessage(), nil + }, + }, } } From 07d27b67b157d0efbe19a914a34ed1dcf325b757 Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Mon, 13 Feb 2017 17:23:36 +0000 Subject: [PATCH 3/3] Fix number of commands test --- src/github.com/matrix-org/go-neb/services/google/google_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/github.com/matrix-org/go-neb/services/google/google_test.go b/src/github.com/matrix-org/go-neb/services/google/google_test.go index 6d7422a..c069cc2 100644 --- a/src/github.com/matrix-org/go-neb/services/google/google_test.go +++ b/src/github.com/matrix-org/go-neb/services/google/google_test.go @@ -100,7 +100,7 @@ func TestCommand(t *testing.T) { // Execute the matrix !command cmds := google.Commands(matrixCli) - if len(cmds) != 2 { + if len(cmds) != 3 { t.Fatalf("Unexpected number of commands: %d", len(cmds)) } // cmd := cmds[0]