Documentation ¶
Overview ¶
Package raas facilitates interacting with Workday Reports as a Service (RaaS).
Example (CustomClient) ¶
ExampleCustomClient demonstrates how a custom clients can be implemented.
package main import ( "context" "fmt" "log" "github.com/ianlopshire/go-workday/pkg/raas" "github.com/ianlopshire/go-workday/pkg/wd/session" ) // Worker conforms to the layout of the data in the custom report. type Worker struct { EmployeeID string `xml:"Employee_ID"` FirstName string `xml:"First_Name"` LastName string `xml:"Last_Name"` } // WorkerClient extends raas.Client with the ability to list workers. type WorkerClient struct { *raas.Client } var workerDef = raas.Definition{ Owner: "Owner", Name: "Workers", } // List workers fetches a list of workers via RaaS. func (c *WorkerClient) ListWorkers(ctx context.Context) (workers []Worker, err error) { if err := c.CallXML(ctx, workerDef, nil, &workers); err != nil { return nil, err } return workers, nil } // ExampleCustomClient demonstrates how a custom clients can be implemented. func main() { sess, err := session.NewSession() if err != nil { log.Fatal(err) } raasClient := raas.NewClient(sess) workerClient := &WorkerClient{ Client: raasClient, } // Call the custom implemented ListWorkers method. workers, err := workerClient.ListWorkers(context.Background()) if err != nil { log.Fatal(err) } // Use the resulting data. for _, worker := range workers { fmt.Printf("%+v", worker) } }
Output:
Index ¶
- Constants
- type APIBackend
- type APIError
- type Backend
- type Client
- func (c *Client) CallCSV(ctx context.Context, def Definition, query url.Values) (*csv.Reader, error)
- func (c *Client) CallRaw(ctx context.Context, def Definition, query url.Values) (*bytes.Buffer, error)
- func (c *Client) CallXML(ctx context.Context, def Definition, query url.Values, v interface{}) error
- type Definition
Examples ¶
Constants ¶
const ( DefaultBaseURLProduction = "https://services1.myworkday.com/ccx/service/customreport2" DefaultBaseURLImplementation = "https://wd2-impl-services1.workday.com/ccx/service/customreport2" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIBackend ¶
type APIBackend struct { // HTTPClient is the http client that will be used to request reports. If HTTPClient // is nil http.DefaultClient will be used. HTTPClient *http.Client // BaseURL, if set, will override the base URL used to request reports. This is useful // for testing. BaseURL string }
APIBackend is a low level RaaS client. Most users should use Client instead.
This is the main implementation of the Backend interface. The zero value of APIBackend is usable.
func (*APIBackend) BuildURL ¶
func (b *APIBackend) BuildURL(sess *session.Session, def Definition, query url.Values) (string, error)
BuildURL builds the URL for a report.
The URL format is `{baseURL}/{tenant}/{ownerUsername}/{reportName}`. If a base URL is not provided it will automatically determined based on the provided session.
func (*APIBackend) Call ¶
func (b *APIBackend) Call(ctx context.Context, sess *session.Session, def Definition, query url.Values) (io.ReadCloser, error)
Call fetches report data via the Workday RaaS HTTP endpoint. If the endpoint response contains an error an *APIError will be returned.
Credentials for authentication are taken from the provided session. Currently only basic auth credentials are supported.
Call does not close the http response body.
type Backend ¶
type Backend interface {
Call(ctx context.Context, sess *session.Session, def Definition, query url.Values) (io.ReadCloser, error)
}
Backend defines the low level interface needed to request Workday RaaS report data.
This interface primarily exists for testing.
type Client ¶
Client provides general purpose methods for fetching data via Workday RaaS.
func (*Client) CallCSV ¶
func (c *Client) CallCSV(ctx context.Context, def Definition, query url.Values) (*csv.Reader, error)
CallCSV fetches report data as a CSV and exposes it via a *csv.Reader.
Example ¶
package main import ( "context" "fmt" "io" "log" "net/url" "github.com/ianlopshire/go-workday/pkg/raas" "github.com/ianlopshire/go-workday/pkg/wd/session" ) func main() { sess, err := session.NewSession() if err != nil { log.Fatal(err) } client := raas.NewClient(sess) def := raas.Definition{ Owner: "imlopshire", Name: "example_worker_report", } // Define the values for any report prompts. query := url.Values{} query.Set("workers", "Employee_ID:1001") // Fetch the report data and decode into layout. reader, err := client.CallCSV(context.Background(), def, query) if err != nil { log.Fatal(err) } // Use the resulting data. for { row, err := reader.Read() if err == io.EOF { break } if err != nil { log.Fatal(err) } fmt.Println(row) } }
Output:
func (*Client) CallRaw ¶
func (c *Client) CallRaw(ctx context.Context, def Definition, query url.Values) (*bytes.Buffer, error)
CallRaw fetches report data and returns a buffer of the raw data.
func (*Client) CallXML ¶
func (c *Client) CallXML(ctx context.Context, def Definition, query url.Values, v interface{}) error
CallXML fetches report data as XML and decodes it into v. v must be a compatible with xml.Unmarshal().
Example ¶
package main import ( "context" "fmt" "log" "net/url" "github.com/ianlopshire/go-workday/pkg/raas" "github.com/ianlopshire/go-workday/pkg/wd/session" ) func main() { sess, err := session.NewSession() if err != nil { log.Fatal(err) } client := raas.NewClient(sess) def := raas.Definition{ Owner: "imlopshire", Name: "example_worker_report", } // Define the layout of the data in the custom report. var layout []struct { WID string `xml:"wid"` Name string `xml:"name"` YearsOfService int `xml:"years_of_service"` } // Define the values for any report prompts. query := url.Values{} query.Set("workers", "Employee_ID:1001") // Fetch the report data and decode into layout. err = client.CallXML(context.Background(), def, query, &layout) if err != nil { log.Fatal(err) } // Use the resulting data. for i := range layout { fmt.Printf("%+v", layout[i]) } }
Output:
type Definition ¶
type Definition struct { // Owner is the Workday username of the report owner. Owner string // Name is the name of the custom report in Workday. Name string }
Definition represents a Workday custom report definition.