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

Move API key in request header and change body to json format (#89) #90

Merged
merged 1 commit into from
Feb 6, 2025

Conversation

cougargit
Copy link
Member

  • also add examples for live testing and development scenarios

@cougargit cougargit requested a review from WorksDev February 4, 2025 09:44
@cougargit cougargit changed the title Move API key in request header and change body to json format (#89) Move API key in request header and change body to json format #89 Feb 4, 2025
@cougargit cougargit changed the title Move API key in request header and change body to json format #89 Move API key in request header and change body to json format (#89) Feb 4, 2025
@WorksDev WorksDev requested a review from a team February 4, 2025 15:35
private DeeplRequestFactoryInterface $deeplRequestFactory;

private ClientInterface $httpClient;

private RequestFactoryInterface $requestFactory;

public function __construct(
string $apiKey,
Copy link
Contributor

Choose a reason for hiding this comment

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

possibly nullable if you don't have one?

Copy link
Member

Choose a reason for hiding this comment

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

possibly nullable if you don't have one?

Does it even make sense constructing the object without having an apikey? I don't think so...

Copy link
Member Author

Choose a reason for hiding this comment

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

possibly nullable if you don't have one?

Does it even make sense constructing the object without having an apikey? I don't think so...

One option for example is to throw an Exception('No API key given'), but the DeepL API cannot be used without apikey, whether you use the free or the Pro version makes no difference.

What solution is prefered?

Copy link
Member

Choose a reason for hiding this comment

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

possibly nullable if you don't have one?

Does it even make sense constructing the object without having an apikey? I don't think so...

One option for example is to throw an Exception('No API key given'), but the DeepL API cannot be used without apikey, whether you use the free or the Pro version makes no difference.

What solution is prefered?

The only reason to make the api-key nullable + default-null here (and as the last parameter in the list) is backward compatibility.
If the api-key is not nullable, then this change is not compatible and requires a new major version in case someone creates the client without using the factory.

However, since the code is no longer 100% backwards compatible even with an exception in the case of a missing api key, it will end up with a new major version anyway. And then we can do without it and not make the api key nullable.

Unless you find a way to implement the whole thing in a way that makes it backwards compatible. But since the effort is probably not worth it, I would personally be in favor of: non-nullable and a new major version.

Copy link
Member Author

Choose a reason for hiding this comment

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

Unless you find a way to implement the whole thing in a way that makes it backwards compatible. But since the effort is probably not worth it, I would personally be in favor of: non-nullable and a new major version.

I would agree with that "non-nullable and a new major version" to prevent surprises using this lib.

src/Handler/DeeplBatchTranslationRequestHandler.php Outdated Show resolved Hide resolved
- also add examples for live testing and development scenarios
@cougargit cougargit merged commit c85bfe2 into master Feb 6, 2025
2 checks passed
@cougargit cougargit deleted the moveApiKeyInHeader branch February 6, 2025 13:04
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.

3 participants