Skip to content

Commit

Permalink
Add NotifyMessage method
Browse files Browse the repository at this point in the history
  • Loading branch information
utahta committed Nov 23, 2017
1 parent c8eaacd commit 1f9c5d4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# go-linenotify

[![GoDoc Reference](https://godoc.org/github.com/utahta/go-linenotify?status.svg)](http://godoc.org/github.com/utahta/go-linenotify)
[![Build Status](https://travis-ci.org/utahta/go-linenotify.svg?branch=master)](https://travis-ci.org/utahta/go-linenotify)
[![GitHub release](https://img.shields.io/github/release/utahta/go-linenotify.svg)](https://github.com/utahta/go-linenotify/releases)

Go client library for the [LINE Notify](https://notify-bot.line.me/doc/)

Expand Down
12 changes: 10 additions & 2 deletions notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

type (
// NotifyResponse
// NotifyResponse represents response that LINE Notify API
NotifyResponse struct {
Status int `json:"status"`
Message string `json:"message"`
Expand All @@ -24,16 +24,23 @@ type (
)

var (
ErrNotifyInvalidAccessToken = errors.New("Invalid access token")
ErrNotifyInvalidAccessToken = errors.New("invalid access token")
)

// Notify provides convenient Notify* interface
func (c *Client) Notify(token, message, imageThumbnail, imageFullsize string, image io.Reader) (*NotifyResponse, error) {
if image != nil {
return c.NotifyWithImage(token, message, image)
}
return c.NotifyWithImageURL(token, message, imageThumbnail, imageFullsize)
}

// NotifyMessage notify text message
func (c *Client) NotifyMessage(token, message string) (*NotifyResponse, error) {
return c.NotifyWithImageURL(token, message, "", "")
}

// NotifyWithImage notify text message and image by binary
func (c *Client) NotifyWithImage(token, message string, image io.Reader) (*NotifyResponse, error) {
body, contentType, err := c.requestBodyWithImage(message, image)
if err != nil {
Expand All @@ -42,6 +49,7 @@ func (c *Client) NotifyWithImage(token, message string, image io.Reader) (*Notif
return c.notify(token, message, body, contentType)
}

// NotifyWithImageURL notify text message and image by url
func (c *Client) NotifyWithImageURL(token, message, imageThumbnail, imageFullsize string) (*NotifyResponse, error) {
body, contentType, err := c.requestBody(message, imageThumbnail, imageFullsize)
if err != nil {
Expand Down

0 comments on commit 1f9c5d4

Please sign in to comment.