Skip to content

Commit

Permalink
🔇 silent changes: rename functions #14
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Jan 13, 2024
1 parent e9b4cfa commit cb52d2f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion pkg/ami/ami_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func Hangup(ctx context.Context, s AMISocket, channel, cause string) (AmiReply,

// Originate originates a call.
// Generates an outgoing call to a Extension/Context/Priority or Application/Data.
func Originate(ctx context.Context, s AMISocket, originate AMIPayloadOriginate) (AmiReply, error) {
func Originate(ctx context.Context, s AMISocket, originate AMIOriginate) (AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionOriginate)
c.SetVCmd(originate)
callback := NewAmiCallbackService(ctx, s, c, []string{}, []string{})
Expand Down
8 changes: 4 additions & 4 deletions pkg/ami/ami_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,11 +706,11 @@ func (c *AMICore) Hangup(ctx context.Context, channel, cause string) (AmiReply,
}

// Originate
func (c *AMICore) Originate(ctx context.Context, originate AMIPayloadOriginate) (AmiReply, error) {
func (c *AMICore) Originate(ctx context.Context, originate AMIOriginate) (AmiReply, error) {
return Originate(ctx, *c.Socket, originate)
}

func (c *AMICore) MakeCall(ctx context.Context, originate AMIPayloadOriginate) (AmiReply, error) {
func (c *AMICore) MakeCall(ctx context.Context, originate AMIOriginate) (AmiReply, error) {
return c.Originate(ctx, originate)
}

Expand Down Expand Up @@ -1350,12 +1350,12 @@ func (c *AMICore) ConfbridgeStopRecord(ctx context.Context, conference string) (
}

// DialOut
func (c *AMICore) DialOut(ctx context.Context, d AMIOriginateDirection) (AmiReply, bool, error) {
func (c *AMICore) DialOut(ctx context.Context, d AMIDialCall) (AmiReply, bool, error) {
return DialOut(ctx, *c.Socket, d)
}

// DialIn
func (c *AMICore) DialIn(ctx context.Context, d AMIOriginateDirection) (AmiReply, bool, error) {
func (c *AMICore) DialIn(ctx context.Context, d AMIDialCall) (AmiReply, bool, error) {
return DialIn(ctx, *c.Socket, d)
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/ami/ami_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ type AMIPayloadQueue struct {
Parameters string `ami:"Parameters,omitempty"`
}

// AMIPayloadOriginate holds information used to originate outgoing calls.
// AMIOriginate holds information used to originate outgoing calls.
//
// Channel - Channel name to call.
// Exten - Extension to use (requires Context and Priority)
Expand All @@ -184,7 +184,7 @@ type AMIPayloadQueue struct {
// Codecs - Comma-separated list of codecs to use for this call.
// ChannelId - Channel UniqueId to be set on the channel.
// OtherChannelId - Channel UniqueId to be set on the second local channel.
type AMIPayloadOriginate struct {
type AMIOriginate struct {
Channel string `ami:"Channel,omitempty"`
Exten string `ami:"Exten,omitempty"`
Context string `ami:"Context,omitempty"`
Expand Down Expand Up @@ -328,7 +328,7 @@ type AMIPayloadDb struct {
Value string `ami:"Val,omitempty"`
}

type AMIOriginateDirection struct {
type AMIDialCall struct {
Telephone string `json:"telephone" binding:"required"` // like customer phone number or no. extension internal from all routes
ChannelProtocol string `json:"channel_protocol" binding:"required"` // protocols include: SIP, H323, IAX...
Extension int `json:"extension" binding:"required"` // like current user using no. extension
Expand Down
70 changes: 35 additions & 35 deletions pkg/ami/ami_originate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,61 +8,61 @@ import (
"github.com/pnguyen215/voipkit/pkg/ami/config"
)

func NewAMIPayloadOriginate() *AMIPayloadOriginate {
o := &AMIPayloadOriginate{}
func NewAmiOriginate() *AMIOriginate {
o := &AMIOriginate{}
return o
}

func NewAMIOriginateDirection() *AMIOriginateDirection {
o := &AMIOriginateDirection{}
func NewAmiDialCall() *AMIDialCall {
o := &AMIDialCall{}
o.SetExtensionExists(true)
return o
}

func (o *AMIPayloadOriginate) SetAsync(value bool) *AMIPayloadOriginate {
func (o *AMIOriginate) SetAsync(value bool) *AMIOriginate {
states := map[bool]string{true: "true", false: "false"}
o.Async = states[value]
return o
}

func (o *AMIPayloadOriginate) SetChannel(value string) *AMIPayloadOriginate {
func (o *AMIOriginate) SetChannel(value string) *AMIOriginate {
o.Channel = strings.TrimSpace(value)
return o
}

func (o *AMIPayloadOriginate) SetExtension(value string) *AMIPayloadOriginate {
func (o *AMIOriginate) SetExtension(value string) *AMIOriginate {
o.Exten = strings.TrimSpace(value)
return o
}

func (o *AMIPayloadOriginate) SetContext(value string) *AMIPayloadOriginate {
func (o *AMIOriginate) SetContext(value string) *AMIOriginate {
o.Context = strings.TrimSpace(value)
return o
}

func (o *AMIPayloadOriginate) SetPriority(value int) *AMIPayloadOriginate {
func (o *AMIOriginate) SetPriority(value int) *AMIOriginate {
if value >= 0 {
o.Priority = value
}
return o
}

func (o *AMIPayloadOriginate) SetApplication(value string) *AMIPayloadOriginate {
func (o *AMIOriginate) SetApplication(value string) *AMIOriginate {
o.Application = strings.TrimSpace(value)
return o
}

func (o *AMIPayloadOriginate) SetData(value string) *AMIPayloadOriginate {
func (o *AMIOriginate) SetData(value string) *AMIOriginate {
o.Data = value
return o
}

func (o *AMIPayloadOriginate) SetDataWith(value interface{}) *AMIPayloadOriginate {
func (o *AMIOriginate) SetDataWith(value interface{}) *AMIOriginate {
o.SetData(JsonString(value))
return o
}

func (o *AMIPayloadOriginate) SetTimeout(value int) *AMIPayloadOriginate {
func (o *AMIOriginate) SetTimeout(value int) *AMIOriginate {
if value >= config.AmiMinTimeoutInMsForCall && value <= config.AmiMaxTimeoutInMsForCall {
o.Timeout = value
} else {
Expand All @@ -71,17 +71,17 @@ func (o *AMIPayloadOriginate) SetTimeout(value int) *AMIPayloadOriginate {
return o
}

func (o *AMIPayloadOriginate) SetCallerId(value string) *AMIPayloadOriginate {
func (o *AMIOriginate) SetCallerId(value string) *AMIOriginate {
o.CallerID = value
return o
}

func (o *AMIPayloadOriginate) SetVar(value ...string) *AMIPayloadOriginate {
func (o *AMIOriginate) SetVar(value ...string) *AMIOriginate {
o.Variable = append(o.Variable, value...)
return o
}

func (c *AMIPayloadOriginate) SetVars(delimiter string, variables ...string) *AMIPayloadOriginate {
func (c *AMIOriginate) SetVars(delimiter string, variables ...string) *AMIOriginate {
if strings.EqualFold(delimiter, "") {
delimiter = ";"
}
Expand All @@ -90,7 +90,7 @@ func (c *AMIPayloadOriginate) SetVars(delimiter string, variables ...string) *AM
return c
}

func (c *AMIPayloadOriginate) SetVarsMap(delimiter string, variables map[string]interface{}) *AMIPayloadOriginate {
func (c *AMIOriginate) SetVarsMap(delimiter string, variables map[string]interface{}) *AMIOriginate {
if len(variables) <= 0 {
return c
}
Expand All @@ -105,75 +105,75 @@ func (c *AMIPayloadOriginate) SetVarsMap(delimiter string, variables map[string]
return c
}

func (o *AMIPayloadOriginate) SetAccount(value string) *AMIPayloadOriginate {
func (o *AMIOriginate) SetAccount(value string) *AMIOriginate {
o.Account = value
return o
}

func (o *AMIPayloadOriginate) SetEarlyMedia(value string) *AMIPayloadOriginate {
func (o *AMIOriginate) SetEarlyMedia(value string) *AMIOriginate {
o.EarlyMedia = value
return o
}

func (o *AMIPayloadOriginate) SetCodecs(value string) *AMIPayloadOriginate {
func (o *AMIOriginate) SetCodecs(value string) *AMIOriginate {
o.Codecs = strings.TrimSpace(value)
return o
}

func (o *AMIPayloadOriginate) SetChannelId(value string) *AMIPayloadOriginate {
func (o *AMIOriginate) SetChannelId(value string) *AMIOriginate {
o.ChannelID = strings.TrimSpace(value)
return o
}

func (o *AMIPayloadOriginate) SetOtherChannelId(value string) *AMIPayloadOriginate {
func (o *AMIOriginate) SetOtherChannelId(value string) *AMIOriginate {
o.OtherChannelID = strings.TrimSpace(value)
return o
}

func (o *AMIPayloadOriginate) Json() string {
func (o *AMIOriginate) Json() string {
return JsonString(o)
}

func (o *AMIOriginateDirection) SetTelephone(value string) *AMIOriginateDirection {
func (o *AMIDialCall) SetTelephone(value string) *AMIDialCall {
o.Telephone = strings.TrimSpace(value)
return o
}

func (o *AMIOriginateDirection) SetChannelProtocol(value string) *AMIOriginateDirection {
func (o *AMIDialCall) SetChannelProtocol(value string) *AMIDialCall {
o.ChannelProtocol = strings.TrimSpace(value)
return o
}

func (o *AMIOriginateDirection) SetExtension(value int) *AMIOriginateDirection {
func (o *AMIDialCall) SetExtension(value int) *AMIDialCall {
if value >= 0 {
o.Extension = value
}
return o
}

func (o *AMIOriginateDirection) SetDebugMode(value bool) *AMIOriginateDirection {
func (o *AMIDialCall) SetDebugMode(value bool) *AMIDialCall {
o.DebugMode = value
return o
}

func (o *AMIOriginateDirection) SetTimeout(value int) *AMIOriginateDirection {
func (o *AMIDialCall) SetTimeout(value int) *AMIDialCall {
if value >= config.AmiMinTimeoutInMsForCall && value <= config.AmiMaxTimeoutInMsForCall {
o.Timeout = value
}
return o
}

func (o *AMIOriginateDirection) SetExtensionExists(value bool) *AMIOriginateDirection {
func (o *AMIDialCall) SetExtensionExists(value bool) *AMIDialCall {
o.ExtensionExists = value
return o
}

func (o *AMIOriginateDirection) Json() string {
func (o *AMIDialCall) Json() string {
return JsonString(o)
}

// DialCall
func DialCall(ctx context.Context, s AMISocket, originate AMIPayloadOriginate) (AmiReply, error) {
func DialCall(ctx context.Context, s AMISocket, originate AMIOriginate) (AmiReply, error) {
return Originate(ctx, s, originate)
}

Expand All @@ -186,10 +186,10 @@ func DialCall(ctx context.Context, s AMISocket, originate AMIPayloadOriginate) (
// exten: 012345678
// priority: 1
// timeout: 60000
func DialOut(ctx context.Context, s AMISocket, d AMIOriginateDirection) (AmiReply, bool, error) {
func DialOut(ctx context.Context, s AMISocket, d AMIDialCall) (AmiReply, bool, error) {
channel := NewChannel().
SetChannelProtocol(d.ChannelProtocol)
o := NewAMIPayloadOriginate().
o := NewAmiOriginate().
SetPriority(1).
SetAsync(true).
SetTimeout(d.Timeout).
Expand Down Expand Up @@ -224,10 +224,10 @@ func DialOut(ctx context.Context, s AMISocket, d AMIOriginateDirection) (AmiRepl
// exten: 1001
// priority: 1
// timeout: 60000
func DialIn(ctx context.Context, s AMISocket, d AMIOriginateDirection) (AmiReply, bool, error) {
func DialIn(ctx context.Context, s AMISocket, d AMIDialCall) (AmiReply, bool, error) {
channel := NewChannel().
SetChannelProtocol(d.ChannelProtocol)
o := NewAMIPayloadOriginate().
o := NewAmiOriginate().
SetPriority(1).
SetAsync(true).
SetTimeout(d.Timeout).
Expand Down

0 comments on commit cb52d2f

Please sign in to comment.