Skip to content

Commit 6d8a4d7

Browse files
SergTanchenkoSerhii Tanchenko
andauthored
added "page" and "per_page" search parameters (#105)
* added "page" and "per_page" search parameters according to https://docs.github.com/en/[email protected]/rest/search#search-repositories specification * cover with test case when page and per_page params are missing Co-authored-by: Serhii Tanchenko <[email protected]>
1 parent 4a61f43 commit 6d8a4d7

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

src/main/java/com/spotify/github/v3/search/requests/SearchParameters.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@
2020

2121
package com.spotify.github.v3.search.requests;
2222

23+
import java.util.Optional;
24+
25+
import javax.annotation.Nullable;
26+
27+
import org.immutables.value.Value;
28+
2329
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
2430
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
2531
import com.spotify.github.GithubStyle;
2632
import com.spotify.github.Parameters;
27-
import java.util.Optional;
28-
import javax.annotation.Nullable;
29-
import org.immutables.value.Value;
3033

3134
/**
3235
* Search parameters resource defines required and optional parameters. To be serialized as
@@ -47,4 +50,15 @@ public interface SearchParameters extends Parameters {
4750

4851
/** The sort order if sort parameter is provided. One of asc or desc. Default: desc */
4952
Optional<String> order();
53+
54+
/**
55+
* The number of results per page (max 100). Default: 30
56+
*/
57+
@SuppressWarnings("checkstyle:methodname")
58+
Optional<Integer> per_page();
59+
60+
/**
61+
* Page number of the results to fetch. Default: 1
62+
*/
63+
Optional<Integer> page();
5064
}

src/test/java/com/spotify/github/v3/search/requests/SearchParametersTest.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -34,8 +34,22 @@ public void testFullSerialize() {
3434
.q("bogus-query")
3535
.sort("bogus-sort")
3636
.order("bogus-order")
37+
.per_page(50)
38+
.page(2)
3739
.build();
3840

41+
assertThat(params.serialize(), is("order=bogus-order&page=2&per_page=50&q=bogus-query&sort=bogus-sort"));
42+
}
43+
44+
@Test
45+
public void testSerializeWithoutPageAndPerPageParameters() {
46+
final SearchParameters params =
47+
ImmutableSearchParameters.builder()
48+
.q("bogus-query")
49+
.sort("bogus-sort")
50+
.order("bogus-order")
51+
.build();
52+
3953
assertThat(params.serialize(), is("order=bogus-order&q=bogus-query&sort=bogus-sort"));
4054
}
4155
}

0 commit comments

Comments
 (0)