ustal / rapidapi-library
与API一起工作的包。根据元数据进行验证和解析
Requires
- php: >7.0.0
- guzzlehttp/guzzle: ^6.2
Requires (Dev)
- phpunit/phpunit: 6.1.*
README
手册
调用管理者 $manager = $this->get('manager');
传递块名称(即要使用的哪个块)。$manager->setBlockName($blockName);
获取所有有效数据(根据元数据)$validData = $manager->getValidData();
解析元数据和传递的URL。将 {someVar} 替换为 $validData 中的值。如果元数据中只有片段,例如 /someAction/。这取决于元数据是如何创建的,并且可能对于每个端点有不同的链接。$url = $manager->createFullUrl($validData, $url);
创建 headers。必须从 $validData 中删除不需要传递的变量(用于生成头部。需要链接 function createHeaders(&$data)。这个函数在包中定义。$headers = $manager->createHeaders($validData);
获取变量。有时在POST请求中可能需要发送大量的参数到URL。因此,使用 urlParam 可以将参数分成两部分。$urlParams = $manager->getUrlParams(); $bodyParams = $manager->getBodyParams();
$result = $manager->send($url, $urlParams, $bodyParams, $headers);
仅在使用带有 "custom" 键的关联数组变量和块的参数时使用自定义标记。
块
特定标记(取决于参数的数据类型)
地图
地图(暂时不可用)
| lat | String | 如果分割为真,将列表信息转换为具有键 = lat 值的关联数组 | lng | String | 如果分割为真,将列表信息转换为具有键 = lng 值的关联数组
日期选择器
布尔值
数字
字符串
选择
文件
数组
列表
所有标签(与所有数据类型一起工作)
示例综合体
{"contacts":
[
"type": "facebook",
"value": {value}
],
[
"type": "twitter",
"value": {value}
]
}
第一个示例(多部分)POST https://your-domain-name.example.com/forum/1/category/2/newPost?insertPostSafeAndWhatEver=1&draft=true 预期获取标题、内容、附件
{
"name": "createNewPost",
"description": "Create new post",
"custom": {
"method": "POST",
"type": "multipart", //default json
"url": "https://{domain}.example.com/forum/{forumId}/category/{category_id}/newPost"
},
"args": [
{
"name": "domain",
"type": "String",
"info": "",
"required": true
},
{
"name": "forumId",
"type": "String",
"info": "",
"required": true,
"custom": {
"vendorName": "forumId" // always use vendorName or snake style of "name". Repace forumId, not forum_id
}
},
{
"name": "categoryId", // transform to category_id, and replace it in url
"type": "String",
"info": "",
"required": true
},
{
"name": "insertSafe",
"type": "Boolean",
"info": "Insert post safe and what ever bla-bla-bla",
"required": false,
"custom": {
"vendorName": "insertPostSafeAndWhatEver", //if not set, param name will be insert_safe (snake case)
"toInt": true, //default false
"urlParam": true // default false
}
},
{
"name": "draft",
"type": "Boolean",
"info": "",
"required": true,
"custom": {
"urlParam": true
}
},
{
"name": "title",
....
},
{
"name": "content"
},
{
"name": "attachment",
"type": "File",
"info": "",
"required": false
}
],
"callbacks": [
{
"name": "error",
"info": "Error"
},
{
"name": "success",
"info": "Success"
}
]
}
第二个示例(base64)POST https://your-domain-name.example.com/forum/1/category/2/newPost?insertPostSafeAndWhatEver=1&draft=true 预期获取标题、内容、附件
{
"name": "createNewPost",
"description": "Create new post",
"custom": {
"method": "POST",
"url": "https://{domain}.example.com/forum/{forumId}/category/{categoryId}/newPost"
},
"args": [
{
"name": "domain",
"type": "String",
"info": "",
"required": true
},
{
"name": "forumId",
"type": "String",
"info": "",
"required": true,
"custom": {
"vendorName": "forumId"
}
},
{
"name": "categoryId",
"type": "String",
"info": "",
"required": true,
"custom": {
"vendorName": "categoryId"
}
},
{
"name": "insertSafe",
"type": "Boolean",
"info": "Insert post safe and what ever bla-bla-bla",
"required": false,
"custom": {
"vendorName": "insertPostSafeAndWhatEver",
"toInt": true,
"urlParam": true
}
},
{
"name": "draft",
"type": "Boolean",
"info": "",
"required": true,
"custom": {
"urlParam": true
}
},
{
"name": "title",
....
},
{
"name": "content"
},
{
"name": "attachment",
"type": "File",
"info": "",
"required": false,
"custom": {
"base64encode": true
}
}
],
"callbacks": [
{
"name": "error",
"info": "Error"
},
{
"name": "success",
"info": "Success"
}
]
}
第三个示例 POST https://your-domain-name.example.com/forum/1/category/2/newPost 预期获取如下JSON类型的JSON
{
"post": {
"title": "Post title",
"content": "Post content",
"attachment": "base64(image)"
"user": {
"name": "John Doe",
"contacts": [
{"typeContact": "email", "valueContact": "john@example.com"},
{"typeContact": "twitter", "valueContact": "john111"}
]
},
"voting": {
"question": "Be or not to be?",
"answers": [
"yes",
"no",
"dont know"
]
},
"other": {Object}
}
}
{
"name": "createNewPost",
"description": "Create new post",
"custom": {
"method": "POST",
"url": "https://{domain}.example.com/forum/{forum_id}/category/{category_id}/newPost"
}
"args": [
{
"name": "domain",
"type": "String",
"info": "",
"required": true
},
{
"name": "forumId",
"type": "String",
"info": "",
"required": true
},
{
"name": "categoryId",
"type": "String",
"info": "",
"required": true
},
{
"name": "title",
"type": "String",
"info": "",
"required": "",
"custom": {
"wrapName": "post"
}
},
{
"name": "content",
"type": "String",
"info": "",
"required": "",
"custom": {
"wrapName": "post"
}
},
{
"name": "file",
"type": "File",
"info": "",
"required": "",
"custom": {
"wrapName": "post",
"vendorName": "attachment",
"base64encode": true
}
},
{
"name": "userName",
"type": "String",
"info": "",
"required": "",
"custom": {
"vendorName": "name",
"wrapName": "post.user"
}
},
{
"name": "email",
"type": "String",
"info": "User contact email",
"required": "",
"custom": {
"wrapName": "post.user.contacts",
"complex": true,
"keyName": "typeContact",
"valueName": "valueContact"
}
},
{
"name": "twitter",
"type": "String",
"info": "User contact twitter",
"required": "",
"custom": {
"wrapName": "post.user.contacts",
"complex": true,
"keyName": "typeContact",
"valueName": "valueContact"
}
},
{
"name": "votingQuestion",
"type": "String",
"info": "",
"required": "",
"custom": {
"vendorName": "question",
"wrapName": "post.voting"
}
},
{
"name": "answers",
"type": "Array",
"info": "If send String comma separated it make array???",
"required": "",
"custom": {
"wrapName": "post.voting"
}
},
{
"name": "other",
"type": "File",
"info": "Data in JSON format unknown structure or cannot be translate into metadata. Example: Unknown elements"
"required": "",
"custom": {
"jsonParse": true
"wrapName": "post"
}
}
],
"callbacks": [
{
"name": "error",
"info": "Error"
},
{
"name": "success",
"info": "Success"
}
]
}