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

Replace Requestor with StripeClient and HttpClient #1487

Merged
merged 1 commit into from
Feb 11, 2019

Conversation

ob-stripe
Copy link
Contributor

@ob-stripe ob-stripe commented Jan 28, 2019

Alright, this should be the last of the big changes to the internal requestor logic.

The Stripe.Infrastructure.Requestor static class is replaced by several new concepts:

  • IStripeClient is the interface for a Stripe client class. Its contract defines a single method MakeRequestAsync<T>, which accepts a request's arguments (HTTP method, path, options class containing the request's parameters and request options class containing the request's special modifiers) and returns an instance of T (where T is a type that implements IStripeEntity)
  • StripeClient is the concrete class that implements IStripeClient. It accepts an optional HttpClient in its constructor. StripeClient delegates HTTP communications to the HttpClient instance and only takes care of decoding the response from Stripe's API
  • IHttpClient is the interface for HTTP clients. Its contract defines a single method MakeRequestAsync which accepts a Request and returns a Response
  • SystemNetHttpClient is the default concrete implementation that implements IHttpClient. It accepts an optional System.Net.HttpClient instance, or initializes one with default parameters.

This might seem over-engineered but it offers a clear separation of concepts and makes the library easier to test and mock, both by ourselves and by users. (This design is very similar to Twilio's C# library.)

Also, I've renamed the new Request class I added in #1508 to StripeRequest to make it consistent with StripeResponse. I've also extended StripeResponse to contain ~all information about the response and added some helpers to access custom Stripe headers.

Breaking changes:
HttpMessageHandler and Timeout were removed from StripeConfiguration and replaced by StripeClient. Users who want to pass a custom message handler can still do so by passing a custom client. This is a bit more complex, but it's a lot more powerful:

StripeConfiguration.StripeClient = new StripeClient(new HttpClient(new System.Net.HttpClient(messageHandler)));

@ob-stripe ob-stripe force-pushed the ob-rewrite-requestor branch 3 times, most recently from dc32d10 to 0dc4c4c Compare January 28, 2019 21:22
@ob-stripe ob-stripe force-pushed the ob-rewrite-requestor branch 2 times, most recently from ea2793a to 740585c Compare January 28, 2019 23:00
@ob-stripe ob-stripe mentioned this pull request Jan 28, 2019
52 tasks
@ob-stripe ob-stripe force-pushed the ob-rewrite-requestor branch 2 times, most recently from fb9898a to f21abfb Compare February 1, 2019 21:31
@ob-stripe ob-stripe force-pushed the ob-rewrite-requestor branch 7 times, most recently from 6233010 to a6ffb68 Compare February 10, 2019 19:01
@ob-stripe
Copy link
Contributor Author

r? @remi-stripe @brandur-stripe

Whew! I think this is finally ready for review.

@ob-stripe ob-stripe changed the title [WIP] Revamp HTTP client requestor Replace Requestor with StripeClient and HttpClient Feb 10, 2019
@remi-stripe remi-stripe removed their assignment Feb 10, 2019
Copy link
Contributor

@remi-stripe remi-stripe left a comment

Choose a reason for hiding this comment

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

minor comments while skimming but deferring the real review to Brandur here.

@ob-stripe ob-stripe force-pushed the ob-rewrite-requestor branch from a6ffb68 to 1d5b8c1 Compare February 11, 2019 12:36
Copy link
Contributor

@brandur-stripe brandur-stripe left a comment

Choose a reason for hiding this comment

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

Left one comment below, but this looks great — I'm really liking these clean layers!

ptal @ob-stripe

Assert.NotNull(charge);
Assert.Equal("ch_123", charge.Id);
Assert.Equal(response, charge.StripeResponse);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wanted to echo again that I love how short + succinct these sorts of tests come out! Very readable.

src/Stripe.net/Infrastructure/Public/HttpClient.cs Outdated Show resolved Hide resolved
@ob-stripe ob-stripe force-pushed the ob-rewrite-requestor branch from 1d5b8c1 to 069ed1e Compare February 11, 2019 22:35
@ob-stripe ob-stripe force-pushed the ob-rewrite-requestor branch from 069ed1e to a6dd748 Compare February 11, 2019 22:38
@ob-stripe
Copy link
Contributor Author

I've removed the unsafe properties and changed HttpClient from an abstract class to an interface (and renamed it to IHttpClient).

ptal @brandur-stripe

@brandur-stripe
Copy link
Contributor

I've removed the unsafe properties and changed HttpClient from an abstract class to an interface (and renamed it to IHttpClient).

👍

LGTM.

@ob-stripe ob-stripe merged commit df113ab into integration-v23 Feb 11, 2019
@ob-stripe ob-stripe deleted the ob-rewrite-requestor branch February 11, 2019 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants