siri/siri/notify_estimated_timetable_response.go

Summary

Maintainability
B
5 hrs
Test Coverage
package siri

import (
    "bytes"
    "fmt"
    "time"

    "bitbucket.org/enroute-mobi/ara/logger"
)

type SIRINotifyEstimatedTimetable struct {
    Address                   string
    RequestMessageRef         string
    ProducerRef               string
    ResponseMessageIdentifier string
    SubscriberRef             string
    SubscriptionIdentifier    string

    ResponseTimestamp time.Time
    Status            bool
    ErrorType         string
    ErrorNumber       int
    ErrorText         string

    EstimatedJourneyVersionFrames []*SIRIEstimatedJourneyVersionFrame
}

func (notify *SIRINotifyEstimatedTimetable) ErrorString() string {
    return fmt.Sprintf("%v: %v", notify.errorType(), notify.ErrorText)
}

func (notify *SIRINotifyEstimatedTimetable) errorType() string {
    if notify.ErrorType == "OtherError" {
        return fmt.Sprintf("%v %v", notify.ErrorType, notify.ErrorNumber)
    }
    return notify.ErrorType
}

func (notify *SIRINotifyEstimatedTimetable) BuildXML(envelopeType ...string) (string, error) {
    var buffer bytes.Buffer
    var envType string
    var templateName string

    if len(envelopeType) != 0 && envelopeType[0] != "soap" && envelopeType[0] != "" {
        envType = "_" + envelopeType[0]
    }

    templateName = fmt.Sprintf("estimated_timetable_notify%s.template", envType)

    if err := templates.ExecuteTemplate(&buffer, templateName, notify); err != nil {
        logger.Log.Debugf("Error while executing template: %v", err)
        return "", err
    }
    return buffer.String(), nil
}