示例#1
0
// AttributeHandler is a web handler
func AttributeHandler(w http.ResponseWriter, r *http.Request) {
	c, status, err := models.MakeContext(r, w)
	if err != nil {
		c.RespondWithErrorDetail(err, status)
		return
	}

	ctl := AttributeController{}

	switch c.GetHTTPMethod() {
	case "OPTIONS":
		c.RespondWithOptions([]string{"OPTIONS", "GET", "HEAD", "POST", "PUT", "DELETE"})
		return
	case "GET":
		ctl.Read(c)
	case "HEAD":
		ctl.Read(c)
	case "PUT":
		ctl.Update(c)
	case "DELETE":
		ctl.Delete(c)
	default:
		c.RespondWithStatus(http.StatusMethodNotAllowed)
		return
	}
}
示例#2
0
// V1Handler is a web handler
func V1Handler(w http.ResponseWriter, r *http.Request) {
	c, status, err := models.MakeContext(r, w)
	if err != nil {
		c.RespondWithErrorDetail(err, status)
		return
	}

	switch c.GetHTTPMethod() {
	case "OPTIONS":
		c.RespondWithOptions([]string{"OPTIONS", "GET"})
		return
	case "GET":
		c.RespondWithData(
			h.LinkArrayType{Links: []h.LinkType{
				h.GetLink("activity", "", h.ItemTypeActivity, 0),
				h.GetLink("auth", "", h.ItemTypeAuth, 0),
				h.GetLink("comment", "", h.ItemTypeComment, 0),
				h.GetLink("conversation", "", h.ItemTypeConversation, 0),
				h.GetLink("event", "", h.ItemTypeEvent, 0),
				h.GetLink("microcosm", "", h.ItemTypeMicrocosm, 0),
				h.GetLink("poll", "", h.ItemTypePoll, 0),
				h.GetLink("profile", "", h.ItemTypeProfile, 0),
				h.LinkType{Rel: "site", Href: "/api/v1/site"},
				h.GetLink("update", "", h.ItemTypeUpdate, 0),
				h.GetLink("watcher", "", h.ItemTypeWatcher, 0),
				h.GetLink("whoami", "", h.ItemTypeWhoAmI, 0),
			}},
		)
		return
	default:
		c.RespondWithStatus(http.StatusMethodNotAllowed)
		return
	}
}
示例#3
0
// GeoCodeHandler is a web handler
func GeoCodeHandler(w http.ResponseWriter, r *http.Request) {
	c, status, err := models.MakeContext(r, w)
	if err != nil {
		c.RespondWithErrorDetail(err, status)
		return
	}

	if c.Request.Method != "GET" {
		c.RespondWithNotImplemented()
		return
	}

	ctl := GeoCodeController{}
	ctl.Read(c)
}
示例#4
0
// MenuHandler is a web handler
func MenuHandler(w http.ResponseWriter, r *http.Request) {
	c, status, err := models.MakeContext(r, w)
	if err != nil {
		c.RespondWithErrorDetail(err, status)
		return
	}

	var siteID int64

	if id, exists := c.RouteVars["site_id"]; exists {
		siteID, err = strconv.ParseInt(id, 10, 64)
		if err != nil {
			c.RespondWithErrorMessage(
				fmt.Sprintf("The supplied site_id ('%s') is not a number.", id),
				http.StatusBadRequest,
			)
			return
		}
	}

	if siteID == 0 {
		siteID = c.Site.ID
	}

	ctl := MenuController{}

	switch c.GetHTTPMethod() {
	case "OPTIONS":
		c.RespondWithOptions([]string{"OPTIONS", "GET", "HEAD", "POST", "PUT", "DELETE"})
		return
	case "GET":
		ctl.Read(c, siteID)
	case "HEAD":
		ctl.Read(c, siteID)
	case "PUT":
		ctl.Update(c, siteID)
	case "DELETE":
		ctl.Delete(c, siteID)
	default:
		c.RespondWithStatus(http.StatusMethodNotAllowed)
		return
	}
}
示例#5
0
// FilesHandler is a web handler
func FilesHandler(w http.ResponseWriter, r *http.Request) {
	c, status, err := models.MakeContext(r, w)
	if err != nil {
		c.RespondWithErrorDetail(err, status)
	}

	ctl := FilesController{}

	switch c.GetHTTPMethod() {
	case "OPTIONS":
		c.RespondWithOptions([]string{"OPTIONS", "POST"})
		return
	case "POST":
		ctl.Create(c)
	default:
		c.RespondWithStatus(http.StatusMethodNotAllowed)
		return
	}
}
示例#6
0
// TrendingHandler is a web handler
func TrendingHandler(w http.ResponseWriter, r *http.Request) {
	c, status, err := models.MakeContext(r, w)
	if err != nil {
		c.RespondWithErrorDetail(err, status)
		return
	}
	ctl := TrendingController{}
	switch c.GetHTTPMethod() {
	case "OPTIONS":
		c.RespondWithOptions([]string{"OPTIONS", "GET", "HEAD"})
		return
	case "GET":
		ctl.ReadMany(c)
	case "HEAD":
		ctl.ReadMany(c)
	default:
		c.RespondWithStatus(http.StatusMethodNotAllowed)
		return
	}
}
示例#7
0
// APIHandler is a web handler
func APIHandler(w http.ResponseWriter, r *http.Request) {
	c, status, err := models.MakeContext(r, w)
	if err != nil {
		c.RespondWithErrorDetail(err, status)
		return
	}

	switch c.GetHTTPMethod() {
	case "OPTIONS":
		c.RespondWithOptions([]string{"OPTIONS", "GET"})
		return
	case "GET":
		c.RespondWithData(
			h.LinkArrayType{Links: []h.LinkType{
				h.LinkType{Rel: "v1", Href: "/api/v1"},
			}},
		)
		return
	default:
		c.RespondWithStatus(http.StatusMethodNotAllowed)
		return
	}
}
示例#8
0
// LegalsHandler is a web handler
func LegalsHandler(w http.ResponseWriter, r *http.Request) {
	c, status, err := models.MakeContext(r, w)
	if err != nil {
		c.RespondWithErrorDetail(err, status)
		return
	}

	switch c.GetHTTPMethod() {
	case "OPTIONS":
		c.RespondWithOptions([]string{"OPTIONS", "GET"})
		return
	case "GET":
		if c.IsRootSite() {
			// Root site
			c.RespondWithData(
				h.LinkArrayType{Links: []h.LinkType{
					h.LinkType{Rel: "api", Href: "/api/v1/legal/service"},
				}},
			)
			return
		}

		// A customer site
		c.RespondWithData(
			h.LinkArrayType{Links: []h.LinkType{
				h.LinkType{Rel: "cookies", Href: "/api/v1/legal/cookies"},
				h.LinkType{Rel: "privacy", Href: "/api/v1/legal/privacy"},
				h.LinkType{Rel: "terms", Href: "/api/v1/legal/terms"},
			}},
		)
		return
	default:
		c.RespondWithStatus(http.StatusMethodNotAllowed)
		return
	}
}