generated from hashicorp/terraform-provider-scaffolding-framework
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from thijssimonis/feat/channel-resource
feat: channel resource
- Loading branch information
Showing
3 changed files
with
418 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.