T
T
TheSameSon2015-04-06 12:18:09
Laravel
TheSameSon, 2015-04-06 12:18:09

Algorithm for interacting with third-party services through models or packages?

A laravel application accepts a string in a GET/POST request. Then it searches for information on this line by accessing third-party sites through the API (an example of such an application: aviasales.ru and similar services).
The number of sites that you need to access is not known in advance, the API is different for everyone. The question is how in laravel to organize the storage of classes for interacting with the API of each site.
I would like to be able to access sites in the controller as follows:

$keyword = Input::get('keyword');

$results = array();

$APIs = someFunctionToGetAPIs();

foreach ($APIs as $API) {
  $results[] = $API->get($keyword);
}

Those. someFunctionToGetAPIs() must return instances of all API classes.
The option that first comes to mind is to use models without Eloquent, put them in one folder and go through all the files in the folder in someFunctionToGetAPIs() and collect the objects in an array. Or is it better to use packages instead of models? How then to describe someFunctionToGetAPIs()?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vyacheslav Plisko, 2015-04-06
@AmdY

Usual factory, you take out apishki in a config

foreach (Config::get('api.list') as $apiName) {
  $results[$apiName] = Api::create($apiName)->get($keyword);
}

A
Alexey, 2017-12-18
@alexey66

Comrades, gentlemen, there is a similar problem. Who will undertake and help in the implementation? You need to search for products using several third-party APIs, filter and send them to the output.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question