rules

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package rules implements queries for reading and modifying the rules used by streaming search queries.

Reading Rules

Use rules.Get to query for existing rules by ID. If no IDs are given, Get will return all available rules.

myRules := rules.Get(id1, id2, id3)
allRules := rules.Get()

Invoke the query to fetch the rules:

rsp, err := allRules.Invoke(ctx, cli)

The Rules field of the response contains the requested rules.

Updating Rules

Each rule update must either add or delete rules, but not both. Use Adds to describe a Set of rules to add, or Deletes to identify a Set of rules to delete. For example:

adds := rules.Adds{
   {Query: `cat has:images lang:en`, Tag: "cat pictures in English"},
   {Query: `dog or puppy has:images`},
}
dels := rules.Deletes{id1, id2}

Once you have a set, you can build a query to Update or Validate. Update applies the rule change; Validate just reports whether the update would have succeeded (this corresponds to the "dry_run" parameter in the API):

apply := rules.Update(adds)
check := rules.Validate(dels)

Invoke the query to execute the change or check:

rsp, err := apply.Invoke(ctx, cli)

The response will include the updated rules, along with server metadata indicating the effective time of application and summary statistics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Add

type Add struct {
	Query string
	Tag   string
}

Add gives a query and optional tag to define a rule.

type Adds

type Adds []Add

Adds is a Set of search rules to be added.

type Deletes

type Deletes []string

Deletes is a Set of search rule IDs to be deleted.

type Meta

type Meta struct {
	Sent    time.Time `json:"sent"`
	Summary struct {
		Created    int `json:"created,omitempty"`
		NotCreated int `json:"not_created,omitempty"`
		Deleted    int `json:"deleted,omitempty"`
		NotDeleted int `json:"not_deleted,omitempty"`
		Valid      int `json:"valid,omitempty"`
		Invalid    int `json:"invalid,omitempty"`
	} `json:"summary,omitempty"`
}

Meta records rule set metadata reported by the service.

type Query

type Query struct {
	// contains filtered or unexported fields
}

A Query performs a rule fetch or update query.

func Get

func Get(ids ...string) Query

Get constructs a query to fetch the specified streaming search rule IDs. If no rule IDs are given, all known rules are fetched.

API: GET 2/tweets/search/stream/rules

func Update

func Update(r Set) Query

Update constructs a query to add or delete streaming search rules.

API: POST 2/tweets/search/stream/rules

func Validate

func Validate(r Set) Query

Validate constructs a query to validate addition or deletion of streaming search rules, without actually modifying the rules.

API: POST 2/tweets/search/stream/rules, dry_run=true

func (Query) Invoke

func (q Query) Invoke(ctx context.Context, cli *twitter.Client) (*Reply, error)

Invoke executes the query on the given context and client.

type Reply

type Reply struct {
	*twitter.Reply
	Rules []Rule
	Meta  *Meta
}

A Reply is the response from a Query.

type Rule

type Rule struct {
	ID    string `json:"id,omitempty"`
	Value string `json:"value"`
	Tag   string `json:"tag,omitempty"`
}

A Rule encodes a single streaming search rule.

type Set

type Set interface {
	// contains filtered or unexported methods
}

A Set encodes a set of rule additions or deletions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL