Пример #1
0
// Reindex fetches all objects for a class and indexes them.
// Could be long-running.
func (i *Indexer) Reindex(className string) error {
	//TODO(tmc): add counters/progress reporting
	client, err := parse.NewClient(i.appID, "")
	if err != nil {
		return err
	}
	client.TraceOn(log.New(os.Stderr, "[parse api] ", log.LstdFlags))
	client = client.WithMasterKey(i.masterKey)
	iter, err := client.NewQueryIter(className, "{}")
	if err != nil {
		return err
	}
	status := &indexStatus{class: className}

	i.status.register(status)
	defer i.status.unregister(status)

	for o := iter.Next(); o != nil; o = iter.Next() {
		obj := o.(map[string]interface{})
		if err := i.index.Index(obj["objectId"].(string), obj); err != nil {
			log.Println("index error:", err)
		}

		log.Println("index incremented")
		status.incr()
	}
	return iter.Err()
}
Пример #2
0
// RegisterHooks auto-registers the search service with a Parse Application.
func (i *Indexer) RegisterHooks(className string) error {
	c, err := parse.NewClient(i.appID, "")
	c.TraceOn(log.New(os.Stderr, "[parse api] ", log.LstdFlags))
	if err != nil {
		return err
	}
	c = c.WithMasterKey(i.masterKey)
	urlPrefix := os.Getenv("URL")
	if urlPrefix == "" {
		return fmt.Errorf("Skipping registering Webhooks as the 'URL' environment variable is empty.")
	}
	err = squelchAlreadyExists(c.CreateHookFunction(&parse.HookFunction{
		FunctionName: "search",
		URL:          pathJoin(urlPrefix, "search"),
	}))
	if err != nil {
		return err
	}
	err = squelchAlreadyExists(c.CreateTriggerFunction(&parse.TriggerFunction{
		ClassName:   className,
		TriggerName: "afterSave",
		URL:         pathJoin(urlPrefix, "index"),
	}))
	if err != nil {
		return err
	}
	err = squelchAlreadyExists(c.CreateTriggerFunction(&parse.TriggerFunction{
		ClassName:   className,
		TriggerName: "afterDelete",
		URL:         pathJoin(urlPrefix, "unindex"),
	}))
	return err
}
Пример #3
0
func ExampleNewClient() {
	appID := os.Getenv("APPLICATION_ID")
	apiKey := os.Getenv("REST_API_KEY")
	_, err := parse.NewClient(appID, apiKey)
	fmt.Println(err)
	// output: <nil>
}
Пример #4
0
func New(appID, masterKey, className string) (*Iter, error) {
	c, err := parse.NewClient(appID, "")
	if err != nil {
		return nil, err
	}
	c = c.WithMasterKey(masterKey)
	return &Iter{client: c, currentTime: toISO(time.Time{}), class: className}, nil
}
Пример #5
0
func mkclient(t *testing.T) *parse.Client {
	appID := os.Getenv("APPLICATION_ID")
	apiKey := os.Getenv("REST_API_KEY")
	client, err := parse.NewClient(appID, apiKey)
	if testing.Verbose() {
		client.TraceOn(log.New(os.Stderr, "[parse test] ", log.LstdFlags))
	}
	if err != nil {
		t.Fatal(err)
	}
	return client
}
Пример #6
0
func main() {
	appID := os.Getenv("APPLICATION_ID")
	apiKey := os.Getenv("REST_API_KEY")
	client, _ := parse.NewClient(appID, apiKey)

	objID, err := client.Create(&GameScore{
		CheatMode:  true,
		PlayerName: "Sean Plott",
		Score:      1337,
	})
	if err != nil {
		fmt.Println("error:", err)
		os.Exit(1)
	}
	fmt.Println("Created", objID)
}
Пример #7
0
func (c *ServeOptions) Execute(args []string) error {
	log.Println(c)
	schema := schema.New()

	client, err := parse.NewClient(c.ParseApplicationID, c.ParseRESTAPIKey)
	if err != nil {
		return err
	}
	mClient := client.WithMasterKey(c.ParseMasterKey)
	client.TraceOn(log.New(os.Stdout, "[parse] ", log.LstdFlags))
	classes, err := mClient.GetFullSchema()
	if err != nil {
		return fmt.Errorf("error fetching parse app schema: %v", err)
	}
	hooks, err := mClient.GetHookFunctions()
	if err != nil {
		return fmt.Errorf("error fetching parse app hooks: %v", err)
	}
	parseSchema, err := parse_graphql.NewParseSchema(client, classes, hooks)
	if err != nil {
		return err
	}
	for _, class := range parseSchema.Schema {
		parseClass, err := parse_graphql.NewParseClass(client, class.ClassName, parseSchema.Schema)
		if err != nil {
			return err
		}
		schema.Register(parseClass)
	}
	schema.Register(parseSchema) // for top-level fields
	executor := executor.New(schema)

	mux := http.NewServeMux()
	mux.Handle("/", handler.New(executor))
	return http.ListenAndServe(c.ListenAddr, mux)
}