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

file_link support #1244

Merged
merged 1 commit into from
Aug 3, 2018
Merged

file_link support #1244

merged 1 commit into from
Aug 3, 2018

Conversation

ob-stripe
Copy link
Contributor

r? @brandur-stripe @remi-stripe
cc @stripe/api-libraries

Adds support for file_links.


public virtual StripeFileLink Create(StripeFileLinkCreateOptions createOptions, StripeRequestOptions requestOptions = null)
{
return CreateAsync(createOptions, requestOptions).Result;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've used a style I'd like to see us adopt for new services (and apply to the existing services):

  1. Methods are in alphabetical order (like in tests)
  2. Non-async methods simply call their async version + .Result, as suggested by @jaymedavis in concept (do not merge): reducing code in the services #940.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure it works across all .NET frameworks?

Also, if we approve this, should we convert the whole library once and for all?

Copy link
Contributor

@jaymedavis jaymedavis Aug 2, 2018

Choose a reason for hiding this comment

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

Thanks @ob-stripe for keeping things nice and neat and caring about details. Warms my ❤️

Copy link
Contributor

Choose a reason for hiding this comment

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

@remi-stripe The library almost does this anyway on non async calls. Notice it uses the addition of GetAwaiter().GetResult(). I believe this was determined good practice from #1145. This stack overflow post sheds some light about the differences... which makes me wonder if this change was necessary.

Copy link
Contributor

@jaymedavis jaymedavis Aug 3, 2018

Choose a reason for hiding this comment

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

Further reading concludes that it is necessary! You’d get the real exception vs an Aggregate exception. I would change .Result everywhere to GetAwaiter().GetResult()

Source: aspnet/Security#59

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.

Some minor comments but LGTM

/// <summary>
/// A future timestamp after which the link will no longer be usable.
/// </summary>
public DateTime? ExpiresAt { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

you likely should have a StripeFileLinkSharedOptions class since they have 2 parameters in common. Not a huge deal though since it does work that way

Copy link
Contributor Author

@ob-stripe ob-stripe Aug 3, 2018

Choose a reason for hiding this comment

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

Ack. I've updated the PR with a StripeFileLinkSharedOptions class.

{
using Newtonsoft.Json;

public class StripeFileLinkListOptions : StripeListOptions
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor but there's a class called StripeListOptionsWithCreated that should either be used everywhere we have created or canned.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack. I've updated the PR to use it.


public virtual StripeFileLink Create(StripeFileLinkCreateOptions createOptions, StripeRequestOptions requestOptions = null)
{
return CreateAsync(createOptions, requestOptions).Result;
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure it works across all .NET frameworks?

Also, if we approve this, should we convert the whole library once and for all?

await Requestor.PostStringAsync(
this.ApplyAllParameters(createOptions, classUrl, false),
this.SetupRequestOptions(requestOptions),
cancellationToken).ConfigureAwait(false));
Copy link
Contributor

@jaymedavis jaymedavis Aug 2, 2018

Choose a reason for hiding this comment

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

I would format the last line (ConfigureAwait) like so:

return Mapper<StripeFileLink>.MapFromJson(
    await Requestor.PostStringAsync(
        this.ApplyAllParameters(createOptions, classUrl, false),
        this.SetupRequestOptions(requestOptions),
        cancellationToken
    ).ConfigureAwait(false));

I like this JavaScript/jQuery style formatting practice. A quick glance shows where the function call ends imo

edit: fixed spacing

Copy link
Contributor

Choose a reason for hiding this comment

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

@jaymedavis We now use StyleCop for the coding styles and one of the rules requires that the last bit is on the same line as cancelation token so it would have to look like what @ob-stripe did.

@ob-stripe ob-stripe force-pushed the ob-file-link branch 3 times, most recently from b80f114 to bc0f7af Compare August 3, 2018 10:38
@ob-stripe
Copy link
Contributor Author

I've reverted the sync/async thing for now. I still want to move forward with this, but this PR isn't the best place for it.

@ob-stripe
Copy link
Contributor Author

ptal @remi-stripe

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, but feel free to merge anyway!

@@ -1,6 +1,7 @@
namespace Stripe
{
using System;

Copy link
Contributor

Choose a reason for hiding this comment

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

curious about that one, is it a convention you want to start respecting? I don't think it was in any of the StyleCop rules

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't seem to conventional in C#, so I've reverted.

/// The ID of the file.
/// </summary>
[JsonProperty("file")]
public string File { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

The convention in stripe-dotnet is to name things like this with Id at the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch. Fixed.

public bool? Expired { get; set; }

[JsonProperty("file")]
public string File { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Fixed.

@remi-stripe remi-stripe assigned ob-stripe and unassigned remi-stripe Aug 3, 2018
@ob-stripe ob-stripe force-pushed the ob-file-link branch 2 times, most recently from 98223b9 to a97a3fa Compare August 3, 2018 14:01
@ob-stripe ob-stripe merged commit 3afd0e4 into master Aug 3, 2018
@ob-stripe ob-stripe deleted the ob-file-link branch August 3, 2018 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants