msgraph

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package gomsgraph is the Microsoft Graph API client for Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddOptions

func AddOptions(urlBase string, opts interface{}) (string, error)

AddOptions adds the parameters in opts as URL query parameters to urlBase. opts must be a struct whose fields may contain "url" tags.

func Bool

func Bool(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range or equal to 202 Accepted. API error responses are expected to have response body, and a JSON response body that maps to ErrorResponse.

The error type will be *RateLimitError for rate limit exceeded errors, *AcceptedError for 202 Accepted status codes, and *TwoFactorAuthError for two-factor authentication errors.

func GetOAuth2Client

func GetOAuth2Client(ctx context.Context, tenantID string, clientID string, clientSecret string) *http.Client

func Int

func Int(v int) *int

Int is a helper routine that allocates a new int value to store v and returns a pointer to it.

func Int64

func Int64(v int64) *int64

Int64 is a helper routine that allocates a new int64 value to store v and returns a pointer to it.

func NewOAuth2ClientFromEnvsOrFail

func NewOAuth2ClientFromEnvsOrFail(ctx context.Context) *http.Client

NewOAuth2ClientFromEnvsOrFail create oauth2 client from environment variables. Fails if envs are not provided.

func String

func String(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

func URL

func URL(resourceName UrlPart, resourceID ...string) *urlStrBuilder

Types

type BaseClient

type BaseClient struct {
	// HTTP client used to communicate with the API.
	Client *http.Client

	// Base URL for API requests with a trailing slash.
	BaseURL *url.URL

	// User agent used when communicating with the MS Graph API.
	UserAgent string
}

A BaseClient manages communication with the MS Graph API.

func (*BaseClient) BareDo

func (c *BaseClient) BareDo(ctx context.Context, req *http.Request) (*Response, error)

BareDo sends an API request and lets you handle the api response. If an error or API Error occurs, the error will contain more information. Otherwise you are supposed to read and close the response's Body. If rate limit is exceeded and reset time is in the future, BareDo returns *RateLimitError immediately without making a network API call.

The provided ctx must be non-nil, if it is nil an error is returned. If it is canceled or times out, ctx.Err() will be returned.

func (*BaseClient) Do

func (c *BaseClient) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it. If v is nil, and no error happens, the response is returned as is. If rate limit is exceeded and reset time is in the future, Do returns *RateLimitError immediately without making a network API call.

The provided ctx must be non-nil, if it is nil an error is returned. If it is canceled or times out, ctx.Err() will be returned.

func (*BaseClient) NewRequest

func (c *BaseClient) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response // HTTP response that caused this error
	Err      *struct {
		Message    string `json:"message"` // error message
		Code       string `json:"code"`    // error code
		InnerError *struct {
			Date            string `json:"date,omitempty"`
			RequestID       string `json:"request-id,omitempty"`
			ClientRequestID string `json:"client-request-id,omitempty"`
		} `json:"innerError,omitempty"`
	} `json:"error"`
}

An ErrorResponse reports one or more errors caused by an API request.

Example:

{
	"error": {
		"code": "BadRequest",
		"message": "Invalid version.",
		"innerError": {
			"date": "2021-04-02T10:39:31",
			"request-id": "d856e698-27f5-4242-9529-555bff83ca4e",
			"client-request-id": "d856e698-27f5-4242-9529-555bff83ca4e"
		}
	}
}

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type Response

type Response struct {
	*http.Response

	NextPageToken string
}

type UrlPart

type UrlPart string

Directories

Path Synopsis
v1

Jump to

Keyboard shortcuts

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