views

package
v0.0.0-...-7a56003 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package views retrieves data and controls which of it is visible.

This is the only package that should interact directly with Twilio - all other code should talk to this package to determine whether a particular piece of information should be visible, or not.

Example
package main

import (
	"context"
	"fmt"
	"time"

	"github.com/kevinburke/handlers"
	"github.com/kevinburke/logrole/config"
	"github.com/kevinburke/logrole/views"
	"github.com/kevinburke/nacl"

	twilio "github.com/kevinburke/twilio-go"
)

func main() {
	c := twilio.NewClient("AC123", "123", nil)
	key := nacl.NewKey()
	permission := config.NewPermission(24 * time.Hour)
	user := config.NewUser(config.AllUserSettings())

	vc := views.NewClient(handlers.Logger, c, key, permission)

	message, _ := vc.GetMessage(context.TODO(), user, "SM123")
	sid, _ := message.Sid()
	fmt.Println(sid)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

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

func NewAlert

func NewAlert(alert *twilio.Alert, p *config.Permission, u *config.User) (*Alert, error)

func (*Alert) CanViewDescription

func (a *Alert) CanViewDescription() bool

func (*Alert) CanViewProperty

func (c *Alert) CanViewProperty(property string) bool

func (*Alert) CanViewStatusCode

func (a *Alert) CanViewStatusCode() bool

func (*Alert) DateCreated

func (a *Alert) DateCreated() (twilio.TwilioTime, error)

func (*Alert) DateUpdated

func (a *Alert) DateUpdated() (twilio.TwilioTime, error)

func (*Alert) Description

func (a *Alert) Description() (string, error)

func (*Alert) ErrorCode

func (a *Alert) ErrorCode() (twilio.Code, error)

func (*Alert) LogLevel

func (a *Alert) LogLevel() (twilio.LogLevel, error)

func (*Alert) MoreInfo

func (a *Alert) MoreInfo() (string, error)

func (*Alert) RequestMethod

func (a *Alert) RequestMethod() (string, error)

func (*Alert) RequestURL

func (a *Alert) RequestURL() (string, error)

func (*Alert) RequestVariables

func (a *Alert) RequestVariables() (twilio.Values, error)

func (*Alert) ResourceSid

func (a *Alert) ResourceSid() (string, error)

func (*Alert) ResponseBody

func (a *Alert) ResponseBody() (string, error)

func (*Alert) ResponseHeaders

func (a *Alert) ResponseHeaders() (twilio.Values, error)

func (*Alert) ServiceSid

func (a *Alert) ServiceSid() (string, error)

func (*Alert) Sid

func (a *Alert) Sid() (string, error)

func (*Alert) StatusCode

func (a *Alert) StatusCode() (int, error)

type AlertPage

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

func NewAlertPage

func NewAlertPage(ap *twilio.AlertPage, p *config.Permission, u *config.User) (*AlertPage, error)

func (*AlertPage) Alerts

func (a *AlertPage) Alerts() []*Alert

func (*AlertPage) NextPageURI

func (ap *AlertPage) NextPageURI() types.NullString

func (*AlertPage) PreviousPageURI

func (ap *AlertPage) PreviousPageURI() types.NullString

func (*AlertPage) ShowHeader

func (ap *AlertPage) ShowHeader(fieldName string) bool

type CacheResult

type CacheResult struct {
	Time  uint64
	Value interface{}
}

type Call

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

func NewCall

func NewCall(call *twilio.Call, p *config.Permission, u *config.User) (*Call, error)

func (*Call) CanViewCallAlerts

func (c *Call) CanViewCallAlerts() bool

func (*Call) CanViewNumRecordings

func (c *Call) CanViewNumRecordings() bool

func (*Call) CanViewProperty

func (c *Call) CanViewProperty(property string) bool

func (*Call) DateCreated

func (c *Call) DateCreated() (twilio.TwilioTime, error)

func (*Call) Direction

func (c *Call) Direction() (twilio.Direction, error)

func (*Call) Duration

func (c *Call) Duration() (twilio.TwilioDuration, error)

func (*Call) Failed

func (c *Call) Failed() (bool, error)

func (*Call) FriendlyPrice

func (c *Call) FriendlyPrice() (string, error)

func (*Call) From

func (c *Call) From() (twilio.PhoneNumber, error)

func (*Call) Sid

func (c *Call) Sid() (string, error)

func (*Call) StartTime

func (c *Call) StartTime() (twilio.TwilioTime, error)

func (*Call) Status

func (c *Call) Status() (twilio.Status, error)

func (*Call) To

func (c *Call) To() (twilio.PhoneNumber, error)

type CallPage

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

func NewCallPage

func NewCallPage(cp *twilio.CallPage, p *config.Permission, u *config.User) (*CallPage, error)

func (*CallPage) Calls

func (cp *CallPage) Calls() []*Call

func (*CallPage) NextPageURI

func (cp *CallPage) NextPageURI() types.NullString

func (*CallPage) PreviousPageURI

func (cp *CallPage) PreviousPageURI() types.NullString

func (*CallPage) ShowHeader

func (cp *CallPage) ShowHeader(fieldName string) bool

ShowHeader returns true if we should show the table header in the call list view. This is true if the user is allowed to view the fieldName on any message in the list, and true if there are no messages.

type Client

type Client interface {
	SetBasicAuth(r *http.Request)
	GetMessage(context.Context, *config.User, string) (*Message, error)
	GetCall(context.Context, *config.User, string) (*Call, error)
	GetConference(context.Context, *config.User, string) (*Conference, error)
	GetIncomingNumber(ctx context.Context, u *config.User, sid string) (*IncomingNumber, error)
	GetIncomingNumberByPN(ctx context.Context, u *config.User, pn string) (*IncomingNumber, error)
	GetAlert(context.Context, *config.User, string) (*Alert, error)
	GetMediaURLs(context.Context, *config.User, string) ([]*url.URL, error)
	GetMessagePageInRange(context.Context, *config.User, time.Time, time.Time, url.Values) (*MessagePage, uint64, error)
	GetCallPageInRange(context.Context, *config.User, time.Time, time.Time, url.Values) (*CallPage, uint64, error)
	GetNumberPage(context.Context, *config.User, url.Values) (*IncomingNumberPage, uint64, error)
	GetConferencePageInRange(context.Context, *config.User, time.Time, time.Time, url.Values) (*ConferencePage, uint64, error)
	GetAlertPageInRange(context.Context, *config.User, time.Time, time.Time, url.Values) (*AlertPage, uint64, error)
	GetNextMessagePageInRange(context.Context, *config.User, time.Time, time.Time, string) (*MessagePage, uint64, error)
	GetNextNumberPage(context.Context, *config.User, string) (*IncomingNumberPage, uint64, error)
	GetNextCallPageInRange(context.Context, *config.User, time.Time, time.Time, string) (*CallPage, uint64, error)
	GetNextConferencePageInRange(context.Context, *config.User, time.Time, time.Time, string) (*ConferencePage, uint64, error)
	GetNextAlertPageInRange(context.Context, *config.User, time.Time, time.Time, string) (*AlertPage, uint64, error)
	GetNextRecordingPage(context.Context, *config.User, string) (*RecordingPage, error)
	GetCallRecordings(context.Context, *config.User, string, url.Values) (*RecordingPage, error)
	GetCallAlerts(context.Context, *config.User, string) (*AlertPage, error)
	CacheCommonQueries(uint, <-chan bool)
	IsTwilioNumber(num twilio.PhoneNumber) bool
}

A Client retrieves resources from a backend API, and hides information that shouldn't be seen before returning them to the caller.

func NewClient

func NewClient(l log.Logger, c *twilio.Client, secretKey *[32]byte, p *config.Permission) Client

NewClient creates a new Client encapsulating the provided values.

type Conference

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

func NewConference

func NewConference(conference *twilio.Conference, p *config.Permission, u *config.User) (*Conference, error)

func (*Conference) CanViewProperty

func (c *Conference) CanViewProperty(property string) bool

func (*Conference) DateCreated

func (c *Conference) DateCreated() (twilio.TwilioTime, error)

func (*Conference) FriendlyName

func (c *Conference) FriendlyName() (string, error)

func (*Conference) Region

func (c *Conference) Region() (string, error)

func (*Conference) Sid

func (c *Conference) Sid() (string, error)

func (*Conference) Status

func (c *Conference) Status() (twilio.Status, error)

type ConferencePage

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

func NewConferencePage

func NewConferencePage(mp *twilio.ConferencePage, p *config.Permission, u *config.User) (*ConferencePage, error)

func (*ConferencePage) Conferences

func (c *ConferencePage) Conferences() []*Conference

func (*ConferencePage) NextPageURI

func (cp *ConferencePage) NextPageURI() types.NullString

func (*ConferencePage) PreviousPageURI

func (cp *ConferencePage) PreviousPageURI() types.NullString

func (*ConferencePage) ShowHeader

func (cp *ConferencePage) ShowHeader(fieldName string) bool

type IncomingNumber

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

func (*IncomingNumber) Beta

func (n *IncomingNumber) Beta() (bool, error)

func (*IncomingNumber) CanViewProperty

func (n *IncomingNumber) CanViewProperty(property string) bool

func (*IncomingNumber) Capabilities

func (n *IncomingNumber) Capabilities() (*twilio.NumberCapability, error)

func (*IncomingNumber) DateCreated

func (a *IncomingNumber) DateCreated() (twilio.TwilioTime, error)

func (*IncomingNumber) EmergencyStatus

func (n *IncomingNumber) EmergencyStatus() (string, error)

func (*IncomingNumber) FriendlyName

func (n *IncomingNumber) FriendlyName() (string, error)

func (*IncomingNumber) PhoneNumber

func (n *IncomingNumber) PhoneNumber() (twilio.PhoneNumber, error)

func (*IncomingNumber) SMSApplicationSid

func (n *IncomingNumber) SMSApplicationSid() (string, error)

func (*IncomingNumber) SMSFallbackMethod

func (n *IncomingNumber) SMSFallbackMethod() (string, error)

func (*IncomingNumber) SMSFallbackURL

func (n *IncomingNumber) SMSFallbackURL() (string, error)

func (*IncomingNumber) SMSMethod

func (n *IncomingNumber) SMSMethod() (string, error)

func (*IncomingNumber) SMSURL

func (n *IncomingNumber) SMSURL() (string, error)

func (*IncomingNumber) Sid

func (n *IncomingNumber) Sid() (string, error)

func (*IncomingNumber) StatusCallback

func (n *IncomingNumber) StatusCallback() (string, error)

func (*IncomingNumber) StatusCallbackMethod

func (n *IncomingNumber) StatusCallbackMethod() (string, error)

func (*IncomingNumber) TrunkSid

func (n *IncomingNumber) TrunkSid() (types.NullString, error)

func (*IncomingNumber) VoiceApplicationSid

func (n *IncomingNumber) VoiceApplicationSid() (string, error)

func (*IncomingNumber) VoiceFallbackMethod

func (n *IncomingNumber) VoiceFallbackMethod() (string, error)

func (*IncomingNumber) VoiceFallbackURL

func (n *IncomingNumber) VoiceFallbackURL() (string, error)

func (*IncomingNumber) VoiceMethod

func (n *IncomingNumber) VoiceMethod() (string, error)

func (*IncomingNumber) VoiceURL

func (n *IncomingNumber) VoiceURL() (string, error)

type IncomingNumberPage

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

func (*IncomingNumberPage) NextPageURI

func (p *IncomingNumberPage) NextPageURI() types.NullString

func (*IncomingNumberPage) Numbers

func (p *IncomingNumberPage) Numbers() []*IncomingNumber

func (*IncomingNumberPage) PreviousPageURI

func (p *IncomingNumberPage) PreviousPageURI() types.NullString

func (*IncomingNumberPage) ShowHeader

func (page *IncomingNumberPage) ShowHeader(property string) bool

type Message

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

func NewMessage

func NewMessage(msg *twilio.Message, p *config.Permission, u *config.User) (*Message, error)

NewMessage creates a new Message, setting fields to be hidden or shown as appropriate for the given Permission and User.

func (*Message) Body

func (m *Message) Body() (string, error)

func (*Message) CanViewMedia

func (m *Message) CanViewMedia() bool

func (*Message) CanViewProperty

func (m *Message) CanViewProperty(property string) bool

CanViewProperty returns true if the caller can access the given property. CanViewProperty panics if the property does not exist. The input is case-sensitive; "MessagingServiceSid" is the correct casing.

func (*Message) DateCreated

func (m *Message) DateCreated() (twilio.TwilioTime, error)

func (*Message) Direction

func (m *Message) Direction() (twilio.Direction, error)

func (*Message) ErrorCode

func (m *Message) ErrorCode() (twilio.Code, error)

func (*Message) ErrorMessage

func (m *Message) ErrorMessage() (string, error)

func (*Message) FriendlyPrice

func (m *Message) FriendlyPrice() (string, error)

func (*Message) From

func (m *Message) From() (twilio.PhoneNumber, error)

func (*Message) MessagingServiceSid

func (m *Message) MessagingServiceSid() (types.NullString, error)

func (*Message) NumMedia

func (m *Message) NumMedia() (twilio.NumMedia, error)

func (*Message) NumSegments

func (m *Message) NumSegments() (twilio.Segments, error)

func (*Message) Price

func (m *Message) Price() (string, error)

func (*Message) PriceUnit

func (m *Message) PriceUnit() (string, error)

func (*Message) Sid

func (m *Message) Sid() (string, error)

func (*Message) Status

func (m *Message) Status() (twilio.Status, error)

func (*Message) To

func (m *Message) To() (twilio.PhoneNumber, error)

type MessagePage

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

func NewMessagePage

func NewMessagePage(mp *twilio.MessagePage, p *config.Permission, u *config.User) (*MessagePage, error)

func (*MessagePage) Messages

func (mp *MessagePage) Messages() []*Message

func (*MessagePage) NextPageURI

func (mp *MessagePage) NextPageURI() types.NullString

func (*MessagePage) PreviousPageURI

func (mp *MessagePage) PreviousPageURI() types.NullString

func (*MessagePage) ShowHeader

func (mp *MessagePage) ShowHeader(fieldName string) bool

ShowHeader returns true if we should show the table header in the message list view. This is true if the user is allowed to view the fieldName on any message in the list, and true if there are no messages.

type Recording

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

func NewRecording

func NewRecording(r *twilio.Recording, p *config.Permission, u *config.User, key *[32]byte) (*Recording, error)

func (*Recording) CanPlay

func (r *Recording) CanPlay() bool

func (*Recording) CanViewProperty

func (r *Recording) CanViewProperty(property string) bool

func (*Recording) DateCreated

func (r *Recording) DateCreated() (twilio.TwilioTime, error)

func (*Recording) Duration

func (r *Recording) Duration() (twilio.TwilioDuration, error)

func (*Recording) FriendlyPrice

func (r *Recording) FriendlyPrice() (string, error)

func (*Recording) MediaType

func (r *Recording) MediaType() string

MediaType returns the Content-Type for the encrypted recording's URL.

func (*Recording) Price

func (r *Recording) Price() (string, error)

func (*Recording) PriceUnit

func (r *Recording) PriceUnit() (string, error)

func (*Recording) Sid

func (r *Recording) Sid() (string, error)

func (*Recording) URL

func (r *Recording) URL() (string, error)

URL returns the encrypted URL of the recording.

type RecordingPage

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

func NewRecordingPage

func NewRecordingPage(rp *twilio.RecordingPage, p *config.Permission, u *config.User, key *[32]byte) (*RecordingPage, error)

func (*RecordingPage) NextPageURI

func (r *RecordingPage) NextPageURI() types.NullString

func (*RecordingPage) Recordings

func (r *RecordingPage) Recordings() []*Recording

Jump to

Keyboard shortcuts

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