-
Notifications
You must be signed in to change notification settings - Fork 501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
horizonclient: next and prev methods #1278
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -539,5 +539,29 @@ func (c *Client) PrevAssetsPage(page hProtocol.AssetsPage) (assets hProtocol.Ass | |
return | ||
} | ||
|
||
// NextLedgersPage returns the next page of ledgers | ||
func (c *Client) NextLedgersPage(page hProtocol.LedgersPage) (ledgers hProtocol.LedgersPage, err error) { | ||
err = c.sendRequestURL(page.Links.Next.Href, "get", &ledgers) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since these are simple and repetitive I think you could just inline all these next/prev returns, and lose the |
||
return | ||
} | ||
|
||
// PrevLedgersPage returns the previous page of ledgers | ||
func (c *Client) PrevLedgersPage(page hProtocol.LedgersPage) (ledgers hProtocol.LedgersPage, err error) { | ||
err = c.sendRequestURL(page.Links.Prev.Href, "get", &ledgers) | ||
return | ||
} | ||
|
||
// NextEffectsPage returns the next page of effects | ||
func (c *Client) NextEffectsPage(page effects.EffectsPage) (efp effects.EffectsPage, err error) { | ||
err = c.sendRequestURL(page.Links.Next.Href, "get", &efp) | ||
return | ||
} | ||
|
||
// PrevEffectsPage returns the previous page of effects | ||
func (c *Client) PrevEffectsPage(page effects.EffectsPage) (efp effects.EffectsPage, err error) { | ||
err = c.sendRequestURL(page.Links.Prev.Href, "get", &efp) | ||
return | ||
} | ||
|
||
// ensure that the horizon client implements ClientInterface | ||
var _ ClientInterface = &Client{} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,45 @@ func TestEffectRequestBuildUrl(t *testing.T) { | |
|
||
} | ||
|
||
func ExampleClient_NextEffectsPage() { | ||
client := DefaultPublicNetClient | ||
// all effects | ||
effectRequest := EffectRequest{Limit: 20} | ||
efp, err := client.Effects(effectRequest) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
fmt.Print(efp) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any will do actually. Oped for |
||
|
||
// next page | ||
nextPage, err := client.NextEffectsPage(efp) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be cool to have the example use a loop, to show calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes that's a good point. will need to confirm what the indicates the end of a collection of pages here. |
||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
fmt.Println(nextPage) | ||
} | ||
|
||
func ExampleClient_PrevEffectsPage() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comments as for previous example |
||
client := DefaultPublicNetClient | ||
// all effects | ||
effectRequest := EffectRequest{Limit: 20} | ||
efp, err := client.Effects(effectRequest) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
fmt.Print(efp) | ||
|
||
// prev page | ||
prevPage, err := client.PrevEffectsPage(efp) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
fmt.Println(prevPage) | ||
} | ||
func ExampleClient_StreamEffects() { | ||
client := DefaultTestNetClient | ||
// all effects | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,5 +199,29 @@ func (m *MockClient) PrevAssetsPage(page hProtocol.AssetsPage) (hProtocol.Assets | |
return a.Get(0).(hProtocol.AssetsPage), a.Error(1) | ||
} | ||
|
||
// NextLedgersPage is a mocking method | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens when there is no further Next/Prev to return? Can this be tested? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will look into this. |
||
func (m *MockClient) NextLedgersPage(page hProtocol.LedgersPage) (hProtocol.LedgersPage, error) { | ||
a := m.Called(page) | ||
return a.Get(0).(hProtocol.LedgersPage), a.Error(1) | ||
} | ||
|
||
// PrevLedgersPage is a mocking method | ||
func (m *MockClient) PrevLedgersPage(page hProtocol.LedgersPage) (hProtocol.LedgersPage, error) { | ||
a := m.Called(page) | ||
return a.Get(0).(hProtocol.LedgersPage), a.Error(1) | ||
} | ||
|
||
// NextEffectsPage is a mocking method | ||
func (m *MockClient) NextEffectsPage(page effects.EffectsPage) (effects.EffectsPage, error) { | ||
a := m.Called(page) | ||
return a.Get(0).(effects.EffectsPage), a.Error(1) | ||
} | ||
|
||
// PrevEffectsPage is a mocking method | ||
func (m *MockClient) PrevEffectsPage(page effects.EffectsPage) (effects.EffectsPage, error) { | ||
a := m.Called(page) | ||
return a.Get(0).(effects.EffectsPage), a.Error(1) | ||
} | ||
|
||
// ensure that the MockClient implements ClientInterface | ||
var _ ClientInterface = &MockClient{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a period to the end of all the godoc strings here.