Add MinID to Pagination

pull/91/head
178inaba 2019-02-14 22:23:25 +09:00 committed by mattn
parent 6bf95fc751
commit b8bb5ae68c
2 changed files with 13 additions and 2 deletions

View File

@ -268,6 +268,7 @@ type Results struct {
type Pagination struct { type Pagination struct {
MaxID ID MaxID ID
SinceID ID SinceID ID
MinID ID
Limit int64 Limit int64
} }
@ -291,6 +292,12 @@ func newPagination(rawlink string) (*Pagination, error) {
return nil, err return nil, err
} }
p.SinceID = sinceID p.SinceID = sinceID
minID, err := getPaginationID(link.URL, "min_id")
if err != nil {
return nil, err
}
p.MinID = minID
} }
} }
@ -323,9 +330,13 @@ func (p *Pagination) toValues() url.Values {
func (p *Pagination) setValues(params url.Values) url.Values { func (p *Pagination) setValues(params url.Values) url.Values {
if p.MaxID != "" { if p.MaxID != "" {
params.Set("max_id", string(p.MaxID)) params.Set("max_id", string(p.MaxID))
} else if p.SinceID != "" { }
if p.SinceID != "" {
params.Set("since_id", string(p.SinceID)) params.Set("since_id", string(p.SinceID))
} }
if p.MinID != "" {
params.Set("min_id", string(p.MinID))
}
if p.Limit > 0 { if p.Limit > 0 {
params.Set("limit", fmt.Sprint(p.Limit)) params.Set("limit", fmt.Sprint(p.Limit))
} }

View File

@ -339,7 +339,7 @@ func TestPaginationSetValues(t *testing.T) {
if after.Get("max_id") != "123" { if after.Get("max_id") != "123" {
t.Fatalf("want %q but %q", "123", after.Get("max_id")) t.Fatalf("want %q but %q", "123", after.Get("max_id"))
} }
if after.Get("since_id") != "" { if after.Get("since_id") != "789" {
t.Fatalf("result should be empty string: %q", after.Get("since_id")) t.Fatalf("result should be empty string: %q", after.Get("since_id"))
} }
if after.Get("limit") != "10" { if after.Get("limit") != "10" {