{$AppName}
{AppName} is a XQuery library for searching across the data shared by Allegro RESTApi.
Getting Started
To get started download .zip file of main repository or clone repository to your local machine.
Prerequisites
- Java 8 or greater
- XQuery processor i.e BaseX
Example usage
Authorization
Before being granted with access to Allegro resources user has to register application in order to get client id and client secret.
To authorize {$AppName} uses OAuth2 Client_credentials flow. It demands access token concated with token type to be sent with every request to Allegro RESTApi as a Authorization header. For more informations about authorization click here.
Assuming you put project files under /home directory in order to use any function you need to create new XQuery module to execute code and import authorization.xqm library module with proper namespace.
Below example assumes that your module is placed under /home/src
- Get your base64 encoded application client id and client secret joined by ':' and pass as function argument along with authorization url.
xquery version "3.1";
import module namespace auth="http://release11.com/allegro/authorization" at "authorization.xqm";
let $accessToken := auth:get-access-token("https://allegro.pl/auth/oauth/token?grant_type=client_credentials","yourClientId:yourClientSecretEncoded")
- Concat token type and access token to get authorization header that will be sent in every request to Allegro RESTApi and authorize your application.
let $authorizationHeader := auth:get-authorization-header($accessToken, "Bearer")
Executing module
Below example assumes that your module is placed under /home/src
- In order to use any function you need to import to your module from above example api.xqm library module with proper namespace.
Xquery version "3.1";
import module namespace allegro="http://release11.com/allegro/api" at "api.xqm";
import module namespace auth="http://release11.com/allegro/authorization" at "authorization.xqm";
let $accessToken := auth:get-access-token("https://allegro.pl/auth/oauth/token?grant_type=client_credentials","yourBase64EncodedCredentials")
let $authorizationHeader := auth:get-authorization-header($accessToken, "Bearer")
- The next step is to create return statement that contains function you want to use. In below example we pass categories endpoint given by Allegro, authorization header and number of category which data should be fetched.
return
allegro:get-category-by-id($$authorizationHeader, $categoriesUrl, 5)
If you are using BaseX press ctrl + enter to check the result in console. You should see xml document that represents informations about category with id 5 as shown below.
Authors
Tomasz Kaleta
License
This project is licensed under the MIT License - see the LICENSE.md file for details
