gosnow

package module
v0.0.0-...-876d7d9 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2022 License: MIT Imports: 13 Imported by: 0

README

gosnow

GitHub go.mod Go version GitHub Workflow Status GitHub release (latest by date) GitHub issues GitHub GitHub all releases

Current Ideas:

  • Remove need for "resource"
  • Build out Tables API

GoSnow is a Golang wrapper for the Service Now API.

Install gosnow

go get github.com/michaeldcanady/gosnow

Creating a client instance

client, _ := gosnow.New(username, password, instance)

Create table instance

CSTable, _ := client.Table("TableName")

Get a table value

query := map[string]interface{}{"field": "value"}
respose, _ := CSTable.Get(query, )

Update a table value

query := map[string]interface{}{"field": "value"}
respose, _ := CSTable.Update(query, 1, 0, true, nil)

Delete a table value

query := map[string]interface{}{"field": "value"}
respose, _ := CSTable.Delete(query)

Create a table value

respose, _ := CSTable.Create(query)

Contributing

Author

Michael Canady

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HASMAGIC = false
)

HASMAGIC if the attachment has magic currently not in use

Functions

func AFTER

func AFTER(str string) string

AFTER is obvious

func AND

func AND() string

AND is obvious

func ATORAFTER

func ATORAFTER(str string) string

ATORAFTER is obvious

func ATORBEFORE

func ATORBEFORE(str string) string

ATORBEFORE is obvious

func BEFORE

func BEFORE(str string) string

BEFORE is obvious

func BETWEEN

func BETWEEN(str string) string

BETWEEN is obvious

func DisableLogger

func DisableLogger()

DisableLogger disables the built-in module logger

func Filter

func Filter(str string) string

Filter is a item to base a filter on

func GetWriter

func GetWriter() io.Writer

GetWriter returns the writer

func IS

func IS(str string) string

IS is obvious

func ISANYTHING

func ISANYTHING() string

ISANYTHING is obvious

func ISBETWEEN

func ISBETWEEN(str1, str2 string) string

ISBETWEEN is obvious

func ISDIFFERENTFROM

func ISDIFFERENTFROM(str string) string

ISDIFFERENTFROM is obvious

func ISEMPTY

func ISEMPTY() string

ISEMPTY is obvious

func ISGREATERTHAN

func ISGREATERTHAN(str string) string

ISGREATERTHAN is obvious

func ISGREATERTHANOREQUALS

func ISGREATERTHANOREQUALS(str string) string

ISGREATERTHANOREQUALS is obvious

func ISLESSTHAN

func ISLESSTHAN(str string) string

ISLESSTHAN is obvious

func ISLESSTHANOREQUALS

func ISLESSTHANOREQUALS(str string) string

ISLESSTHANOREQUALS is obvious

func ISLIKE

func ISLIKE(str string) string

ISLIKE is obvious

func ISNOT

func ISNOT(str string) string

ISNOT is obvious

func ISNOTEMPTY

func ISNOTEMPTY() string

ISNOTEMPTY is obvious

func ISNOTLIKE

func ISNOTLIKE(str string) string

ISNOTLIKE is obvious

func ISNOTONEOF

func ISNOTONEOF(str ...string) string

ISNOTONEOF is obvious

func ISONEOF

func ISONEOF(str ...string) string

ISONEOF is obvious

func ISSAMEAS

func ISSAMEAS(str string) string

ISSAMEAS is obvious

func Item

func Item(str ...string) (total string)

Item is deprecated, do not use

func LESSTHAN

func LESSTHAN(str string) string

LESSTHAN is for date-type fields only!

func MORETHAN

func MORETHAN(str string) string

MORETHAN is for date-type fields only!

func NOTON

func NOTON(str string) string

NOTON is obvious

func NewInvalidResource

func NewInvalidResource(msg string) error

func NewMissingParameter

func NewMissingParameter(msg string) error

func ON

func ON(str string) string

ON is obvious

func OR

func OR() string

OR is obvious

func ORDERBY

func ORDERBY(str string) string

ORDERBY is obvious

func ORDERBYDESC

func ORDERBYDESC(str string) string

ORDERBYDESC is obvious

func SetLogOutput

func SetLogOutput(writer io.Writer)

SetLogOutput used to change where the logger writes to

Types

type Attachment

type Attachment struct {
	TableName string
	// contains filtered or unexported fields
}

Attachment the ServiceNow Attachments API

func NewAttachment

func NewAttachment(resource Resource, TableName string) (A Attachment)

NewAttachment returns new instance of the attachments API

func (Attachment) Delete

func (A Attachment) Delete(sys_id string) (Response, error)

Delete delete a specific attachment by sys_id

func (Attachment) Download

func (A Attachment) Download(sys_id string, destinationPath string) (Response, error)

Download download specified attachment to desintationPath from ServiceNow

func (Attachment) Get

func (A Attachment) Get(sys_id string, limit int) (Response, error)

Get used to query a specific attachment

func (Attachment) GetTicket

func (A Attachment) GetTicket(sys_id string, limit int) (Response, error)

func (Attachment) Upload

func (A Attachment) Upload(sys_id, file_path string, multipart bool) (Response, error)

Upload new attachment to table

type Client

type Client struct {
	Username string `validate:"required"`
	Instance string
	Use_ssl  bool

	Session *grequests.Session
	BaseURL *url.URL
	// contains filtered or unexported fields
}

Client used as main client for service-now

func New

func New(username, password, instance string) (C Client, err error)

New Creates a new Client struct using the provided username, password, and instance

func (Client) Attachments

func (C Client) Attachments() (Attachment, error)

Attachments returns a new instance of the Attachments API

func (Client) Resource

func (C Client) Resource(apiPath string) (Resource, error)

Resource is used to create table resources Each new table that can be queried needs its own .Resource

func (Client) ServiceCatalog

func (C Client) ServiceCatalog(apiPath string) (ServiceCatalog, error)

ServiceCatalog returns a new instance of the Service Catalog API

func (Client) Table

func (C Client) Table(tableName string) (Resource, error)

Table returns a new instance of the Table API

type InvalidResource

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

func (InvalidResource) Error

func (err InvalidResource) Error() string

type MissingClientID

type MissingClientID struct {
}

type MissingParameter

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

func (MissingParameter) Error

func (err MissingParameter) Error() string

type OauthClient

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

func NewOauth

func NewOauth(clientId, clientSecret, tokenUpdater string) (O OauthClient, err error)

type ParamsBuilder

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

ParamsBuilder representation of ServiceNow Parameter

func NewParamsBuilder

func NewParamsBuilder() (P ParamsBuilder)

NewParamsBuilder returns new instance of builder for ServiceNow parameters

func (ParamsBuilder) AddCustom

func (P ParamsBuilder) AddCustom(params map[string]interface{})

AddCustom used to add custom parameters

type ReponseError

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

func (ReponseError) Error

func (err ReponseError) Error() string

type Request

type Request struct {
	Session *grequests.Session

	URLBuilder     *url.URL
	Chunk_size     int
	Resource       Resource
	ServiceCatalog ServiceCatalog
	Parameters     ParamsBuilder
	// contains filtered or unexported fields
}

Request used to preform requests against the ServiceNow APIs. Contains the querying URL and the parameters

func NewRequest

func NewRequest(parameters ParamsBuilder, session *grequests.Session, url_builder *url.URL, chunk_size int, resource interface{}) (R Request)

NewRequest used to create a new serviceNow request

type Resource

type Resource struct {
	Session *grequests.Session

	ChunkSize  int
	Parameters ParamsBuilder
	// contains filtered or unexported fields
}

Resource representations of the vague service now API api/now

func NewResource

func NewResource(BaseURL *url.URL, BasePath, ApiPath string, session *grequests.Session, chunkSize int) (R Resource)

NewResource returns a new serviceNow API resource

func (Resource) Create

func (R Resource) Create(args map[string]string) (resp Response, err error)

Create used to create a new record

func (Resource) Delete

func (R Resource) Delete(query interface{}) (Response, error)

Delete used to remove a record

func (Resource) Get

func (R Resource) Get(query interface{}, limits int, offset int, stream bool, fields ...interface{}) (resp Response, err error)

Get used to fetch a record

func (Resource) String

func (R Resource) String() string

returns the string version of the path <[api/now/component/component]>

func (Resource) Update

func (R Resource) Update(query interface{}, args map[string]string) (resp Response, err error)

Update used to modify an existing record

type Response

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

Response a ServiceNow API response

func NewResponse

func NewResponse(response *grequests.Response, chunk_size int, resource Resource, stream bool) (R Response)

NewResponse generates a response struct

func (Response) All

func (R Response) All() ([]map[string]interface{}, int, error)

All returns all found serviceNow records in a map slice

func (Response) First

func (R Response) First() (map[string]interface{}, error)

First returns the first record in the map

type ServiceCatalog

type ServiceCatalog struct {
	Session    *grequests.Session
	ChunkSize  int
	Parameters ParamsBuilder
	// contains filtered or unexported fields
}

ServiceCatalog the service catalog API

func NewServiceCatalog

func NewServiceCatalog(BaseURL *url.URL, BasePath, ApiPath string, session *grequests.Session, chunkSize int) (S ServiceCatalog)

NewServiceCatalog returns a new instance of the service catalog API

func (ServiceCatalog) Get

func (S ServiceCatalog) Get(query interface{}) (resp Response, err error)

Get returns a response and an error

func (ServiceCatalog) String

func (S ServiceCatalog) String() string

String returns a string representation of the path

type ServiceCatalogError

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

func (ServiceCatalogError) Error

func (err ServiceCatalogError) Error() string

Jump to

Keyboard shortcuts

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