diff options
Diffstat (limited to 'vendor/github.com/peterhellberg/giphy/gif.go')
-rw-r--r-- | vendor/github.com/peterhellberg/giphy/gif.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/vendor/github.com/peterhellberg/giphy/gif.go b/vendor/github.com/peterhellberg/giphy/gif.go new file mode 100644 index 00000000..8c317c97 --- /dev/null +++ b/vendor/github.com/peterhellberg/giphy/gif.go @@ -0,0 +1,44 @@ +package giphy + +import ( + "encoding/json" + "fmt" + "strings" +) + +// GIF returns a ID response from the Giphy API +func (c *Client) GIF(id string) (GIF, error) { + if strings.ContainsAny(id, "/&?") { + return GIF{}, fmt.Errorf("Invalid giphy id: `%v`", id) + } + + req, err := c.NewRequest("/gifs/" + id) + if err != nil { + return GIF{}, err + } + + var gif GIF + if _, err = c.Do(req, &gif); err != nil { + return GIF{}, err + } + + if gif.RawData == nil || gif.RawData[0] == '[' { + return GIF{}, ErrNoImageFound + } + + // Check if the first character in Data is a { + if gif.RawData[0] == '{' { + var d Data + + err = json.Unmarshal(gif.RawData, &d) + if err != nil { + return GIF{}, err + } + + gif.Data = d + + return gif, nil + } + + return GIF{}, ErrUnknown +} |