fb

package
v0.0.0-...-e977e96 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns whether the error is a fb error with specific code and subcode.

func SetPageAccessToken

func SetPageAccessToken(ctx context.Context, token string) context.Context

SetPageAccessToken adds token to the context to be used for making requests.

Types

type Client

type Client struct {
	*http.Client
	// contains filtered or unexported fields
}

Client holds an http.Client and provides additional functionality.

func NewClient

func NewClient(l log.Logger, token, clientKey string) *Client

NewClient returns a http.Client containing a special transport with injects the version, token, and clientkey.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, url string) error

Delete sends a DELETE request to the given URL.

func (*Client) DeleteJSON

func (c *Client) DeleteJSON(ctx context.Context, url string, req, res interface{}) error

DeleteJSON sends a DELETE request to url with a body and marshals the response to res.

func (*Client) GetJSON

func (c *Client) GetJSON(ctx context.Context, url string, res interface{}) error

GetJSON retrieves url and parses the resulting body into v.

func (*Client) GetList

func (c *Client) GetList(ctx context.Context, url string, res interface{}) error

GetList uses reflection to append to res when the result is a list.

func (*Client) PostJSON

func (c *Client) PostJSON(ctx context.Context, url string, req, res interface{}) error

PostJSON encodes req as JSON into a buffer, sends this as a POST body to the url and parses the response as JSON into res.

func (*Client) PostValues

func (c *Client) PostValues(ctx context.Context, u string, vals url.Values) error

PostValues sends an POST request to the Facebook Graph API.

func (*Client) ReadList

func (c *Client) ReadList(ctx context.Context, url string, res chan<- json.RawMessage) error

ReadList writes json.RawMessage to a chan when the response is a list.

func (*Client) UploadFile

func (c *Client) UploadFile(ctx context.Context, url, name string, r io.Reader, additionalFields map[string]string, res interface{}) error

UploadFile uses a multipart form for uploading a file from r.

type Error

type Error struct {
	Message        string          `json:"message"`
	Type           string          `json:"type"`
	Code           uint64          `json:"code"`
	ErrorSubcode   uint64          `json:"error_subcode"`
	FbtraceID      string          `json:"fbtrace_id"`
	IsTransient    bool            `json:"is_transient"`
	ErrorUserTitle string          `json:"error_user_title"`
	ErrorUserMsg   string          `json:"error_user_msg"`
	ErrorData      json.RawMessage `json:"error_data"`
}

Error implements error.

func (*Error) Error

func (e *Error) Error() string

Error implements error.

type ErrorContainer

type ErrorContainer struct {
	Error *Error `json:"error"`
}

ErrorContainer is a convenient type for embedding in other structs.

func (*ErrorContainer) GetError

func (ec *ErrorContainer) GetError() error

GetError returns an error if available.

type Filter

type Filter struct {
	Field    string      `json:"field"`
	Operator string      `json:"operator"`
	Value    interface{} `json:"value"`
}

Filter is used for filtering lists.

type ID

type ID struct {
	ID string `json:"id"`
}

ID contains the ID field.

type InsightsStatus

type InsightsStatus struct {
	IsCreated bool   `json:"is_created"`
	Current   uint64 `json:"current"`
	Total     uint64 `json:"total"`
}

InsightsStatus contains information about the progress of a single insights report.

type KeyValue

type KeyValue struct {
	ActionType string      `json:"action_type"`
	Value      json.Number `json:"value"`
}

KeyValue represents a Facebook k/v entry in a API JSON response.

type Metadata

type Metadata struct {
	Type        string            `json:"type"`
	Connections map[string]string `json:"connections"`
	Fields      []struct {
		Name        string `json:"name"`
		Description string `json:"description"`
		Type        string `json:"type,omitempty"`
	} `json:"fields"`
}

Metadata contains information about a graph API object.

type MetadataContainer

type MetadataContainer struct {
	Metadata *Metadata `json:"metadata"`
}

MetadataContainer contains a graph APIs object metadata.

type MinimalResponse

type MinimalResponse struct {
	ID          string `json:"id"`
	Success     bool   `json:"success"`
	UpdatedTime Time   `json:"updated_time"`
	ErrorContainer
}

MinimalResponse contains some information about a object being updated.

type Paging

type Paging struct {
	Paging struct {
		Cursors struct {
			Before string `json:"before"`
			After  string `json:"after"`
		} `json:"cursors"`
		Next string `json:"next"`
	} `json:"paging"`
}

Paging is a convenient type for embedding in other structs.

type RouteBuilder

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

RouteBuilder helps building facebook API request routes.

func NewRoute

func NewRoute(version, format string, a ...interface{}) *RouteBuilder

NewRoute starts building a new route.

func (*RouteBuilder) ActionAttributionWindows

func (rb *RouteBuilder) ActionAttributionWindows(s ...string) *RouteBuilder

ActionAttributionWindows sets the action_attribution_windows param or deletes it.

func (*RouteBuilder) ActionBreakdowns

func (rb *RouteBuilder) ActionBreakdowns(s string) *RouteBuilder

ActionBreakdowns sets the action_breakdowns param.

func (*RouteBuilder) AdFormat

func (rb *RouteBuilder) AdFormat(s string) *RouteBuilder

AdFormat sets the ad_format param or deletes it.

func (*RouteBuilder) Aggregation

func (rb *RouteBuilder) Aggregation(s string) *RouteBuilder

Aggregation sets the aggregation param or deletes it.

func (*RouteBuilder) Breakdowns

func (rb *RouteBuilder) Breakdowns(s ...string) *RouteBuilder

Breakdowns sets the breakdowns array param.

func (*RouteBuilder) Class

func (rb *RouteBuilder) Class(s string) *RouteBuilder

Class sets the type param.

func (*RouteBuilder) DailyTimeIncrement

func (rb *RouteBuilder) DailyTimeIncrement(b bool) *RouteBuilder

DailyTimeIncrement sets whether time_increment should be 1.

func (*RouteBuilder) DatePreset

func (rb *RouteBuilder) DatePreset(s string) *RouteBuilder

DatePreset sets date_preset param and deletes the time_range one.

func (*RouteBuilder) DefaultSummary

func (rb *RouteBuilder) DefaultSummary(t bool) *RouteBuilder

DefaultSummary sets default_summary param or deletes it.

func (*RouteBuilder) EffectiveStatus

func (rb *RouteBuilder) EffectiveStatus(s ...string) *RouteBuilder

EffectiveStatus sets the effective_status param or deletes it.

func (*RouteBuilder) ExportFormat

func (rb *RouteBuilder) ExportFormat(s string) *RouteBuilder

ExportFormat sets the export_format level param.

func (*RouteBuilder) Fields

func (rb *RouteBuilder) Fields(f ...string) *RouteBuilder

Fields sets the fields query param.

func (*RouteBuilder) Filter

func (rb *RouteBuilder) Filter(s string) *RouteBuilder

Filter sets the filter param or deletes it.

func (*RouteBuilder) Filtering

func (rb *RouteBuilder) Filtering(f ...Filter) *RouteBuilder

Filtering sets filtering param or deletes it.

func (*RouteBuilder) Level

func (rb *RouteBuilder) Level(s string) *RouteBuilder

Level sets the location_types level param.

func (*RouteBuilder) Limit

func (rb *RouteBuilder) Limit(limit int) *RouteBuilder

Limit sets the limit param.

func (*RouteBuilder) LocationTypes

func (rb *RouteBuilder) LocationTypes(s ...string) *RouteBuilder

LocationTypes sets the location_types array param.

func (*RouteBuilder) Metadata

func (rb *RouteBuilder) Metadata(t bool) *RouteBuilder

Metadata sets the ad_format param or deletes it.

func (*RouteBuilder) Order

func (rb *RouteBuilder) Order(s string) *RouteBuilder

Order sets the order param or deletes it.

func (*RouteBuilder) Q

func (rb *RouteBuilder) Q(s string) *RouteBuilder

Q sets the q param or deletes it.

func (*RouteBuilder) String

func (rb *RouteBuilder) String() string

String implements fmt.Stringer and returns the finished url.

func (*RouteBuilder) Summary

func (rb *RouteBuilder) Summary(s string) *RouteBuilder

Summary sets the summary param or deletes it.

func (*RouteBuilder) TargetingOptionList

func (rb *RouteBuilder) TargetingOptionList(s ...string) *RouteBuilder

TargetingOptionList sets the targeting_option_list param or deletes it.

func (*RouteBuilder) TargetingSpec

func (rb *RouteBuilder) TargetingSpec(ts interface{}) *RouteBuilder

TargetingSpec sets the action_attribution_windows param or deletes it.

func (*RouteBuilder) TimeRange

func (rb *RouteBuilder) TimeRange(minDate, maxDate time.Time) *RouteBuilder

TimeRange sets time_range param and deletes the date_preset one.

func (*RouteBuilder) Type

func (rb *RouteBuilder) Type(s string) *RouteBuilder

Type sets the type param.

type Stat

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

Stat contains stat information about a list job.

func StatFromContext

func StatFromContext(ctx context.Context) *Stat

StatFromContext tries to retrieve the stat from the context.

func (*Stat) Add

func (s *Stat) Add(delta uint64)

Add adds delta to the current value.

func (*Stat) AddToContext

func (s *Stat) AddToContext(ctx context.Context) context.Context

AddToContext adds the stat container to the given context.

func (*Stat) SetCreated

func (s *Stat) SetCreated()

SetCreated sets created to true.

func (*Stat) SetProgress

func (s *Stat) SetProgress(current, total uint64)

SetProgress sets the current and total values.

type StatsContainer

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

StatsContainer contains a set of stats.

func NewStatsContainer

func NewStatsContainer() *StatsContainer

NewStatsContainer initializes a new StatsContainer.

func (*StatsContainer) AddStats

func (sc *StatsContainer) AddStats(id string) *Stat

AddStats adds new stats to the StatsContainer.

func (*StatsContainer) RemoveStats

func (sc *StatsContainer) RemoveStats(id string)

RemoveStats removes the stats from the stats container.

func (*StatsContainer) Stats

func (sc *StatsContainer) Stats() map[string]InsightsStatus

Stats returns a map of all insights stats.

type SummaryContainer

type SummaryContainer struct {
	Summary struct {
		TotalCount uint64 `json:"total_count"`
	} `json:"summary"`
}

SummaryContainer contains a summary with a total count of items.

type Time

type Time time.Time

Time is used since the timestamp format used by the Graph API is not 100% the one used for unmarshaling time fields by the encoding/json Go package.

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type TimeRange

type TimeRange struct {
	Since string `json:"since"`
	Until string `json:"until"`
}

TimeRange is the standard time range used by facebook.

Jump to

Keyboard shortcuts

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