github.com/line/line-bot-sdk-go/v7@v7.21.0/linebot/get_count.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  )
    21  
    22  // GetGroupMemberCount method
    23  func (client *Client) GetGroupMemberCount(groupID string) *GetGroupMemberCountCall {
    24  	return &GetGroupMemberCountCall{
    25  		c:       client,
    26  		groupID: groupID,
    27  	}
    28  }
    29  
    30  // GetGroupMemberCountCall type
    31  type GetGroupMemberCountCall struct {
    32  	c   *Client
    33  	ctx context.Context
    34  
    35  	groupID string
    36  }
    37  
    38  // WithContext method
    39  func (call *GetGroupMemberCountCall) WithContext(ctx context.Context) *GetGroupMemberCountCall {
    40  	call.ctx = ctx
    41  	return call
    42  }
    43  
    44  // Do method
    45  func (call *GetGroupMemberCountCall) Do() (*MemberCountResponse, error) {
    46  	endpoint := fmt.Sprintf(APIEndpointGetGroupMemberCount, call.groupID)
    47  	res, err := call.c.get(call.ctx, call.c.endpointBase, endpoint, nil)
    48  	if err != nil {
    49  		return nil, err
    50  	}
    51  	defer closeResponse(res)
    52  	return decodeToMemberCountResponse(res)
    53  }
    54  
    55  // GetRoomMemberCount method
    56  func (client *Client) GetRoomMemberCount(roomID string) *GetRoomMemberCountCall {
    57  	return &GetRoomMemberCountCall{
    58  		c:      client,
    59  		roomID: roomID,
    60  	}
    61  }
    62  
    63  // GetRoomMemberCountCall type
    64  type GetRoomMemberCountCall struct {
    65  	c   *Client
    66  	ctx context.Context
    67  
    68  	roomID string
    69  }
    70  
    71  // WithContext method
    72  func (call *GetRoomMemberCountCall) WithContext(ctx context.Context) *GetRoomMemberCountCall {
    73  	call.ctx = ctx
    74  	return call
    75  }
    76  
    77  // Do method
    78  func (call *GetRoomMemberCountCall) Do() (*MemberCountResponse, error) {
    79  	endpoint := fmt.Sprintf(APIEndpointGetRoomMemberCount, call.roomID)
    80  	res, err := call.c.get(call.ctx, call.c.endpointBase, endpoint, nil)
    81  	if err != nil {
    82  		return nil, err
    83  	}
    84  	defer closeResponse(res)
    85  	return decodeToMemberCountResponse(res)
    86  }