|
- package main
-
- import "log"
-
- //abstract CRUD operation for espoCRM Entity
- var crmSite = "https://c.hitxy.org.au/"
-
- func createEntity(entityType string, jsonB []byte) (entity interface{}, err error) {
- url := crmSite + "api/v1/" + entityType
- json, err := postRAW(jsonB, url, crmBuildCommonAPIHeader())
- if err != nil {
- log.Println(err)
- return
- }
- return json, err
- }
-
- func updateEntity(entityType string, id string, jsonB []byte) (entity interface{}, err error) {
- url := crmSite + "api/v1/" + entityType + "/" + id
- json, err := patchRAW(jsonB, url, crmBuildCommonAPIHeader())
- if err != nil {
- log.Println(err)
- return
- }
- return json, err
- }
-
- func replaceEntity(entityType string, id string, jsonB []byte) (entity interface{}, err error) {
- url := crmSite + "api/v1/" + entityType + "/" + id
- json, err := putRAW(jsonB, url, crmBuildCommonAPIHeader())
- if err != nil {
- log.Println(err)
- return
- }
- return json, err
- }
-
- func deleteEntity(entityType string, id string) (json string, err error) {
- url := crmSite + "api/v1/" + entityType + "/" + id
- json, err = deleteRAW(url, crmBuildCommonAPIHeader())
- if err != nil {
- log.Println(err)
- return
- }
- return
- }
-
- //give an id, return json
- func crmGetEntity(entityType string, id string) (json string, err error) {
- url := crmSite + "api/v1/" + entityType + "/" + id
- json, err = getRAW(url, crmBuildCommonAPIHeader())
- if err != nil {
- log.Println(err)
- return
- }
- return json, err
- }
-
- func crmBuildCommonAPIHeader() (headers map[string]string) {
- headers = map[string]string{}
- headers["Authorization"] = crmAuthHeader()
- headers["Accept"] = "application/json"
- headers["Content-Type"] = "application/json"
- return headers
- }
-
- //given a json string, convert it to Typed structure
- func json2Entity(entityType string, json string) (r interface{}) {
- switch entityType {
- case "Lead":
- r = crmdLeadInfo
- case "Account":
- }
- return
- }
|