From abe65094845738a86016726a6bff4b3ceabc45ab Mon Sep 17 00:00:00 2001 From: Patrick Peng Sun Date: Thu, 29 Jun 2017 21:33:21 +1000 Subject: [PATCH] all crm function start with crm, all data of crm start with crmd --- crmEntity.go | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/crmEntity.go b/crmEntity.go index 53babba..17215a8 100644 --- a/crmEntity.go +++ b/crmEntity.go @@ -7,37 +7,37 @@ import "strings" //abstract CRUD operation for espoCRM Entity var crmSite = "https://c.hitxy.org.au/" -func createEntity(entityType string, jsonB []byte) (entity interface{}, err error) { +func crmCreateEntity(entityType string, jsonB []byte) (entity interface{}, err error) { url := crmSite + "api/v1/" + entityType jsonStr, err := postRAW(jsonB, url, crmBuildCommonAPIHeader()) if err != nil { - entity, _ = rescueDuplicate(err, entityType) + entity, _ = crmRescueDuplicateCreate(err, entityType) return } - return json2Entity(entityType, jsonStr) + return crmJSON2Entity(entityType, jsonStr) } -func updateEntity(entityType string, id string, jsonB []byte) (entity interface{}, err error) { +func crmUpdateEntity(entityType string, id string, jsonB []byte) (entity interface{}, err error) { url := crmSite + "api/v1/" + entityType + "/" + id jsonStr, err := patchRAW(jsonB, url, crmBuildCommonAPIHeader()) if err != nil { log.Println(err) return } - return json2Entity(entityType, jsonStr) + return crmJSON2Entity(entityType, jsonStr) } -func replaceEntity(entityType string, id string, jsonB []byte) (entity interface{}, err error) { +func crmReplaceEntity(entityType string, id string, jsonB []byte) (entity interface{}, err error) { url := crmSite + "api/v1/" + entityType + "/" + id jsonStr, err := putRAW(jsonB, url, crmBuildCommonAPIHeader()) if err != nil { log.Println(err) return } - return json2Entity(entityType, jsonStr) + return crmJSON2Entity(entityType, jsonStr) } -func deleteEntity(entityType string, id string) (deleted bool, err error) { +func crmDeleteEntity(entityType string, id string) (deleted bool, err error) { url := crmSite + "api/v1/" + entityType + "/" + id resp, err := deleteRAW(url, crmBuildCommonAPIHeader()) if err != nil { @@ -56,7 +56,7 @@ func crmGetEntity(entityType string, id string) (entity interface{}, err error) log.Println(err) return } - return json2Entity(entityType, jsonStr) + return crmJSON2Entity(entityType, jsonStr) } func crmBuildCommonAPIHeader() (headers map[string]string) { @@ -68,7 +68,7 @@ func crmBuildCommonAPIHeader() (headers map[string]string) { } //given a json string, convert it to Typed structure -func json2Entity(entityType string, data string) (r interface{}, err error) { +func crmJSON2Entity(entityType string, data string) (r interface{}, err error) { switch entityType { case "Lead": e := crmdLead{} @@ -77,7 +77,7 @@ func json2Entity(entityType string, data string) (r interface{}, err error) { case "Account": //r = crmdAccount{} default: - log.Fatalf("json2Entity: Unknown EntityType %s", entityType) + log.Fatalf("crmJSON2Entity: Unknown EntityType %s", entityType) } if err != nil { @@ -86,7 +86,7 @@ func json2Entity(entityType string, data string) (r interface{}, err error) { return } -func rescueDuplicate(e error, entityType string) (entity interface{}, success bool) { +func crmRescueDuplicateCreate(e error, entityType string) (entity interface{}, success bool) { if !isErrIndicateDuplicate(e) { return } @@ -104,3 +104,6 @@ func isErrIndicateDuplicate(e error) (yes bool) { yes = strings.ToLower(reason.Reason) == "duplicate" return } + + +func searchEntity \ No newline at end of file