mirror of
https://github.com/documize/community.git
synced 2025-08-08 06:55:28 +02:00
Refactored smart section registration and organization
This commit is contained in:
parent
f44695186b
commit
29bc955c6d
21 changed files with 340 additions and 392 deletions
|
@ -20,12 +20,12 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/dgrijalva/jwt-go"
|
jwt "github.com/dgrijalva/jwt-go"
|
||||||
"github.com/documize/community/documize/api/endpoint/models"
|
"github.com/documize/community/documize/api/endpoint/models"
|
||||||
"github.com/documize/community/documize/api/entity"
|
"github.com/documize/community/documize/api/entity"
|
||||||
"github.com/documize/community/documize/api/request"
|
"github.com/documize/community/documize/api/request"
|
||||||
"github.com/documize/community/documize/api/util"
|
"github.com/documize/community/documize/api/util"
|
||||||
"github.com/documize/community/documize/section"
|
"github.com/documize/community/documize/section/provider"
|
||||||
"github.com/documize/community/wordsmith/log"
|
"github.com/documize/community/wordsmith/log"
|
||||||
"github.com/documize/community/wordsmith/utility"
|
"github.com/documize/community/wordsmith/utility"
|
||||||
)
|
)
|
||||||
|
@ -228,7 +228,7 @@ func ValidateAuthToken(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// TODO should this go after token validation?
|
// TODO should this go after token validation?
|
||||||
if s := r.URL.Query().Get("section"); s != "" {
|
if s := r.URL.Query().Get("section"); s != "" {
|
||||||
if err:=section.Callback(s, w, r); err!=nil {
|
if err := provider.Callback(s, w, r); err != nil {
|
||||||
log.Error("section validation failure", err)
|
log.Error("section validation failure", err)
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
w.WriteHeader(http.StatusUnauthorized)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ import (
|
||||||
"github.com/documize/community/documize/api/entity"
|
"github.com/documize/community/documize/api/entity"
|
||||||
"github.com/documize/community/documize/api/request"
|
"github.com/documize/community/documize/api/request"
|
||||||
"github.com/documize/community/documize/api/util"
|
"github.com/documize/community/documize/api/util"
|
||||||
"github.com/documize/community/documize/section"
|
"github.com/documize/community/documize/section/provider"
|
||||||
"github.com/documize/community/wordsmith/log"
|
"github.com/documize/community/wordsmith/log"
|
||||||
"github.com/documize/community/wordsmith/utility"
|
"github.com/documize/community/wordsmith/utility"
|
||||||
|
|
||||||
|
@ -90,9 +90,9 @@ func AddDocumentPage(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
p.Context.Transaction = tx
|
p.Context.Transaction = tx
|
||||||
|
|
||||||
output, ok := section.Render(model.Page.ContentType, model.Meta.Config, model.Meta.RawBody)
|
output, ok := provider.Render(model.Page.ContentType, model.Meta.Config, model.Meta.RawBody)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.ErrorString("section.Render could not find: " + model.Page.ContentType)
|
log.ErrorString("provider.Render could not find: " + model.Page.ContentType)
|
||||||
}
|
}
|
||||||
|
|
||||||
model.Page.Body = output
|
model.Page.Body = output
|
||||||
|
@ -433,9 +433,9 @@ func UpdateDocumentPage(w http.ResponseWriter, r *http.Request) {
|
||||||
model.Page.SetDefaults()
|
model.Page.SetDefaults()
|
||||||
model.Meta.SetDefaults()
|
model.Meta.SetDefaults()
|
||||||
|
|
||||||
output, ok := section.Render(model.Page.ContentType, model.Meta.Config, model.Meta.RawBody)
|
output, ok := provider.Render(model.Page.ContentType, model.Meta.Config, model.Meta.RawBody)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.ErrorString("section.Render could not find: " + model.Page.ContentType)
|
log.ErrorString("provider.Render could not find: " + model.Page.ContentType)
|
||||||
}
|
}
|
||||||
model.Page.Body = output
|
model.Page.Body = output
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
"github.com/documize/community/documize/api/entity"
|
"github.com/documize/community/documize/api/entity"
|
||||||
"github.com/documize/community/documize/api/request"
|
"github.com/documize/community/documize/api/request"
|
||||||
"github.com/documize/community/documize/api/util"
|
"github.com/documize/community/documize/api/util"
|
||||||
"github.com/documize/community/documize/section"
|
"github.com/documize/community/documize/section/provider"
|
||||||
"github.com/documize/community/wordsmith/log"
|
"github.com/documize/community/wordsmith/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ import (
|
||||||
func GetSections(w http.ResponseWriter, r *http.Request) {
|
func GetSections(w http.ResponseWriter, r *http.Request) {
|
||||||
method := "GetSections"
|
method := "GetSections"
|
||||||
|
|
||||||
json, err := json.Marshal(section.GetSectionMeta())
|
json, err := json.Marshal(provider.GetSectionMeta())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeJSONMarshalError(w, method, "section", err)
|
writeJSONMarshalError(w, method, "section", err)
|
||||||
|
@ -70,8 +70,8 @@ func RunSectionCommand(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !section.Command(sectionName, w, r) {
|
if !provider.Command(sectionName, w, r) {
|
||||||
log.ErrorString("Unable to run section.Command() for: " + sectionName)
|
log.ErrorString("Unable to run provider.Command() for: " + sectionName)
|
||||||
writeNotFoundError(w, "RunSectionCommand", sectionName)
|
writeNotFoundError(w, "RunSectionCommand", sectionName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,15 +126,15 @@ func RefreshSections(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ask for data refresh
|
// Ask for data refresh
|
||||||
data, ok := section.Refresh(page.ContentType, pm.Config, pm.RawBody)
|
data, ok := provider.Refresh(page.ContentType, pm.Config, pm.RawBody)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.ErrorString("section.Refresh could not find: " + page.ContentType)
|
log.ErrorString("provider.Refresh could not find: " + page.ContentType)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render again
|
// Render again
|
||||||
body, ok := section.Render(page.ContentType, pm.Config, data)
|
body, ok := provider.Render(page.ContentType, pm.Config, data)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.ErrorString("section.Render could not find: " + page.ContentType)
|
log.ErrorString("provider.Render could not find: " + page.ContentType)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare to stored render
|
// Compare to stored render
|
||||||
|
|
|
@ -14,6 +14,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/documize/community/documize/api/endpoint"
|
"github.com/documize/community/documize/api/endpoint"
|
||||||
|
"github.com/documize/community/documize/section"
|
||||||
"github.com/documize/community/wordsmith/environment"
|
"github.com/documize/community/wordsmith/environment"
|
||||||
|
|
||||||
_ "github.com/go-sql-driver/mysql" // the mysql driver is required behind the scenes
|
_ "github.com/go-sql-driver/mysql" // the mysql driver is required behind the scenes
|
||||||
|
@ -23,5 +24,7 @@ func main() {
|
||||||
environment.Parse("db") // process the db value first
|
environment.Parse("db") // process the db value first
|
||||||
ready := make(chan struct{}, 1) // channel is used for testing
|
ready := make(chan struct{}, 1) // channel is used for testing
|
||||||
|
|
||||||
|
section.Register()
|
||||||
|
|
||||||
endpoint.Serve(ready)
|
endpoint.Serve(ready)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,21 +9,21 @@
|
||||||
//
|
//
|
||||||
// https://documize.com
|
// https://documize.com
|
||||||
|
|
||||||
package section
|
package asana
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/documize/community/documize/section/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
type asana struct {
|
// Provider represents Asana
|
||||||
|
type Provider struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
// Meta describes us.
|
||||||
sectionsMap["asana"] = &asana{}
|
func (*Provider) Meta() provider.TypeMeta {
|
||||||
}
|
section := provider.TypeMeta{}
|
||||||
|
|
||||||
func (*asana) Meta() TypeMeta {
|
|
||||||
section := TypeMeta{}
|
|
||||||
|
|
||||||
section.ID = "3a3f4661-2195-46b1-a69c-546eaccb5f93"
|
section.ID = "3a3f4661-2195-46b1-a69c-546eaccb5f93"
|
||||||
section.Title = "Asana"
|
section.Title = "Asana"
|
||||||
|
@ -35,16 +35,16 @@ func (*asana) Meta() TypeMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command stub.
|
// Command stub.
|
||||||
func (*asana) Command(w http.ResponseWriter, r *http.Request) {
|
func (*Provider) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
writeEmpty(w)
|
provider.WriteEmpty(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render just sends back HMTL as-is.
|
// Render just sends back HMTL as-is.
|
||||||
func (*asana) Render(config, data string) string {
|
func (*Provider) Render(config, data string) string {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh just sends back data as-is.
|
// Refresh just sends back data as-is.
|
||||||
func (*asana) Refresh(config, data string) string {
|
func (*Provider) Refresh(config, data string) string {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
|
@ -9,21 +9,21 @@
|
||||||
//
|
//
|
||||||
// https://documize.com
|
// https://documize.com
|
||||||
|
|
||||||
package section
|
package code
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/documize/community/documize/section/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
type code struct {
|
// Provider represents code snippet
|
||||||
|
type Provider struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
// Meta describes us.
|
||||||
sectionsMap["code"] = &code{}
|
func (*Provider) Meta() provider.TypeMeta {
|
||||||
}
|
section := provider.TypeMeta{}
|
||||||
|
|
||||||
func (*code) Meta() TypeMeta {
|
|
||||||
section := TypeMeta{}
|
|
||||||
|
|
||||||
section.ID = "4f6f2b02-8397-483d-9bb9-eea1fef13304"
|
section.ID = "4f6f2b02-8397-483d-9bb9-eea1fef13304"
|
||||||
section.Title = "Code"
|
section.Title = "Code"
|
||||||
|
@ -35,16 +35,16 @@ func (*code) Meta() TypeMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command stub.
|
// Command stub.
|
||||||
func (*code) Command(w http.ResponseWriter, r *http.Request) {
|
func (*Provider) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
writeEmpty(w)
|
provider.WriteEmpty(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render just sends back HMTL as-is.
|
// Render just sends back HMTL as-is.
|
||||||
func (*code) Render(config, data string) string {
|
func (*Provider) Render(config, data string) string {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh just sends back data as-is.
|
// Refresh just sends back data as-is.
|
||||||
func (*code) Refresh(config, data string) string {
|
func (*Provider) Refresh(config, data string) string {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
|
@ -9,21 +9,21 @@
|
||||||
//
|
//
|
||||||
// https://documize.com
|
// https://documize.com
|
||||||
|
|
||||||
package section
|
package docusign
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/documize/community/documize/section/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
type docusign struct {
|
// Provider represents DocuSign
|
||||||
|
type Provider struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
// Meta describes us.
|
||||||
sectionsMap["docusign"] = &docusign{}
|
func (*Provider) Meta() provider.TypeMeta {
|
||||||
}
|
section := provider.TypeMeta{}
|
||||||
|
|
||||||
func (*docusign) Meta() TypeMeta {
|
|
||||||
section := TypeMeta{}
|
|
||||||
|
|
||||||
section.ID = "a195f983-4bd7-412b-879e-2d71d2f822a7"
|
section.ID = "a195f983-4bd7-412b-879e-2d71d2f822a7"
|
||||||
section.Title = "DocuSign"
|
section.Title = "DocuSign"
|
||||||
|
@ -35,16 +35,16 @@ func (*docusign) Meta() TypeMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command stub.
|
// Command stub.
|
||||||
func (*docusign) Command(w http.ResponseWriter, r *http.Request) {
|
func (*Provider) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
writeEmpty(w)
|
provider.WriteEmpty(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render just sends back HMTL as-is.
|
// Render just sends back HMTL as-is.
|
||||||
func (*docusign) Render(config, data string) string {
|
func (*Provider) Render(config, data string) string {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh just sends back data as-is.
|
// Refresh just sends back data as-is.
|
||||||
func (*docusign) Refresh(config, data string) string {
|
func (*Provider) Refresh(config, data string) string {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
|
@ -9,7 +9,7 @@
|
||||||
//
|
//
|
||||||
// https://documize.com
|
// https://documize.com
|
||||||
|
|
||||||
package section
|
package gemini
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -21,6 +21,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/documize/community/documize/section/provider"
|
||||||
"github.com/documize/community/wordsmith/log"
|
"github.com/documize/community/wordsmith/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -55,17 +56,13 @@ const renderTemplate = `
|
||||||
{{end}}
|
{{end}}
|
||||||
`
|
`
|
||||||
|
|
||||||
type gemini struct {
|
// Provider represents Gemini
|
||||||
|
type Provider struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register ourselves.
|
// Meta describes us.
|
||||||
func init() {
|
func (*Provider) Meta() provider.TypeMeta {
|
||||||
sectionsMap["gemini"] = &gemini{}
|
section := provider.TypeMeta{}
|
||||||
}
|
|
||||||
|
|
||||||
// Meta describes this section type.
|
|
||||||
func (*gemini) Meta() TypeMeta {
|
|
||||||
section := TypeMeta{}
|
|
||||||
section.ID = "23b133f9-4020-4616-9291-a98fb939735f"
|
section.ID = "23b133f9-4020-4616-9291-a98fb939735f"
|
||||||
section.Title = "Gemini"
|
section.Title = "Gemini"
|
||||||
section.Description = "Display work items and tickets from workspaces"
|
section.Description = "Display work items and tickets from workspaces"
|
||||||
|
@ -75,7 +72,7 @@ func (*gemini) Meta() TypeMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render converts Gemini data into HTML suitable for browser rendering.
|
// Render converts Gemini data into HTML suitable for browser rendering.
|
||||||
func (*gemini) Render(config, data string) string {
|
func (*Provider) Render(config, data string) string {
|
||||||
var items []geminiItem
|
var items []geminiItem
|
||||||
var payload = geminiRender{}
|
var payload = geminiRender{}
|
||||||
var c = geminiConfig{}
|
var c = geminiConfig{}
|
||||||
|
@ -99,12 +96,12 @@ func (*gemini) Render(config, data string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command handles authentication, workspace listing and items retrieval.
|
// Command handles authentication, workspace listing and items retrieval.
|
||||||
func (*gemini) Command(w http.ResponseWriter, r *http.Request) {
|
func (*Provider) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
query := r.URL.Query()
|
query := r.URL.Query()
|
||||||
method := query.Get("method")
|
method := query.Get("method")
|
||||||
|
|
||||||
if len(method) == 0 {
|
if len(method) == 0 {
|
||||||
writeMessage(w, "gemini", "missing method name")
|
provider.WriteMessage(w, "gemini", "missing method name")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +116,7 @@ func (*gemini) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh just sends back data as-is.
|
// Refresh just sends back data as-is.
|
||||||
func (*gemini) Refresh(config, data string) (newData string) {
|
func (*Provider) Refresh(config, data string) (newData string) {
|
||||||
var c = geminiConfig{}
|
var c = geminiConfig{}
|
||||||
err := json.Unmarshal([]byte(config), &c)
|
err := json.Unmarshal([]byte(config), &c)
|
||||||
|
|
||||||
|
@ -234,7 +231,7 @@ func auth(w http.ResponseWriter, r *http.Request) {
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
body, err := ioutil.ReadAll(r.Body)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeMessage(w, "gemini", "Bad payload")
|
provider.WriteMessage(w, "gemini", "Bad payload")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,24 +239,24 @@ func auth(w http.ResponseWriter, r *http.Request) {
|
||||||
err = json.Unmarshal(body, &config)
|
err = json.Unmarshal(body, &config)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeMessage(w, "gemini", "Bad payload")
|
provider.WriteMessage(w, "gemini", "Bad payload")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
config.Clean()
|
config.Clean()
|
||||||
|
|
||||||
if len(config.URL) == 0 {
|
if len(config.URL) == 0 {
|
||||||
writeMessage(w, "gemini", "Missing URL value")
|
provider.WriteMessage(w, "gemini", "Missing URL value")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(config.Username) == 0 {
|
if len(config.Username) == 0 {
|
||||||
writeMessage(w, "gemini", "Missing Username value")
|
provider.WriteMessage(w, "gemini", "Missing Username value")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(config.APIKey) == 0 {
|
if len(config.APIKey) == 0 {
|
||||||
writeMessage(w, "gemini", "Missing APIKey value")
|
provider.WriteMessage(w, "gemini", "Missing APIKey value")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,12 +270,12 @@ func auth(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
writeError(w, "gemini", err)
|
provider.WriteError(w, "gemini", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if res.StatusCode != http.StatusOK {
|
if res.StatusCode != http.StatusOK {
|
||||||
writeForbidden(w)
|
provider.WriteForbidden(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,11 +287,11 @@ func auth(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
writeError(w, "gemini", err)
|
provider.WriteError(w, "gemini", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
writeJSON(w, g)
|
provider.WriteJSON(w, g)
|
||||||
}
|
}
|
||||||
|
|
||||||
func workspace(w http.ResponseWriter, r *http.Request) {
|
func workspace(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -302,7 +299,7 @@ func workspace(w http.ResponseWriter, r *http.Request) {
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
body, err := ioutil.ReadAll(r.Body)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeMessage(w, "gemini", "Bad payload")
|
provider.WriteMessage(w, "gemini", "Bad payload")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,29 +307,29 @@ func workspace(w http.ResponseWriter, r *http.Request) {
|
||||||
err = json.Unmarshal(body, &config)
|
err = json.Unmarshal(body, &config)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeMessage(w, "gemini", "Bad payload")
|
provider.WriteMessage(w, "gemini", "Bad payload")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
config.Clean()
|
config.Clean()
|
||||||
|
|
||||||
if len(config.URL) == 0 {
|
if len(config.URL) == 0 {
|
||||||
writeMessage(w, "gemini", "Missing URL value")
|
provider.WriteMessage(w, "gemini", "Missing URL value")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(config.Username) == 0 {
|
if len(config.Username) == 0 {
|
||||||
writeMessage(w, "gemini", "Missing Username value")
|
provider.WriteMessage(w, "gemini", "Missing Username value")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(config.APIKey) == 0 {
|
if len(config.APIKey) == 0 {
|
||||||
writeMessage(w, "gemini", "Missing APIKey value")
|
provider.WriteMessage(w, "gemini", "Missing APIKey value")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.UserID == 0 {
|
if config.UserID == 0 {
|
||||||
writeMessage(w, "gemini", "Missing UserId value")
|
provider.WriteMessage(w, "gemini", "Missing UserId value")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,12 +343,12 @@ func workspace(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
writeError(w, "gemini", err)
|
provider.WriteError(w, "gemini", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if res.StatusCode != http.StatusOK {
|
if res.StatusCode != http.StatusOK {
|
||||||
writeForbidden(w)
|
provider.WriteForbidden(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,11 +360,11 @@ func workspace(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
writeError(w, "gemini", err)
|
provider.WriteError(w, "gemini", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
writeJSON(w, workspace)
|
provider.WriteJSON(w, workspace)
|
||||||
}
|
}
|
||||||
|
|
||||||
func items(w http.ResponseWriter, r *http.Request) {
|
func items(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -375,7 +372,7 @@ func items(w http.ResponseWriter, r *http.Request) {
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
body, err := ioutil.ReadAll(r.Body)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeMessage(w, "gemini", "Bad payload")
|
provider.WriteMessage(w, "gemini", "Bad payload")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,24 +380,24 @@ func items(w http.ResponseWriter, r *http.Request) {
|
||||||
err = json.Unmarshal(body, &config)
|
err = json.Unmarshal(body, &config)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeMessage(w, "gemini", "Bad payload")
|
provider.WriteMessage(w, "gemini", "Bad payload")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
config.Clean()
|
config.Clean()
|
||||||
|
|
||||||
if len(config.URL) == 0 {
|
if len(config.URL) == 0 {
|
||||||
writeMessage(w, "gemini", "Missing URL value")
|
provider.WriteMessage(w, "gemini", "Missing URL value")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(config.Username) == 0 {
|
if len(config.Username) == 0 {
|
||||||
writeMessage(w, "gemini", "Missing Username value")
|
provider.WriteMessage(w, "gemini", "Missing Username value")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(config.APIKey) == 0 {
|
if len(config.APIKey) == 0 {
|
||||||
writeMessage(w, "gemini", "Missing APIKey value")
|
provider.WriteMessage(w, "gemini", "Missing APIKey value")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -409,7 +406,7 @@ func items(w http.ResponseWriter, r *http.Request) {
|
||||||
filter, err := json.Marshal(config.Filter)
|
filter, err := json.Marshal(config.Filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
writeError(w, "gemini", err)
|
provider.WriteError(w, "gemini", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,12 +420,12 @@ func items(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
writeError(w, "gemini", err)
|
provider.WriteError(w, "gemini", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if res.StatusCode != http.StatusOK {
|
if res.StatusCode != http.StatusOK {
|
||||||
writeForbidden(w)
|
provider.WriteForbidden(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,9 +437,9 @@ func items(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
writeError(w, "gemini", err)
|
provider.WriteError(w, "gemini", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
writeJSON(w, items)
|
provider.WriteJSON(w, items)
|
||||||
}
|
}
|
|
@ -1,36 +0,0 @@
|
||||||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
|
||||||
//
|
|
||||||
// This software (Documize Community Edition) is licensed under
|
|
||||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
|
||||||
//
|
|
||||||
// You can operate outside the AGPL restrictions by purchasing
|
|
||||||
// Documize Enterprise Edition and obtaining a commercial license
|
|
||||||
// by contacting <sales@documize.com>.
|
|
||||||
//
|
|
||||||
// https://documize.com
|
|
||||||
|
|
||||||
package section
|
|
||||||
|
|
||||||
import gh "github.com/documize/community/documize/section/github"
|
|
||||||
|
|
||||||
type github struct {
|
|
||||||
gh.GithubT
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*github) Meta() TypeMeta {
|
|
||||||
section := TypeMeta{}
|
|
||||||
|
|
||||||
section.ID = "38c0e4c5-291c-415e-8a4d-262ee80ba5df"
|
|
||||||
section.Title = "GitHub"
|
|
||||||
section.Description = "Code commits and branches"
|
|
||||||
section.ContentType = "github"
|
|
||||||
//section.Preview = true
|
|
||||||
|
|
||||||
section.Callback = gh.Callback
|
|
||||||
|
|
||||||
return section
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
sectionsMap["github"] = &github{}
|
|
||||||
}
|
|
|
@ -24,12 +24,32 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/documize/community/documize/api/request"
|
"github.com/documize/community/documize/api/request"
|
||||||
|
"github.com/documize/community/documize/section/provider"
|
||||||
"github.com/documize/community/wordsmith/log"
|
"github.com/documize/community/wordsmith/log"
|
||||||
|
|
||||||
gogithub "github.com/google/go-github/github"
|
gogithub "github.com/google/go-github/github"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Provider represents GitHub
|
||||||
|
type Provider struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Meta describes us.
|
||||||
|
func (*Provider) Meta() provider.TypeMeta {
|
||||||
|
section := provider.TypeMeta{}
|
||||||
|
|
||||||
|
section.ID = "38c0e4c5-291c-415e-8a4d-262ee80ba5df"
|
||||||
|
section.Title = "GitHub"
|
||||||
|
section.Description = "Code commits and branches"
|
||||||
|
section.ContentType = "github"
|
||||||
|
//section.Preview = true
|
||||||
|
|
||||||
|
section.Callback = Callback
|
||||||
|
|
||||||
|
return section
|
||||||
|
}
|
||||||
|
|
||||||
const configKey = "SECTION-GITHUB"
|
const configKey = "SECTION-GITHUB"
|
||||||
|
|
||||||
func clientID() string {
|
func clientID() string {
|
||||||
|
@ -43,46 +63,15 @@ func authorizationCallbackURL() string {
|
||||||
return request.ConfigString(configKey, "authorizationCallbackURL")
|
return request.ConfigString(configKey, "authorizationCallbackURL")
|
||||||
}
|
}
|
||||||
|
|
||||||
type GithubT struct {
|
|
||||||
|
|
||||||
/* TODO use the shared functions in the "section" package
|
|
||||||
WriteJSON func (w http.ResponseWriter, v interface{})
|
|
||||||
WriteString func(w http.ResponseWriter, data string)
|
|
||||||
WriteEmpty func (w http.ResponseWriter)
|
|
||||||
WriteMarshalError func (w http.ResponseWriter, err error)
|
|
||||||
WriteMessage func (w http.ResponseWriter, section, msg string)
|
|
||||||
WriteError func (w http.ResponseWriter, section string, err error)
|
|
||||||
WriteForbidden func (w http.ResponseWriter)
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
/* done at top level in the "section" package
|
|
||||||
func init() {
|
|
||||||
sectionsMap["github"] = &GithubT{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*GithubT) Meta() TypeMeta {
|
|
||||||
section := TypeMeta{}
|
|
||||||
|
|
||||||
section.ID = "38c0e4c5-291c-415e-8a4d-262ee80ba5df"
|
|
||||||
section.Title = "GitHub"
|
|
||||||
section.Description = "Code commits and branches"
|
|
||||||
section.ContentType = "github"
|
|
||||||
//section.Preview = true
|
|
||||||
|
|
||||||
return section
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Command to run the various functions required...
|
// Command to run the various functions required...
|
||||||
func (t *GithubT) Command(w http.ResponseWriter, r *http.Request) {
|
func (t *Provider) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
query := r.URL.Query()
|
query := r.URL.Query()
|
||||||
method := query.Get("method")
|
method := query.Get("method")
|
||||||
|
|
||||||
if len(method) == 0 {
|
if len(method) == 0 {
|
||||||
msg := "missing method name"
|
msg := "missing method name"
|
||||||
log.ErrorString("github: " + msg)
|
log.ErrorString("github: " + msg)
|
||||||
writeMessage(w, "gitub", msg)
|
provider.WriteMessage(w, "gitub", msg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +82,7 @@ func (t *GithubT) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
ret.CID = clientID()
|
ret.CID = clientID()
|
||||||
ret.URL = authorizationCallbackURL()
|
ret.URL = authorizationCallbackURL()
|
||||||
writeJSON(w, ret)
|
provider.WriteJSON(w, ret)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +92,7 @@ func (t *GithubT) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := "Bad body"
|
msg := "Bad body"
|
||||||
log.ErrorString("github: " + msg)
|
log.ErrorString("github: " + msg)
|
||||||
writeMessage(w, "gitub", msg)
|
provider.WriteMessage(w, "gitub", msg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +101,7 @@ func (t *GithubT) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("github Command Unmarshal", err)
|
log.Error("github Command Unmarshal", err)
|
||||||
writeError(w, "github", err)
|
provider.WriteError(w, "github", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +110,7 @@ func (t *GithubT) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
if len(config.Token) == 0 {
|
if len(config.Token) == 0 {
|
||||||
msg := "Missing token"
|
msg := "Missing token"
|
||||||
log.ErrorString("github: " + msg)
|
log.ErrorString("github: " + msg)
|
||||||
writeMessage(w, "gitub", msg)
|
provider.WriteMessage(w, "gitub", msg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,25 +123,25 @@ func (t *GithubT) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
render, err := t.getCommits(client, config)
|
render, err := t.getCommits(client, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("github getCommits:", err)
|
log.Error("github getCommits:", err)
|
||||||
writeError(w, "github", err)
|
provider.WriteError(w, "github", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
writeJSON(w, render)
|
provider.WriteJSON(w, render)
|
||||||
|
|
||||||
case "repos":
|
case "repos":
|
||||||
|
|
||||||
me, _, err := client.Users.Get("")
|
me, _, err := client.Users.Get("")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("github get user details:", err)
|
log.Error("github get user details:", err)
|
||||||
writeError(w, "github", err)
|
provider.WriteError(w, "github", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
orgs, _, err := client.Organizations.List("", nil)
|
orgs, _, err := client.Organizations.List("", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("github get user's organisations:", err)
|
log.Error("github get user's organisations:", err)
|
||||||
writeError(w, "github", err)
|
provider.WriteError(w, "github", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +164,7 @@ func (t *GithubT) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("github get user/org repositories:", err)
|
log.Error("github get user/org repositories:", err)
|
||||||
writeError(w, "github", err)
|
provider.WriteError(w, "github", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for kr, vr := range repos {
|
for kr, vr := range repos {
|
||||||
|
@ -197,18 +186,18 @@ func (t *GithubT) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
render = sortRepos(render)
|
render = sortRepos(render)
|
||||||
|
|
||||||
writeJSON(w, render)
|
provider.WriteJSON(w, render)
|
||||||
|
|
||||||
case "lists":
|
case "lists":
|
||||||
if config.Owner == "" || config.Repo == "" {
|
if config.Owner == "" || config.Repo == "" {
|
||||||
writeJSON(w, []githubBranch{}) // we have nothing to return
|
provider.WriteJSON(w, []githubBranch{}) // we have nothing to return
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
branches, _, err := client.Repositories.ListBranches(config.Owner, config.Repo,
|
branches, _, err := client.Repositories.ListBranches(config.Owner, config.Repo,
|
||||||
&gogithub.ListOptions{PerPage: 100})
|
&gogithub.ListOptions{PerPage: 100})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("github get branch details:", err)
|
log.Error("github get branch details:", err)
|
||||||
writeError(w, "github", err)
|
provider.WriteError(w, "github", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
render := make([]githubBranch, len(branches))
|
render := make([]githubBranch, len(branches))
|
||||||
|
@ -221,15 +210,14 @@ func (t *GithubT) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
writeJSON(w, render)
|
provider.WriteJSON(w, render)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
provider.WriteEmpty(w)
|
||||||
writeEmpty(w)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*GithubT) githubClient(config githubConfig) *gogithub.Client {
|
func (*Provider) githubClient(config githubConfig) *gogithub.Client {
|
||||||
ts := oauth2.StaticTokenSource(
|
ts := oauth2.StaticTokenSource(
|
||||||
&oauth2.Token{AccessToken: config.Token},
|
&oauth2.Token{AccessToken: config.Token},
|
||||||
)
|
)
|
||||||
|
@ -238,7 +226,7 @@ func (*GithubT) githubClient(config githubConfig) *gogithub.Client {
|
||||||
return gogithub.NewClient(tc)
|
return gogithub.NewClient(tc)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*GithubT) getCommits(client *gogithub.Client, config githubConfig) ([]githubBranchCommits, error) {
|
func (*Provider) getCommits(client *gogithub.Client, config githubConfig) ([]githubBranchCommits, error) {
|
||||||
|
|
||||||
opts := &gogithub.CommitsListOptions{
|
opts := &gogithub.CommitsListOptions{
|
||||||
SHA: config.Branch,
|
SHA: config.Branch,
|
||||||
|
@ -320,7 +308,7 @@ func (*GithubT) getCommits(client *gogithub.Client, config githubConfig) ([]gith
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh ... gets the latest version
|
// Refresh ... gets the latest version
|
||||||
func (t *GithubT) Refresh(configJSON, data string) string {
|
func (t *Provider) Refresh(configJSON, data string) string {
|
||||||
var c = githubConfig{}
|
var c = githubConfig{}
|
||||||
json.Unmarshal([]byte(configJSON), &c)
|
json.Unmarshal([]byte(configJSON), &c)
|
||||||
c.Clean()
|
c.Clean()
|
||||||
|
@ -349,7 +337,7 @@ type githubRender struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render ... just returns the data given
|
// Render ... just returns the data given
|
||||||
func (*GithubT) Render(config, data string) string {
|
func (*Provider) Render(config, data string) string {
|
||||||
|
|
||||||
raw := []githubBranchCommits{}
|
raw := []githubBranchCommits{}
|
||||||
payload := githubRender{}
|
payload := githubRender{}
|
||||||
|
@ -535,68 +523,3 @@ func Callback(res http.ResponseWriter, req *http.Request) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO don't copy these functions... use the ones in the "section" package
|
|
||||||
|
|
||||||
// writeJSON writes data as JSON to HTTP response.
|
|
||||||
func writeJSON(w http.ResponseWriter, v interface{}) {
|
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
j, err := json.Marshal(v)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
writeMarshalError(w, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = w.Write(j)
|
|
||||||
log.IfErr(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// writeString writes string tp HTTP response.
|
|
||||||
func writeString(w http.ResponseWriter, data string) {
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
_, err := w.Write([]byte(data))
|
|
||||||
log.IfErr(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// writeEmpty returns just OK to HTTP response.
|
|
||||||
func writeEmpty(w http.ResponseWriter) {
|
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
_, err := w.Write([]byte("{}"))
|
|
||||||
log.IfErr(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// writeMarshalError write JSON marshalling error to HTTP response.
|
|
||||||
func writeMarshalError(w http.ResponseWriter, err error) {
|
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
|
||||||
_, err2 := w.Write([]byte("{Error: 'JSON marshal failed'}"))
|
|
||||||
log.IfErr(err2)
|
|
||||||
log.Error("JSON marshall failed", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func writeMessage(w http.ResponseWriter, section, msg string) {
|
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
|
||||||
_, err := w.Write([]byte("{Message: " + msg + "}"))
|
|
||||||
log.IfErr(err)
|
|
||||||
log.Info(fmt.Sprintf("Error for section %s: %s", section, msg))
|
|
||||||
}
|
|
||||||
|
|
||||||
func writeError(w http.ResponseWriter, section string, err error) {
|
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
|
||||||
_, err2 := w.Write([]byte("{Error: 'Internal server error'}"))
|
|
||||||
log.IfErr(err2)
|
|
||||||
log.Error(fmt.Sprintf("Error for section %s", section), err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func writeForbidden(w http.ResponseWriter) {
|
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
||||||
w.WriteHeader(http.StatusForbidden)
|
|
||||||
_, err := w.Write([]byte("{Error: 'Unauthorized'}"))
|
|
||||||
log.IfErr(err)
|
|
||||||
}
|
|
||||||
|
|
|
@ -9,21 +9,21 @@
|
||||||
//
|
//
|
||||||
// https://documize.com
|
// https://documize.com
|
||||||
|
|
||||||
package section
|
package intercom
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/documize/community/documize/section/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
type intercom struct {
|
// Provider represents Intercom
|
||||||
|
type Provider struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
// Meta describes us
|
||||||
sectionsMap["intercom"] = &intercom{}
|
func (*Provider) Meta() provider.TypeMeta {
|
||||||
}
|
section := provider.TypeMeta{}
|
||||||
|
|
||||||
func (*intercom) Meta() TypeMeta {
|
|
||||||
section := TypeMeta{}
|
|
||||||
|
|
||||||
section.ID = "bf40314d-3b3c-41f9-b283-517da56aa7e4"
|
section.ID = "bf40314d-3b3c-41f9-b283-517da56aa7e4"
|
||||||
section.Title = "Intercom"
|
section.Title = "Intercom"
|
||||||
|
@ -35,16 +35,16 @@ func (*intercom) Meta() TypeMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command stub.
|
// Command stub.
|
||||||
func (*intercom) Command(w http.ResponseWriter, r *http.Request) {
|
func (*Provider) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
writeEmpty(w)
|
provider.WriteEmpty(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render just sends back HMTL as-is.
|
// Render just sends back HMTL as-is.
|
||||||
func (*intercom) Render(config, data string) string {
|
func (*Provider) Render(config, data string) string {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh just sends back data as-is.
|
// Refresh just sends back data as-is.
|
||||||
func (*intercom) Refresh(config, data string) string {
|
func (*Provider) Refresh(config, data string) string {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
|
@ -9,21 +9,21 @@
|
||||||
//
|
//
|
||||||
// https://documize.com
|
// https://documize.com
|
||||||
|
|
||||||
package section
|
package mailchimp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/documize/community/documize/section/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
type mailchimp struct {
|
// Provider represents Mailchimp
|
||||||
|
type Provider struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
// Meta descibes us.
|
||||||
sectionsMap["mailchimp"] = &mailchimp{}
|
func (*Provider) Meta() provider.TypeMeta {
|
||||||
}
|
section := provider.TypeMeta{}
|
||||||
|
|
||||||
func (*mailchimp) Meta() TypeMeta {
|
|
||||||
section := TypeMeta{}
|
|
||||||
|
|
||||||
section.ID = "feab735b-2d02-4bb1-b501-ced825e22465"
|
section.ID = "feab735b-2d02-4bb1-b501-ced825e22465"
|
||||||
section.Title = "Mailchimp"
|
section.Title = "Mailchimp"
|
||||||
|
@ -35,16 +35,16 @@ func (*mailchimp) Meta() TypeMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command stub.
|
// Command stub.
|
||||||
func (*mailchimp) Command(w http.ResponseWriter, r *http.Request) {
|
func (*Provider) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
writeEmpty(w)
|
provider.WriteEmpty(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render just sends back HMTL as-is.
|
// Render just sends back HMTL as-is.
|
||||||
func (*mailchimp) Render(config, data string) string {
|
func (*Provider) Render(config, data string) string {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh just sends back data as-is.
|
// Refresh just sends back data as-is.
|
||||||
func (*mailchimp) Refresh(config, data string) string {
|
func (*Provider) Refresh(config, data string) string {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
|
@ -9,23 +9,22 @@
|
||||||
//
|
//
|
||||||
// https://documize.com
|
// https://documize.com
|
||||||
|
|
||||||
package section
|
package markdown
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/documize/blackfriday"
|
"github.com/documize/blackfriday"
|
||||||
|
"github.com/documize/community/documize/section/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
type markdown struct {
|
// Provider represents Markdown
|
||||||
|
type Provider struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
// Meta describes us
|
||||||
sectionsMap["markdown"] = &markdown{}
|
func (*Provider) Meta() provider.TypeMeta {
|
||||||
}
|
section := provider.TypeMeta{}
|
||||||
|
|
||||||
func (*markdown) Meta() TypeMeta {
|
|
||||||
section := TypeMeta{}
|
|
||||||
|
|
||||||
section.ID = "1470bb4a-36c6-4a98-a443-096f5658378b"
|
section.ID = "1470bb4a-36c6-4a98-a443-096f5658378b"
|
||||||
section.Title = "Markdown"
|
section.Title = "Markdown"
|
||||||
|
@ -37,18 +36,18 @@ func (*markdown) Meta() TypeMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command stub.
|
// Command stub.
|
||||||
func (*markdown) Command(w http.ResponseWriter, r *http.Request) {
|
func (*Provider) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
writeEmpty(w)
|
provider.WriteEmpty(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render converts markdown data into HTML suitable for browser rendering.
|
// Render converts markdown data into HTML suitable for browser rendering.
|
||||||
func (*markdown) Render(config, data string) string {
|
func (*Provider) Render(config, data string) string {
|
||||||
result := blackfriday.MarkdownCommon([]byte(data))
|
result := blackfriday.MarkdownCommon([]byte(data))
|
||||||
|
|
||||||
return string(result)
|
return string(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh just sends back data as-is.
|
// Refresh just sends back data as-is.
|
||||||
func (*markdown) Refresh(config, data string) string {
|
func (*Provider) Refresh(config, data string) string {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
|
@ -9,7 +9,7 @@
|
||||||
//
|
//
|
||||||
// https://documize.com
|
// https://documize.com
|
||||||
|
|
||||||
package section
|
package provider
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
@ -22,7 +22,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// sectionsMap is where individual sections register themselves.
|
// sectionsMap is where individual sections register themselves.
|
||||||
var sectionsMap = make(map[string]section)
|
var sectionsMap = make(map[string]Provider)
|
||||||
|
|
||||||
// TypeMeta details a "smart section" that represents a "page" in a document.
|
// TypeMeta details a "smart section" that represents a "page" in a document.
|
||||||
type TypeMeta struct {
|
type TypeMeta struct {
|
||||||
|
@ -35,14 +35,24 @@ type TypeMeta struct {
|
||||||
Callback func(http.ResponseWriter, *http.Request) error `json:"-"`
|
Callback func(http.ResponseWriter, *http.Request) error `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// section represents a 'page' in a document.
|
// Provider represents a 'page' in a document.
|
||||||
type section interface {
|
type Provider interface {
|
||||||
Meta() TypeMeta // Meta returns section details
|
Meta() TypeMeta // Meta returns section details
|
||||||
Command(w http.ResponseWriter, r *http.Request) // Command is general-purpose method that can return data to UI
|
Command(w http.ResponseWriter, r *http.Request) // Command is general-purpose method that can return data to UI
|
||||||
Render(config, data string) string // Render converts section data into presentable HTML
|
Render(config, data string) string // Render converts section data into presentable HTML
|
||||||
Refresh(config, data string) string // Refresh returns latest data
|
Refresh(config, data string) string // Refresh returns latest data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register makes document section type available
|
||||||
|
func Register(name string, p Provider) {
|
||||||
|
sectionsMap[name] = p
|
||||||
|
}
|
||||||
|
|
||||||
|
// List returns available types
|
||||||
|
func List() map[string]Provider {
|
||||||
|
return sectionsMap
|
||||||
|
}
|
||||||
|
|
||||||
// GetSectionMeta returns a list of smart sections.
|
// GetSectionMeta returns a list of smart sections.
|
||||||
func GetSectionMeta() []TypeMeta {
|
func GetSectionMeta() []TypeMeta {
|
||||||
sections := []TypeMeta{}
|
sections := []TypeMeta{}
|
||||||
|
@ -92,15 +102,15 @@ func Refresh(section, config, data string) (string, bool) {
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeJSON writes data as JSON to HTTP response.
|
// WriteJSON writes data as JSON to HTTP response.
|
||||||
func writeJSON(w http.ResponseWriter, v interface{}) {
|
func WriteJSON(w http.ResponseWriter, v interface{}) {
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|
||||||
j, err := json.Marshal(v)
|
j, err := json.Marshal(v)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeMarshalError(w, err)
|
WriteMarshalError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,23 +118,23 @@ func writeJSON(w http.ResponseWriter, v interface{}) {
|
||||||
log.IfErr(err)
|
log.IfErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeString writes string tp HTTP response.
|
// WriteString writes string tp HTTP response.
|
||||||
func writeString(w http.ResponseWriter, data string) {
|
func WriteString(w http.ResponseWriter, data string) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, err := w.Write([]byte(data))
|
_, err := w.Write([]byte(data))
|
||||||
log.IfErr(err)
|
log.IfErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeEmpty returns just OK to HTTP response.
|
// WriteEmpty returns just OK to HTTP response.
|
||||||
func writeEmpty(w http.ResponseWriter) {
|
func WriteEmpty(w http.ResponseWriter) {
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, err := w.Write([]byte("{}"))
|
_, err := w.Write([]byte("{}"))
|
||||||
log.IfErr(err)
|
log.IfErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeMarshalError write JSON marshalling error to HTTP response.
|
// WriteMarshalError write JSON marshalling error to HTTP response.
|
||||||
func writeMarshalError(w http.ResponseWriter, err error) {
|
func WriteMarshalError(w http.ResponseWriter, err error) {
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
_, err2 := w.Write([]byte("{Error: 'JSON marshal failed'}"))
|
_, err2 := w.Write([]byte("{Error: 'JSON marshal failed'}"))
|
||||||
|
@ -132,7 +142,8 @@ func writeMarshalError(w http.ResponseWriter, err error) {
|
||||||
log.Error("JSON marshall failed", err)
|
log.Error("JSON marshall failed", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeMessage(w http.ResponseWriter, section, msg string) {
|
// WriteMessage write string to HTTP response.
|
||||||
|
func WriteMessage(w http.ResponseWriter, section, msg string) {
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
_, err := w.Write([]byte("{Message: " + msg + "}"))
|
_, err := w.Write([]byte("{Message: " + msg + "}"))
|
||||||
|
@ -140,7 +151,8 @@ func writeMessage(w http.ResponseWriter, section, msg string) {
|
||||||
log.Info(fmt.Sprintf("Error for section %s: %s", section, msg))
|
log.Info(fmt.Sprintf("Error for section %s: %s", section, msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeError(w http.ResponseWriter, section string, err error) {
|
// WriteError write given error to HTTP response.
|
||||||
|
func WriteError(w http.ResponseWriter, section string, err error) {
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
_, err2 := w.Write([]byte("{Error: 'Internal server error'}"))
|
_, err2 := w.Write([]byte("{Error: 'Internal server error'}"))
|
||||||
|
@ -148,7 +160,8 @@ func writeError(w http.ResponseWriter, section string, err error) {
|
||||||
log.Error(fmt.Sprintf("Error for section %s", section), err)
|
log.Error(fmt.Sprintf("Error for section %s", section), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeForbidden(w http.ResponseWriter) {
|
// WriteForbidden write 403 to HTTP response.
|
||||||
|
func WriteForbidden(w http.ResponseWriter) {
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusForbidden)
|
w.WriteHeader(http.StatusForbidden)
|
||||||
_, err := w.Write([]byte("{Error: 'Unauthorized'}"))
|
_, err := w.Write([]byte("{Error: 'Unauthorized'}"))
|
54
documize/section/register.go
Normal file
54
documize/section/register.go
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||||
|
//
|
||||||
|
// This software (Documize Community Edition) is licensed under
|
||||||
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||||
|
//
|
||||||
|
// You can operate outside the AGPL restrictions by purchasing
|
||||||
|
// Documize Enterprise Edition and obtaining a commercial license
|
||||||
|
// by contacting <sales@documize.com>.
|
||||||
|
//
|
||||||
|
// https://documize.com
|
||||||
|
|
||||||
|
package section
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/documize/community/documize/section/asana"
|
||||||
|
"github.com/documize/community/documize/section/code"
|
||||||
|
"github.com/documize/community/documize/section/docusign"
|
||||||
|
"github.com/documize/community/documize/section/gemini"
|
||||||
|
"github.com/documize/community/documize/section/github"
|
||||||
|
"github.com/documize/community/documize/section/intercom"
|
||||||
|
"github.com/documize/community/documize/section/mailchimp"
|
||||||
|
"github.com/documize/community/documize/section/markdown"
|
||||||
|
"github.com/documize/community/documize/section/provider"
|
||||||
|
"github.com/documize/community/documize/section/salesforce"
|
||||||
|
"github.com/documize/community/documize/section/stripe"
|
||||||
|
"github.com/documize/community/documize/section/table"
|
||||||
|
"github.com/documize/community/documize/section/trello"
|
||||||
|
"github.com/documize/community/documize/section/wysiwyg"
|
||||||
|
"github.com/documize/community/documize/section/zendesk"
|
||||||
|
"github.com/documize/community/wordsmith/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Register sections
|
||||||
|
func Register() {
|
||||||
|
provider.Register("asana", &asana.Provider{})
|
||||||
|
provider.Register("code", &code.Provider{})
|
||||||
|
provider.Register("docusign", &docusign.Provider{})
|
||||||
|
provider.Register("gemini", &gemini.Provider{})
|
||||||
|
provider.Register("github", &github.Provider{})
|
||||||
|
provider.Register("intercom", &intercom.Provider{})
|
||||||
|
provider.Register("mailchimp", &mailchimp.Provider{})
|
||||||
|
provider.Register("markdown", &markdown.Provider{})
|
||||||
|
provider.Register("salesforce", &salesforce.Provider{})
|
||||||
|
provider.Register("stripe", &stripe.Provider{})
|
||||||
|
provider.Register("table", &table.Provider{})
|
||||||
|
provider.Register("trello", &trello.Provider{})
|
||||||
|
provider.Register("wysiwyg", &wysiwyg.Provider{})
|
||||||
|
provider.Register("zendesk", &zendesk.Provider{})
|
||||||
|
|
||||||
|
p := provider.List()
|
||||||
|
log.Info(fmt.Sprintf("Documize registered %d smart sections", len(p)))
|
||||||
|
}
|
|
@ -9,21 +9,21 @@
|
||||||
//
|
//
|
||||||
// https://documize.com
|
// https://documize.com
|
||||||
|
|
||||||
package section
|
package salesforce
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/documize/community/documize/section/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
type salesforce struct {
|
// Provider represents Salesforce
|
||||||
|
type Provider struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
// Meta describes us
|
||||||
sectionsMap["salesforce"] = &salesforce{}
|
func (*Provider) Meta() provider.TypeMeta {
|
||||||
}
|
section := provider.TypeMeta{}
|
||||||
|
|
||||||
func (*salesforce) Meta() TypeMeta {
|
|
||||||
section := TypeMeta{}
|
|
||||||
|
|
||||||
section.ID = "2240c0f8-b795-47b0-bcd4-5f6b171a2ffd"
|
section.ID = "2240c0f8-b795-47b0-bcd4-5f6b171a2ffd"
|
||||||
section.Title = "Salesforce"
|
section.Title = "Salesforce"
|
||||||
|
@ -35,16 +35,16 @@ func (*salesforce) Meta() TypeMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command stub.
|
// Command stub.
|
||||||
func (*salesforce) Command(w http.ResponseWriter, r *http.Request) {
|
func (*Provider) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
writeEmpty(w)
|
provider.WriteEmpty(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render just sends back HMTL as-is.
|
// Render just sends back HMTL as-is.
|
||||||
func (*salesforce) Render(config, data string) string {
|
func (*Provider) Render(config, data string) string {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh just sends back data as-is.
|
// Refresh just sends back data as-is.
|
||||||
func (*salesforce) Refresh(config, data string) string {
|
func (*Provider) Refresh(config, data string) string {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
|
@ -9,21 +9,21 @@
|
||||||
//
|
//
|
||||||
// https://documize.com
|
// https://documize.com
|
||||||
|
|
||||||
package section
|
package stripe
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/documize/community/documize/section/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
type stripe struct {
|
// Provider represents Stripe
|
||||||
|
type Provider struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
// Meta describes us
|
||||||
sectionsMap["stripe"] = &stripe{}
|
func (*Provider) Meta() provider.TypeMeta {
|
||||||
}
|
section := provider.TypeMeta{}
|
||||||
|
|
||||||
func (*stripe) Meta() TypeMeta {
|
|
||||||
section := TypeMeta{}
|
|
||||||
|
|
||||||
section.ID = "cb597d8d-c724-4034-b272-e8d9e261444f"
|
section.ID = "cb597d8d-c724-4034-b272-e8d9e261444f"
|
||||||
section.Title = "Stripe"
|
section.Title = "Stripe"
|
||||||
|
@ -35,16 +35,16 @@ func (*stripe) Meta() TypeMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command stub.
|
// Command stub.
|
||||||
func (*stripe) Command(w http.ResponseWriter, r *http.Request) {
|
func (*Provider) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
writeEmpty(w)
|
provider.WriteEmpty(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render just sends back HMTL as-is.
|
// Render just sends back HMTL as-is.
|
||||||
func (*stripe) Render(config, data string) string {
|
func (*Provider) Render(config, data string) string {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh just sends back data as-is.
|
// Refresh just sends back data as-is.
|
||||||
func (*stripe) Refresh(config, data string) string {
|
func (*Provider) Refresh(config, data string) string {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
|
@ -9,21 +9,21 @@
|
||||||
//
|
//
|
||||||
// https://documize.com
|
// https://documize.com
|
||||||
|
|
||||||
package section
|
package table
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/documize/community/documize/section/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
type table struct {
|
// Provider represents Table
|
||||||
|
type Provider struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
// Meta describes us
|
||||||
sectionsMap["table"] = &table{}
|
func (*Provider) Meta() provider.TypeMeta {
|
||||||
}
|
section := provider.TypeMeta{}
|
||||||
|
|
||||||
func (*table) Meta() TypeMeta {
|
|
||||||
section := TypeMeta{}
|
|
||||||
|
|
||||||
section.ID = "81a2ea93-2dfc-434d-841e-54b832492c92"
|
section.ID = "81a2ea93-2dfc-434d-841e-54b832492c92"
|
||||||
section.Title = "Tabular"
|
section.Title = "Tabular"
|
||||||
|
@ -35,16 +35,16 @@ func (*table) Meta() TypeMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command stub.
|
// Command stub.
|
||||||
func (*table) Command(w http.ResponseWriter, r *http.Request) {
|
func (*Provider) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
writeEmpty(w)
|
provider.WriteEmpty(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render sends back data as-is (HTML).
|
// Render sends back data as-is (HTML).
|
||||||
func (*table) Render(config, data string) string {
|
func (*Provider) Render(config, data string) string {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh just sends back data as-is.
|
// Refresh just sends back data as-is.
|
||||||
func (*table) Refresh(config, data string) string {
|
func (*Provider) Refresh(config, data string) string {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
|
@ -9,7 +9,7 @@
|
||||||
//
|
//
|
||||||
// https://documize.com
|
// https://documize.com
|
||||||
|
|
||||||
package section
|
package trello
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -20,18 +20,17 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/documize/community/documize/section/provider"
|
||||||
"github.com/documize/community/wordsmith/log"
|
"github.com/documize/community/wordsmith/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type trello struct {
|
// Provider represents Trello
|
||||||
|
type Provider struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
// Meta describes us
|
||||||
sectionsMap["trello"] = &trello{}
|
func (*Provider) Meta() provider.TypeMeta {
|
||||||
}
|
section := provider.TypeMeta{}
|
||||||
|
|
||||||
func (*trello) Meta() TypeMeta {
|
|
||||||
section := TypeMeta{}
|
|
||||||
section.ID = "c455a552-202e-441c-ad79-397a8152920b"
|
section.ID = "c455a552-202e-441c-ad79-397a8152920b"
|
||||||
section.Title = "Trello"
|
section.Title = "Trello"
|
||||||
section.Description = "Embed cards from boards and lists"
|
section.Description = "Embed cards from boards and lists"
|
||||||
|
@ -41,12 +40,12 @@ func (*trello) Meta() TypeMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command stub.
|
// Command stub.
|
||||||
func (*trello) Command(w http.ResponseWriter, r *http.Request) {
|
func (*Provider) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
query := r.URL.Query()
|
query := r.URL.Query()
|
||||||
method := query.Get("method")
|
method := query.Get("method")
|
||||||
|
|
||||||
if len(method) == 0 {
|
if len(method) == 0 {
|
||||||
writeMessage(w, "trello", "missing method name")
|
provider.WriteMessage(w, "trello", "missing method name")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +53,7 @@ func (*trello) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
body, err := ioutil.ReadAll(r.Body)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeMessage(w, "trello", "Bad body")
|
provider.WriteMessage(w, "trello", "Bad body")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,19 +61,19 @@ func (*trello) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
err = json.Unmarshal(body, &config)
|
err = json.Unmarshal(body, &config)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, "trello", err)
|
provider.WriteError(w, "trello", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
config.Clean()
|
config.Clean()
|
||||||
|
|
||||||
if len(config.AppKey) == 0 {
|
if len(config.AppKey) == 0 {
|
||||||
writeMessage(w, "trello", "Missing appKey")
|
provider.WriteMessage(w, "trello", "Missing appKey")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(config.Token) == 0 {
|
if len(config.Token) == 0 {
|
||||||
writeMessage(w, "trello", "Missing token")
|
provider.WriteMessage(w, "trello", "Missing token")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,38 +83,38 @@ func (*trello) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
writeError(w, "trello", err)
|
provider.WriteError(w, "trello", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
writeJSON(w, render)
|
provider.WriteJSON(w, render)
|
||||||
|
|
||||||
case "boards":
|
case "boards":
|
||||||
render, err := getBoards(config)
|
render, err := getBoards(config)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
writeError(w, "trello", err)
|
provider.WriteError(w, "trello", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
writeJSON(w, render)
|
provider.WriteJSON(w, render)
|
||||||
|
|
||||||
case "lists":
|
case "lists":
|
||||||
render, err := getLists(config)
|
render, err := getLists(config)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
writeError(w, "trello", err)
|
provider.WriteError(w, "trello", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
writeJSON(w, render)
|
provider.WriteJSON(w, render)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render just sends back HMTL as-is.
|
// Render just sends back HMTL as-is.
|
||||||
func (*trello) Render(config, data string) string {
|
func (*Provider) Render(config, data string) string {
|
||||||
raw := []trelloListCards{}
|
raw := []trelloListCards{}
|
||||||
payload := trelloRender{}
|
payload := trelloRender{}
|
||||||
var c = trelloConfig{}
|
var c = trelloConfig{}
|
||||||
|
@ -141,7 +140,7 @@ func (*trello) Render(config, data string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh just sends back data as-is.
|
// Refresh just sends back data as-is.
|
||||||
func (*trello) Refresh(config, data string) string {
|
func (*Provider) Refresh(config, data string) string {
|
||||||
var c = trelloConfig{}
|
var c = trelloConfig{}
|
||||||
json.Unmarshal([]byte(config), &c)
|
json.Unmarshal([]byte(config), &c)
|
||||||
|
|
|
@ -9,25 +9,21 @@
|
||||||
//
|
//
|
||||||
// https://documize.com
|
// https://documize.com
|
||||||
|
|
||||||
package section
|
package wysiwyg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/documize/community/documize/section/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
// reading:
|
// Provider represents WYSIWYG
|
||||||
// composition
|
type Provider struct {
|
||||||
// reflection
|
|
||||||
|
|
||||||
type wysiwyg struct {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
// Meta describes us
|
||||||
sectionsMap["wysiwyg"] = &wysiwyg{}
|
func (*Provider) Meta() provider.TypeMeta {
|
||||||
}
|
section := provider.TypeMeta{}
|
||||||
|
|
||||||
func (*wysiwyg) Meta() TypeMeta {
|
|
||||||
section := TypeMeta{}
|
|
||||||
|
|
||||||
section.ID = "0f024fa0-d017-4bad-a094-2c13ce6edad7"
|
section.ID = "0f024fa0-d017-4bad-a094-2c13ce6edad7"
|
||||||
section.Title = "Rich Text"
|
section.Title = "Rich Text"
|
||||||
|
@ -39,16 +35,16 @@ func (*wysiwyg) Meta() TypeMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command stub.
|
// Command stub.
|
||||||
func (*wysiwyg) Command(w http.ResponseWriter, r *http.Request) {
|
func (*Provider) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
writeEmpty(w)
|
provider.WriteEmpty(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render returns data as-is (HTML).
|
// Render returns data as-is (HTML).
|
||||||
func (*wysiwyg) Render(config, data string) string {
|
func (*Provider) Render(config, data string) string {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh just sends back data as-is.
|
// Refresh just sends back data as-is.
|
||||||
func (*wysiwyg) Refresh(config, data string) string {
|
func (*Provider) Refresh(config, data string) string {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
|
@ -9,21 +9,21 @@
|
||||||
//
|
//
|
||||||
// https://documize.com
|
// https://documize.com
|
||||||
|
|
||||||
package section
|
package zendesk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/documize/community/documize/section/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
type zendesk struct {
|
// Provider represents Zendesk
|
||||||
|
type Provider struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
// Meta describes us
|
||||||
sectionsMap["zendesk"] = &zendesk{}
|
func (*Provider) Meta() provider.TypeMeta {
|
||||||
}
|
section := provider.TypeMeta{}
|
||||||
|
|
||||||
func (*zendesk) Meta() TypeMeta {
|
|
||||||
section := TypeMeta{}
|
|
||||||
|
|
||||||
section.ID = "05b02331-4ca2-4fc2-a31a-82bc45dceafe"
|
section.ID = "05b02331-4ca2-4fc2-a31a-82bc45dceafe"
|
||||||
section.Title = "Zendesk"
|
section.Title = "Zendesk"
|
||||||
|
@ -35,16 +35,16 @@ func (*zendesk) Meta() TypeMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command stub.
|
// Command stub.
|
||||||
func (*zendesk) Command(w http.ResponseWriter, r *http.Request) {
|
func (*Provider) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
writeEmpty(w)
|
provider.WriteEmpty(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render just sends back HMTL as-is.
|
// Render just sends back HMTL as-is.
|
||||||
func (*zendesk) Render(config, data string) string {
|
func (*Provider) Render(config, data string) string {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh just sends back data as-is.
|
// Refresh just sends back data as-is.
|
||||||
func (*zendesk) Refresh(config, data string) string {
|
func (*Provider) Refresh(config, data string) string {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue