Skip to content
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

Merged
merged 3 commits into from
May 16, 2019

Conversation

poliha
Copy link
Contributor

@poliha poliha commented May 15, 2019

This is part of a set of PRs to add methods to get the previous and next pages of a response from horizon.
This PR implements these methods for the ledgers and effects page.
Other pages will be implemented as listed in #985

@poliha poliha added the horizonclient tag for new horizon client located in clients/horizonclient label May 15, 2019
Copy link
Member

@ire-and-curses ire-and-curses left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some small changes suggested.

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The 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 err variable.

@@ -539,5 +539,29 @@ func (c *Client) PrevAssetsPage(page hProtocol.AssetsPage) (assets hProtocol.Ass
return
}

// NextLedgersPage returns the next page of ledgers
Copy link
Member

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.

fmt.Println(err)
return
}
fmt.Print(efp)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be ftm.Println?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any will do actually. Oped for fmt.Print here because the response will not be a simple string.

fmt.Print(efp)

// next page
nextPage, err := client.NextEffectsPage(efp)
Copy link
Member

Choose a reason for hiding this comment

The 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 NextEffectsPage repeatedly. How do we know when we reach the end? Would be good to show that too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

fmt.Println(nextPage)
}

func ExampleClient_PrevEffectsPage() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as for previous example

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will look into this.

@poliha poliha merged commit 2900559 into release-horizonclient-v1.2.0 May 16, 2019
@poliha poliha deleted the horizonclient-ledger-methods branch May 16, 2019 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
horizonclient tag for new horizon client located in clients/horizonclient
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants