-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathtypes.go
More file actions
144 lines (120 loc) · 4.21 KB
/
types.go
File metadata and controls
144 lines (120 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package dashboard
import "errors"
// OAuthTokenResponse is the response from POST /2/oauth/token.
type OAuthTokenResponse struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
TokenType string `json:"token_type"`
ExpiresIn int `json:"expires_in"`
Scope string `json:"scope"`
CreatedAt int64 `json:"created_at"`
User *User `json:"user,omitempty"`
}
// User represents the authenticated user from the OAuth token response.
type User struct {
ID int `json:"id"`
Email string `json:"email"`
Name string `json:"name"`
AvatarURL string `json:"avatar_url"`
}
// ApplicationResource is a JSON:API resource wrapper for an application.
type ApplicationResource struct {
ID string `json:"id"`
Type string `json:"type"`
Attributes ApplicationAttributes `json:"attributes"`
}
// ApplicationAttributes contains the actual application fields.
type ApplicationAttributes struct {
Name string `json:"name"`
ApplicationID string `json:"application_id"`
APIKey string `json:"api_key"`
}
// Application is a flattened view of an Algolia application for CLI consumption.
type Application struct {
ID string `json:"id"`
Name string `json:"name"`
APIKey string `json:"api_key,omitempty"`
}
// ApplicationsResponse is the JSON:API response from GET /1/applications.
type ApplicationsResponse struct {
Data []ApplicationResource `json:"data"`
}
// SingleApplicationResponse is the JSON:API response from GET /1/application/:id.
type SingleApplicationResponse struct {
Data ApplicationResource `json:"data"`
}
// CreateApplicationRequest is the payload for POST /1/applications.
type CreateApplicationRequest struct {
RegionCode string `json:"region_code"`
Name string `json:"name"`
}
// Region represents a hosting region from GET /1/hosting/regions.
type Region struct {
Code string `json:"code"`
Name string `json:"name"`
}
// RegionsResponse is the response from GET /1/hosting/regions.
type RegionsResponse struct {
RegionCodes []Region `json:"region_codes"`
}
// ErrSessionExpired is returned when an API call gets a 401 Unauthorized.
var ErrSessionExpired = errors.New("session expired")
// ErrClusterUnavailable is returned when a region has no available cluster.
type ErrClusterUnavailable struct {
Region string
Message string
}
func (e *ErrClusterUnavailable) Error() string {
return e.Message
}
// OAuthErrorResponse is the error format from the OAuth endpoints.
type OAuthErrorResponse struct {
Error string `json:"error"`
ErrorDescription string `json:"error_description"`
}
// CreateAPIKeyRequest is the payload for POST /1/applications/{application_id}/api-keys.
type CreateAPIKeyRequest struct {
ACL []string `json:"acl"`
Description string `json:"description"`
}
// APIKeyResource is a JSON:API resource wrapper for an API key.
type APIKeyResource struct {
ID string `json:"id"`
Type string `json:"type"`
Attributes APIKeyAttributes `json:"attributes"`
}
// APIKeyAttributes contains the actual API key fields.
type APIKeyAttributes struct {
Value string `json:"value"`
}
// CreateAPIKeyResponse is the JSON:API response from POST /1/applications/{application_id}/api-keys.
type CreateAPIKeyResponse struct {
Data APIKeyResource `json:"data"`
}
// DashboardCrawlerUserData contains the user information from the crawler API
type DashboardCrawlerUserData struct {
ID string `json:"id"`
Email string `json:"email"`
Name string `json:"name"`
APIKey string `json:"apiKey"`
}
// DashboardCrawlerUserResponse is the JSON:API response from GET /1/crawler/user
type DashboardCrawlerUserResponse struct {
Data DashboardCrawlerUserData `json:"data"`
}
type DashboardCrawlerErrorResponse struct {
Errors []DashboardCrawlerError `json:"errors"`
}
type DashboardCrawlerError struct {
Status string `json:"status"`
Title string `json:"title"`
Detail *string `json:"detail"`
}
// toApplication flattens a JSON:API resource into a simple Application.
func (r *ApplicationResource) toApplication() Application {
return Application{
ID: r.Attributes.ApplicationID,
Name: r.Attributes.Name,
APIKey: r.Attributes.APIKey,
}
}