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

     1  // Copyright 2019 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  	"context"
    19  	"fmt"
    20  	"net/url"
    21  )
    22  
    23  // DeliveryType type
    24  type DeliveryType string
    25  
    26  // DeliveryType constants
    27  const (
    28  	DeliveryTypeMulticast DeliveryType = "multicast"
    29  	DeliveryTypePush      DeliveryType = "push"
    30  	DeliveryTypeReply     DeliveryType = "reply"
    31  	DeliveryTypeBroadcast DeliveryType = "broadcast"
    32  )
    33  
    34  // GetNumberReplyMessages method
    35  func (client *Client) GetNumberReplyMessages(date string) *GetNumberMessagesCall {
    36  	return &GetNumberMessagesCall{
    37  		c:            client,
    38  		date:         date,
    39  		deliveryType: DeliveryTypeReply,
    40  	}
    41  }
    42  
    43  // GetNumberPushMessages method
    44  func (client *Client) GetNumberPushMessages(date string) *GetNumberMessagesCall {
    45  	return &GetNumberMessagesCall{
    46  		c:            client,
    47  		date:         date,
    48  		deliveryType: DeliveryTypePush,
    49  	}
    50  }
    51  
    52  // GetNumberMulticastMessages method
    53  func (client *Client) GetNumberMulticastMessages(date string) *GetNumberMessagesCall {
    54  	return &GetNumberMessagesCall{
    55  		c:            client,
    56  		date:         date,
    57  		deliveryType: DeliveryTypeMulticast,
    58  	}
    59  }
    60  
    61  // GetNumberBroadcastMessages method
    62  func (client *Client) GetNumberBroadcastMessages(date string) *GetNumberMessagesCall {
    63  	return &GetNumberMessagesCall{
    64  		c:            client,
    65  		date:         date,
    66  		deliveryType: DeliveryTypeBroadcast,
    67  	}
    68  }
    69  
    70  // GetNumberMessagesCall type
    71  type GetNumberMessagesCall struct {
    72  	c   *Client
    73  	ctx context.Context
    74  
    75  	date         string
    76  	deliveryType DeliveryType
    77  }
    78  
    79  // WithContext method
    80  func (call *GetNumberMessagesCall) WithContext(ctx context.Context) *GetNumberMessagesCall {
    81  	call.ctx = ctx
    82  	return call
    83  }
    84  
    85  // Do method
    86  func (call *GetNumberMessagesCall) Do() (*MessagesNumberResponse, error) {
    87  	endpoint := fmt.Sprintf(APIEndpointGetMessageDelivery, call.deliveryType)
    88  	var q url.Values
    89  	if call.date != "" {
    90  		q = url.Values{"date": []string{call.date}}
    91  	}
    92  	res, err := call.c.get(call.ctx, call.c.endpointBase, endpoint, q)
    93  	if err != nil {
    94  		return nil, err
    95  	}
    96  	defer closeResponse(res)
    97  	return decodeToMessagesNumberResponse(res)
    98  }