github.com/line/line-bot-sdk-go/v7@v7.21.0/linebot/account_link.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  // IssueLinkToken method
    23  // https://developers.line.me/en/reference/messaging-api/#issue-link-token
    24  func (client *Client) IssueLinkToken(userID string) *IssueLinkTokenCall {
    25  	return &IssueLinkTokenCall{
    26  		c:      client,
    27  		userID: userID,
    28  	}
    29  }
    30  
    31  // IssueLinkTokenCall type
    32  type IssueLinkTokenCall struct {
    33  	c   *Client
    34  	ctx context.Context
    35  
    36  	userID string
    37  }
    38  
    39  // WithContext method
    40  func (call *IssueLinkTokenCall) WithContext(ctx context.Context) *IssueLinkTokenCall {
    41  	call.ctx = ctx
    42  	return call
    43  }
    44  
    45  // Do method
    46  func (call *IssueLinkTokenCall) Do() (*LinkTokenResponse, error) {
    47  	endpoint := fmt.Sprintf(APIEndpointLinkToken, call.userID)
    48  	res, err := call.c.post(call.ctx, endpoint, nil)
    49  	if err != nil {
    50  		return nil, err
    51  	}
    52  	defer closeResponse(res)
    53  	return decodeToLinkTokenResponse(res)
    54  }