Browse Source

add octocat and zen endpoints

okay, so these aren't really that useful buy hey, why not? :)

               MMM.           .MMM
               MMMMMMMMMMMMMMMMMMM
               MMMMMMMMMMMMMMMMMMM      __________
              MMMMMMMMMMMMMMMMMMMMM    |          |
             MMMMMMMMMMMMMMMMMMMMMMM   | Ship It! |
            MMMMMMMMMMMMMMMMMMMMMMMM   |_   ______|
            MMMM::- -:::::::- -::MMMM    |/
             MM~:~   ~:::::~   ~:~MM
        .. MMMMM::. .:::+:::. .::MMMMM ..
              .MM::::: ._. :::::MM.
                 MMMM;:::::;MMMM
          -MM        MMMMMMM
          ^  M+     MMMMMMMMM
              MMMMMMM MM MM MM
                   MM MM MM MM
                   MM MM MM MM
                .~~MM~MM~MM~MM~~.
             ~~~~MM:~MM~~~MM~:MM~~~~
            ~~~~~~==~==~~~==~==~~~~~~
             ~~~~~~==~==~==~==~~~~~~
                 :~==~==~==~==~~
Will Norris 11 years ago
parent
commit
d148dc0c24
2 changed files with 91 additions and 3 deletions
  1. +45
    -3
      github/misc.go
  2. +46
    -0
      github/misc_test.go

+ 45
- 3
github/misc.go View File

@ -7,6 +7,8 @@ package github
import ( import (
"bytes" "bytes"
"fmt"
"net/url"
) )
// MarkdownOptions specifies optional parameters to the Markdown method. // MarkdownOptions specifies optional parameters to the Markdown method.
@ -48,7 +50,7 @@ func (c *Client) Markdown(text string, opt *MarkdownOptions) (string, *Response,
} }
} }
req, err := c.NewRequest("POST", "/markdown", request)
req, err := c.NewRequest("POST", "markdown", request)
if err != nil { if err != nil {
return "", nil, err return "", nil, err
} }
@ -66,7 +68,7 @@ func (c *Client) Markdown(text string, opt *MarkdownOptions) (string, *Response,
// //
// GitHub API docs: https://developer.github.com/v3/emojis/ // GitHub API docs: https://developer.github.com/v3/emojis/
func (c *Client) ListEmojis() (map[string]string, *Response, error) { func (c *Client) ListEmojis() (map[string]string, *Response, error) {
req, err := c.NewRequest("GET", "/emojis", nil)
req, err := c.NewRequest("GET", "emojis", nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -104,7 +106,7 @@ type APIMeta struct {
// //
// GitHub API docs: https://developer.github.com/v3/meta/ // GitHub API docs: https://developer.github.com/v3/meta/
func (c *Client) APIMeta() (*APIMeta, *Response, error) { func (c *Client) APIMeta() (*APIMeta, *Response, error) {
req, err := c.NewRequest("GET", "/meta", nil)
req, err := c.NewRequest("GET", "meta", nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -117,3 +119,43 @@ func (c *Client) APIMeta() (*APIMeta, *Response, error) {
return meta, resp, nil return meta, resp, nil
} }
// Octocat returns an ASCII art octocat with the specified message in a speech
// bubble. If message is empty, a random zen phrase is used.
func (c *Client) Octocat(message string) (string, *Response, error) {
u := "octocat"
if message != "" {
u = fmt.Sprintf("%s?s=%s", u, url.QueryEscape(message))
}
req, err := c.NewRequest("GET", u, nil)
if err != nil {
return "", nil, err
}
buf := new(bytes.Buffer)
resp, err := c.Do(req, buf)
if err != nil {
return "", resp, err
}
return buf.String(), resp, nil
}
// Zen returns a random line from The Zen of GitHub.
//
// see also: http://warpspire.com/posts/taste/
func (c *Client) Zen() (string, *Response, error) {
req, err := c.NewRequest("GET", "zen", nil)
if err != nil {
return "", nil, err
}
buf := new(bytes.Buffer)
resp, err := c.Do(req, buf)
if err != nil {
return "", resp, err
}
return buf.String(), resp, nil
}

+ 46
- 0
github/misc_test.go View File

@ -89,3 +89,49 @@ func TestAPIMeta(t *testing.T) {
t.Errorf("APIMeta returned %+v, want %+v", meta, want) t.Errorf("APIMeta returned %+v, want %+v", meta, want)
} }
} }
func TestOctocat(t *testing.T) {
setup()
defer teardown()
input := "input"
output := "sample text"
mux.HandleFunc("/octocat", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{"s": input})
w.Header().Set("Content-Type", "application/octocat-stream")
fmt.Fprint(w, output)
})
got, _, err := client.Octocat(input)
if err != nil {
t.Errorf("Octocat returned error: %v", err)
}
if want := output; got != want {
t.Errorf("Octocat returned %+v, want %+v", got, want)
}
}
func TestZen(t *testing.T) {
setup()
defer teardown()
output := "sample text"
mux.HandleFunc("/zen", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
w.Header().Set("Content-Type", "text/plain;charset=utf-8")
fmt.Fprint(w, output)
})
got, _, err := client.Zen()
if err != nil {
t.Errorf("Zen returned error: %v", err)
}
if want := output; got != want {
t.Errorf("Zen returned %+v, want %+v", got, want)
}
}

Loading…
Cancel
Save