diff --git a/github/misc.go b/github/misc.go index 628372d..1cec5a2 100644 --- a/github/misc.go +++ b/github/misc.go @@ -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 +} diff --git a/github/misc_test.go b/github/misc_test.go index a79568f..9b7e5c9 100644 --- a/github/misc_test.go +++ b/github/misc_test.go @@ -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) + } +} diff --git a/tests/integration/misc_test.go b/tests/integration/misc_test.go index 14ee424..1bfb215 100644 --- a/tests/integration/misc_test.go +++ b/tests/integration/misc_test.go @@ -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") + } +}