Browse Source

add support for meta API endpoint

Will Norris 12 years ago
parent
commit
a4a5c1e667
3 changed files with 81 additions and 0 deletions
  1. +38
    -0
      github/misc.go
  2. +24
    -0
      github/misc_test.go
  3. +19
    -0
      tests/integration/misc_test.go

+ 38
- 0
github/misc.go View File

@ -79,3 +79,41 @@ func (c *Client) ListEmojis() (map[string]string, *Response, error) {
return emoji, resp, nil
}
// APIMeta represents metadata about the GitHub API.
type APIMeta struct {
// An Array of IP addresses in CIDR format specifying the addresses
// that incoming service hooks will originate from on GitHub.com.
Hooks []string `json:"hooks,omitempty"`
// An Array of IP addresses in CIDR format specifying the Git servers
// for GitHub.com.
Git []string `json:"git,omitempty"`
// Whether authentication with username and password is supported.
// (GitHub Enterprise instances using CAS or OAuth for authentication
// will return false. Features like Basic Authentication with a
// username and password, sudo mode, and two-factor authentication are
// not supported on these servers.)
VerifiablePasswordAuthentication *bool `json:"verifiable_password_authentication,omitempty"`
}
// APIMeta returns information about GitHub.com, the service. Or, if you access
// this endpoint on your organization’s GitHub Enterprise installation, this
// endpoint provides information about that installation.
//
// GitHub API docs: https://developer.github.com/v3/meta/
func (c *Client) APIMeta() (*APIMeta, *Response, error) {
req, err := c.NewRequest("GET", "/meta", nil)
if err != nil {
return nil, nil, err
}
meta := new(APIMeta)
resp, err := c.Do(req, meta)
if err != nil {
return nil, resp, err
}
return meta, resp, nil
}

+ 24
- 0
github/misc_test.go View File

@ -65,3 +65,27 @@ func TestListEmojis(t *testing.T) {
t.Errorf("ListEmojis returned %+v, want %+v", emoji, want)
}
}
func TestAPIMeta(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/meta", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"hooks":["h"], "git":["g"], "verifiable_password_authentication": true}`)
})
meta, _, err := client.APIMeta()
if err != nil {
t.Errorf("APIMeta returned error: %v", err)
}
want := &APIMeta{
Hooks: []string{"h"},
Git: []string{"g"},
VerifiablePasswordAuthentication: Bool(true),
}
if !reflect.DeepEqual(want, meta) {
t.Errorf("APIMeta returned %+v, want %+v", meta, want)
}
}

+ 19
- 0
tests/integration/misc_test.go View File

@ -21,3 +21,22 @@ func TestEmojis(t *testing.T) {
t.Errorf("ListEmojis missing '+1' emoji")
}
}
func TestAPIMeta(t *testing.T) {
meta, _, err := client.APIMeta()
if err != nil {
t.Fatalf("APIMeta returned error: %v", err)
}
if len(meta.Hooks) == 0 {
t.Errorf("APIMeta returned no hook addresses")
}
if len(meta.Git) == 0 {
t.Errorf("APIMeta returned no git addresses")
}
if !*meta.VerifiablePasswordAuthentication {
t.Errorf("APIMeta VerifiablePasswordAuthentication is false")
}
}

Loading…
Cancel
Save