github.com/schmorrison/Zoho@v1.1.4/books/users.go (about) 1 package books 2 3 import ( 4 "encoding/json" 5 "fmt" 6 7 zoho "github.com/schmorrison/Zoho" 8 ) 9 10 // GetCurrentUser will return the currently authenticated users 11 // https://www.zoho.com/books/api/v3/users/#get-current-user 12 func (c *API) GetCurrentUser() (data CurrentUserResponse, err error) { 13 endpoint := zoho.Endpoint{ 14 Name: "users", 15 URL: fmt.Sprintf("https://books.zoho.%s/api/v3/users/me", c.ZohoTLD), 16 Method: zoho.HTTPGet, 17 ResponseData: &CurrentUserResponse{}, 18 } 19 20 err = c.Zoho.HTTPRequest(&endpoint) 21 if err != nil { 22 return CurrentUserResponse{}, fmt.Errorf("Failed to retrieve current user: %s", err) 23 } 24 25 if v, ok := endpoint.ResponseData.(*CurrentUserResponse); ok { 26 return *v, nil 27 } 28 29 return CurrentUserResponse{}, fmt.Errorf("Data retrieved was not 'UsersResponse'") 30 } 31 32 func (m *MorePermissions) UnmarshalJSON(data []byte) error { 33 if string(data) == `""` { 34 return nil 35 } 36 37 type tmp MorePermissions 38 return json.Unmarshal(data, (*tmp)(m)) 39 } 40 41 type MorePermissions []Permission 42 43 type Permission struct { 44 IsEnabled bool `json:"is_enabled,omitempty"` 45 PermissionFormatted string `json:"permission_formatted,omitempty"` 46 Permission string `json:"permission,omitempty"` 47 } 48 49 // CurrentUserResponse is the data returned by GetCurrentUser 50 type CurrentUserResponse struct { 51 Code int `json:"code,omitempty"` 52 Message string `json:"message,omitempty"` 53 User struct { 54 UserID string `json:"user_id,omitempty"` 55 Name string `json:"name,omitempty"` 56 EmailIds []struct { 57 IsSelected bool `json:"is_selected,omitempty"` 58 Email string `json:"email,omitempty"` 59 } `json:"email_ids,omitempty"` 60 Status string `json:"status,omitempty"` 61 UserRole string `json:"user_role,omitempty"` 62 UserType string `json:"user_type,omitempty"` 63 RoleID string `json:"role_id,omitempty"` 64 PhotoURL string `json:"photo_url,omitempty"` 65 Role struct { 66 Role struct { 67 RoleName string `json:"role_name,omitempty"` 68 Permissions []struct { 69 FullAccess bool `json:"full_access,omitempty"` 70 Entity string `json:"entity,omitempty"` 71 MorePermissions MorePermissions `json:"more_permissions,omitempty"` 72 ReportPermissions []struct { 73 Reports []struct { 74 FullAccess bool `json:"full_access,omitempty"` 75 CanSchedule bool `json:"can_schedule,omitempty"` 76 ReportConstant string `json:"report_constant,omitempty"` 77 CanShare bool `json:"can_share,omitempty"` 78 IsExportEnabled bool `json:"is_export_enabled,omitempty"` 79 ReportNameFormatted string `json:"report_name_formatted,omitempty"` 80 IsScheduleEnabled bool `json:"is_schedule_enabled,omitempty"` 81 CanExport bool `json:"can_export,omitempty"` 82 CanAccess bool `json:"can_access,omitempty"` 83 } `json:"reports,omitempty"` 84 ReportGroupFormatted string `json:"report_group_formatted,omitempty"` 85 ReportGroup string `json:"report_group,omitempty"` 86 } `json:"report_permissions,omitempty"` 87 } `json:"permissions,omitempty"` 88 Description string `json:"description,omitempty"` 89 DisplayName string `json:"display_name,omitempty"` 90 } `json:"role,omitempty"` 91 RoleID string `json:"role_id,omitempty"` 92 Name string `json:"name,omitempty"` 93 Email string `json:"email,omitempty"` 94 Zuid string `json:"zuid,omitempty"` 95 } `json:"role,omitempty"` 96 IsClaimant bool `json:"is_claimant,omitempty"` 97 IsEmployee bool `json:"is_employee,omitempty"` 98 Email string `json:"email,omitempty"` 99 IsCustomerSegmented bool `json:"is_customer_segmented,omitempty"` 100 IsVendorSegmented bool `json:"is_vendor_segmented,omitempty"` 101 IsAccountant bool `json:"is_accountant,omitempty"` 102 CreatedTime string `json:"created_time,omitempty"` 103 CustomFields []interface{} `json:"custom_fields,omitempty"` 104 CustomFieldHash struct { 105 } `json:"custom_field_hash,omitempty"` 106 IsAssociatedForApproval bool `json:"is_associated_for_approval,omitempty"` 107 IsAssociatedWithOrgEmail bool `json:"is_associated_with_org_email,omitempty"` 108 Branches []interface{} `json:"branches,omitempty"` 109 DefaultBranchID string `json:"default_branch_id,omitempty"` 110 } `json:"user,omitempty"` 111 }