Skip to content

Commit

Permalink
Merge pull request #18 from thijssimonis/feat/channel-resource
Browse files Browse the repository at this point in the history
 feat: channel resource
  • Loading branch information
0xfrej authored Jul 9, 2024
2 parents f4a2d0d + 1488805 commit 2010332
Show file tree
Hide file tree
Showing 3 changed files with 418 additions and 0 deletions.
61 changes: 61 additions & 0 deletions internal/akeneox/channel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package akeneox

import (
"fmt"

goakeneo "github.com/ezifyio/go-akeneo"
)

const (
channelPath = "/api/rest/v1/channels"
channelSinglePath = "/api/rest/v1/channels/%s"
)

type ChannelService struct {
goakeneo.ChannelService
client *goakeneo.Client
}

func NewChannelClient(client *goakeneo.Client) *ChannelService {
return &ChannelService{
ChannelService: client.Channel,
client: client,
}
}

func (a *ChannelService) CreateChannel(channel goakeneo.Channel) error {
return a.client.POST(
channelPath,
nil,
channel,
nil,
)
}

func (a *ChannelService) UpdateChannel(channel goakeneo.Channel) (*goakeneo.Channel, error) {
response := new(goakeneo.Channel)
err := a.client.PATCH(
fmt.Sprintf(channelSinglePath, channel.Code),
nil,
channel,
response,
)
if err != nil {
return nil, err
}
return response, nil
}

func (a *ChannelService) GetChannel(code string) (*goakeneo.Channel, error) {
response := new(goakeneo.Channel)
err := a.client.GET(
fmt.Sprintf(channelSinglePath, code),
nil,
nil,
response,
)
if err != nil {
return nil, err
}
return response, nil
}
Loading

0 comments on commit 2010332

Please sign in to comment.