@@ -15,65 +15,47 @@ import (
1515
1616type Client struct {
1717 HTTPClient * http.Client
18- token string
1918}
2019
21- type ClientOption func (* Client )
22-
2320var (
2421 ErrNotifyInvalidAccessToken = errors .New ("Invalid access token." )
2522)
2623
27- // https://notify-bot.line.me/doc/ja/
28- func New (options ... ClientOption ) * Client {
29- c := & Client {HTTPClient : http .DefaultClient }
30-
31- for _ , opt := range options {
32- opt (c )
33- }
34- return c
35- }
36-
37- func WithToken (token string ) ClientOption {
38- return func (c * Client ) {
39- c .token = token
40- }
41- }
42-
43- func (c * Client ) SetToken (token string ) {
44- c .token = token
24+ // https://notify-bot.line.me/doc/
25+ func New () * Client {
26+ return & Client {HTTPClient : http .DefaultClient }
4527}
4628
47- func (c * Client ) Notify (message , imageThumbnail , imageFullsize string , image io.Reader ) error {
29+ func (c * Client ) Notify (token , message , imageThumbnail , imageFullsize string , image io.Reader ) error {
4830 if image != nil {
49- return c .NotifyWithImage (message , image )
31+ return c .NotifyWithImage (token , message , image )
5032 }
51- return c .NotifyWithImageURL (message , imageThumbnail , imageFullsize )
33+ return c .NotifyWithImageURL (token , message , imageThumbnail , imageFullsize )
5234}
5335
54- func (c * Client ) NotifyWithImage (message string , image io.Reader ) error {
36+ func (c * Client ) NotifyWithImage (token , message string , image io.Reader ) error {
5537 body , contentType , err := c .requestBodyWithImage (message , image )
5638 if err != nil {
5739 return err
5840 }
59- return c .notify (message , body , contentType )
41+ return c .notify (token , message , body , contentType )
6042}
6143
62- func (c * Client ) NotifyWithImageURL (message , imageThumbnail , imageFullsize string ) error {
44+ func (c * Client ) NotifyWithImageURL (token , message , imageThumbnail , imageFullsize string ) error {
6345 body , contentType , err := c .requestBody (message , imageThumbnail , imageFullsize )
6446 if err != nil {
6547 return err
6648 }
67- return c .notify (message , body , contentType )
49+ return c .notify (token , message , body , contentType )
6850}
6951
70- func (c * Client ) notify (message string , body io.Reader , contentType string ) error {
52+ func (c * Client ) notify (token , message string , body io.Reader , contentType string ) error {
7153 req , err := http .NewRequest ("POST" , "https://notify-api.line.me/api/notify" , body )
7254 if err != nil {
7355 return err
7456 }
7557 req .Header .Set ("Content-Type" , contentType )
76- req .Header .Set ("Authorization" , fmt .Sprintf ("Bearer %s" , c . token ))
58+ req .Header .Set ("Authorization" , fmt .Sprintf ("Bearer %s" , token ))
7759
7860 resp , err := c .HTTPClient .Do (req )
7961 if err != nil {
0 commit comments