Skip to content

Commit 625bdff

Browse files
authored
chore: add nil check for ListOptions receivers; update useragent value (#20)
1 parent e5ca1b1 commit 625bdff

File tree

8 files changed

+74
-23
lines changed

8 files changed

+74
-23
lines changed

crowdin/crowdin.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ import (
99
"io"
1010
"net/http"
1111
"net/url"
12-
"time"
1312

1413
"github.com/crowdin/crowdin-api-client-go/crowdin/model"
1514
)
1615

1716
const (
1817
baseURL = "https://api.crowdin.com/"
1918

20-
userAgent = "crowdin-api-client-go/0.0.1"
19+
userAgent = "crowdin-api-client-go/0.1.0"
2120
)
2221

2322
// Client is a Crowdin API client.
@@ -106,14 +105,6 @@ func WithHTTPClient(hc *http.Client) ClientOption {
106105
}
107106
}
108107

109-
// WithTimeout modifies the default HTTP client timeout.
110-
func WithTimeout(timeout time.Duration) ClientOption {
111-
return func(c *Client) error {
112-
c.httpClient.Timeout = timeout
113-
return nil
114-
}
115-
}
116-
117108
// RequestOption represents an option that can be used to modify a http.Request.
118109
type RequestOption func(*http.Request) error
119110

crowdin/model/branches.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ type BranchesListOptions struct {
3838

3939
// Values returns the url.Values representation of BranchesListOptions.
4040
func (o *BranchesListOptions) Values() (url.Values, bool) {
41+
if o == nil {
42+
return nil, false
43+
}
44+
4145
v, _ := o.ListOptions.Values()
4246
if o.Name != "" {
4347
v.Add("name", o.Name)

crowdin/model/projects.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,21 @@ type ProjectsListOptions struct {
117117

118118
// Values returns the url.Values representation of ProjectsListOptions.
119119
// It implements the crowdin.ListOptionsProvider interface.
120-
func (p *ProjectsListOptions) Values() (url.Values, bool) {
121-
v, _ := p.ListOptions.Values()
122-
if p.UserID > 0 {
123-
v.Add("userId", fmt.Sprintf("%d", p.UserID))
120+
func (o *ProjectsListOptions) Values() (url.Values, bool) {
121+
if o == nil {
122+
return nil, false
124123
}
125-
if p.HasManagerAccess != nil &&
126-
(*p.HasManagerAccess == 0 || *p.HasManagerAccess == 1) {
127-
v.Add("hasManagerAccess", fmt.Sprintf("%d", *p.HasManagerAccess))
124+
125+
v, _ := o.ListOptions.Values()
126+
if o.UserID > 0 {
127+
v.Add("userId", fmt.Sprintf("%d", o.UserID))
128+
}
129+
if o.HasManagerAccess != nil &&
130+
(*o.HasManagerAccess == 0 || *o.HasManagerAccess == 1) {
131+
v.Add("hasManagerAccess", fmt.Sprintf("%d", *o.HasManagerAccess))
128132
}
129-
if p.Type != nil && (*p.Type == 0 || *p.Type == 1) {
130-
v.Add("type", fmt.Sprintf("%d", *p.Type))
133+
if o.Type != nil && (*o.Type == 0 || *o.Type == 1) {
134+
v.Add("type", fmt.Sprintf("%d", *o.Type))
131135
}
132136
return v, len(v) > 0
133137
}

crowdin/model/source_files.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ type DirectoryListOptions struct {
5454

5555
// Values returns the url.Values representation of DirectoryListOptions.
5656
func (o *DirectoryListOptions) Values() (url.Values, bool) {
57+
if o == nil {
58+
return nil, false
59+
}
60+
5761
v, _ := o.ListOptions.Values()
5862
if o.BranchID > 0 {
5963
v.Add("branchId", fmt.Sprintf("%d", o.BranchID))
@@ -167,6 +171,10 @@ type FileListOptions struct {
167171

168172
// Values returns the url.Values representation of FileListOptions.
169173
func (o *FileListOptions) Values() (url.Values, bool) {
174+
if o == nil {
175+
return nil, false
176+
}
177+
170178
v, _ := o.ListOptions.Values()
171179
if o.BranchID > 0 {
172180
v.Add("branchId", fmt.Sprintf("%d", o.BranchID))
@@ -537,6 +545,10 @@ type ReviewedBuildListOptions struct {
537545

538546
// Values returns the url.Values representation of ReviewedBuildListOptions.
539547
func (o *ReviewedBuildListOptions) Values() (url.Values, bool) {
548+
if o == nil {
549+
return nil, false
550+
}
551+
540552
v, _ := o.ListOptions.Values()
541553
if o.BranchID > 0 {
542554
v.Add("branchId", fmt.Sprintf("%d", o.BranchID))

crowdin/model/source_strings.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ type SourceStringsListOptions struct {
7474
// Values returns the url.Values representation of SourceStringListOptions.
7575
// It implements the crowdin.ListOptionsProvider interface.
7676
func (o *SourceStringsListOptions) Values() (url.Values, bool) {
77+
if o == nil {
78+
return nil, false
79+
}
80+
7781
v, _ := o.ListOptions.Values()
7882
if o.DenormalizePlaceholders != nil &&
7983
(*o.DenormalizePlaceholders == 0 || *o.DenormalizePlaceholders == 1) {
@@ -113,6 +117,10 @@ type SourceStringsGetOptions struct {
113117

114118
// Values returns the url.Values representation of SourceStringsGetOptions.
115119
func (o *SourceStringsGetOptions) Values() (url.Values, bool) {
120+
if o == nil {
121+
return nil, false
122+
}
123+
116124
v := url.Values{}
117125
if o.DenormalizePlaceholders != nil &&
118126
(*o.DenormalizePlaceholders == 0 || *o.DenormalizePlaceholders == 1) {

crowdin/model/string_translations.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ type ApprovalsListOptions struct {
6262
// Values returns the url.Values representation of the ApprovalsListOptions.
6363
// It implements the crowdin.ListOptionsProvider interface.
6464
func (o *ApprovalsListOptions) Values() (url.Values, bool) {
65+
if o == nil {
66+
return nil, false
67+
}
68+
6569
v, _ := o.ListOptions.Values()
6670
if o.FileID > 0 {
6771
v.Add("fileId", fmt.Sprintf("%d", o.FileID))
@@ -204,6 +208,10 @@ type LanguageTranslationsListOptions struct {
204208
// Values returns the url.Values representation of the LanguageTranslationsListOptions.
205209
// It implements the crowdin.ListOptionsProvider interface.
206210
func (o *LanguageTranslationsListOptions) Values() (url.Values, bool) {
211+
if o == nil {
212+
return nil, false
213+
}
214+
207215
v, _ := o.ListOptions.Values()
208216
if len(o.StringIDs) > 0 {
209217
v.Add("stringIds", joinIntSlice(o.StringIDs))
@@ -266,6 +274,10 @@ type TranslationGetOptions struct {
266274
// Values returns the url.Values representation of the TranslationGetOptions.
267275
// It implements the crowdin.ListOptionsProvider interface.
268276
func (o *TranslationGetOptions) Values() (url.Values, bool) {
277+
if o == nil {
278+
return nil, false
279+
}
280+
269281
v := url.Values{}
270282
if o.DenormalizePlaceholders != nil &&
271283
(*o.DenormalizePlaceholders == 0 || *o.DenormalizePlaceholders == 1) {
@@ -293,6 +305,10 @@ type StringTranslationsListOptions struct {
293305
// Values returns the url.Values representation of the StringTranslationsListOptions.
294306
// It implements the crowdin.ListOptionsProvider interface.
295307
func (o *StringTranslationsListOptions) Values() (url.Values, bool) {
308+
if o == nil {
309+
return nil, false
310+
}
311+
296312
v, _ := o.ListOptions.Values()
297313
if o.StringID > 0 {
298314
v.Add("stringId", fmt.Sprintf("%d", o.StringID))
@@ -391,6 +407,10 @@ type VotesListOptions struct {
391407
// Values returns the url.Values representation of the VotesListOptions.
392408
// It implements the crowdin.ListOptionsProvider interface.
393409
func (o *VotesListOptions) Values() (url.Values, bool) {
410+
if o == nil {
411+
return nil, false
412+
}
413+
394414
v, _ := o.ListOptions.Values()
395415
if o.StringID > 0 {
396416
v.Add("stringId", fmt.Sprintf("%d", o.StringID))

crowdin/model/translation_status.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ type ProjectProgressListOptions struct {
3535
// Values returns the url.Values representation of ProjectProgressListOptions.
3636
// It implements the crowdin.ListOptionsProvider interface.
3737
func (o *ProjectProgressListOptions) Values() (url.Values, bool) {
38+
if o == nil {
39+
return nil, false
40+
}
41+
3842
v, _ := o.ListOptions.Values()
3943
if o.LanguageIDs != "" {
4044
v.Add("languageIds", o.LanguageIDs)
@@ -94,6 +98,10 @@ type QACheckListOptions struct {
9498
// Values returns the url.Values representation of QACheckListOptions.
9599
// It implements the crowdin.ListOptionsProvider interface.
96100
func (o *QACheckListOptions) Values() (url.Values, bool) {
101+
if o == nil {
102+
return nil, false
103+
}
104+
97105
v, _ := o.ListOptions.Values()
98106
if o.Category != "" {
99107
v.Add("category", o.Category)

crowdin/model/translations.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,14 @@ type TranslationsBuildsListOptions struct {
179179
}
180180

181181
// Values returns the url.Values representation of the query options.
182-
func (p *TranslationsBuildsListOptions) Values() (url.Values, bool) {
183-
v, _ := p.ListOptions.Values()
184-
if p.BranchID > 0 {
185-
v.Add("branchId", fmt.Sprintf("%d", p.BranchID))
182+
func (o *TranslationsBuildsListOptions) Values() (url.Values, bool) {
183+
if o == nil {
184+
return nil, false
185+
}
186+
187+
v, _ := o.ListOptions.Values()
188+
if o.BranchID > 0 {
189+
v.Add("branchId", fmt.Sprintf("%d", o.BranchID))
186190
}
187191

188192
return v, len(v) > 0

0 commit comments

Comments
 (0)