github.com/line/line-bot-sdk-go/v7@v7.21.0/linebot/imagemap.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  	"encoding/json"
    19  )
    20  
    21  // ImagemapActionType type
    22  type ImagemapActionType string
    23  
    24  // ImagemapActionType constants
    25  const (
    26  	ImagemapActionTypeURI     ImagemapActionType = "uri"
    27  	ImagemapActionTypeMessage ImagemapActionType = "message"
    28  )
    29  
    30  // ImagemapBaseSize type
    31  type ImagemapBaseSize struct {
    32  	Width  int `json:"width"`
    33  	Height int `json:"height"`
    34  }
    35  
    36  // ImagemapArea type
    37  type ImagemapArea struct {
    38  	X      int `json:"x"`
    39  	Y      int `json:"y"`
    40  	Width  int `json:"width"`
    41  	Height int `json:"height"`
    42  }
    43  
    44  // ImagemapVideo type
    45  type ImagemapVideo struct {
    46  	OriginalContentURL string                     `json:"originalContentUrl"`
    47  	PreviewImageURL    string                     `json:"previewImageUrl"`
    48  	Area               ImagemapArea               `json:"area"`
    49  	ExternalLink       *ImagemapVideoExternalLink `json:"externalLink,omitempty"`
    50  }
    51  
    52  // ImagemapVideoExternalLink type
    53  type ImagemapVideoExternalLink struct {
    54  	LinkURI string `json:"linkUri"`
    55  	Label   string `json:"label"`
    56  }
    57  
    58  // ImagemapAction type
    59  type ImagemapAction interface {
    60  	json.Marshaler
    61  	ImagemapAction()
    62  }
    63  
    64  // URIImagemapAction type
    65  type URIImagemapAction struct {
    66  	Label   string
    67  	LinkURL string
    68  	Area    ImagemapArea
    69  }
    70  
    71  // MarshalJSON method of URIImagemapAction
    72  func (a *URIImagemapAction) MarshalJSON() ([]byte, error) {
    73  	return json.Marshal(&struct {
    74  		Type    ImagemapActionType `json:"type"`
    75  		Label   string             `json:"label,omitempty"`
    76  		LinkURL string             `json:"linkUri"`
    77  		Area    ImagemapArea       `json:"area"`
    78  	}{
    79  		Type:    ImagemapActionTypeURI,
    80  		Label:   a.Label,
    81  		LinkURL: a.LinkURL,
    82  		Area:    a.Area,
    83  	})
    84  }
    85  
    86  // MessageImagemapAction type
    87  type MessageImagemapAction struct {
    88  	Label string
    89  	Text  string
    90  	Area  ImagemapArea
    91  }
    92  
    93  // MarshalJSON method of MessageImagemapAction
    94  func (a *MessageImagemapAction) MarshalJSON() ([]byte, error) {
    95  	return json.Marshal(&struct {
    96  		Type  ImagemapActionType `json:"type"`
    97  		Label string             `json:"label,omitempty"`
    98  		Text  string             `json:"text"`
    99  		Area  ImagemapArea       `json:"area"`
   100  	}{
   101  		Type:  ImagemapActionTypeMessage,
   102  		Label: a.Label,
   103  		Text:  a.Text,
   104  		Area:  a.Area,
   105  	})
   106  }
   107  
   108  // ImagemapAction implements ImagemapAction interface
   109  func (a *URIImagemapAction) ImagemapAction() {}
   110  
   111  // ImagemapAction implements ImagemapAction interface
   112  func (a *MessageImagemapAction) ImagemapAction() {}
   113  
   114  // NewURIImagemapAction function
   115  func NewURIImagemapAction(label, linkURL string, area ImagemapArea) *URIImagemapAction {
   116  	return &URIImagemapAction{
   117  		Label:   label,
   118  		LinkURL: linkURL,
   119  		Area:    area,
   120  	}
   121  }
   122  
   123  // NewMessageImagemapAction function
   124  func NewMessageImagemapAction(label, text string, area ImagemapArea) *MessageImagemapAction {
   125  	return &MessageImagemapAction{
   126  		Label: label,
   127  		Text:  text,
   128  		Area:  area,
   129  	}
   130  }