Skip to content

Commit

Permalink
Implement Retrieve API
Browse files Browse the repository at this point in the history
* continued trend of hacking the crap out of gosoap
* add basic Retrieve function and definitions to get objects' metadata
* added TestRetrieveEvent and TestRetrieveUser to test it
* added StructGen method to generate go structs for CvObjects
* added definitions files for Contact, Event, Reg and User
* updated README with notes on StructGen
  • Loading branch information
matthewpoer committed Jun 5, 2019
1 parent fa73331 commit 4f4b816
Show file tree
Hide file tree
Showing 10 changed files with 517 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,22 @@ A Golang wrapper for some common [Cvent SOAP API](https://developers.cvent.com/d
## Thanks to gosoap
[gosoap](https://github.com/tiaguinho/gosoap) gave this wrapper a big head start. There was a lot of hacking on gosoap to make it work with Cvent's API, so you will find it forked and included with `gocvent`.

## Build your own Definitions
This package includes Golang Structures for the out-of-the-box versions of Contacts, Events, Registrations and Users CvObjects in the [`definitions/`](definitions/) directory. If you want to work with other CvObjects and/or use custom fields on these structures, you will need to build your own `struct`s using `cvent.StructGen("filePath", "CvObject")`, then use the resulting `struct`s in your Cvent API retrieve calls, e.g.

```go
var objectDef objDefs.EventRetrieveResult
err := cvent.Retrieve("Event", v, &objectDef)
if err != nil {
fmt.Printf("TestRetrieveEvent err from cvent.Retrieve: %s", err)
}
fmt.Printf("Event Title: %s\n", objectDef.CvObject.EventTitle)
```

## Check out the Tests
Demonstrations of each of the implemented Cvent API methods has at least one corresponding test in [gocvent_test.go](gocvent_test.go). Current implementation includes:
* [Login](https://developers.cvent.com/documentation/soap-api/call-definitions/authentication/login/)
* [DescribeCvObject](https://developers.cvent.com/documentation/soap-api/call-definitions/object-metadata-calls/describecvobject/)
* [DescribeGlobal](https://developers.cvent.com/documentation/soap-api/call-definitions/object-metadata-calls/describeglobal/)
* [Search](https://developers.cvent.com/documentation/soap-api/call-definitions/search-and-retrieve/search/) (only _AndSearch_ style filtering is currently implemented, see [CvSearchObject](https://developers.cvent.com/documentation/soap-api/object-definitions/cvsearchobject/) and [`gosoap/encode.go`](gosoap/encode.go#L76))
* [Retrieve](https://developers.cvent.com/documentation/soap-api/call-definitions/search-and-retrieve/retrieve/) (gocvent only supports retrieval of one record at a time, which is different than the Cvent's function which would support several. Pull requests welcomed.)
19 changes: 19 additions & 0 deletions definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ type CventAPI struct {
soap *gosoap.Client
}

// CvObject is a generic result of a Retrieve call, so this is mostly just metadata fields
type CvObject struct {
Type string `xml:"type,attr"`
ID string `xml:"Id,attr"`
CreatedBy string `xml:"CreatedBy,attr"`
CreatedDate string `xml:"CreatedDate,attr"`
LastModifiedDate string `xml:"LastModifiedDate,attr"`
}

// AnswerDetail looks and smells a lot like LookUpDetail IMO
type AnswerDetail struct {
AnswerText string `xml:"AnswerText,attr"`
Expand Down Expand Up @@ -116,6 +125,16 @@ type LookUpDetail struct {
Value string `xml:"Value,attr"`
}

// RetrieveResponse wrapper for RetrieveResult
type RetrieveResponse struct {
RetrieveResult RetrieveResult
}

// RetrieveResult contains information about the records returned by a Retrieve API Call
type RetrieveResult struct {
CvObject CvObject `xml:"CvObject"`
}

// SearchResponse wrapper for SearchResult
type SearchResponse struct {
SearchResult SearchResult
Expand Down
82 changes: 82 additions & 0 deletions definitions/Contact.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package gocvent

// ContactRetrieveResult defines the result wrapper
type ContactRetrieveResult struct {
CvObject Contact `xml:"RetrieveResult>CvObject"`
}

// Contact defines the CvObject
type Contact struct {
Active bool `xml:"Active,attr"`
ActivityId string `xml:"ActivityId,attr"`
CCEmailAddress string `xml:"CCEmailAddress,attr"`
Company string `xml:"Company,attr"`
ContactType string `xml:"ContactType,attr"`
ContactTypeCode string `xml:"ContactTypeCode,attr"`
CreatedBy string `xml:"CreatedBy,attr"`
CreatedDate string `xml:"CreatedDate,attr"`
DateOfBirth string `xml:"DateOfBirth,attr"`
Designation string `xml:"Designation,attr"`
EmailAddress string `xml:"EmailAddress,attr"`
EmailAddressStatus string `xml:"EmailAddressStatus,attr"`
ExcludedFromEmail bool `xml:"ExcludedFromEmail,attr"`
ExpirationDate string `xml:"ExpirationDate,attr"`
FacebookURL string `xml:"FacebookURL,attr"`
FirstName string `xml:"FirstName,attr"`
Gender string `xml:"Gender,attr"`
HomeAddress1 string `xml:"HomeAddress1,attr"`
HomeAddress2 string `xml:"HomeAddress2,attr"`
HomeAddress3 string `xml:"HomeAddress3,attr"`
HomeCity string `xml:"HomeCity,attr"`
HomeCountry string `xml:"HomeCountry,attr"`
HomeCountryCode string `xml:"HomeCountryCode,attr"`
HomeFax string `xml:"HomeFax,attr"`
HomePhone string `xml:"HomePhone,attr"`
HomePostalCode string `xml:"HomePostalCode,attr"`
HomeState string `xml:"HomeState,attr"`
HomeStateCode string `xml:"HomeStateCode,attr"`
Id string `xml:"Id,attr"`
ImageURL string `xml:"ImageURL,attr"`
IsCreatedViaTestReg bool `xml:"IsCreatedViaTestReg,attr"`
IsObfuscated bool `xml:"IsObfuscated,attr"`
JoinDate string `xml:"JoinDate,attr"`
LastModifiedBy string `xml:"LastModifiedBy,attr"`
LastModifiedDate string `xml:"LastModifiedDate,attr"`
LastName string `xml:"LastName,attr"`
LastOptOutBy string `xml:"LastOptOutBy,attr"`
LastOptOutDate string `xml:"LastOptOutDate,attr"`
LastRenewalDate string `xml:"LastRenewalDate,attr"`
LinkedInURL string `xml:"LinkedInURL,attr"`
LogDate string `xml:"LogDate,attr"`
LogReason string `xml:"LogReason,attr"`
LogResponse string `xml:"LogResponse,attr"`
MembershipCode string `xml:"MembershipCode,attr"`
MiddleName string `xml:"MiddleName,attr"`
MobilePhone string `xml:"MobilePhone,attr"`
NationalIdentificationNumber string `xml:"NationalIdentificationNumber,attr"`
Nickname string `xml:"Nickname,attr"`
OptedIn bool `xml:"OptedIn,attr"`
Pager string `xml:"Pager,attr"`
ParentContactId string `xml:"ParentContactId,attr"`
PassportCountry string `xml:"PassportCountry,attr"`
PassportCountryCode string `xml:"PassportCountryCode,attr"`
PassportNumber string `xml:"PassportNumber,attr"`
PrimaryAddress string `xml:"PrimaryAddress,attr"`
Salutation string `xml:"Salutation,attr"`
SMTPCode string `xml:"SMTPCode,attr"`
SocialSecurityNumber string `xml:"SocialSecurityNumber,attr"`
SourceId string `xml:"SourceId,attr"`
Title string `xml:"Title,attr"`
TwitterURL string `xml:"TwitterURL,attr"`
WorkAddress1 string `xml:"WorkAddress1,attr"`
WorkAddress2 string `xml:"WorkAddress2,attr"`
WorkAddress3 string `xml:"WorkAddress3,attr"`
WorkCity string `xml:"WorkCity,attr"`
WorkCountry string `xml:"WorkCountry,attr"`
WorkCountryCode string `xml:"WorkCountryCode,attr"`
WorkFax string `xml:"WorkFax,attr"`
WorkPhone string `xml:"WorkPhone,attr"`
WorkPostalCode string `xml:"WorkPostalCode,attr"`
WorkState string `xml:"WorkState,attr"`
WorkStateCode string `xml:"WorkStateCode,attr"`
}
70 changes: 70 additions & 0 deletions definitions/Event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package gocvent

// EventRetrieveResult defines the result wrapper
type EventRetrieveResult struct {
CvObject Event `xml:"RetrieveResult>CvObject"`
}

// Event defines the CvObject
type Event struct {
ArchiveDate string `xml:"ArchiveDate,attr"`
Capacity string `xml:"Capacity,attr"`
Category string `xml:"Category,attr"`
City string `xml:"City,attr"`
ClosedBy string `xml:"ClosedBy,attr"`
Country string `xml:"Country,attr"`
CountryCode string `xml:"CountryCode,attr"`
CreatedBy string `xml:"CreatedBy,attr"`
Currency string `xml:"Currency,attr"`
EventCalendarAlternateURL string `xml:"EventCalendarAlternateURL,attr"`
EventCalendarCompletedURL string `xml:"EventCalendarCompletedURL,attr"`
EventCalendarLinkText string `xml:"EventCalendarLinkText,attr"`
EventCode string `xml:"EventCode,attr"`
EventDescription string `xml:"EventDescription,attr"`
EventEndDate string `xml:"EventEndDate,attr"`
EventLaunchDate string `xml:"EventLaunchDate,attr"`
EventStartDate string `xml:"EventStartDate,attr"`
EventStatus string `xml:"EventStatus,attr"`
EventTitle string `xml:"EventTitle,attr"`
ExternalAuthentication bool `xml:"ExternalAuthentication,attr"`
Hidden bool `xml:"Hidden,attr"`
Id string `xml:"Id,attr"`
InternalNote string `xml:"InternalNote,attr"`
LastModifiedDate string `xml:"LastModifiedDate,attr"`
Location string `xml:"Location,attr"`
MeetingRequestId string `xml:"MeetingRequestId,attr"`
MerchantAccount string `xml:"MerchantAccount,attr"`
MerchantAccountId string `xml:"MerchantAccountId,attr"`
PhoneNumber string `xml:"PhoneNumber,attr"`
PlannerCompany string `xml:"PlannerCompany,attr"`
PlannerEmailAddress string `xml:"PlannerEmailAddress,attr"`
PlannerFirstName string `xml:"PlannerFirstName,attr"`
PlannerLastName string `xml:"PlannerLastName,attr"`
PlannerPrefix string `xml:"PlannerPrefix,attr"`
PlannerTitle string `xml:"PlannerTitle,attr"`
PlanningStatus string `xml:"PlanningStatus,attr"`
PostalCode string `xml:"PostalCode,attr"`
RSVPbyDate string `xml:"RSVPbyDate,attr"`
StakeholderAddress1 string `xml:"StakeholderAddress1,attr"`
StakeholderAddress2 string `xml:"StakeholderAddress2,attr"`
StakeholderAddress3 string `xml:"StakeholderAddress3,attr"`
StakeholderCity string `xml:"StakeholderCity,attr"`
StakeholderCompany string `xml:"StakeholderCompany,attr"`
StakeholderCountryCode string `xml:"StakeholderCountryCode,attr"`
StakeholderEmailAddress string `xml:"StakeholderEmailAddress,attr"`
StakeholderFirstName string `xml:"StakeholderFirstName,attr"`
StakeholderHomePhone string `xml:"StakeholderHomePhone,attr"`
StakeholderLastName string `xml:"StakeholderLastName,attr"`
StakeholderMobilePhone string `xml:"StakeholderMobilePhone,attr"`
StakeholderPostalCode string `xml:"StakeholderPostalCode,attr"`
StakeholderStateCode string `xml:"StakeholderStateCode,attr"`
StakeholderTitle string `xml:"StakeholderTitle,attr"`
StakeholderWorkFax string `xml:"StakeholderWorkFax,attr"`
StakeholderWorkPhone string `xml:"StakeholderWorkPhone,attr"`
State string `xml:"State,attr"`
StateCode string `xml:"StateCode,attr"`
StreetAddress1 string `xml:"StreetAddress1,attr"`
StreetAddress2 string `xml:"StreetAddress2,attr"`
StreetAddress3 string `xml:"StreetAddress3,attr"`
Timezone string `xml:"Timezone,attr"`
}
45 changes: 45 additions & 0 deletions definitions/Registration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package gocvent

// RegistrationRetrieveResult defines the result wrapper
type RegistrationRetrieveResult struct {
CvObject Registration `xml:"RetrieveResult>CvObject"`
}

// Registration defines the CvObject
type Registration struct {
CancelledDate string `xml:"CancelledDate,attr"`
CCEmailAddress string `xml:"CCEmailAddress,attr"`
Company string `xml:"Company,attr"`
ConfirmationNumber string `xml:"ConfirmationNumber,attr"`
ContactId string `xml:"ContactId,attr"`
Credit string `xml:"Credit,attr"`
EmailAddress string `xml:"EmailAddress,attr"`
EventCode string `xml:"EventCode,attr"`
EventId string `xml:"EventId,attr"`
EventStartDate string `xml:"EventStartDate,attr"`
EventTitle string `xml:"EventTitle,attr"`
FirstName string `xml:"FirstName,attr"`
GroupId string `xml:"GroupId,attr"`
GroupLeader bool `xml:"GroupLeader,attr"`
Id string `xml:"Id,attr"`
InternalNote string `xml:"InternalNote,attr"`
InvitedBy string `xml:"InvitedBy,attr"`
InviteeId string `xml:"InviteeId,attr"`
IsTestRegistrant bool `xml:"IsTestRegistrant,attr"`
LastModifiedDate string `xml:"LastModifiedDate,attr"`
LastName string `xml:"LastName,attr"`
ModifiedBy string `xml:"ModifiedBy,attr"`
OriginalResponseDate string `xml:"OriginalResponseDate,attr"`
Participant bool `xml:"Participant,attr"`
ReferenceId string `xml:"ReferenceId,attr"`
RegistrationDate string `xml:"RegistrationDate,attr"`
RegistrationType string `xml:"RegistrationType,attr"`
RegistrationTypeCode string `xml:"RegistrationTypeCode,attr"`
ResponseMethod string `xml:"ResponseMethod,attr"`
SourceId string `xml:"SourceId,attr"`
Status string `xml:"Status,attr"`
TargetedListId string `xml:"TargetedListId,attr"`
TargetedListName string `xml:"TargetedListName,attr"`
Title string `xml:"Title,attr"`
WorkPhone string `xml:"WorkPhone,attr"`
}
51 changes: 51 additions & 0 deletions definitions/User.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package gocvent

// UserRetrieveResult defines the result wrapper
type UserRetrieveResult struct {
CvObject User `xml:"RetrieveResult>CvObject"`
}

// User defines the CvObject
type User struct {
Active bool `xml:"Active,attr"`
Address1 string `xml:"Address1,attr"`
Address2 string `xml:"Address2,attr"`
Address3 string `xml:"Address3,attr"`
AllEventVisibility bool `xml:"AllEventVisibility,attr"`
AllRFPVisibility bool `xml:"AllRFPVisibility,attr"`
AllSurveyVisibility bool `xml:"AllSurveyVisibility,attr"`
ChangePasswordOnLogin bool `xml:"ChangePasswordOnLogin,attr"`
City string `xml:"City,attr"`
Company string `xml:"Company,attr"`
Country string `xml:"Country,attr"`
CountryCode string `xml:"CountryCode,attr"`
CreatedBy string `xml:"CreatedBy,attr"`
CreatedDate string `xml:"CreatedDate,attr"`
DefaultContactGroupId string `xml:"DefaultContactGroupId,attr"`
Email string `xml:"Email,attr"`
FederatedId string `xml:"FederatedId,attr"`
FirstName string `xml:"FirstName,attr"`
HomeFax string `xml:"HomeFax,attr"`
HomePhone string `xml:"HomePhone,attr"`
Id string `xml:"Id,attr"`
LastLoginDate string `xml:"LastLoginDate,attr"`
LastModifiedBy string `xml:"LastModifiedBy,attr"`
LastModifiedDate string `xml:"LastModifiedDate,attr"`
LastName string `xml:"LastName,attr"`
MobilePhone string `xml:"MobilePhone,attr"`
Pager string `xml:"Pager,attr"`
Password string `xml:"Password,attr"`
Passwordstrong string `xml:"Password (strong),attr"`
PasswordSalt string `xml:"Password Salt,attr"`
PostalCode string `xml:"PostalCode,attr"`
Prefix string `xml:"Prefix,attr"`
State string `xml:"State,attr"`
StateCode string `xml:"StateCode,attr"`
Title string `xml:"Title,attr"`
Username string `xml:"Username,attr"`
UserRole string `xml:"UserRole,attr"`
UserRoleId string `xml:"UserRoleId,attr"`
UserType string `xml:"UserType,attr"`
WorkFax string `xml:"WorkFax,attr"`
WorkPhone string `xml:"WorkPhone,attr"`
}
Loading

0 comments on commit 4f4b816

Please sign in to comment.