Skip to content

Commit

Permalink
Merge pull request #95 from sugyan/update-liff-api
Browse files Browse the repository at this point in the history
Update around LIFF API
  • Loading branch information
sugyan authored Jul 24, 2018
2 parents 94192b9 + 47c0dbe commit 0d01ff1
Show file tree
Hide file tree
Showing 5 changed files with 326 additions and 30 deletions.
8 changes: 4 additions & 4 deletions linebot/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ const (
APIEndpointDownloadRichMenuImage = "/v2/bot/richmenu/%s/content" // Download: GET / Upload: POST
APIEndpointUploadRichMenuImage = "/v2/bot/richmenu/%s/content" // Download: GET / Upload: POST

APIEndpointGetLIFFAPP = "/liff/v1/apps"
APIEndpointAddLIFFAPP = "/liff/v1/apps"
APIEndpointUpdateLIFFAPP = "/liff/v1/apps/%s/view"
APIEndpointDeleteLIFFAPP = "/liff/v1/apps/%s"
APIEndpointGetAllLIFFApps = "/liff/v1/apps"
APIEndpointAddLIFFApp = "/liff/v1/apps"
APIEndpointUpdateLIFFApp = "/liff/v1/apps/%s/view"
APIEndpointDeleteLIFFApp = "/liff/v1/apps/%s"

APIEndpointLinkToken = "/v2/bot/user/%s/linkToken"
)
Expand Down
49 changes: 29 additions & 20 deletions linebot/liff.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2018 LINE Corporation
//
// LINE Corporation licenses this file to you under the Apache License,
// version 2.0 (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.

package linebot

import (
Expand All @@ -14,17 +28,12 @@ type LIFFViewType string
// LIFFViewType constants
const (
LIFFViewTypeCompact LIFFViewType = "compact"
LIFFViewTypeTail LIFFViewType = "tail"
LIFFViewTypeTall LIFFViewType = "tall"
LIFFViewTypeFull LIFFViewType = "full"
)

// LIFFIDResponse type
type LIFFIDResponse struct {
LIFFID string `json:"liffId"`
}

// LIFFAPP type
type LIFFAPP struct {
// LIFFApp type
type LIFFApp struct {
LIFFID string `json:"liffId"`
View View `json:"view"`
}
Expand Down Expand Up @@ -60,8 +69,8 @@ func (call *GetLIFFAllCall) WithContext(ctx context.Context) *GetLIFFAllCall {
}

// Do method
func (call *GetLIFFAllCall) Do() (*LIFFResponse, error) {
res, err := call.c.get(call.ctx, APIEndpointGetLIFFAPP, nil)
func (call *GetLIFFAllCall) Do() (*LIFFAppsResponse, error) {
res, err := call.c.get(call.ctx, APIEndpointGetAllLIFFApps, nil)
if res != nil && res.Body != nil {
defer res.Body.Close()
}
Expand All @@ -75,7 +84,7 @@ func (call *GetLIFFAllCall) Do() (*LIFFResponse, error) {
func (client *Client) AddLIFF(view View) *AddLIFFCall {
return &AddLIFFCall{
c: client,
View: view,
view: view,
}
}

Expand All @@ -84,7 +93,7 @@ type AddLIFFCall struct {
c *Client
ctx context.Context

View View
view View
}

// WithContext method
Expand All @@ -98,7 +107,7 @@ func (call *AddLIFFCall) encodeJSON(w io.Writer) error {
return enc.Encode(&struct {
View View `json:"view"`
}{
View: call.View,
View: call.view,
})
}

Expand All @@ -108,7 +117,7 @@ func (call *AddLIFFCall) Do() (*LIFFIDResponse, error) {
if err := call.encodeJSON(&buf); err != nil {
return nil, err
}
res, err := call.c.post(call.ctx, APIEndpointAddLIFFAPP, &buf)
res, err := call.c.post(call.ctx, APIEndpointAddLIFFApp, &buf)
if res != nil && res.Body != nil {
defer res.Body.Close()
}
Expand All @@ -122,7 +131,7 @@ func (call *AddLIFFCall) Do() (*LIFFIDResponse, error) {
func (client *Client) UpdateLIFF(liffID string, view View) *UpdateLIFFCall {
return &UpdateLIFFCall{
c: client,
LIFFID: liffID,
liffID: liffID,
view: view,
}
}
Expand All @@ -132,7 +141,7 @@ type UpdateLIFFCall struct {
c *Client
ctx context.Context

LIFFID string
liffID string
view View
}

Expand Down Expand Up @@ -160,7 +169,7 @@ func (call *UpdateLIFFCall) Do() (*BasicResponse, error) {
return nil, err
}

endpoint := fmt.Sprintf(APIEndpointUpdateLIFFAPP, call.LIFFID)
endpoint := fmt.Sprintf(APIEndpointUpdateLIFFApp, call.liffID)
res, err := call.c.put(call.ctx, endpoint, &buf)
if res != nil && res.Body != nil {
defer res.Body.Close()
Expand All @@ -175,7 +184,7 @@ func (call *UpdateLIFFCall) Do() (*BasicResponse, error) {
func (client *Client) DeleteLIFF(liffID string) *DeleteLIFFCall {
return &DeleteLIFFCall{
c: client,
LIFFID: liffID,
liffID: liffID,
}
}

Expand All @@ -184,7 +193,7 @@ type DeleteLIFFCall struct {
c *Client
ctx context.Context

LIFFID string
liffID string
}

// WithContext method
Expand All @@ -195,7 +204,7 @@ func (call *DeleteLIFFCall) WithContext(ctx context.Context) *DeleteLIFFCall {

// Do method
func (call *DeleteLIFFCall) Do() (*BasicResponse, error) {
endpoint := fmt.Sprintf(APIEndpointDeleteLIFFAPP, call.LIFFID)
endpoint := fmt.Sprintf(APIEndpointDeleteLIFFApp, call.liffID)
res, err := call.c.delete(call.ctx, endpoint)
if res != nil && res.Body != nil {
defer res.Body.Close()
Expand Down
Loading

0 comments on commit 0d01ff1

Please sign in to comment.