Skip to content

Commit

Permalink
Merge pull request #35 from LayerXcom/feature/segment-tags
Browse files Browse the repository at this point in the history
feat(segment-tags): implements segment_tags
  • Loading branch information
yyoshiki41 authored Apr 13, 2021
2 parents f8a9eb7 + fab4fb1 commit 3ac593f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 6 deletions.
3 changes: 1 addition & 2 deletions sections.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ func (c *Client) CreateSection(

func (c *Client) UpdateSection(
ctx context.Context, oauth2Token *oauth2.Token,
params SectionParams,
sectionID uint32,
sectionID uint32, params SectionParams,
) (*Section, *oauth2.Token, error) {
var result SectionResponse
oauth2Token, err := c.call(ctx, path.Join(APIPathSections, fmt.Sprint(sectionID)), http.MethodPut, oauth2Token, nil, params, &result)
Expand Down
65 changes: 63 additions & 2 deletions segment_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ type SegmentTags struct {
SegmentTags []SegmentTag `json:"segment_tags"`
}

type SegmentTagResponse struct {
SegmentTag SegmentTag `json:"segment_tag"`
}

type SegmentTag struct {
// セグメントタグID
ID int32 `json:"id"`
Expand All @@ -34,14 +38,28 @@ type SegmentTag struct {
Shortcut2 *string `json:"shortcut2"`
}

type SegmentTagParams struct {
// 事業所ID
CompanyID int32 `json:"company_id"`
// セグメントタグ名 (30文字以内)
Name string `json:"name"`
// 備考 (30文字以内)
Description *string `json:"description,omitempty"`
// ショートカット1 (20文字以内)
Shortcut1 *string `json:"shortcut1,omitempty"`
// ショートカット2 (20文字以内)
Shortcut2 *string `json:"shortcut2,omitempty"`
}

type GetSegmentTagsOpts struct {
Offset uint32 `url:"offset,omitempty"`
Limit uint32 `url:"limit,omitempty"`
}

func (c *Client) GetSegmentTags(
ctx context.Context, oauth2Token *oauth2.Token,
companyID uint32, tagID uint32, opts GetSegmentTagsOpts,
companyID uint32, segmentID uint32,
opts GetSegmentTagsOpts,
) (*SegmentTags, *oauth2.Token, error) {
var result SegmentTags

Expand All @@ -50,10 +68,53 @@ func (c *Client) GetSegmentTags(
return nil, oauth2Token, err
}
SetCompanyID(&v, companyID)
oauth2Token, err = c.call(ctx, path.Join(APIPathSegments, fmt.Sprint(tagID), "tags"), http.MethodGet, oauth2Token, v, nil, &result)
oauth2Token, err = c.call(ctx, path.Join(APIPathSegments, fmt.Sprint(segmentID), "tags"), http.MethodGet, oauth2Token, v, nil, &result)
if err != nil {
return nil, oauth2Token, err
}

return &result, oauth2Token, nil
}

func (c *Client) CreateSegmentTag(
ctx context.Context, oauth2Token *oauth2.Token,
segmentID uint32, params SegmentTagParams,
) (*SegmentTag, *oauth2.Token, error) {
var result SegmentTagResponse
oauth2Token, err := c.call(ctx, path.Join(APIPathSegments, fmt.Sprint(segmentID), "tags"), http.MethodPost, oauth2Token, nil, params, &result)
if err != nil {
return nil, oauth2Token, err
}
return &result.SegmentTag, oauth2Token, nil
}

func (c *Client) UpdateSegmentTag(
ctx context.Context, oauth2Token *oauth2.Token,
segmentID uint32, id uint32,
params SegmentTagParams,
) (*SegmentTag, *oauth2.Token, error) {
var result SegmentTagResponse
oauth2Token, err := c.call(ctx, path.Join(APIPathSegments, fmt.Sprint(segmentID), "tags", fmt.Sprint(id)), http.MethodPut, oauth2Token, nil, params, &result)
if err != nil {
return nil, oauth2Token, err
}
return &result.SegmentTag, oauth2Token, nil
}

func (c *Client) DestroySegmentTag(
ctx context.Context, oauth2Token *oauth2.Token,
companyID uint32,
segmentID uint32, id uint32,
) (*oauth2.Token, error) {
v, err := query.Values(nil)
if err != nil {
return oauth2Token, err
}
SetCompanyID(&v, companyID)
oauth2Token, err = c.call(ctx, path.Join(APIPathSegments, fmt.Sprint(segmentID), "tags", fmt.Sprint(id)), http.MethodDelete, oauth2Token, v, nil, nil)
if err != nil {
return oauth2Token, err
}

return oauth2Token, nil
}
3 changes: 1 addition & 2 deletions tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ func (c *Client) CreateTag(

func (c *Client) UpdateTag(
ctx context.Context, oauth2Token *oauth2.Token,
params TagParams,
tagID uint32,
tagID uint32, params TagParams,
) (*Tag, *oauth2.Token, error) {
var result TagResponse
oauth2Token, err := c.call(ctx, path.Join(APIPathTags, fmt.Sprint(tagID)), http.MethodPut, oauth2Token, nil, params, &result)
Expand Down

0 comments on commit 3ac593f

Please sign in to comment.