github.com/line/line-bot-sdk-go/v7@v7.21.0/linebot/validate_message.go (about)

     1  // Copyright 2022 LINE Corporation
     2  //
     3  // LINE Corporation licenses this file to you under the Apache License,
     4  // version 2.0 (the "License"); you may not use this file except in compliance
     5  // with the License. You may obtain a copy of the License at:
     6  //
     7  //   http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    11  // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    12  // License for the specific language governing permissions and limitations
    13  // under the License.
    14  
    15  package linebot
    16  
    17  import (
    18  	"bytes"
    19  	"context"
    20  	"encoding/json"
    21  	"io"
    22  )
    23  
    24  // ValidatePushMessage method
    25  func (client *Client) ValidatePushMessage(messages ...SendingMessage) *ValidatePushMessageCall {
    26  	return &ValidatePushMessageCall{
    27  		c:        client,
    28  		messages: messages,
    29  	}
    30  }
    31  
    32  // ValidatePushMessageCall type
    33  type ValidatePushMessageCall struct {
    34  	c   *Client
    35  	ctx context.Context
    36  
    37  	messages []SendingMessage
    38  }
    39  
    40  // WithContext method
    41  func (call *ValidatePushMessageCall) WithContext(ctx context.Context) *ValidatePushMessageCall {
    42  	call.ctx = ctx
    43  	return call
    44  }
    45  
    46  func (call *ValidatePushMessageCall) encodeJSON(w io.Writer) error {
    47  	enc := json.NewEncoder(w)
    48  	return enc.Encode(&struct {
    49  		Messages []SendingMessage `json:"messages"`
    50  	}{
    51  		Messages: call.messages,
    52  	})
    53  }
    54  
    55  // Do method
    56  func (call *ValidatePushMessageCall) Do() (*BasicResponse, error) {
    57  	var buf bytes.Buffer
    58  	if err := call.encodeJSON(&buf); err != nil {
    59  		return nil, err
    60  	}
    61  	res, err := call.c.post(call.ctx, APIEndpointValidatePushMessage, &buf)
    62  	if err != nil {
    63  		return nil, err
    64  	}
    65  	defer closeResponse(res)
    66  	return decodeToBasicResponse(res)
    67  }
    68  
    69  // ValidateReplyMessage method
    70  func (client *Client) ValidateReplyMessage(messages ...SendingMessage) *ValidateReplyMessageCall {
    71  	return &ValidateReplyMessageCall{
    72  		c:        client,
    73  		messages: messages,
    74  	}
    75  }
    76  
    77  // ValidateReplyMessageCall type
    78  type ValidateReplyMessageCall struct {
    79  	c   *Client
    80  	ctx context.Context
    81  
    82  	messages []SendingMessage
    83  }
    84  
    85  // WithContext method
    86  func (call *ValidateReplyMessageCall) WithContext(ctx context.Context) *ValidateReplyMessageCall {
    87  	call.ctx = ctx
    88  	return call
    89  }
    90  
    91  func (call *ValidateReplyMessageCall) encodeJSON(w io.Writer) error {
    92  	enc := json.NewEncoder(w)
    93  	return enc.Encode(&struct {
    94  		Messages []SendingMessage `json:"messages"`
    95  	}{
    96  		Messages: call.messages,
    97  	})
    98  }
    99  
   100  // Do method
   101  func (call *ValidateReplyMessageCall) Do() (*BasicResponse, error) {
   102  	var buf bytes.Buffer
   103  	if err := call.encodeJSON(&buf); err != nil {
   104  		return nil, err
   105  	}
   106  	res, err := call.c.post(call.ctx, APIEndpointValidateReplyMessage, &buf)
   107  	if err != nil {
   108  		return nil, err
   109  	}
   110  	defer closeResponse(res)
   111  	return decodeToBasicResponse(res)
   112  }
   113  
   114  // ValidateMulticastMessage method
   115  func (client *Client) ValidateMulticastMessage(messages ...SendingMessage) *ValidateMulticastMessageCall {
   116  	return &ValidateMulticastMessageCall{
   117  		c:        client,
   118  		messages: messages,
   119  	}
   120  }
   121  
   122  // ValidateMulticastMessageCall type
   123  type ValidateMulticastMessageCall struct {
   124  	c   *Client
   125  	ctx context.Context
   126  
   127  	messages []SendingMessage
   128  }
   129  
   130  // WithContext method
   131  func (call *ValidateMulticastMessageCall) WithContext(ctx context.Context) *ValidateMulticastMessageCall {
   132  	call.ctx = ctx
   133  	return call
   134  }
   135  
   136  func (call *ValidateMulticastMessageCall) encodeJSON(w io.Writer) error {
   137  	enc := json.NewEncoder(w)
   138  	return enc.Encode(&struct {
   139  		Messages []SendingMessage `json:"messages"`
   140  	}{
   141  		Messages: call.messages,
   142  	})
   143  }
   144  
   145  // Do method
   146  func (call *ValidateMulticastMessageCall) Do() (*BasicResponse, error) {
   147  	var buf bytes.Buffer
   148  	if err := call.encodeJSON(&buf); err != nil {
   149  		return nil, err
   150  	}
   151  	res, err := call.c.post(call.ctx, APIEndpointValidateMulticastMessage, &buf)
   152  	if err != nil {
   153  		return nil, err
   154  	}
   155  	defer closeResponse(res)
   156  	return decodeToBasicResponse(res)
   157  }
   158  
   159  // ValidateBroadcastMessage method
   160  func (client *Client) ValidateBroadcastMessage(messages ...SendingMessage) *ValidateBroadcastMessageCall {
   161  	return &ValidateBroadcastMessageCall{
   162  		c:        client,
   163  		messages: messages,
   164  	}
   165  }
   166  
   167  // ValidateBroadcastMessageCall type
   168  type ValidateBroadcastMessageCall struct {
   169  	c   *Client
   170  	ctx context.Context
   171  
   172  	messages []SendingMessage
   173  }
   174  
   175  // WithContext method
   176  func (call *ValidateBroadcastMessageCall) WithContext(ctx context.Context) *ValidateBroadcastMessageCall {
   177  	call.ctx = ctx
   178  	return call
   179  }
   180  
   181  func (call *ValidateBroadcastMessageCall) encodeJSON(w io.Writer) error {
   182  	enc := json.NewEncoder(w)
   183  	return enc.Encode(&struct {
   184  		Messages []SendingMessage `json:"messages"`
   185  	}{
   186  		Messages: call.messages,
   187  	})
   188  }
   189  
   190  // Do method
   191  func (call *ValidateBroadcastMessageCall) Do() (*BasicResponse, error) {
   192  	var buf bytes.Buffer
   193  	if err := call.encodeJSON(&buf); err != nil {
   194  		return nil, err
   195  	}
   196  	res, err := call.c.post(call.ctx, APIEndpointValidateBroadcastMessage, &buf)
   197  	if err != nil {
   198  		return nil, err
   199  	}
   200  	defer closeResponse(res)
   201  	return decodeToBasicResponse(res)
   202  }
   203  
   204  // ValidateNarrowcastMessage method
   205  func (client *Client) ValidateNarrowcastMessage(messages ...SendingMessage) *ValidateNarrowcastMessageCall {
   206  	return &ValidateNarrowcastMessageCall{
   207  		c:        client,
   208  		messages: messages,
   209  	}
   210  }
   211  
   212  // ValidateNarrowcastMessageCall type
   213  type ValidateNarrowcastMessageCall struct {
   214  	c   *Client
   215  	ctx context.Context
   216  
   217  	messages []SendingMessage
   218  }
   219  
   220  // WithContext method
   221  func (call *ValidateNarrowcastMessageCall) WithContext(ctx context.Context) *ValidateNarrowcastMessageCall {
   222  	call.ctx = ctx
   223  	return call
   224  }
   225  
   226  func (call *ValidateNarrowcastMessageCall) encodeJSON(w io.Writer) error {
   227  	enc := json.NewEncoder(w)
   228  	return enc.Encode(&struct {
   229  		Messages []SendingMessage `json:"messages"`
   230  	}{
   231  		Messages: call.messages,
   232  	})
   233  }
   234  
   235  // Do method
   236  func (call *ValidateNarrowcastMessageCall) Do() (*BasicResponse, error) {
   237  	var buf bytes.Buffer
   238  	if err := call.encodeJSON(&buf); err != nil {
   239  		return nil, err
   240  	}
   241  	res, err := call.c.post(call.ctx, APIEndpointValidateNarrowcastMessage, &buf)
   242  	if err != nil {
   243  		return nil, err
   244  	}
   245  	defer closeResponse(res)
   246  	return decodeToBasicResponse(res)
   247  }