|
| 1 | +package projects |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "encoding/json" |
| 6 | + "fmt" |
| 7 | + "net/http" |
| 8 | + |
| 9 | + twapi "github.com/teamwork/twapi-go-sdk" |
| 10 | +) |
| 11 | + |
| 12 | +var ( |
| 13 | + _ twapi.HTTPRequester = (*IndustryListRequest)(nil) |
| 14 | + _ twapi.HTTPResponser = (*IndustryListResponse)(nil) |
| 15 | +) |
| 16 | + |
| 17 | +// Industry refers to the business sector or market category that a company |
| 18 | +// belongs to, such as technology, healthcare, finance, or education. It helps |
| 19 | +// provide context about the nature of a company’s work and can be used to |
| 20 | +// better organize and filter data across the platform. By associating companies |
| 21 | +// and projects with specific industries, Teamwork.com allows teams to gain |
| 22 | +// clearer insights, tailor communication, and segment information in ways that |
| 23 | +// make it easier to manage relationships and understand the broader business |
| 24 | +// landscape in which their clients and partners operate. |
| 25 | +type Industry struct { |
| 26 | + // ID is the unique identifier of the industry. |
| 27 | + ID LegacyNumber `json:"id"` |
| 28 | + |
| 29 | + // Name is the name of the industry. |
| 30 | + Name string `json:"name"` |
| 31 | +} |
| 32 | + |
| 33 | +// IndustryListRequest represents the request body for loading multiple industries. |
| 34 | +// |
| 35 | +// Not documented. |
| 36 | +type IndustryListRequest struct{} |
| 37 | + |
| 38 | +// NewIndustryListRequest creates a new IndustryListRequest with default values. |
| 39 | +func NewIndustryListRequest() IndustryListRequest { |
| 40 | + return IndustryListRequest{} |
| 41 | +} |
| 42 | + |
| 43 | +// HTTPRequest creates an HTTP request for the IndustryListRequest. |
| 44 | +func (p IndustryListRequest) HTTPRequest(ctx context.Context, server string) (*http.Request, error) { |
| 45 | + uri := server + "/industries.json" |
| 46 | + |
| 47 | + req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil) |
| 48 | + if err != nil { |
| 49 | + return nil, err |
| 50 | + } |
| 51 | + return req, nil |
| 52 | +} |
| 53 | + |
| 54 | +// IndustryListResponse contains information by multiple industries matching the |
| 55 | +// request filters. |
| 56 | +// |
| 57 | +// Not documented. |
| 58 | +type IndustryListResponse struct { |
| 59 | + Industries []Industry `json:"industries"` |
| 60 | +} |
| 61 | + |
| 62 | +// HandleHTTPResponse handles the HTTP response for the IndustryListResponse. If |
| 63 | +// some unexpected HTTP status code is returned by the API, a twapi.HTTPError is |
| 64 | +// returned. |
| 65 | +func (p *IndustryListResponse) HandleHTTPResponse(resp *http.Response) error { |
| 66 | + if resp.StatusCode != http.StatusOK { |
| 67 | + return twapi.NewHTTPError(resp, "failed to list industries") |
| 68 | + } |
| 69 | + |
| 70 | + if err := json.NewDecoder(resp.Body).Decode(p); err != nil { |
| 71 | + return fmt.Errorf("failed to decode list industries response: %w", err) |
| 72 | + } |
| 73 | + return nil |
| 74 | +} |
| 75 | + |
| 76 | +// IndustryList retrieves multiple industries using the provided request |
| 77 | +// and returns the response. |
| 78 | +func IndustryList( |
| 79 | + ctx context.Context, |
| 80 | + engine *twapi.Engine, |
| 81 | + req IndustryListRequest, |
| 82 | +) (*IndustryListResponse, error) { |
| 83 | + return twapi.Execute[IndustryListRequest, *IndustryListResponse](ctx, engine, req) |
| 84 | +} |
0 commit comments