| @@ -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 | |||