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 CURL Json POST #3489 #8373

Closed
wants to merge 3 commits into from
Closed

Fix CURL Json POST #3489 #8373

wants to merge 3 commits into from

Conversation

Grohotun
Copy link
Contributor

@Grohotun Grohotun commented Feb 1, 2017

Add ability to make json requests
Issue #3489

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Feb 1, 2017

CLA assistant check
All committers have signed the CLA.

* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function makeRequest($method, $uri, $params = [])
protected function makeRequest($method, $uri, $params = [], $json = false)
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for your contribution to Magento 2 project.

Adding this logic to protected method requires extension developers inherit this class. This is what we are trying to avoid in Magento 2.

Could you please provide more details about your use case? Maybe we will suggest a better way how we can achieve your goal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@okorshenko how should we do get/post requests?

In our case we need to send post with json.

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 got your point, we need to modify post, get method too. Not just this protected method.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for the fixes. Unfortunately, by this fix you modified public interface of the class and added knowledge about JSON for Curl client. On the other hand, how to post XML request for instance? We don't want to add $isXML flag to the method again. So we need to have something more general - string format.

Let me suggest another approach:

 * @param array|string $params
protected function makeReques (...) {
 
   ...
   $this->curlOption(CURLOPT_POSTFIELDS, is_array($params) ? http_build_query($params) : $params);
   ...
}

We are extending our contract by adding new supported type string wihtout changes in public method parameters.

Please, do not forget to align makeRequest and post method signatures.

Thank you for reporting and fixing this issue. Good catch! +100500 to your karma! ;)

@Grohotun
Copy link
Contributor Author

Grohotun commented Feb 3, 2017

@okorshenko pull request is updated.

* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function makeRequest($method, $uri, $params = [])
protected function makeRequest($method, $uri, $params = [], $json = false)
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for the fixes. Unfortunately, by this fix you modified public interface of the class and added knowledge about JSON for Curl client. On the other hand, how to post XML request for instance? We don't want to add $isXML flag to the method again. So we need to have something more general - string format.

Let me suggest another approach:

 * @param array|string $params
protected function makeReques (...) {
 
   ...
   $this->curlOption(CURLOPT_POSTFIELDS, is_array($params) ? http_build_query($params) : $params);
   ...
}

We are extending our contract by adding new supported type string wihtout changes in public method parameters.

Please, do not forget to align makeRequest and post method signatures.

Thank you for reporting and fixing this issue. Good catch! +100500 to your karma! ;)

@Grohotun
Copy link
Contributor Author

Grohotun commented Feb 7, 2017

@okorshenko good point, I've updated pull request

@okorshenko
Copy link
Contributor

@Grohotun thank you for contribution! We accepted your initial code with some small fixes. Thank you!

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.

4 participants