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

     1  // Copyright 2016 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  // GetProfile method
    23  func (client *Client) GetProfile(userID string) *GetProfileCall {
    24  	return &GetProfileCall{
    25  		c:      client,
    26  		userID: userID,
    27  	}
    28  }
    29  
    30  // GetProfileCall type
    31  type GetProfileCall struct {
    32  	c   *Client
    33  	ctx context.Context
    34  
    35  	userID string
    36  }
    37  
    38  // WithContext method
    39  func (call *GetProfileCall) WithContext(ctx context.Context) *GetProfileCall {
    40  	call.ctx = ctx
    41  	return call
    42  }
    43  
    44  // Do method
    45  func (call *GetProfileCall) Do() (*UserProfileResponse, error) {
    46  	endpoint := fmt.Sprintf(APIEndpointGetProfile, call.userID)
    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 decodeToUserProfileResponse(res)
    53  }
    54  
    55  // GetGroupMemberProfile method
    56  func (client *Client) GetGroupMemberProfile(groupID, userID string) *GetGroupMemberProfileCall {
    57  	return &GetGroupMemberProfileCall{
    58  		c:       client,
    59  		groupID: groupID,
    60  		userID:  userID,
    61  	}
    62  }
    63  
    64  // GetGroupMemberProfileCall type
    65  type GetGroupMemberProfileCall struct {
    66  	c   *Client
    67  	ctx context.Context
    68  
    69  	groupID string
    70  	userID  string
    71  }
    72  
    73  // WithContext method
    74  func (call *GetGroupMemberProfileCall) WithContext(ctx context.Context) *GetGroupMemberProfileCall {
    75  	call.ctx = ctx
    76  	return call
    77  }
    78  
    79  // Do method
    80  func (call *GetGroupMemberProfileCall) Do() (*UserProfileResponse, error) {
    81  	endpoint := fmt.Sprintf(APIEndpointGetGroupMemberProfile, call.groupID, call.userID)
    82  	res, err := call.c.get(call.ctx, call.c.endpointBase, endpoint, nil)
    83  	if err != nil {
    84  		return nil, err
    85  	}
    86  	defer closeResponse(res)
    87  	return decodeToUserProfileResponse(res)
    88  }
    89  
    90  // GetRoomMemberProfile method
    91  func (client *Client) GetRoomMemberProfile(roomID, userID string) *GetRoomMemberProfileCall {
    92  	return &GetRoomMemberProfileCall{
    93  		c:      client,
    94  		roomID: roomID,
    95  		userID: userID,
    96  	}
    97  }
    98  
    99  // GetRoomMemberProfileCall type
   100  type GetRoomMemberProfileCall struct {
   101  	c   *Client
   102  	ctx context.Context
   103  
   104  	roomID string
   105  	userID string
   106  }
   107  
   108  // WithContext method
   109  func (call *GetRoomMemberProfileCall) WithContext(ctx context.Context) *GetRoomMemberProfileCall {
   110  	call.ctx = ctx
   111  	return call
   112  }
   113  
   114  // Do method
   115  func (call *GetRoomMemberProfileCall) Do() (*UserProfileResponse, error) {
   116  	endpoint := fmt.Sprintf(APIEndpointGetRoomMemberProfile, call.roomID, call.userID)
   117  	res, err := call.c.get(call.ctx, call.c.endpointBase, endpoint, nil)
   118  	if err != nil {
   119  		return nil, err
   120  	}
   121  	defer closeResponse(res)
   122  	return decodeToUserProfileResponse(res)
   123  }