📜 ⬆️ ⬇️

Open Yandex PHP Library to work with the Yandex API

Hello to all!

Long time I did not write on Habr. Not that I wouldn’t have anything to tell about, just to share stories, so that the itch would appear to work until midnight. Especially if they are about the cooperation of PHP-developers and Yandex. Especially if they are about the fact that the long-awaited PHP library for working with the Yandex API has appeared .


')
I'll tell you a bit about myself. My name is Anton Shevchuk. I’ve been on Habré for a long time, and if you’ve studied jQuery, you’ve read my blog with a high degree of probability. At the same time, my main activity is still PHP development, and the position requires me - I work as a PHP expert in NIX Solutions .

But enough of the lyrics, I promised an informative story.

It began in 2008 with the writing of a PHP library for working with the Yandex.XML service; I modestly called the library yandex-xml and tried to support it. In fact, I took on some of the responsibilities of supporting Yandex, but I think it didn’t upset them much. Of course, I wondered: “Where, in fact, is my native library from Yandex?” Who knew that I would know the answer after five years :)

As time went on, Yandex had more and more new services, and where there are services, there is also an API. They multiplied and multiplied, but somehow there was no convenient tool for PHP developers. At the same time, interest in services continued to grow, and out of idle curiosity grew into a professional one.

A year ago, during the period of summer aggravation of perfectionism, patience snapped, and my company turned to Yandex with a proposal to write a php-library for all Yandex APIs. We needed help in answering numerous questions, as well as instructions from teams of various APIs, who better understand how their service is organized and how it works. One of the arguments was just an example with the library yandex-xml, and its download count was over a couple of thousand.

Dmitry Vulbrun, one of the managers of Yandex, volunteered to help us, connect with different departments / groups / services and simplify communication with various teams.

I will allow myself to insert his comment on this subject here.

Historically, there is no php in Yandex. Absolutely not. We understand the pain of developers trying to use our technologies on their sites, but we don’t have the opportunity to deploy a large infrastructure within the company to create such a library. For this you need machines, admins, php-developers, testers, technical writers, support. In the end, you need a manager of this project. Technically, this is, of course, feasible, and we even tried to create such an infrastructure inside Yandex to develop our SDK-php, but soon we realized that before that they didn’t reach at all. We tried to create such things on an outsource, but then we still have to support all this ourselves. And we had not so many people who know php and various CMS. Therefore, we really liked the idea of ​​creating a library outside the company - by people who have ready infrastructure for this and who understand webmasters and web developers. Of course, we strongly support this initiative.


And then we started work. Determined requirements.



The path for development was set, there remained technical subtleties. It was necessary to understand how we will give the opportunity to connect the library. At first they decided that Composer is the best and only correct solution: modern, tasty, appetizing. However, this option is not suitable for all web developers, so it was decided to combine the composer with phar archives as with a simpler way of integration, albeit with their own problems.

The choice of the order in which to write modules for the library remained with Yandex. And I will quote Dmitry again:

When Anton and I started discussing the creation of the library, the first thing was for me to put together all the information about all the Yandex APIs. It was not as easy as it seemed at first glance, and took a lot of time - Yandex is big :)
All the teams reacted differently to our idea: someone caught fire with it right away, someone more calmly took our idea. In addition, some teams planned to redo or release new versions to their APIs, and in this case the library needed to be written for new, not yet released, API versions.

In general, of course, everyone understood that a general PHP library for working with all Yandex APIs is a necessary thing and we “make the world a better place”. It was necessary to decide where to start.

Since I am engaged in the Search service for the site, and it has one small and simple API handle, we decided to issue a project on the githaba and develop the infrastructure for developing the library, creating a module specifically for the Search for the site. This is logical: it is always easier to start work with something simpler.
Next, we analyzed the available information about all our APIs. We found out that most of them have OAuth authorization, so the next step was to create a separate authorization module. So that later this module could be used further.

Well, after that the order of services was mainly conditioned by the activity of the team of a specific service and the desire of its members to help colleagues from NIX Solutions and guide them in the creation of the library. So we got the first list: Safe Browsing API, Disk API, Shopping on the Market, API Metrics.


So, as far as providing us with information from the Yandex teams, the modules were also sawed, not without bugs, but the work was going on.

To date, the library has grown and includes several modules:

I will say literally a couple of phrases about each module, without technical details. We posted all the details on github .

OAuth authorization module
One of the first developed modules is authorization on the Yandex API services. At the current time, Yandex services mainly use OAuth authentication, which greatly simplifies working with them, and working with our library becomes even easier. Documentation


Module for pinger search service for the site
If on your site you use the Search service for the site, then you should pay attention to the pinger library, whose task is to inform Yandex about new and changed documents on the site. Documentation


Module for Safe Browsing API
This package is responsible for checking the URL for involvement in untrusted sites, so that in an hour no infection has come to you. This service is useful for sites that host links to other resources on the network. Documentation


Module for Yandex.Disk API (WebDAV)
Yandex.Disk is confidently gaining points as an alternative to various drives, and, I hope, this library will serve as another step in winning the market. Documentation


Module for “Shopping on the Market” under the Affiliate API Market
If your store places offers on Yandex.Market, then you should pay attention to the appropriate library. Documentation


Now the module is being developed for working with the Metrics API.

Development infrastructure


We not only make a library, but also acquire facilities for development and testing. GitHub has long been for many the “default” development platform. He managed to get some nice buns that can be screwed to the project in a couple of clicks or in a couple of lines, and I wanted to dwell on them a little more in detail.

Travis ci

To connect the Travis continuous integration service, you will need to create a configuration file (you can use ours as a basis) and connect your project to GitHub on the travis-ci.org site.

At the moment, Travis is running the run of unit tests and PSR standards on various PHP versions (including even HHVM and PHP 5.6 version), as well as creating a phar archive with a further download of it on Yandex.Disk using our own library :)

More about Travis CI has already been told on Habré - habrahabr.ru/post/140344

The result of the integration is available here.

Scrutinizer CI

Another tool to control the quality of the code, allows you to identify potential problems and gives recommendations for improvement (you can directly patch, it remains to copy and apply). The main part of the work falls on PHP_Analyzer, but not one.

The result of the project integration - scrutinizer-ci.com/g/nixsolutions/yandex-php-library

Coveralls

This is a simple tool that stores test coverage for your project. For those familiar with phpunit , this is a clover.xml visualization with tracking changes. Travis is responsible for the data upload, for work it is required to install the “satooshi / php-coveralls” package and the configuration file for the example - github.com/nixsolutions/yandex-php-library/blob/master/.coveralls.yml

Result: coveralls.io/r/nixsolutions/yandex-php-library

And some more “badges” for the collection can be obtained at poser.pugx.org .

Instead of conclusion


... And to avoid in the comments pictures of the trolley from a loaf of bread.

Profit for the company NIX Solutions - PR of our cooperation with the company Yandex (actually this is the third mention of the company name in this article :). Plus, we have acquired a non-sickly knownledge base on API and can help PHP developers to answer frequently asked questions about the integration of Yandex services.

Profit for Yandex - library development for a huge PHP-community by PHP developers. Partly shifting support onto our shoulders.

Profit for the community - now we have an up-to-date library for working with Yandex services, while every developer can participate in the development of this

So, dear Habr, do not be shy and send your questions, but rather pull requests to GitHub - github.com/nixsolutions/yandex-php-library .

We wait, kiss, love.

Source: https://habr.com/ru/post/231495/


All Articles