Skip to content

Commit

Permalink
Merge pull request #129 from sugyan/issue-124
Browse files Browse the repository at this point in the history
Update FlexValue type
  • Loading branch information
sugyan authored Feb 20, 2019
2 parents bc678e0 + 23c2c37 commit 50b8ef0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ if err != nil {

## Requirements

This library requires Go 1.7 or later.
This library requires Go 1.10 or later.

## LICENSE

Expand Down
23 changes: 14 additions & 9 deletions linebot/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ package linebot
import "encoding/json"

// FlexContainerType type
type FlexContainerType string
type FlexContainerType = string // alias type

// IntPtr is a helper function for using *int values
func IntPtr(v int) *int {
return &v
}

// FlexContainerType constants
const (
Expand Down Expand Up @@ -323,7 +328,7 @@ type BoxComponent struct {
Type FlexComponentType
Layout FlexBoxLayoutType
Contents []FlexComponent
Flex int
Flex *int
Spacing FlexComponentSpacingType
Margin FlexComponentMarginType
}
Expand All @@ -334,7 +339,7 @@ func (c *BoxComponent) MarshalJSON() ([]byte, error) {
Type FlexComponentType `json:"type"`
Layout FlexBoxLayoutType `json:"layout"`
Contents []FlexComponent `json:"contents"`
Flex int `json:"flex,omitempty"`
Flex *int `json:"flex,omitempty"`
Spacing FlexComponentSpacingType `json:"spacing,omitempty"`
Margin FlexComponentMarginType `json:"margin,omitempty"`
}{
Expand All @@ -351,7 +356,7 @@ func (c *BoxComponent) MarshalJSON() ([]byte, error) {
type ButtonComponent struct {
Type FlexComponentType
Action TemplateAction
Flex int
Flex *int
Margin FlexComponentMarginType
Height FlexButtonHeightType
Style FlexButtonStyleType
Expand All @@ -364,7 +369,7 @@ func (c *ButtonComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
Action TemplateAction `json:"action"`
Flex int `json:"flex,omitempty"`
Flex *int `json:"flex,omitempty"`
Margin FlexComponentMarginType `json:"margin,omitempty"`
Height FlexButtonHeightType `json:"height,omitempty"`
Style FlexButtonStyleType `json:"style,omitempty"`
Expand Down Expand Up @@ -426,7 +431,7 @@ func (c *IconComponent) MarshalJSON() ([]byte, error) {
type ImageComponent struct {
Type FlexComponentType
URL string
Flex int
Flex *int
Margin FlexComponentMarginType
Align FlexComponentAlignType
Gravity FlexComponentGravityType
Expand All @@ -442,7 +447,7 @@ func (c *ImageComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
URL string `json:"url"`
Flex int `json:"flex,omitempty"`
Flex *int `json:"flex,omitempty"`
Margin FlexComponentMarginType `json:"margin,omitempty"`
Align FlexComponentAlignType `json:"align,omitempty"`
Gravity FlexComponentGravityType `json:"gravity,omitempty"`
Expand Down Expand Up @@ -507,7 +512,7 @@ func (c *SpacerComponent) MarshalJSON() ([]byte, error) {
type TextComponent struct {
Type FlexComponentType
Text string
Flex int
Flex *int
Margin FlexComponentMarginType
Size FlexTextSizeType
Align FlexComponentAlignType
Expand All @@ -523,7 +528,7 @@ func (c *TextComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
Text string `json:"text"`
Flex int `json:"flex,omitempty"`
Flex *int `json:"flex,omitempty"`
Margin FlexComponentMarginType `json:"margin,omitempty"`
Size FlexTextSizeType `json:"size,omitempty"`
Align FlexComponentAlignType `json:"align,omitempty"`
Expand Down
11 changes: 6 additions & 5 deletions linebot/flex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func TestUnmarshalFlexMessageJSON(t *testing.T) {
&TextComponent{
Type: FlexComponentTypeText,
Text: "4.0",
Flex: 0,
Flex: IntPtr(0),
Margin: FlexComponentMarginTypeMd,
Size: FlexTextSizeTypeSm,
Color: "#999999",
Expand All @@ -353,14 +353,14 @@ func TestUnmarshalFlexMessageJSON(t *testing.T) {
&TextComponent{
Type: FlexComponentTypeText,
Text: "Place",
Flex: 1,
Flex: IntPtr(1),
Size: FlexTextSizeTypeSm,
Color: "#aaaaaa",
},
&TextComponent{
Type: FlexComponentTypeText,
Text: "Miraina Tower, 4-1-6 Shinjuku, Tokyo",
Flex: 5,
Flex: IntPtr(5),
Size: FlexTextSizeTypeSm,
Wrap: true,
Color: "#666666",
Expand All @@ -375,14 +375,14 @@ func TestUnmarshalFlexMessageJSON(t *testing.T) {
&TextComponent{
Type: FlexComponentTypeText,
Text: "Time",
Flex: 1,
Flex: IntPtr(1),
Size: FlexTextSizeTypeSm,
Color: "#aaaaaa",
},
&TextComponent{
Type: FlexComponentTypeText,
Text: "10:00 - 23:00",
Flex: 5,
Flex: IntPtr(5),
Size: FlexTextSizeTypeSm,
Wrap: true,
Color: "#666666",
Expand Down Expand Up @@ -431,6 +431,7 @@ func TestUnmarshalFlexMessageJSON(t *testing.T) {
},
},
Spacing: FlexComponentSpacingTypeSm,
Flex: IntPtr(0),
},
},
},
Expand Down
3 changes: 2 additions & 1 deletion linebot/send_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ func TestPushMessages(t *testing.T) {
&TextComponent{
Type: FlexComponentTypeText,
Text: "world",
Flex: IntPtr(0),
},
&SpacerComponent{
Type: FlexComponentTypeSpacer,
Expand All @@ -396,7 +397,7 @@ func TestPushMessages(t *testing.T) {
ResponseCode: 200,
Response: []byte(`{}`),
Want: want{
RequestBody: []byte(`{"to":"U0cc15697597f61dd8b01cea8b027050e","messages":[{"type":"flex","altText":"this is a flex message","contents":{"type":"bubble","body":{"type":"box","layout":"vertical","contents":[{"type":"text","text":"hello"},{"type":"text","text":"world"},{"type":"spacer"}]}}}]}` + "\n"),
RequestBody: []byte(`{"to":"U0cc15697597f61dd8b01cea8b027050e","messages":[{"type":"flex","altText":"this is a flex message","contents":{"type":"bubble","body":{"type":"box","layout":"vertical","contents":[{"type":"text","text":"hello"},{"type":"text","text":"world","flex":0},{"type":"spacer"}]}}}]}` + "\n"),
Response: &BasicResponse{},
},
},
Expand Down

0 comments on commit 50b8ef0

Please sign in to comment.