Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/epgstationctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
_ "github.com/miscord-dev/epgstationctl/internal/commands/programs"
_ "github.com/miscord-dev/epgstationctl/internal/commands/recordings"
"github.com/miscord-dev/epgstationctl/internal/commands/root"
_ "github.com/miscord-dev/epgstationctl/internal/commands/rules"
)

func main() {
Expand Down
Binary file added epgstationctl
Binary file not shown.
154 changes: 154 additions & 0 deletions internal/client/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ import (
"github.com/miscord-dev/epgstationctl/internal/epgstation"
)

// RuleWithID represents a complete rule with ID information
// This fixes the issue where the generated Rule type doesn't include the ID field
type RuleWithID struct {
ID int `json:"id"`
ReservesCnt *int `json:"reservesCnt,omitempty"`
epgstation.AddRuleOption
}

// RulesWithID represents the corrected rules response
type RulesWithID struct {
Rules []RuleWithID `json:"rules"`
Total int `json:"total"`
}

type EPGStationClient struct {
client *epgstation.Client
config *config.Config
Expand Down Expand Up @@ -143,3 +157,143 @@ func (c *EPGStationClient) PostSchedulesSearch(ctx interface{}, body epgstation.

return &programs, nil
}

// GetRules retrieves all recording rules
func (c *EPGStationClient) GetRules(params *epgstation.GetRulesParams) (*RulesWithID, error) {
resp, err := c.client.GetRules(context.Background(), params)
if err != nil {
return nil, err
}
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusOK {
return nil, handleErrorResponse(resp)
}

var rules RulesWithID
if err := parseJSONResponse(resp, &rules); err != nil {
return nil, err
}

return &rules, nil
}

// GetRule retrieves a specific recording rule by ID
func (c *EPGStationClient) GetRule(ruleId int) (*RuleWithID, error) {
resp, err := c.client.GetRulesRuleId(context.Background(), ruleId)
if err != nil {
return nil, err
}
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusOK {
return nil, handleErrorResponse(resp)
}

var rule RuleWithID
if err := parseJSONResponse(resp, &rule); err != nil {
return nil, err
}

return &rule, nil
}

// CreateRule creates a new recording rule
func (c *EPGStationClient) CreateRule(ruleOption epgstation.AddRuleOption) (*epgstation.AddedRule, error) {
resp, err := c.client.PostRules(context.Background(), ruleOption)
if err != nil {
return nil, err
}
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusCreated {
return nil, handleErrorResponse(resp)
}

var result epgstation.AddedRule
if err := parseJSONResponse(resp, &result); err != nil {
return nil, err
}

return &result, nil
}

// UpdateRule updates an existing recording rule
func (c *EPGStationClient) UpdateRule(ruleId int, ruleOption epgstation.AddRuleOption) error {
resp, err := c.client.PutRulesRuleId(context.Background(), ruleId, ruleOption)
if err != nil {
return err
}
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusOK {
return handleErrorResponse(resp)
}

return nil
}

// DeleteRule deletes a recording rule
func (c *EPGStationClient) DeleteRule(ruleId int) error {
resp, err := c.client.DeleteRulesRuleId(context.Background(), ruleId)
if err != nil {
return err
}
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusOK {
return handleErrorResponse(resp)
}

return nil
}

// EnableRule enables a recording rule
func (c *EPGStationClient) EnableRule(ruleId int) error {
resp, err := c.client.PutRulesRuleIdEnable(context.Background(), ruleId)
if err != nil {
return err
}
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusOK {
return handleErrorResponse(resp)
}

return nil
}

// DisableRule disables a recording rule
func (c *EPGStationClient) DisableRule(ruleId int) error {
resp, err := c.client.PutRulesRuleIdDisable(context.Background(), ruleId)
if err != nil {
return err
}
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusOK {
return handleErrorResponse(resp)
}

return nil
}

// SearchRulesKeyword searches for keywords that can be used in rules
func (c *EPGStationClient) SearchRulesKeyword(params *epgstation.GetRulesKeywordParams) (*[]string, error) {
resp, err := c.client.GetRulesKeyword(context.Background(), params)
if err != nil {
return nil, err
}
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusOK {
return nil, handleErrorResponse(resp)
}

var keywords []string
if err := parseJSONResponse(resp, &keywords); err != nil {
return nil, err
}

return &keywords, nil
}
Loading
Loading