rets

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserAgent   string = "User-Agent"
	Accept      string = "Accept"
	ContentType string = "Content-Type"
	WWWAuth     string = "Www-Authenticate"
	WWWAuthResp string = "Authorization"
)

standard http header names

View Source
const (
	RETSVersion   string = "RETS-Version"
	RETSSessionID string = "RETS-Session-ID"
	RETSRequestID string = "RETS-Request-ID"
	RETSUAAuth    string = "RETS-UA-Authorization"
)

rets http header names

View Source
const (
	// XMLElemRETS tag for RETS responses
	XMLElemRETS = "RETS"
	// XMLElemRETSStatus tag for RETS responses
	XMLElemRETSStatus = "RETS-STATUS"
)
View Source
const (
	// CountNone dont include a count
	CountNone = iota
	// CountIncluded include a count after the data
	CountIncluded = iota
	// CountOnly returns only the count
	CountOnly = iota
)

Count is the type of serverside count response that should be included

View Source
const (
	// StandardNames requests normalized naming
	StandardNames = iota
	// SystemNames (the default) requests whatever field names are used by the server
	SystemNames = iota
)
View Source
const (
	StatusOK          = 0
	StatusSystemError = 10000

	StatusZeroBalance               = 20003
	StatusBrokerCodeRequired        = 20012
	StatusBrokerCodeInvalid         = 20013
	StatusMultipleLogins            = 20022
	StatusServerLoginError          = 20036
	StatusClientAuthFailed          = 20037
	StatusUserAgentAuthRequired     = 20041
	StatusServerTemporarilyDisabled = 20050

	StatusInsecurePassword         = 20140
	StatusRepeatPassword           = 20141
	StatusInvalidEncryptedUsername = 20142

	StatusUnknownQueryField         = 20200
	StatusNoRecords                 = 20201
	StatusInvalidSelect             = 20202
	StatusSearchError               = 20203
	StatusInvalidQuerySyntax        = 20206
	StatusUnauthorizedQuery         = 20207
	StatusMaxRecordsExceeded        = 20208
	StatusTimeout                   = 20209
	StatusTooManyOutstandingQueries = 20210
	StatusQueryTooComplex           = 20211
	StatusInvalidKeyRequest         = 20212 // deprecated
	StatusInvalidKey                = 20213 // deprecated

	StatusInvalidParameter = 20301
	StatusSaveError        = 20302
	StatusUpdateError      = 20303
	StatusWarningResponse2 = 20311
	StatusWarningResponse0 = 20312

	StatusInvalidResource            = 20400
	StatusInvalidType                = 20401
	StatusInvalidIdentifier          = 20402
	StatusObjectNotFound             = 20403
	StatusUnsupportedMimeType        = 20406
	StatusUnauthorizedRetrieval      = 20407
	StatusResourceUnvailable         = 20408
	StatusObjectUnavailable          = 20409
	StatusRequestTooLarge            = 20410
	StatusExecutionTimeout           = 20411
	StatusTooManyOutstandingRequests = 20412
	StatusMiscGetObjectError         = 20413

	StatusUnknwownMetadataResource           = 20500
	StatusUnknownMetadataType                = 20501
	StatusUnknownMetadataIdentifier          = 20502
	StatusNoMetadataFound                    = 20503
	StatusUnsupportedMetadataMimeType        = 20506
	StatusUnauthorizedMetadataRetrieval      = 20507
	StatusMetadataResourceUnvailable         = 20508
	StatusMetadataUnavailable                = 20509
	StatusMetadataRequestTooLarge            = 20510
	StatusMetadataExecutionTimeout           = 20511
	StatusTooManyOutstandingMetadataRequests = 20512

	StatusMiscMetadataError     = 20513
	StatusDTDVersionUnavailable = 20514

	StatusNotLoggedIn     = 20701
	StatusMiscLogoutError = 20702
)
View Source
const CompactDefaultDelim = "\t"

CompactDefaultDelim is the default field delimiter for COMPACT data

View Source
const CompactMetadataDelim = "\t"

CompactMetadataDelim is the only delimiter option for compact metadata

View Source
const (
	DefaultHTTPMethod = "GET"
)

const DefaultTimeout int = 300000

Variables

View Source
var DefaultReEncodeReader = ReEncodeReader

DefaultReEncodeReader allows overriding the re-encoding operation

View Source
var DefaultXMLDecoder = CreateXMLDecoder

DefaultXMLDecoder the variable used to set a selected charset

Functions

func ChangePassword

func ChangePassword(requester Requester, url string) error

ChangePassword ....

func CreateXMLDecoder

func CreateXMLDecoder(input io.Reader, strict bool) *xml.Decoder

CreateXMLDecoder decodes xml using the given the header if needed

func Get

func Get(ctx context.Context, requester Requester, r GetRequest) error

Get gets an arbitrary file from the server or performs an arbitrary action, specified by URI

func GetObjects

func GetObjects(ctx context.Context, requester Requester, r GetObjectRequest) (*http.Response, error)

GetObjects sends the GetObject request

func MetadataResponse

func MetadataResponse(ctx context.Context, requester Requester, r MetadataRequest) (*http.Response, error)

MetadataResponse processes the request... TODO may no longer be necessary

func MetadataStream

func MetadataStream(resp *http.Response, err error) (io.ReadCloser, error)

MetadataStream encodes the http response stream for us

func OptionalIntValue

func OptionalIntValue(values url.Values) func(string, int)

OptionalIntValue ...

func OptionalStringValue

func OptionalStringValue(values url.Values) func(string, string)

OptionalStringValue ...

func PostObject

func PostObject(ctx context.Context, requester Requester, url string) error

PostObject ...

func PrepGetObjects

func PrepGetObjects(r GetObjectRequest) (*http.Request, error)

PrepGetObjects creates an http.Request from a GetObjectRequest

func PrepGetPayloadList

func PrepGetPayloadList(r PayloadListRequest) (*http.Request, error)

PrepGetPayloadList creates an http.Request from a PayloadListRequest

func PrepMetadataRequest

func PrepMetadataRequest(r MetadataRequest) (*http.Request, error)

PrepMetadataRequest creates an http.Request from a MetadataRequest

func PrepSearchRequest

func PrepSearchRequest(r SearchRequest) (*http.Request, error)

PrepSearchRequest creates an http.Request from a SearchRequest

func ReEncodeReader

func ReEncodeReader(input io.ReadCloser, contentType string) io.ReadCloser

ReEncodeReader re-encodes a reader based on the http content type provided

func SearchResponse

func SearchResponse(ctx context.Context, requester Requester, r SearchRequest) (*http.Response, error)

SearchResponse returns the raw stream from the RETS server response

func SearchStream

func SearchStream(resp *http.Response, err error) (io.ReadCloser, error)

SearchStream wraps the body with proper content decoding given the content type or char encoding

func Update

func Update(ctx context.Context, requester Requester, url string) error

Update ...

Types

type CapabilityURLs

type CapabilityURLs struct {
	Response Response

	MemberName,
	User,
	Broker,
	MetadataVersion,
	MinMetadataVersion string
	OfficeList     []string
	TimeoutSeconds int64
	// X-urls
	AdditionalURLs map[string]string
	// urls for web calls
	Action,
	ChangePassword,
	GetMetadata,
	GetObject,
	Login,
	LoginComplete,
	Logout,
	Search,
	Update,
	PostObject,
	GetPayloadList string
}

CapabilityURLs ...

func Login

func Login(ctx context.Context, requester Requester, r LoginRequest) (*CapabilityURLs, error)

Login ...

type CompactData

type CompactData struct {
	Element   string
	Delimiter string
	Attr      map[string]string
	// parse these values out with decode
	CompactDelimiter Delimiter    `xml:"DELIMITER"`
	CompactColumns   CompactRow   `xml:"COLUMNS"`
	CompactRows      []CompactRow `xml:"DATA"`
}

CompactData is the common compact decoded structure

func NewCompactData

func NewCompactData(start xml.StartElement, decoder *xml.Decoder, delim string) (CompactData, error)

NewCompactData parses a CompactData from a start element. If delim is explicitly passed, it will override the DELIMITER element value, which defaults to \t. Pass empty string to automatically parse DELIMITER value or fallback to default of \t.

func (CompactData) Columns

func (cd CompactData) Columns() Row

Columns parses the compact values for the cols

func (CompactData) Entries

func (cd CompactData) Entries() []CompactEntry

Entries turns all rows into maps

func (*CompactData) Indexer

func (cd *CompactData) Indexer() Indexer

Indexer create the cache

func (CompactData) Rows

func (cd CompactData) Rows(each func(i int, row Row))

Rows provides callback to access each row

type CompactEntry

type CompactEntry map[string]string

CompactEntry ...

func (CompactEntry) SetFields

func (ce CompactEntry) SetFields(target interface{})

SetFields ...

type CompactMSystem

type CompactMSystem struct {
	Version  string        `xml:"Version,attr"`
	Date     string        `xml:"Date,attr"`
	Comments string        `xml:"COMMENTS"`
	System   CompactSystem `xml:"SYSTEM"`
}

CompactMSystem ...

type CompactMetadata

type CompactMetadata struct {
	Response Response
	MSystem  CompactMSystem
	Elements map[string][]CompactData
}

CompactMetadata ...

func GetCompactMetadata

func GetCompactMetadata(ctx context.Context, requester Requester, r MetadataRequest) (*CompactMetadata, error)

GetCompactMetadata ...

func ParseMetadataCompactResult

func ParseMetadataCompactResult(body io.ReadCloser) (*CompactMetadata, error)

ParseMetadataCompactResult ...

type CompactRow

type CompactRow string

CompactRow ...

func (CompactRow) Parse

func (cr CompactRow) Parse(delim string) Row

Parse ...

type CompactSearchResult

type CompactSearchResult struct {
	Response      Response
	Count         int
	Delimiter     string
	Columns       Row
	BytesReceived int64
	// contains filtered or unexported fields
}

CompactSearchResult provides processing given the components from the search

func NewCompactSearchResult

func NewCompactSearchResult(body io.ReadCloser) (*CompactSearchResult, error)

NewCompactSearchResult _always_ close this

func SearchCompact

func SearchCompact(ctx context.Context, requester Requester, r SearchRequest) (*CompactSearchResult, error)

SearchCompact wraps up most of the intermediate steps

func (*CompactSearchResult) Close

func (c *CompactSearchResult) Close() error

Close ...

func (*CompactSearchResult) ForEach

func (c *CompactSearchResult) ForEach(each EachRow) (bool, error)

ForEach returns MaxRows and any error that 'each' wont handle

type CompactSystem

type CompactSystem struct {
	ID             string `xml:"SystemID,attr"`
	Description    string `xml:"SystemDescription,attr"`
	TimeZoneOffset string `xml:",attr,omitempty"`
	MetadataID     string `xml:",attr,omitempty"`
}

CompactSystem ...

type Delimiter

type Delimiter struct {
	Value string `xml:"value,attr"`
}

Delimiter is the optional <DELIMITER value="2C"/> element

type DelimiterTag

type DelimiterTag xml.StartElement

DelimiterTag holds the separator for compact data

func (DelimiterTag) Parse

func (dt DelimiterTag) Parse() (string, error)

Parse ...

type Digest

type Digest struct {
	Realm      string
	Nonce      string
	Algorithm  string
	Opaque     string
	Qop        string
	NonceCount int
	// contains filtered or unexported fields
}

Digest http://en.wikipedia.org/wiki/Digest_access_authentication

func NewDigest

func NewDigest(chall string) (*Digest, error)

NewDigest ...

func (*Digest) CreateDigestResponse

func (d *Digest) CreateDigestResponse(username, password, method, uri string) string

CreateDigestResponse ...

type EachPayload

type EachPayload func(CompactData, error) error

EachPayload ...

type EachRow

type EachRow func(row Row, err error) error

EachRow ...

type GetObjectParams

type GetObjectParams struct {
	Resource,
	Type,
	UID,

	ID string
	/** 5.4.2 listing data to be embedded in the response */
	ObjectData []string
	/* 5.4.1 */
	Location int
}

GetObjectParams holds the parameters for GetObject requests

type GetObjectRequest

type GetObjectRequest struct {
	/* 5.3 */
	URL,
	HTTPMethod string
	HTTPFormEncodedValues bool // POST style http params
	GetObjectParams
}

GetObjectRequest ...

type GetObjectResponse

type GetObjectResponse struct {
	Response *http.Response
}

GetObjectResponse is the response holder for processing GetObject requests

func (*GetObjectResponse) Close

func (r *GetObjectResponse) Close() error

Close ...

func (*GetObjectResponse) ForEach

func (r *GetObjectResponse) ForEach(ctx context.Context, result GetObjectResult) error

ForEach ...

type GetObjectResult

type GetObjectResult func(context.Context, *Object, error) error

GetObjectResult is the callback walking func for retrieving objets

type GetRequest

type GetRequest struct {
	URL string
}

GetRequest ...

type Indexer

type Indexer func(col string, row Row) (val string, ok bool)

Indexer provides cached lookup for CompactData

type LoginRequest

type LoginRequest struct {
	URL, HTTPMethod string
}

LoginRequest ...

type LogoutRequest

type LogoutRequest struct {
	URL, HTTPMethod string
}

LogoutRequest ...

type LogoutResponse

type LogoutResponse struct {
	ReplyCode      int
	ReplyText      string
	ConnectTime    uint64
	Billing        string
	SignOffMessage string
}

LogoutResponse ...

func Logout

func Logout(ctx context.Context, requester Requester, r LogoutRequest) (*LogoutResponse, error)

Logout ...

type MetadataParams

type MetadataParams struct {
	Format, MType, ID string
}

MetadataParams for the request

type MetadataRequest

type MetadataRequest struct {
	// RETS request options
	URL, HTTPMethod       string
	HTTPFormEncodedValues bool // POST style http params
	MetadataParams
}

MetadataRequest ...

type Object

type Object struct {
	// ContentID required
	ContentID,
	ContentType string
	// ObjectID 5.5.2 this is probably a bad idea, though its solid with the spec
	ObjectID int
	// optional-ish _must_ return if the request used this field
	UID string
	/** optional */
	Description,
	SubDescription,
	Location string
	/* 5.6.7 - because why would you want to use standard http errors when we can reinvent! */
	RetsError   bool
	RetsMessage *Response
	/* 5.6.3 */
	Preferred bool
	/* 5.6.5 */
	ObjectData map[string]string
	/** it may be wiser to convert this to a readcloser with a content-length */
	Blob []byte
}

Object provides the photo extraction core for RETS section 5.5

func NewObjectFromStream

func NewObjectFromStream(header textproto.MIMEHeader, body io.ReadCloser) (*Object, error)

NewObjectFromStream ...

func (*Object) Content

func (obj *Object) Content() ([]byte, error)

Content is a helper to abstract the location concept (not thread safe)

func (*Object) ContentWithContext

func (obj *Object) ContentWithContext(ctx context.Context) ([]byte, error)

ContentWithContext is a helper to abstract the location concept (not thread safe)

type PayloadList

type PayloadList struct {
	Response Response
	// contains filtered or unexported fields
}

PayloadList ...

func GetPayloadList

func GetPayloadList(ctx context.Context, requester Requester, r PayloadListRequest) (PayloadList, error)

GetPayloadList ...

func NewPayloadList

func NewPayloadList(body io.ReadCloser) (PayloadList, error)

NewPayloadList parse a stream and reads PayloadLists

func (PayloadList) ForEach

func (pl PayloadList) ForEach(each EachPayload) error

ForEach ...

type PayloadListRequest

type PayloadListRequest struct {
	URL, HTTPMethod, ID string
}

PayloadListRequest ...

type RequestIDer

type RequestIDer func(req *http.Request) string

RequestIDer allows functions to be provided to generate request ids

func CreateRETSVersioner

func CreateRETSVersioner(version string) RequestIDer

CreateRETSVersioner provides a hook to get a RETS Version from a request

func CreateSessionIDer

func CreateSessionIDer(jar http.CookieJar) RequestIDer

CreateSessionIDer provides a default implement for extracting the session from a cookie jar

type Requester

type Requester func(ctx context.Context, req *http.Request) (*http.Response, error)

Requester implmenters should not assume any order of ops

func DefaultSession

func DefaultSession(user, pwd, userAgent, userAgentPw, retsVersion string, transport http.RoundTripper) (Requester, error)

DefaultSession configures the default rets session

type Response

type Response struct {
	Code int    `xml:"ReplyCode,attr"`
	Text string `xml:"ReplyText,attr"`
}

Response is the common wrapper details for each response

func ReadResponse

func ReadResponse(body io.ReadCloser) (*Response, error)

ReadResponse ...

type ResponseTag

type ResponseTag xml.StartElement

ResponseTag holds the separator for compact data

func (ResponseTag) Parse

func (start ResponseTag) Parse() (*Response, error)

Parse ...

type Row

type Row []string

Row is a string slice typedef for convenience

type SearchParams

type SearchParams struct {
	SearchType,
	Class string // Residential

	Format,
	Select string

	// Payload should not be used with the format,select pair
	Payload string //The Client may request a specific XML format for the return set.

	// Query should be in the format specified by QueryType
	Query,
	QueryType string // DMQL2 is the standard option

	// RestrictedIndicator is the symbol to be used for fields that are blanked serverside (e.g. ####)
	RestrictedIndicator string

	StandardNames int // (0|1|)
	Count         int // (|0|1|2)
	Limit         int // <0 => "NONE"
	// Offset is properly started at 1, or left blank and assumed to have been 1
	Offset int
}

SearchParams is the configuration for creating a SearchReqeust

type SearchRequest

type SearchRequest struct {
	URL,
	HTTPMethod string
	HTTPFormEncodedValues bool // POST style http params

	SearchParams
}

SearchRequest holds the information needed to send a RETS request

type StandardXMLSearchResult

type StandardXMLSearchResult struct {
	Response Response
	// contains filtered or unexported fields
}

StandardXMLSearchResult ...

func NewStandardXMLSearchResult

func NewStandardXMLSearchResult(body io.ReadCloser) (*StandardXMLSearchResult, error)

NewStandardXMLSearchResult returns an XML search result handler to listen to elements

func StandardXMLSearch

func StandardXMLSearch(ctx context.Context, requester Requester, r SearchRequest) (*StandardXMLSearchResult, error)

StandardXMLSearch if you set the wrong request Format you will get nothing back

func (*StandardXMLSearchResult) Close

func (c *StandardXMLSearchResult) Close() error

Close closesthe connection

func (*StandardXMLSearchResult) ForEach

func (c *StandardXMLSearchResult) ForEach(match minidom.Matcher, each minidom.EachDOM) (int, bool, error)

ForEach returns Count and MaxRows and any error that 'each' wont handle

type UserAgentAuthentication

type UserAgentAuthentication struct {
	Requester Requester

	UserAgent,
	UserAgentPassword string
	// usually a constant, but a func hook just in case it changes mid-session
	GetRETSVersion RequestIDer
	// go create one if you want, sadist
	CreateRequestID RequestIDer
	// extracts from a cookie, but that cookie isnt guaranteed to be in the req that we receive
	GetSessionID RequestIDer
}

UserAgentAuthentication ... RETS 1.8 - 3.10 Computing the RETS-UA-Authorization Value

func (*UserAgentAuthentication) Request

Request allows ua-auth to be hooked into requests prior to sending

type WWWAuthTransport

type WWWAuthTransport struct {
	Requester          Requester
	Username, Password string
	// contains filtered or unexported fields
}

WWWAuthTransport manages rfc2617 authentication

func (*WWWAuthTransport) Request

func (auth *WWWAuthTransport) Request(ctx context.Context, req *http.Request) (*http.Response, error)

Request ...

Jump to

Keyboard shortcuts

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