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

     1  // Copyright 2020 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  // ProgressType type
    24  type ProgressType string
    25  
    26  // ProgressType constants
    27  const (
    28  	ProgressTypeNarrowcast ProgressType = "narrowcast"
    29  )
    30  
    31  // GetProgressNarrowcastMessages method
    32  func (client *Client) GetProgressNarrowcastMessages(requestID string) *GetProgressMessagesCall {
    33  	return &GetProgressMessagesCall{
    34  		c:            client,
    35  		requestID:    requestID,
    36  		progressType: ProgressTypeNarrowcast,
    37  	}
    38  }
    39  
    40  // GetProgressMessagesCall type
    41  type GetProgressMessagesCall struct {
    42  	c   *Client
    43  	ctx context.Context
    44  
    45  	requestID    string
    46  	progressType ProgressType
    47  }
    48  
    49  // WithContext method
    50  func (call *GetProgressMessagesCall) WithContext(ctx context.Context) *GetProgressMessagesCall {
    51  	call.ctx = ctx
    52  	return call
    53  }
    54  
    55  // Do method
    56  func (call *GetProgressMessagesCall) Do() (*MessagesProgressResponse, error) {
    57  	endpoint := fmt.Sprintf(APIEndpointGetMessageProgress, call.progressType)
    58  	var q url.Values
    59  	if call.requestID != "" {
    60  		q = url.Values{"requestId": []string{call.requestID}}
    61  	}
    62  	res, err := call.c.get(call.ctx, call.c.endpointBase, endpoint, q)
    63  	if err != nil {
    64  		return nil, err
    65  	}
    66  	defer closeResponse(res)
    67  	return decodeToMessagesProgressResponse(res)
    68  }