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

Fix FileUploadService #1288

Merged
merged 1 commit into from
Sep 19, 2018
Merged

Conversation

ob-stripe
Copy link
Contributor

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

Changes FileUploadService.Create to accept a new FileUploadCreateOptions class instead of separate arguments.

@@ -18,34 +18,35 @@ public FileUploadService(string apiKey)
{
}

public virtual FileUpload Create(string fileName, Stream fileStream, string purpose, RequestOptions requestOptions = null)
public virtual FileUpload Create(FileUploadCreateOptions options = null, RequestOptions requestOptions = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

wouldn't options be required for file upload creation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. I'll fix.

{
fileName = "blob";
fileName = fileStream.Name;
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it easier to just put the filename in the options instead of trying to get it from the stream? And if it's not in the options we just use blob? I am not a fan of those pre-processor directives as we don't really test them thoroughly

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 think adding options that are not actual API parameters would be a bad precedent. Also, this method has the advantage of not requiring the user to manually provide the filename.

Unfortunately, even if this worked with .NET Standard, I don't think we could test without mocking :/

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep agreed I am just worried a little bit that we're making assumptions but only testing on OSX and all that without knowing how mono and other environments will fare. I might recommend asking @anelder-stripe about this.

I agree on the name that is not an API parameter but we use the filename in all our API examples too.
Why don't we just make filename an optional parameter by the way in the API itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Re. testing, we do test with .NET Framework on AppVeyor, so we know that the code compiles and runs without errors at least (which in this instance is as much as we can say with .NET Core anyway).

Mono is supposed to be largely compatible with .NET Framework, but we've never tested against it (or offered any guarantee that the library works with Mono for that matter).

Why don't we just make filename an optional parameter by the way in the API itself?

The file is encoded as described in RFC 2388, which already includes a way of (optionally) providing the filename.

In that regard, I guess we could add a field for the filename in the options class, but even if we do I'd still be in favor of keeping the code I added to automatically provide the filename if it's not manually provided.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I mean I'm fine with what you do, I'm just raising that .NET is still a platform we don't know as much about where environments would/could matter.

But I'm fine with merging as is, I just wanted to raise an alternative because I never understood why we didn't just make the filename a real argument instead.

private FileUploadService service;
private FileUploadCreateOptions createOptions;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know why the file above had permissions changed?

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 briefly modified the file when I tried to make the filename thing work with .NET Standard. I ended up reverting those changes but it looks like my editor fixed the permissions ¯\_(ツ)_/¯

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

@remi-stripe remi-stripe self-assigned this Sep 19, 2018
@ob-stripe ob-stripe merged commit 7e9bba2 into remi-stripe-dotnet-major-version Sep 19, 2018
@ob-stripe ob-stripe deleted the ob-fix-file-upload branch September 19, 2018 14:02
@ob-stripe ob-stripe mentioned this pull request Sep 21, 2018
32 tasks
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.

2 participants