-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eafdd46
commit aacdf44
Showing
5 changed files
with
130 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package humiographql | ||
|
||
import graphql "github.com/cli/shurcooL-graphql" | ||
|
||
const ( | ||
SearchDomainTypeView graphql.String = "View" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package api | ||
|
||
import ( | ||
"sort" | ||
"strings" | ||
|
||
graphql "github.com/cli/shurcooL-graphql" | ||
) | ||
|
||
type SearchDomains struct { | ||
client *Client | ||
} | ||
|
||
type SearchDomainsQueryData struct { | ||
Name string | ||
Description string | ||
AutomaticSearch bool | ||
Typename graphql.String `graphql:"__typename"` | ||
} | ||
|
||
type SearchDomain struct { | ||
Name string | ||
Description string | ||
AutomaticSearch bool | ||
} | ||
|
||
func (s *Client) SearchDomains() *SearchDomains { return &SearchDomains{client: s} } | ||
|
||
func (s *SearchDomains) Get(name string) (*SearchDomain, error) { | ||
var query struct { | ||
Result SearchDomainsQueryData `graphql:"searchDomain(name: $name)"` | ||
} | ||
|
||
variables := map[string]interface{}{ | ||
"name": graphql.String(name), | ||
} | ||
|
||
err := s.client.Query(&query, variables) | ||
if err != nil { | ||
return nil, SearchDomainNotFound(name) | ||
} | ||
|
||
searchDomain := SearchDomain{ | ||
Name: query.Result.Name, | ||
Description: query.Result.Description, | ||
AutomaticSearch: query.Result.AutomaticSearch, | ||
} | ||
|
||
return &searchDomain, nil | ||
} | ||
|
||
type SearchDomainListItem struct { | ||
Name string | ||
Typename string `graphql:"__typename"` | ||
AutomaticSearch bool | ||
} | ||
|
||
func (s *SearchDomains) List() ([]SearchDomainListItem, error) { | ||
var query struct { | ||
SearchDomain []SearchDomainListItem `graphql:"searchDomains"` | ||
} | ||
|
||
err := s.client.Query(&query, nil) | ||
|
||
sort.Slice(query.SearchDomain, func(i, j int) bool { | ||
return strings.ToLower(query.SearchDomain[i].Name) < strings.ToLower(query.SearchDomain[j].Name) | ||
}) | ||
|
||
return query.SearchDomain, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters