From 4171abcd8d89df4866b9851fa9c1cd7c32d43eef Mon Sep 17 00:00:00 2001 From: Steven Polley Date: Tue, 5 Feb 2019 22:32:41 -0700 Subject: [PATCH] Add GetSystemMembers and GetSystemMemberByIdentifier --- 3.0/connectwise/system.go | 284 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 274 insertions(+), 10 deletions(-) diff --git a/3.0/connectwise/system.go b/3.0/connectwise/system.go index 4800df1..1ae9f85 100644 --- a/3.0/connectwise/system.go +++ b/3.0/connectwise/system.go @@ -21,24 +21,288 @@ type Callback struct { } `json:"_info"` } +type Member struct { + ID int `json:"id"` + Identifier string `json:"identifier"` + FirstName string `json:"firstName"` + LastName string `json:"lastName,omitempty"` + Title string `json:"title,omitempty"` + ReportCard struct { + ID int `json:"id"` + Name string `json:"name"` + Info struct { + ReportCardHref string `json:"reportCard_href"` + } `json:"_info"` + } `json:"reportCard,omitempty"` + LicenseClass string `json:"licenseClass"` + DisableOnlineFlag bool `json:"disableOnlineFlag"` + EnableMobileFlag bool `json:"enableMobileFlag,omitempty"` + Type struct { + ID int `json:"id"` + Name string `json:"name"` + } `json:"type,omitempty"` + EmployeeIdentifer string `json:"employeeIdentifer,omitempty"` + TimeZone struct { + ID int `json:"id"` + Name string `json:"name"` + Info struct { + TimeZoneSetupHref string `json:"timeZoneSetup_href"` + } `json:"_info"` + } `json:"timeZone,omitempty"` + Country struct { + ID int `json:"id"` + Name string `json:"name"` + Info struct { + CountryHref string `json:"country_href"` + } `json:"_info"` + } `json:"country,omitempty"` + ServiceBoardTeamIds []int `json:"serviceBoardTeamIds"` + EnableMobileGpsFlag bool `json:"enableMobileGpsFlag"` + InactiveFlag bool `json:"inactiveFlag"` + LastLogin string `json:"lastLogin,omitempty"` + Photo struct { + ID int `json:"id"` + Name string `json:"name"` + Info struct { + Filename string `json:"filename"` + DocumentHref string `json:"document_href"` + DocumentDownloadHref string `json:"documentDownload_href"` + } `json:"_info"` + } `json:"photo,omitempty"` + OfficeEmail string `json:"officeEmail,omitempty"` + OfficePhone string `json:"officePhone,omitempty"` + OfficeExtension string `json:"officeExtension,omitempty"` + MobilePhone string `json:"mobilePhone,omitempty"` + MobileExtension string `json:"mobileExtension,omitempty"` + HomePhone string `json:"homePhone,omitempty"` + HomeExtension string `json:"homeExtension,omitempty"` + DefaultEmail string `json:"defaultEmail"` + DefaultPhone string `json:"defaultPhone"` + SecurityRole struct { + ID int `json:"id"` + Name string `json:"name"` + } `json:"securityRole,omitempty"` + AdminFlag bool `json:"adminFlag"` + StructureLevel struct { + ID int `json:"id"` + Name string `json:"name"` + Info struct { + } `json:"_info"` + } `json:"structureLevel"` + SecurityLocation struct { + ID int `json:"id"` + Name string `json:"name"` + Info struct { + LocationHref string `json:"location_href"` + } `json:"_info"` + } `json:"securityLocation"` + DefaultLocation struct { + ID int `json:"id"` + Name string `json:"name"` + Info struct { + LocationHref string `json:"location_href"` + } `json:"_info"` + } `json:"defaultLocation,omitempty"` + DefaultDepartment struct { + ID int `json:"id"` + Identifier string `json:"identifier"` + Name string `json:"name"` + Info struct { + DepartmentHref string `json:"department_href"` + } `json:"_info"` + } `json:"defaultDepartment,omitempty"` + RestrictLocationFlag bool `json:"restrictLocationFlag"` + RestrictDepartmentFlag bool `json:"restrictDepartmentFlag"` + WorkRole struct { + ID int `json:"id"` + Name string `json:"name"` + Info struct { + WorkRoleHref string `json:"workRole_href"` + } `json:"_info"` + } `json:"workRole,omitempty"` + WorkType struct { + ID int `json:"id"` + Name string `json:"name"` + Info struct { + WorkTypeHref string `json:"workType_href"` + } `json:"_info"` + } `json:"workType,omitempty"` + TimeApprover struct { + ID int `json:"id"` + Identifier string `json:"identifier"` + Name string `json:"name"` + Info struct { + MemberHref string `json:"member_href"` + } `json:"_info"` + } `json:"timeApprover,omitempty"` + ExpenseApprover struct { + ID int `json:"id"` + Identifier string `json:"identifier"` + Name string `json:"name"` + Info struct { + MemberHref string `json:"member_href"` + } `json:"_info"` + } `json:"expenseApprover,omitempty"` + DailyCapacity float64 `json:"dailyCapacity,omitempty"` + HourlyCost float64 `json:"hourlyCost"` + IncludeInUtilizationReportingFlag bool `json:"includeInUtilizationReportingFlag"` + RequireExpenseEntryFlag bool `json:"requireExpenseEntryFlag"` + RequireTimeSheetEntryFlag bool `json:"requireTimeSheetEntryFlag"` + RequireStartAndEndTimeOnTimeEntryFlag bool `json:"requireStartAndEndTimeOnTimeEntryFlag"` + AllowInCellEntryOnTimeSheet bool `json:"allowInCellEntryOnTimeSheet"` + EnterTimeAgainstCompanyFlag bool `json:"enterTimeAgainstCompanyFlag"` + AllowExpensesEnteredAgainstCompaniesFlag bool `json:"allowExpensesEnteredAgainstCompaniesFlag"` + TimeReminderEmailFlag bool `json:"timeReminderEmailFlag"` + DaysTolerance int `json:"daysTolerance,omitempty"` + MinimumHours float64 `json:"minimumHours,omitempty"` + TimeSheetStartDate string `json:"timeSheetStartDate"` + HireDate string `json:"hireDate,omitempty"` + ServiceDefaultLocation struct { + ID int `json:"id"` + Name string `json:"name"` + Info struct { + LocationHref string `json:"location_href"` + } `json:"_info"` + } `json:"serviceDefaultLocation,omitempty"` + ServiceDefaultDepartment struct { + ID int `json:"id"` + Identifier string `json:"identifier"` + Name string `json:"name"` + Info struct { + DepartmentHref string `json:"department_href"` + } `json:"_info"` + } `json:"serviceDefaultDepartment,omitempty"` + ServiceDefaultBoard struct { + ID int `json:"id"` + Name string `json:"name"` + Info struct { + BoardHref string `json:"board_href"` + } `json:"_info"` + } `json:"serviceDefaultBoard,omitempty"` + RestrictServiceDefaultLocationFlag bool `json:"restrictServiceDefaultLocationFlag"` + RestrictServiceDefaultDepartmentFlag bool `json:"restrictServiceDefaultDepartmentFlag"` + ExcludedServiceBoardIds []int `json:"excludedServiceBoardIds"` + ProjectDefaultLocation struct { + ID int `json:"id"` + Name string `json:"name"` + Info struct { + LocationHref string `json:"location_href"` + } `json:"_info"` + } `json:"projectDefaultLocation,omitempty"` + ProjectDefaultDepartment struct { + ID int `json:"id"` + Identifier string `json:"identifier"` + Name string `json:"name"` + Info struct { + DepartmentHref string `json:"department_href"` + } `json:"_info"` + } `json:"projectDefaultDepartment,omitempty"` + RestrictProjectDefaultLocationFlag bool `json:"restrictProjectDefaultLocationFlag"` + RestrictProjectDefaultDepartmentFlag bool `json:"restrictProjectDefaultDepartmentFlag"` + ExcludedProjectBoardIds []interface{} `json:"excludedProjectBoardIds"` + ScheduleDefaultLocation struct { + ID int `json:"id"` + Name string `json:"name"` + Info struct { + LocationHref string `json:"location_href"` + } `json:"_info"` + } `json:"scheduleDefaultLocation,omitempty"` + ScheduleDefaultDepartment struct { + ID int `json:"id"` + Identifier string `json:"identifier"` + Name string `json:"name"` + Info struct { + DepartmentHref string `json:"department_href"` + } `json:"_info"` + } `json:"scheduleDefaultDepartment,omitempty"` + ScheduleCapacity float64 `json:"scheduleCapacity,omitempty"` + RestrictScheduleFlag bool `json:"restrictScheduleFlag"` + HideMemberInDispatchPortalFlag bool `json:"hideMemberInDispatchPortalFlag"` + SalesDefaultLocation struct { + ID int `json:"id"` + Name string `json:"name"` + Info struct { + LocationHref string `json:"location_href"` + } `json:"_info"` + } `json:"salesDefaultLocation,omitempty"` + RestrictDefaultSalesTerritoryFlag bool `json:"restrictDefaultSalesTerritoryFlag"` + RestrictDefaultWarehouseFlag bool `json:"restrictDefaultWarehouseFlag"` + RestrictDefaultWarehouseBinFlag bool `json:"restrictDefaultWarehouseBinFlag"` + MapiName string `json:"mapiName,omitempty"` + CalendarSyncIntegrationFlag bool `json:"calendarSyncIntegrationFlag"` + EnableLdapAuthenticationFlag bool `json:"enableLdapAuthenticationFlag"` + CompanyActivityTabFormat string `json:"companyActivityTabFormat,omitempty"` + InvoiceTimeTabFormat string `json:"invoiceTimeTabFormat,omitempty"` + InvoiceScreenDefaultTabFormat string `json:"invoiceScreenDefaultTabFormat"` + InvoicingDisplayOptions string `json:"invoicingDisplayOptions"` + AgreementInvoicingDisplayOptions string `json:"agreementInvoicingDisplayOptions"` + TimebasedOneTimePasswordActivated bool `json:"timebasedOneTimePasswordActivated"` + Info struct { + LastUpdated string `json:"lastUpdated"` + UpdatedBy string `json:"updatedBy"` + ImageHref string `json:"image_href"` + } `json:"_info"` + Notes string `json:"notes,omitempty"` + InactiveDate string `json:"inactiveDate,omitempty"` + BillableForecast float64 `json:"billableForecast,omitempty"` + ProjectDefaultBoard struct { + ID int `json:"id"` + Name string `json:"name"` + Info struct { + BoardHref string `json:"board_href"` + } `json:"_info"` + } `json:"projectDefaultBoard,omitempty"` + Calendar struct { + ID int `json:"id"` + Name string `json:"name"` + Info struct { + CalendarHref string `json:"calendar_href"` + } `json:"_info"` + } `json:"calendar,omitempty"` + HourlyRate float64 `json:"hourlyRate,omitempty"` + LdapConfiguration struct { + ID int `json:"id"` + Name string `json:"name"` + Server string `json:"server"` + Info struct { + LdapConfigurationHref string `json:"ldapConfiguration_href"` + } `json:"_info"` + } `json:"ldapConfiguration,omitempty"` + LdapUserName string `json:"ldapUserName,omitempty"` +} + //GetSystemMembers returns a slice of Member structs containing all the members (users) of connectwise //TBD finish this, I don't have permissions with my API key to see the JSON data -func (cw *Site) GetSystemMembers() error { +func (cw *Site) GetSystemMembers() (*[]Member, error) { req := cw.NewRequest("/system/members", "GET", nil) err := req.Do() if err != nil { - return fmt.Errorf("request failed for %s: %s", req.RestAction, err) + return nil, fmt.Errorf("request failed for %s: %s", req.RestAction, err) } - /* - callbacks := &[]Callback{} - err = json.Unmarshal(req.Body, callbacks) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal body into struct: %s", err) - } + members := &[]Member{} + err = json.Unmarshal(req.Body, members) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal body into struct: %s", err) + } - */ - return nil + return members, nil +} + +func (cw *Site) GetSystemMemberByIdentifier(identifier string) (*Member, error) { + req := cw.NewRequest(fmt.Sprintf("/system/members/%s", identifier), "GET", nil) + err := req.Do() + if err != nil { + return nil, fmt.Errorf("request failed for %s: %s", req.RestAction, err) + } + + member := &Member{} + err = json.Unmarshal(req.Body, member) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal body into struct: %s", err) + } + + return member, nil } //GetCallbacks returns a slice of Callback structs containing all the callbacks currently registered with ConnectWise