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

Add streaming requests #1283

Merged
merged 12 commits into from
Jul 6, 2021
Merged

Add streaming requests #1283

merged 12 commits into from
Jul 6, 2021

Conversation

richardm-stripe
Copy link
Contributor

@richardm-stripe richardm-stripe commented May 17, 2021

Notify

r? @dcr-stripe
cc @stripe/api-libraries

Description

Implements support for streaming requests.

How this will be used

// In foo/client.go, something like:
func (c Client) PDF(id string, params *stripe.FooPDFParams) (*stripe.APIStream, error) {
	path := stripe.FormatURLPath("/v1/foo/%s/pdf", id)
	stream := &stripe.APIStream{}
	err := c.B.CallStreaming(http.MethodGet, path, c.Key, params, stream)
	return stream, err
}

and then the user can

stream, err := stripe.foo.PDF("foo_xyz", nil)
if err != nil {
  return err  
}
writer, err := os.Create("/tmp/foo.pdf")
defer writer.Close()
io.Copy(writer, stream.LastResponse.Body)

It might help to review this commit-by-commit. There's some refactoring into helper functions.

@richardm-stripe richardm-stripe changed the title Richardm streaming [WIP] Binary streaming May 19, 2021
@richardm-stripe richardm-stripe changed the title [WIP] Binary streaming Add streaming requests Jun 25, 2021
@richardm-stripe richardm-stripe marked this pull request as ready for review June 25, 2021 17:54
Copy link
Contributor

@dcr-stripe dcr-stripe left a comment

Choose a reason for hiding this comment

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

Looks good overall! Mainly minor comments - thanks Richard!

stripe.go Outdated Show resolved Hide resolved
stripe.go Outdated Show resolved Hide resolved
stripe.go Outdated Show resolved Hide resolved
stripe.go Outdated Show resolved Hide resolved
stripe.go Show resolved Hide resolved
stripe.go Outdated Show resolved Hide resolved
@richardm-stripe
Copy link
Contributor Author

r? @dcr-stripe thanks for the great review! Went a little further in the refactoring/reducing duplication and addressed all comments.

stripe.go Show resolved Hide resolved
Copy link
Contributor

@dcr-stripe dcr-stripe left a comment

Choose a reason for hiding this comment

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

Looks great - thanks Richard! 🥳 Just one comment about naming. Thanks for all the work on this!!

@richardm-stripe richardm-stripe merged commit bc2e6bc into master Jul 6, 2021
@richardm-stripe richardm-stripe deleted the richardm-streaming branch July 6, 2021 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants