From 7f54440a1f0a3e36e32addd256bf6098f5fcebb3 Mon Sep 17 00:00:00 2001 From: Patrick Peng Sun Date: Fri, 30 Jun 2017 17:12:03 +1000 Subject: [PATCH] attachment URL centralized by CRM config. --- configCRM.go | 8 ++++++++ crmAttachment.go | 6 ++---- crmEntity.go | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/configCRM.go b/configCRM.go index b4025ad..d011b77 100644 --- a/configCRM.go +++ b/configCRM.go @@ -58,3 +58,11 @@ func (c EspoCRMAPIConfig) apiEntityURL(entityType, id string) string { func (c EspoCRMAPIConfig) apiLeadURL() string { return c.apiURL("Lead") } + +func (c EspoCRMAPIConfig) apiAuthURL() string { + return c.apiURL("App/user") +} + +func (c EspoCRMAPIConfig) apiUploadAttachmentURL() string { + return c.apiURL("Attachment/action/upload") +} diff --git a/crmAttachment.go b/crmAttachment.go index 50638a2..e174260 100644 --- a/crmAttachment.go +++ b/crmAttachment.go @@ -53,8 +53,7 @@ func crmPrepareAttachmentHTTPHeader(fileInfo crmFileInfo) (headers map[string]st } func crmUploadAttachmentURL() string { - - return CRMConfig.BaseURL + "api/v1/Attachment/action/upload" + return CRMConfig.apiUploadAttachmentURL() } func crmAuthHeader() string { @@ -97,8 +96,7 @@ func crmUploadAttachmentMeta(fileID string, fileInfo crmFileInfo) (resp string, } func crmAttachmentMetaURL(fileID string) string { - //return "https://c.hitxy.org.au/api/v1/Attachment/" + fileID - return CRMConfig.BaseURL + "api/v1/Attachment/" + fileID + return CRMConfig.apiEntityURL("Attachment", fileID) } type attachmentInfo struct { diff --git a/crmEntity.go b/crmEntity.go index b9abfca..93b518a 100644 --- a/crmEntity.go +++ b/crmEntity.go @@ -122,7 +122,7 @@ type crmdSearchResult struct { func crmSearchEntity(entityType string, filters []crmdSearchFilter) (result crmdSearchResult, err error) { - url := CRMConfig.BaseURL + "api/v1/" + entityType + url := CRMConfig.apiURL(entityType) req, err := http.NewRequest("GET", url, nil) if err != nil { log.Println("crmGetRecord: cannot form good http Request")