leaseweb / lswapicallerbundle Goto Github PK
View Code? Open in Web Editor NEWSymfony2 bundle that adds cURL API call functionality with full Web Debug Toolbar integration.
License: MIT License
Symfony2 bundle that adds cURL API call functionality with full Web Debug Toolbar integration.
License: MIT License
If i try to use to library outside a symfony environment like this:
{
"require": {
"leaseweb/api-caller-bundle": "1.2.6"
}
}
and using the code:
<?php
require_once 'vendor/autoload.php';
use Lsw\ApiCallerBundle\Caller\LoggingApiCaller;
use Lsw\ApiCallerBundle\Call\HttpPostJson;
$caller = new LoggingApiCaller([]);
$curlCall = new HttpPostJson(
'http://myurl.com',
['foo' => 'bar']
);
var_dump(array(
'body' => $caller->call($curlCall),
'status' => $caller->getLastStatus()
));
I end up with the following dependency error:
Error: Class 'Doctrine\Common\Util\Inflector' not found in [mypath]/vendor/leaseweb/api-caller-bundle/Lsw/ApiCallerBundle/Helper/Curl.php on line 38
Unfortunately, it is tied to Utils, not separate Inflector lib.
The fix is simple, just include "doctrine/common" in the library composer requirements.
Should I make a PR.
Hi,
Is it possible to POST as JSON. Tried to add the 'Content-type: application/json' header, but can't post a json string :(
Using HttpPostJson always need add an array, and encode all elements of this array with an url_encode.
Any solution?
Thank you.
https://github.com/LeaseWeb/LswApiCallerBundle/blob/master/Call/CurlCall.php#L335
It incorrectly strips headers out of the body in case of redirect, cause in this case we have 2 sets of headers returned and only one stripped.
Set CURLOPT_RETURNTRANSFER default to true
Example of similar implementation: http://unirest.io/#php
Is there a hacky way to do this at the moment?
Hello,
Can you tag master as a new version please? As it fix an issue on Inflector it would be great to set a tag and not master in composer.
Thank you,
Louis
I try to implement an API call with this bundle, and got problem with the token auth required by the API.
Here is a sample of the calls:
// get token url
$tokenUrl = '/api/auth/gettoken';
$parameters = array(
'user' => 'user',
'password' => 'password',
);
// api call
$output = $this->get('api_caller')->call(new HttpGetJson($baseUrl.$tokenUrl.$postUrl, $parameters));
$token = $output->token;
// schedule
$parameters = array(
'token' => $token,
'start' => time(),
'duration' => 24,
);
$progUrl = '/api/get/schedule';
// api call
$output = $this->get('api_caller')->call(new HttpGetJson($baseUrl.$progUrl.$postUrl, $parameters));
The 1st call get me a valid token, but the 2nd call fails because of an "Authentification failed".
Have I missed something?
Thanks.
HTTPS://api.lifx.com:443/v1beta1/lights.json and https://api.lifx.com/v1beta1/lights.json wont work
no request will be send. (Connection failed)
HTTP://api.lifx.com:443/v1beta1/lights.json returns 400 Bad Request (which is good)
controller
$url = "https://api.lifx.com:443/v1beta1/lights.json";
$result = $this->get('api_caller')->call(new HttpGetJson($url, array()));
HttpGetJson
class HttpGetJson extends CurlCall implements ApiCallInterface
{
/**
* {@inheritdoc}
*/
public function generateRequestData()
{
$this->requestData = http_build_query($this->requestObject);
}
/**
* {@inheritdoc}
*/
public function parseResponseData()
{
$this->responseObject = json_decode($this->responseData, $this->asAssociativeArray);
}
/**
* {@inheritdoc}
*/
public function makeRequest($curl, $options)
{
$curl->setopt(CURLOPT_URL, $this->url.'?'.$this->requestData);
$curl->setopt(CURLOPT_HTTPHEADER, array('Content-type: application/json'));
$curl->setoptArray($options);
$this->responseData = $curl->exec();
}
}
When i use the direct way it will work just fine (returns a 401 error cause we're not sending our api key along)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.lifx.com:443/v1beta1/lights.json');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_GET, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
Hello,
I'm currently using this bundle for api calls, but I needed to extend the Call requests to fit more flexible env. My suggestion is this:
public function __construct($url, $requestObject, $asAssociativeArray = false, array $ymlOptions = array())
{
parent::__construct($url, $requestObject, $asAssociativeArray);
$this->ymlOptions = $ymlOptions;
}
public function makeRequest($curl, $options)
{
// merge the options from the API Caller bundle with other set of options
// override the options with the provided from the Yml
foreach($this->ymlOptions as $const => $value)
{
$options[constant($const)] = $value;
}
// call the parent MakeRequest, this way we don't have to copy all it's logic
parent::makeRequest($curl, $options);
}
My extension is to dynamically put options on the Request. In my case I pass options about the credentials because the Live and Test credentials are different.
Regards,
Lachezar Lechev
I am having issues sending a POST request with JSON Body (HttpPostJsonBody) to a node express server. The call appears to be processed correctly on the server but the response received is a 100 - Continue rather than the returned JSON.
I have seen various posts advising to add 'Except:' to the HTTP_HEADER but that resulted in the call failing.
Do you have any advice as to how I might resolve this problem ?
Thank you.
I want to sent a x-wsse header, how does this works?
I tried this:
api_caller.options:
timeout: 10 # maximum transport + execution duration of the call in sec.
ssl_verifypeer: false # to stop cURL from verifying the peer's certificate.
useragent: "LeaseWeb API Caller" # contents of the "User-Agent: " header.
followlocation: true # to follow any "Location: " header that the server sends.
sslversion: 3 # set to 3 to avoid any bugs that relate to automatic version selection.
fresh_connect: false # set to true to force full reconnect every call.
HTTPHEADER:
x-wsse: test
Hello,
Issue with debug bar on SF4
Resources/views/Collector/api.html.twig
-{% extends '@WebProfiler/Profiler/layout.html.twig' %}
+{% extends '@WebProfiler/Profiler/toolbar_item.html.twig' %}
I can push the modification if you allow me to contribute
Using your bundle I have some problems.
Your Bundle is not support uploading files.
Method "generateRequestData()" always generate QueryString but when I need to upload file I need to put array to CURLOPT_POSTFIELDS. I'm ready to fix this problem.
I'm propose remove method "generateRequestData()". And transform data in method "makeRequest()".
Variable $requestData use only "Logger". Maybe we not need to log long requests (when post request so big).
Currently I'm solve this problem:
$result = $this->getContainer()->get('api_caller')->call(
new HttpPost($url, [], false, [
'POSTFIELDS' => $post
])
);
Why your bundle concat "CURLOPT_" prefix?? Maybe you need to use class constants???
SSLv3 is deprecated, and actually removed in Ubuntu 16.04 LTS+PHP 7. We shouldn't force cURL in using any particular version.
Hello. Sorry, but can you write few strings how use this bundle to send POST data
Hey,
Documentation says:
Requirements
Symfony 2.1 (works under Symfony 2.0 as well)
Is it possible to require Symfony 2.0 instead of 2.1 in this case. I'm trying to integrate this to our application that is about 4 years old and is based on Symfony 2.0.
Thanks,
returntransfer: true
verbose: true
header: true
Hey,
I'm trying to send a HttpGetJson to my API. However, my API answers with a 405 (Method not allowed):
$baseUrl = $this->serviceContainer->getParameter('api_base_url');
$me = $this->apiCaller->call(new HttpGetJson($baseUrl.'/user/me', array(
'access_token' => $token->getAccessToken()
))); // results in a 405 (method not allowed, but my API allows GET requests for this endpoint)
// No route found for "POST /user/me" --> but I'm sending a GET
// The request I was sending before, was a POST
If I'm using DHC by Restlet and sending a GET to /user/me, the API is answering correctly:
{
"customer":{
"id": 1,
"email": "[email protected]",
"roles_unserialized":[
"ROLE_FOO_ADMIN"
],
"created_at": "2016-05-06 23:33:29"
}
}
Do you know, what could be the problem?
Best,
Christian
When using this nice debug toolbar I had some browser issue.
The main problem was that Chrome 71.0.3578.98 throws an error in the console when you click on one of the requests or responses.
For more details about the issue see https://ourcodeworld.com/articles/read/682/what-does-the-not-allowed-to-navigate-top-frame-to-data-url-javascript-exception-means-in-google-chrome
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.