Skip to content

Commit

Permalink
More docstrings...
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Mar 13, 2018
1 parent 3ad031f commit 8d6cf92
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/flowserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ type sessionResponse struct {
Log []flows.LogEntry `json:"log"`
}

// MarshalJSON marshals this session reponse into JSON
// MarshalJSON marshals this session response into JSON
func (r *sessionResponse) MarshalJSON() ([]byte, error) {
envelope := sessionResponse{
Session: r.Session,
Expand Down
7 changes: 7 additions & 0 deletions flows/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"github.com/nyaruka/goflow/utils"
)

// ChannelRole is a role that a channel can perform
type ChannelRole string

// different roles that channels can perform
const (
ChannelRoleSend ChannelRole = "send"
ChannelRoleReceive ChannelRole = "receive"
Expand All @@ -25,6 +27,7 @@ type channel struct {
roles []ChannelRole
}

// NewChannel creates a new channel
func NewChannel(uuid ChannelUUID, name string, address string, schemes []string, roles []ChannelRole) Channel {
return &channel{
uuid: uuid,
Expand Down Expand Up @@ -53,6 +56,7 @@ func (c *channel) Roles() []ChannelRole { return c.roles }
// Reference returns a reference to this channel
func (c *channel) Reference() *ChannelReference { return NewChannelReference(c.uuid, c.name) }

// SupportsScheme returns whether this channel supports the given URN scheme
func (c *channel) SupportsScheme(scheme string) bool {
for _, s := range c.schemes {
if s == scheme {
Expand All @@ -62,6 +66,7 @@ func (c *channel) SupportsScheme(scheme string) bool {
return false
}

// HasRole returns whether this channel has the given role
func (c *channel) HasRole(role ChannelRole) bool {
for _, r := range c.roles {
if r == role {
Expand Down Expand Up @@ -103,6 +108,7 @@ type ChannelSet struct {
channelsByUUID map[ChannelUUID]Channel
}

// NewChannelSet creates a new channel set
func NewChannelSet(channels []Channel) *ChannelSet {
s := &ChannelSet{channels: channels, channelsByUUID: make(map[ChannelUUID]Channel, len(channels))}
for _, channel := range s.channels {
Expand All @@ -129,6 +135,7 @@ func (s *ChannelSet) GetForURN(urn *ContactURN) Channel {
return nil
}

// FindByUUID finds the channel with the given UUID
func (s *ChannelSet) FindByUUID(uuid ChannelUUID) Channel {
return s.channelsByUUID[uuid]
}
Expand Down
2 changes: 1 addition & 1 deletion flows/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (f *Field) ParseValue(env utils.Environment, value string) (interface{}, er
return nil, err
}
if locations == nil {
return nil, fmt.Errorf("can't parse field '%s' (type %s) in enviroment which is not location enabled", f.key, f.valueType)
return nil, fmt.Errorf("can't parse field '%s' (type %s) in environment which is not location enabled", f.key, f.valueType)
}
return locations.FindByID(locationID, locationLevel), nil
}
Expand Down
1 change: 1 addition & 0 deletions flows/inputs/envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type baseInputEnvelope struct {
CreatedOn time.Time `json:"created_on" validate:"required"`
}

// ReadInput reads an input from the given typed envelope
func ReadInput(session flows.Session, envelope *utils.TypedEnvelope) (flows.Input, error) {
switch envelope.Type {

Expand Down
18 changes: 14 additions & 4 deletions flows/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,20 @@ func NewMsgOut(urn urns.URN, channel Channel, text string, attachments []Attachm
}
}

func (m *BaseMsg) UUID() MsgUUID { return m.UUID_ }
func (m *BaseMsg) URN() urns.URN { return m.URN_ }
// UUID returns the UUID of this message
func (m *BaseMsg) UUID() MsgUUID { return m.UUID_ }

// URN returns the URN of this message
func (m *BaseMsg) URN() urns.URN { return m.URN_ }

// Channel returns the channel of this message
func (m *BaseMsg) Channel() *ChannelReference { return m.Channel_ }
func (m *BaseMsg) Text() string { return m.Text_ }
func (m *BaseMsg) Attachments() []Attachment { return m.Attachments_ }

// Text returns the text of this message
func (m *BaseMsg) Text() string { return m.Text_ }

// Attachments returns the attachments of this message
func (m *BaseMsg) Attachments() []Attachment { return m.Attachments_ }

// QuickReplies returns the quick replies of this outgoing message
func (m *MsgOut) QuickReplies() []string { return m.QuickReplies_ }
2 changes: 1 addition & 1 deletion flows/runs/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (s *step) MarshalJSON() ([]byte, error) {
if err != nil {
return nil, err
}
se.Events[i] = &utils.TypedEnvelope{event.Type(), eventData}
se.Events[i] = &utils.TypedEnvelope{Type: event.Type(), Data: eventData}
}

return json.Marshal(se)
Expand Down
2 changes: 2 additions & 0 deletions flows/runsummary.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func (r *runSummary) Contact() *Contact { return r.contact }
func (r *runSummary) Status() RunStatus { return r.status }
func (r *runSummary) Results() Results { return r.results }

// NewRunSummaryFromRun creates a new run summary from the given run
func NewRunSummaryFromRun(run FlowRun) RunSummary {
return &runSummary{
uuid: run.UUID(),
Expand All @@ -44,6 +45,7 @@ type runSummaryEnvelope struct {
Results Results `json:"results"`
}

// ReadRunSummary reads a run summary from the given JSON
func ReadRunSummary(session Session, data json.RawMessage) (RunSummary, error) {
var err error
e := runSummaryEnvelope{}
Expand Down
4 changes: 4 additions & 0 deletions flows/urns.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (u *ContactURN) String() string { return string(u.URN) }
// URNList is the list of a contact's URNs
type URNList []*ContactURN

// ReadURNList parses contact URN list from the given list of raw URNs
func ReadURNList(session Session, rawURNs []urns.URN) (URNList, error) {
l := make(URNList, len(rawURNs))

Expand Down Expand Up @@ -98,6 +99,7 @@ func ReadURNList(session Session, rawURNs []urns.URN) (URNList, error) {
return l, nil
}

// RawURNs returns the raw URNs with or without channel information
func (l URNList) RawURNs(includeChannels bool) []urns.URN {
raw := make([]urns.URN, len(l))
for u := range l {
Expand All @@ -112,12 +114,14 @@ func (l URNList) RawURNs(includeChannels bool) []urns.URN {
return raw
}

// Clone returns a clone of this URN list
func (l URNList) Clone() URNList {
urns := make(URNList, len(l))
copy(urns, l)
return urns
}

// WithScheme returns a new URN list containing of only URNs of the given scheme
func (l URNList) WithScheme(scheme string) URNList {
var matching URNList
for _, u := range l {
Expand Down
2 changes: 1 addition & 1 deletion utils/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (r *RequestResponse) UnmarshalJSON(data []byte) error {
return nil
}

// MarshalJSON marshals this request reponse into JSON
// MarshalJSON marshals this request response into JSON
func (r *RequestResponse) MarshalJSON() ([]byte, error) {
var re rrEnvelope

Expand Down
2 changes: 1 addition & 1 deletion utils/locations.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func FindLocations(env Environment, name string, level LocationLevel, parent *Lo
return nil, err
}
if locations == nil {
return nil, fmt.Errorf("can't find locations in enviroment which is not location enabled")
return nil, fmt.Errorf("can't find locations in environment which is not location enabled")
}

return locations.FindByName(name, level, parent), nil
Expand Down

0 comments on commit 8d6cf92

Please sign in to comment.