|
| 1 | +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +package gitpod |
| 4 | + |
| 5 | +import ( |
| 6 | + "context" |
| 7 | + "net/http" |
| 8 | + "net/url" |
| 9 | + "time" |
| 10 | + |
| 11 | + "github.com/gitpod-io/gitpod-sdk-go/internal/apijson" |
| 12 | + "github.com/gitpod-io/gitpod-sdk-go/internal/apiquery" |
| 13 | + "github.com/gitpod-io/gitpod-sdk-go/internal/param" |
| 14 | + "github.com/gitpod-io/gitpod-sdk-go/internal/requestconfig" |
| 15 | + "github.com/gitpod-io/gitpod-sdk-go/option" |
| 16 | + "github.com/gitpod-io/gitpod-sdk-go/packages/pagination" |
| 17 | +) |
| 18 | + |
| 19 | +// UsageService contains methods and other services that help with interacting with |
| 20 | +// the gitpod API. |
| 21 | +// |
| 22 | +// Note, unlike clients, this service does not read variables from the environment |
| 23 | +// automatically. You should not instantiate this service directly, and instead use |
| 24 | +// the [NewUsageService] method instead. |
| 25 | +type UsageService struct { |
| 26 | + Options []option.RequestOption |
| 27 | +} |
| 28 | + |
| 29 | +// NewUsageService generates a new service that applies the given options to each |
| 30 | +// request. These options are applied after the parent client's options (if there |
| 31 | +// is one), and before any request-specific options. |
| 32 | +func NewUsageService(opts ...option.RequestOption) (r *UsageService) { |
| 33 | + r = &UsageService{} |
| 34 | + r.Options = opts |
| 35 | + return |
| 36 | +} |
| 37 | + |
| 38 | +// Lists environment sessions within a specified date range. |
| 39 | +// |
| 40 | +// Returns a list of environment sessions that were active within the specified |
| 41 | +// date range. |
| 42 | +func (r *UsageService) ListEnvironmentSessions(ctx context.Context, params UsageListEnvironmentSessionsParams, opts ...option.RequestOption) (res *pagination.SessionsPage[EnvironmentSession], err error) { |
| 43 | + var raw *http.Response |
| 44 | + opts = append(r.Options[:], opts...) |
| 45 | + opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) |
| 46 | + path := "gitpod.v1.UsageService/ListEnvironmentSessions" |
| 47 | + cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodPost, path, params, &res, opts...) |
| 48 | + if err != nil { |
| 49 | + return nil, err |
| 50 | + } |
| 51 | + err = cfg.Execute() |
| 52 | + if err != nil { |
| 53 | + return nil, err |
| 54 | + } |
| 55 | + res.SetPageConfig(cfg, raw) |
| 56 | + return res, nil |
| 57 | +} |
| 58 | + |
| 59 | +// Lists environment sessions within a specified date range. |
| 60 | +// |
| 61 | +// Returns a list of environment sessions that were active within the specified |
| 62 | +// date range. |
| 63 | +func (r *UsageService) ListEnvironmentSessionsAutoPaging(ctx context.Context, params UsageListEnvironmentSessionsParams, opts ...option.RequestOption) *pagination.SessionsPageAutoPager[EnvironmentSession] { |
| 64 | + return pagination.NewSessionsPageAutoPager(r.ListEnvironmentSessions(ctx, params, opts...)) |
| 65 | +} |
| 66 | + |
| 67 | +type EnvironmentSession struct { |
| 68 | + // Environment session ID. |
| 69 | + ID string `json:"id"` |
| 70 | + // Time when the session was created. |
| 71 | + CreatedAt time.Time `json:"createdAt" format:"date-time"` |
| 72 | + // Environment class ID associated with the session. |
| 73 | + EnvironmentClassID string `json:"environmentClassId"` |
| 74 | + // Environment ID associated with the session. |
| 75 | + EnvironmentID string `json:"environmentId"` |
| 76 | + // Project ID associated with the session. |
| 77 | + ProjectID string `json:"projectId"` |
| 78 | + // Runner ID associated with the session. |
| 79 | + RunnerID string `json:"runnerId"` |
| 80 | + // Time when the session was stopped. |
| 81 | + StoppedAt time.Time `json:"stoppedAt" format:"date-time"` |
| 82 | + // User ID who created the session. |
| 83 | + UserID string `json:"userId"` |
| 84 | + JSON environmentSessionJSON `json:"-"` |
| 85 | +} |
| 86 | + |
| 87 | +// environmentSessionJSON contains the JSON metadata for the struct |
| 88 | +// [EnvironmentSession] |
| 89 | +type environmentSessionJSON struct { |
| 90 | + ID apijson.Field |
| 91 | + CreatedAt apijson.Field |
| 92 | + EnvironmentClassID apijson.Field |
| 93 | + EnvironmentID apijson.Field |
| 94 | + ProjectID apijson.Field |
| 95 | + RunnerID apijson.Field |
| 96 | + StoppedAt apijson.Field |
| 97 | + UserID apijson.Field |
| 98 | + raw string |
| 99 | + ExtraFields map[string]apijson.Field |
| 100 | +} |
| 101 | + |
| 102 | +func (r *EnvironmentSession) UnmarshalJSON(data []byte) (err error) { |
| 103 | + return apijson.UnmarshalRoot(data, r) |
| 104 | +} |
| 105 | + |
| 106 | +func (r environmentSessionJSON) RawJSON() string { |
| 107 | + return r.raw |
| 108 | +} |
| 109 | + |
| 110 | +type UsageListEnvironmentSessionsParams struct { |
| 111 | + Token param.Field[string] `query:"token"` |
| 112 | + PageSize param.Field[int64] `query:"pageSize"` |
| 113 | + // Filter options. |
| 114 | + Filter param.Field[UsageListEnvironmentSessionsParamsFilter] `json:"filter"` |
| 115 | + // Pagination options. |
| 116 | + Pagination param.Field[UsageListEnvironmentSessionsParamsPagination] `json:"pagination"` |
| 117 | +} |
| 118 | + |
| 119 | +func (r UsageListEnvironmentSessionsParams) MarshalJSON() (data []byte, err error) { |
| 120 | + return apijson.MarshalRoot(r) |
| 121 | +} |
| 122 | + |
| 123 | +// URLQuery serializes [UsageListEnvironmentSessionsParams]'s query parameters as |
| 124 | +// `url.Values`. |
| 125 | +func (r UsageListEnvironmentSessionsParams) URLQuery() (v url.Values) { |
| 126 | + return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ |
| 127 | + ArrayFormat: apiquery.ArrayQueryFormatComma, |
| 128 | + NestedFormat: apiquery.NestedQueryFormatBrackets, |
| 129 | + }) |
| 130 | +} |
| 131 | + |
| 132 | +// Filter options. |
| 133 | +type UsageListEnvironmentSessionsParamsFilter struct { |
| 134 | + // Date range to query sessions within. |
| 135 | + DateRange param.Field[UsageListEnvironmentSessionsParamsFilterDateRange] `json:"dateRange,required"` |
| 136 | + // Optional project ID to filter sessions by. |
| 137 | + ProjectID param.Field[string] `json:"projectId"` |
| 138 | +} |
| 139 | + |
| 140 | +func (r UsageListEnvironmentSessionsParamsFilter) MarshalJSON() (data []byte, err error) { |
| 141 | + return apijson.MarshalRoot(r) |
| 142 | +} |
| 143 | + |
| 144 | +// Date range to query sessions within. |
| 145 | +type UsageListEnvironmentSessionsParamsFilterDateRange struct { |
| 146 | + // End time of the date range (exclusive). |
| 147 | + EndTime param.Field[time.Time] `json:"endTime,required" format:"date-time"` |
| 148 | + // Start time of the date range (inclusive). |
| 149 | + StartTime param.Field[time.Time] `json:"startTime,required" format:"date-time"` |
| 150 | +} |
| 151 | + |
| 152 | +func (r UsageListEnvironmentSessionsParamsFilterDateRange) MarshalJSON() (data []byte, err error) { |
| 153 | + return apijson.MarshalRoot(r) |
| 154 | +} |
| 155 | + |
| 156 | +// Pagination options. |
| 157 | +type UsageListEnvironmentSessionsParamsPagination struct { |
| 158 | + // Token for the next set of results that was returned as next_token of a |
| 159 | + // PaginationResponse |
| 160 | + Token param.Field[string] `json:"token"` |
| 161 | + // Page size is the maximum number of results to retrieve per page. Defaults to 25. |
| 162 | + // Maximum 100. |
| 163 | + PageSize param.Field[int64] `json:"pageSize"` |
| 164 | +} |
| 165 | + |
| 166 | +func (r UsageListEnvironmentSessionsParamsPagination) MarshalJSON() (data []byte, err error) { |
| 167 | + return apijson.MarshalRoot(r) |
| 168 | +} |
0 commit comments