sharepoint

package module
v0.0.0-...-46afbc1 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package sharepoint contains a simple interface for retrieving and updating list items from SharePoint Online.

Usage: Each public function from this package requires that an Authentication object be passed in. This object must have all of the public fields instantiated.

Example:

 con := sharepoint.Connection {
        ClientID: "SuperSecretValue",
        TenantID: "0000000-0000000-000000-00001",
        ClientSecret: "SuperSecretValue",
        RefreshToken: "SuperSecretRefreshToken",
        URLHost: "https://contoso.sharepoint.com/teams/marketing",
        DomainHost: "contoso.sharepoint.com",
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToTimeHookFunc

func ToTimeHookFunc() mapstructure.DecodeHookFunc

ToTimeHookFunc is a custom decoder for mapstructure which analyzes if the value being parsed can be converted to a time object

If it can, then the conversion is made. If not, the default value is used.

Types

type Connection

type Connection struct {

	// ClientID holds the client id for the SharePoint connection
	ClientID string `json:"-"`

	// TenantID holds the tenant (or realm) id for the SharePoint connection
	TenantID string `json:"-"`

	// ClientSecret holds the client secret for the SharePoint connection
	ClientSecret string `json:"-"`

	// RefreshToken holds the refresh token for the SharePoint connection
	RefreshToken string `json:"-"`

	// URLHost holds the fqdn to the specific SharePoint group such as constoso.sharepoint.com/teams/marketing
	URLHost string `json:"-"`

	// DomainHost holds the fqdn to the SharePoint root URL such as constoso.sharepoint.com
	DomainHost string `json:"-"`

	// DisableMutations is a flag that when true disables insert and update operations (do this for non-production environments)
	DisableMutations bool `json:"-"`
	// contains filtered or unexported fields
}

Connection holds the configuration settings for the SharePoint online connection.

func (*Connection) DownloadDocumentLibraryFile

func (c *Connection) DownloadDocumentLibraryFile(folderRelativePath string, fileName string) ([]byte, error)

DownloadDocumentLibraryFile returns the byte array pertaining to a file in the passed in document library. If the file is not available, an error is returned.

func (*Connection) GetDocumentLibraryItems

func (c *Connection) GetDocumentLibraryItems(folderRelativePath string) (RawSharePointResponse, error)

GetDocumentLibraryItems will go out the SharePoint site and return an array of items from the specified library. When the list returns empty, an emtpy array will be returned.

func (*Connection) GetListItemByID

func (c *Connection) GetListItemByID(listName string, itemID string, queryString string) (RawSharePointResponse, error)

GetListItemByID populates the output interface with values returned from a sharepoint query where the itemID is specified.

If the itemID is blank, all items from the list will be returned.

func (*Connection) GetListItems

func (c *Connection) GetListItems(listName string, queryString string) (RawSharePointResponse, error)

GetListItems will create the appropriate GET request to SharePoint online from the Authentication, listName, and queryString object and map the result onto a new interface.

func (*Connection) InsertListItem

func (c *Connection) InsertListItem(listName string, item interface{}, fields ...string) error

InsertListItem adds a new Marshalled JSON object to the specified Sharepoint list.

func (*Connection) ScanResponse

func (c *Connection) ScanResponse(rawSPResponse RawSharePointResponse, output interface{}) error

ScanResponse converts a RawSharePointResponse (assuming it has data) into the data type of the output variable. Output variable must be a pointer and must be an array since the type of RawSharePointResponse.Value is an array.

The recommended way to return an output is to pass in an array of a custom struct definition (this assumes that you know which data types SharePoint will return.) Alternatively, you can pass in a []map[string]string to have all values converted to strings or []map[string]interface{} if you want to do the casting yourself.

func (*Connection) Test

func (c *Connection) Test() error

Test attempts to retrieve an access token for the SharePoint connection configuration. If it succeeds, nil is returned. Otherwise, the error is returned.

func (*Connection) UpdateListItem

func (c *Connection) UpdateListItem(listName string, item interface{}, id int, fields ...string) error

UpdateListItem updates an item where a valid sharepoint id is passed in. The item variable passed in will be converted into a JSON object that will be sent in the PATCH request.

By default, all of the "sharepoint" tags on the interface will be passed into the PATCH request. However, this can be overridden by explicitly specifying them in the fields... variable. In this way, the http response body is dynamically created

func (*Connection) UploadDocumentLibraryFile

func (c *Connection) UploadDocumentLibraryFile(folderRelativePath string, fileName string, overwriteOnConflict bool, file []byte) error

UploadDocumentLibraryFile performs a POST request to upload the specified file.

type RawSharePointResponse

type RawSharePointResponse struct {
	Value []interface{} `json:"value" sharepoint:"value"`
}

RawSharePointResponse represents the json data that is returned from a HTTP request

type Token

type Token struct {
	TokenType string `json:"token_type"`
	ExpiresIn string `json:"expires_in"`
	NotBefore string `json:"not_before"` // Unix Timestamp
	ExpiresOn string `json:"expires_on"` // Unix Timestamp
	Resource  string `json:"resource"`
	Token     string `json:"access_token"`
}

Token holds onto the access information returned by the SharePoint Online credentialing service.

It should not be instantiated by the user. Instead, it is created by this package once a successful token has been retrieved.

Jump to

Keyboard shortcuts

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