Skip to content

Commit

Permalink
Simplify naming
Browse files Browse the repository at this point in the history
  • Loading branch information
weppos committed Jun 18, 2019
1 parent 39b2a32 commit 6e3c969
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
30 changes: 15 additions & 15 deletions dnsimple/webhook/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ import (
"github.com/dnsimple/dnsimple-go/dnsimple"
)

func switchEventData(event *EventContainer) (EventDataContainer, error) {
var dataContainer EventDataContainer
func switchEventData(event *Event) (EventDataContainer, error) {
var data EventDataContainer

switch event.Name {
case // account
"account.billing_settings_update",
"account.update",
"account.user_invitation_accept",
"account.user_invite":
dataContainer = &AccountEventData{}
data = &AccountEventData{}
case // certificate
"certificate.remove_private_key":
dataContainer = &CertificateEventData{}
data = &CertificateEventData{}
case // contact
"contact.create",
"contact.delete",
"contact.update":
dataContainer = &ContactEventData{}
data = &ContactEventData{}
case // dnssec
"dnssec.rotation_complete",
"dnssec.rotation_start":
dataContainer = &DNSSECEventData{}
data = &DNSSECEventData{}
case // domain
"domain.auto_renewal_disable",
"domain.auto_renewal_enable",
Expand All @@ -38,37 +38,37 @@ func switchEventData(event *EventContainer) (EventDataContainer, error) {
"domain.resolution_disable",
"domain.resolution_enable",
"domain.transfer": // TODO
dataContainer = &DomainEventData{}
data = &DomainEventData{}
case // email forward
"email_forward.create",
"email_forward.delete",
"email_forward.update":
dataContainer = &EmailForwardEventData{}
data = &EmailForwardEventData{}
case // webhook
"webhook.create",
"webhook.delete":
dataContainer = &WebhookEventData{}
data = &WebhookEventData{}
case // whois privacy
"whois_privacy.disable",
"whois_privacy.enable",
"whois_privacy.purchase",
"whois_privacy.renew": // TODO
dataContainer = &WhoisPrivacyEventData{}
data = &WhoisPrivacyEventData{}
case // zone
"zone.create",
"zone.delete":
dataContainer = &ZoneEventData{}
data = &ZoneEventData{}
case // zone record
"zone_record.create",
"zone_record.delete",
"zone_record.update":
dataContainer = &ZoneRecordEventData{}
data = &ZoneRecordEventData{}
default:
dataContainer = &GenericEventData{}
data = &GenericEventData{}
}

err := dataContainer.unmarshalEventData(event.payload)
return dataContainer, err
err := data.unmarshalEventData(event.payload)
return data, err
}

//
Expand Down
10 changes: 5 additions & 5 deletions dnsimple/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Account struct {
Identifier string `json:"identifier,omitempty"`
}

type EventContainer struct {
type Event struct {
APIVersion string `json:"api_version"`
RequestID string `json:"request_identifier"`
Name string `json:"name"`
Expand All @@ -44,11 +44,11 @@ type EventDataContainer interface {
unmarshalEventData([]byte) error
}

func (e *EventContainer) GetData() EventDataContainer {
func (e *Event) GetData() EventDataContainer {
return e.data
}

func (e *EventContainer) GetPayload() []byte {
func (e *Event) GetPayload() []byte {
return e.payload
}

Expand All @@ -59,8 +59,8 @@ func (e *EventContainer) GetPayload() []byte {
//
// The event data type is an EventContainerData interface. Therefore, you must perform typecasting
// to access any type-specific field.
func ParseEvent(payload []byte) (*EventContainer, error) {
e := &EventContainer{payload: payload}
func ParseEvent(payload []byte) (*Event, error) {
e := &Event{payload: payload}

if err := json.Unmarshal(payload, e); err != nil {
return nil, err
Expand Down

0 comments on commit 6e3c969

Please sign in to comment.