Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sending Transmission content with template_id. #166

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
31 changes: 18 additions & 13 deletions transmissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,26 +126,31 @@ func ParseRecipients(recips interface{}) (ra *[]Recipient, err error) {
func ParseContent(content interface{}) (err error) {
switch rVal := content.(type) {
case map[string]interface{}:
for k, v := range rVal {
switch vVal := v.(type) {
case string:
if strings.EqualFold(k, "template_id") {
return nil
}
default:
return fmt.Errorf("Transmission.Content objects must contain string values, not [%T]", vVal)
var found bool
for key := range rVal {
if strings.ToLower(key) == "template_id" {
found = true
break
}
}
if found {
return nil
}
return fmt.Errorf("Transmission.Content objects must contain a key `template_id`")

case map[string]string:
for k := range rVal {
if strings.EqualFold(k, "template_id") {
return nil
// Have to duplicate logic here, we cannot add it above because it will then conflate rVal as an interface{}
// Exact error message: invalid operation: cannot index rVal (variable of type interface{})
var found bool
for key := range rVal {
if strings.ToLower(key) == "template_id" {
found = true
break
}
}
if found {
return nil
}
return fmt.Errorf("Transmission.Content objects must contain a key `template_id`")

case Content:
te := &Template{Name: "tmp", Content: rVal}
return te.Validate()
Expand Down