Skip to content

Commit

Permalink
fix: map setters
Browse files Browse the repository at this point in the history
  • Loading branch information
franklinkim committed Mar 4, 2024
1 parent 88b23c4 commit 74a9724
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 73 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sesamy
# Sesamy Go SDK

[![Build Status](https://github.com/foomo/sesamy-go/actions/workflows/test.yml/badge.svg?branch=main&event=push)](https://github.com/foomo/sesamy-go/actions/workflows/test.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/foomo/sesamy-go)](https://goreportcard.com/report/github.com/foomo/sesamy-go)
Expand Down
14 changes: 14 additions & 0 deletions measurementprotocol/getset.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ func SetBool(v bool) *string {
return Set("1")
}

func SetStringMap(v map[string]string) map[string]string {
if len(v) == 0 {
return nil
}
return v
}

func AddStringMap(t map[string]string, k string, v *string) {
if v == nil {
return
}
t[k] = *v
}

func Get[T any](v *T) T {
return *v
}
Expand Down
18 changes: 9 additions & 9 deletions measurementprotocol/v2/event/addpaymentinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ func (e *AddPaymentInfo) MPv2() *mpv2.Event {
for i, item := range e.Items {
items[i] = item.MPv2()
}
eventParameter := map[string]string{}
mp.AddStringMap(eventParameter, mpv2.EventParameterCoupon.String(), mp.SetString(e.Coupon))
mp.AddStringMap(eventParameter, mpv2.EventParameterPaymentType.String(), mp.SetString(e.PaymentType))
eventParameterNumber := map[string]string{}
mp.AddStringMap(eventParameterNumber, mpv2.EventParameterNumberValue.String(), mp.SetFloat64(e.Value))
return &mpv2.Event{
Currency: mp.SetString(e.Currency),
EventParameter: map[string]string{
mpv2.EventParameterCoupon.String(): e.Coupon,
mpv2.EventParameterPaymentType.String(): e.PaymentType,
},
EventParameterNumber: map[string]string{
mpv2.EventParameterNumberValue.String(): *mp.SetFloat64(e.Value),
},
Items: items,
Currency: mp.SetString(e.Currency),
EventParameter: mp.SetStringMap(eventParameter),
EventParameterNumber: mp.SetStringMap(eventParameterNumber),
Items: items,
}
}
18 changes: 9 additions & 9 deletions measurementprotocol/v2/event/addshippinginfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ func (e *AddShippingInfo) MPv2() *mpv2.Event {
for i, item := range e.Items {
items[i] = item.MPv2()
}
eventParameter := map[string]string{}
mp.AddStringMap(eventParameter, mpv2.EventParameterCoupon.String(), mp.SetString(e.Coupon))
mp.AddStringMap(eventParameter, mpv2.EventParameterShippingTier.String(), mp.SetString(e.ShippingTier))
eventParameterNumber := map[string]string{}
mp.AddStringMap(eventParameterNumber, mpv2.EventParameterNumberValue.String(), mp.SetFloat64(e.Value))
return &mpv2.Event{
Currency: mp.SetString(e.Currency),
EventParameter: map[string]string{
mpv2.EventParameterCoupon.String(): e.Coupon,
mpv2.EventParameterShippingTier.String(): e.ShippingTier,
},
EventParameterNumber: map[string]string{
mpv2.EventParameterNumberValue.String(): *mp.SetFloat64(e.Value),
},
Items: items,
Currency: mp.SetString(e.Currency),
EventParameter: mp.SetStringMap(eventParameter),
EventParameterNumber: mp.SetStringMap(eventParameterNumber),
Items: items,
}
}
10 changes: 5 additions & 5 deletions measurementprotocol/v2/event/addtocart.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ func (e *AddToCart) MPv2() *mpv2.Event {
for i, item := range e.Items {
items[i] = item.MPv2()
}
eventParameterNumber := map[string]string{}
mp.AddStringMap(eventParameterNumber, mpv2.EventParameterNumberValue.String(), mp.SetFloat64(e.Value))
return &mpv2.Event{
Currency: mp.SetString(e.Currency),
EventParameterNumber: map[string]string{
mpv2.EventParameterNumberValue.String(): *mp.SetFloat64(e.Value),
},
Items: items,
Currency: mp.SetString(e.Currency),
EventParameterNumber: mp.SetStringMap(eventParameterNumber),
Items: items,
}
}
10 changes: 5 additions & 5 deletions measurementprotocol/v2/event/addtowishlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ func (e *AddToWishlist) MPv2() *mpv2.Event {
for i, item := range e.Items {
items[i] = item.MPv2()
}
eventParameterNumber := map[string]string{}
mp.AddStringMap(eventParameterNumber, mpv2.EventParameterNumberValue.String(), mp.SetFloat64(e.Value))
return &mpv2.Event{
Currency: mp.SetString(e.Currency),
EventParameterNumber: map[string]string{
mpv2.EventParameterNumberValue.String(): *mp.SetFloat64(e.Value),
},
Items: items,
Currency: mp.SetString(e.Currency),
EventParameterNumber: mp.SetStringMap(eventParameterNumber),
Items: items,
}
}
16 changes: 8 additions & 8 deletions measurementprotocol/v2/event/begincheckout.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ func (e *BeginCheckout) MPv2() *mpv2.Event {
for i, item := range e.Items {
items[i] = item.MPv2()
}
eventParameter := map[string]string{}
mp.AddStringMap(eventParameter, mpv2.EventParameterCoupon.String(), mp.SetString(e.Coupon))
eventParameterNumber := map[string]string{}
mp.AddStringMap(eventParameterNumber, mpv2.EventParameterNumberValue.String(), mp.SetFloat64(e.Value))
return &mpv2.Event{
Currency: mp.SetString(e.Currency),
EventParameter: map[string]string{
mpv2.EventParameterCoupon.String(): e.Coupon,
},
EventParameterNumber: map[string]string{
mpv2.EventParameterNumberValue.String(): *mp.SetFloat64(e.Value),
},
Items: items,
Currency: mp.SetString(e.Currency),
EventParameter: mp.SetStringMap(eventParameter),
EventParameterNumber: mp.SetStringMap(eventParameterNumber),
Items: items,
}
}
6 changes: 3 additions & 3 deletions measurementprotocol/v2/event/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ type Login struct {
}

func (e *Login) MPv2() *mpv2.Event {
eventParameter := map[string]string{}
mp.AddStringMap(eventParameter, mpv2.EventParameterMethod.String(), mp.SetString(e.Method))
return &mpv2.Event{
EventParameter: map[string]string{
mpv2.EventParameterMethod.String(): *mp.SetString(e.Method),
},
EventParameter: mp.SetStringMap(eventParameter),
}
}
22 changes: 11 additions & 11 deletions measurementprotocol/v2/event/purchase.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ func (e *Purchase) MPv2() *mpv2.Event {
for i, item := range e.Items {
items[i] = item.MPv2()
}
eventParameter := map[string]string{}
mp.AddStringMap(eventParameter, mpv2.EventParameterTransactionID.String(), mp.SetString(e.TransactionID))
mp.AddStringMap(eventParameter, mpv2.EventParameterCoupon.String(), mp.SetString(e.Coupon))
eventParameterNumber := map[string]string{}
mp.AddStringMap(eventParameterNumber, mpv2.EventParameterNumberValue.String(), mp.SetFloat64(e.Value))
mp.AddStringMap(eventParameterNumber, mpv2.EventParameterNumberShipping.String(), mp.SetFloat64(e.Shipping))
mp.AddStringMap(eventParameterNumber, mpv2.EventParameterNumberTax.String(), mp.SetFloat64(e.Tax))
return &mpv2.Event{
Currency: mp.SetString(e.Currency),
EventParameter: map[string]string{
mpv2.EventParameterTransactionID.String(): *mp.SetFloat64(e.Value),
mpv2.EventParameterCoupon.String(): *mp.SetFloat64(e.Value),
},
EventParameterNumber: map[string]string{
mpv2.EventParameterNumberValue.String(): *mp.SetFloat64(e.Value),
mpv2.EventParameterNumberShipping.String(): *mp.SetFloat64(e.Value),
mpv2.EventParameterNumberTax.String(): *mp.SetFloat64(e.Value),
},
Items: items,
Currency: mp.SetString(e.Currency),
EventParameter: mp.SetStringMap(eventParameter),
EventParameterNumber: mp.SetStringMap(eventParameterNumber),
Items: items,
}
}
22 changes: 11 additions & 11 deletions measurementprotocol/v2/event/refund.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ func (e *Refund) MPv2() *mpv2.Event {
for i, item := range e.Items {
items[i] = item.MPv2()
}
eventParameter := map[string]string{}
mp.AddStringMap(eventParameter, mpv2.EventParameterTransactionID.String(), mp.SetString(e.TransactionID))
mp.AddStringMap(eventParameter, mpv2.EventParameterCoupon.String(), mp.SetString(e.Coupon))
eventParameterNumber := map[string]string{}
mp.AddStringMap(eventParameterNumber, mpv2.EventParameterNumberValue.String(), mp.SetFloat64(e.Value))
mp.AddStringMap(eventParameterNumber, mpv2.EventParameterNumberShipping.String(), mp.SetFloat64(e.Shipping))
mp.AddStringMap(eventParameterNumber, mpv2.EventParameterNumberTax.String(), mp.SetFloat64(e.Tax))
return &mpv2.Event{
Currency: mp.SetString(e.Currency),
EventParameter: map[string]string{
mpv2.EventParameterTransactionID.String(): *mp.SetFloat64(e.Value),
mpv2.EventParameterCoupon.String(): *mp.SetFloat64(e.Value),
},
EventParameterNumber: map[string]string{
mpv2.EventParameterNumberValue.String(): *mp.SetFloat64(e.Value),
mpv2.EventParameterNumberShipping.String(): *mp.SetFloat64(e.Value),
mpv2.EventParameterNumberTax.String(): *mp.SetFloat64(e.Value),
},
Items: items,
Currency: mp.SetString(e.Currency),
EventParameter: mp.SetStringMap(eventParameter),
EventParameterNumber: mp.SetStringMap(eventParameterNumber),
Items: items,
}
}
10 changes: 5 additions & 5 deletions measurementprotocol/v2/event/removefromcart.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ func (e *RemoveFromCart) MPv2() *mpv2.Event {
for i, item := range e.Items {
items[i] = item.MPv2()
}
eventParameterNumber := map[string]string{}
mp.AddStringMap(eventParameterNumber, mpv2.EventParameterNumberValue.String(), mp.SetFloat64(e.Value))
return &mpv2.Event{
Currency: mp.SetString(e.Currency),
EventParameterNumber: map[string]string{
mpv2.EventParameterNumberValue.String(): *mp.SetFloat64(e.Value),
},
Items: items,
Currency: mp.SetString(e.Currency),
EventParameterNumber: mp.SetStringMap(eventParameterNumber),
Items: items,
}
}
6 changes: 3 additions & 3 deletions measurementprotocol/v2/event/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ type Search struct {
}

func (e *Search) MPv2() *mpv2.Event {
eventParameter := map[string]string{}
mp.AddStringMap(eventParameter, mpv2.EventParameterSearchTerm.String(), mp.SetString(e.SearchTerm))
return &mpv2.Event{
EventParameter: map[string]string{
mpv2.EventParameterSearchTerm.String(): *mp.SetString(e.SearchTerm),
},
EventParameter: mp.SetStringMap(eventParameter),
}
}
6 changes: 3 additions & 3 deletions measurementprotocol/v2/event/signup.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ type SignUp struct {
}

func (e *SignUp) MPv2() *mpv2.Event {
eventParameter := map[string]string{}
mp.AddStringMap(eventParameter, mpv2.EventParameterMethod.String(), mp.SetString(e.Method))
return &mpv2.Event{
EventParameter: map[string]string{
mpv2.EventParameterMethod.String(): *mp.SetString(e.Method),
},
EventParameter: mp.SetStringMap(eventParameter),
}
}

0 comments on commit 74a9724

Please sign in to comment.