First of all create your API configuration file which should include information's like:
vBulletin API key - you can find it in vBulletin control panel, under API section. |
Unique ID - Unique id is used to identity your client and platform name, it can be any unique string. Be careful, if you will change unique ID your request will be recognized as request from new API client and new API client ID will be returned. |
When configuration object is ready, next step is to initiate connection provider. This provider is responsible for communication between your application and vB forum.
By default you can use included Guzzle provider but before you will do this, you should require guzzlehttp/guzzle package in composer. Guzzle provider required forum URL in constructor with trailing slash.
Contexts gives you possibility to encapsulation logic into single class. Under the hood contexts also uses raw vB API requests.
Every context must extend Signes\vBApi\Context\Context class and can required different parameters in constructor.
Context should handle information about request method type, API request type and should return all required parameters by vB for given request.
For your custom context you can also overwrite parseResponse method to return expected format, not raw vB API response.
Fetch current logged in user data
Fetch user data by email
more contexts soon ...
What do API service for you:
send init request to retrieve access token, secret, api version and client id for future requests,
remember your identity (when you send valid login request, every future requests will be called as this logged in user),
prepare signature for every request and include every required by vBulletin parameters,
If you want to integrate with multiple vBulletin instances, you can use API service as a registry. If instance is not remembered null will be returned.
API service constructor has third parameter $lazy with default true value. This parameter determine moment of init request.
If it is set to trueinit request will be send during the first callRequest method call. So if you provided incorrect configuration you will learn about it until now.
If it is set to falseinit request will be send when API service instance is created
Remember configuration and connection
It is possible to keep information about ApiConfig between PHP requests and it is strongly recommend to do that on production. To do that you can use any of your cache services. Just store ApiConfig in cache, and for future use it instance.
That gives you one more benefit, when you login on user account, this information will be remembered in ApiConfig and you do not have to call login request for some period of time (depends of your cache expiration).