定制 ustal/rapidapi-library 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ustal/rapidapi-library

Composer 安装命令:

composer require ustal/rapidapi-library

包简介

Bundle to work with the API. Validation and parsing according to the metadata

关键字:

README 文档

README

Build status Latest Stable Version Total Downloads Latest Unstable Version License codecov

Manual

Вызываем менеджер $manager = $this->get('manager');

Передаем название блока (т.е. какой именно блок будем юзать). $manager->setBlockName($blockName);

Получаем все валидные данные (согласно метадате) $validData = $manager->getValidData();

Парсим урл из метадаты и переданный. Заменяем {someVar} на значение из $validData. Если в метадате только куски, например /someAction/. Смотря как делали метадату и может для каждоого Endpoint разные ссылки. $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 tags use only in assoc array with "custom" key variable of block and block's arguments.

Blocks

TagName Type Description
method* String One of PUT, POST, GET, DELETE, PATCH etc
url* String Second part of endpoint /endpointName/action or whole endpoint http://example/com/api/v1/endpointName/action can contain {var}, which will be replaced args by name (in case) or vendorName. Args to replace must be without wrapName tag
type String multipart or json. Default: json
snakeCase Boolean True if you want to change all name from exampleVendorName to example_vendor_name. Priority is given to same tag of args. Default: false

Specific tags (depends on dataType of argument)

Map

TagName Type Description
divide Boolean Use with Map. Divide string from marketPlace to List.
toFloat Boolean Convert value or list of values into Float. If u divided Map and vendor wants get float values not strings
length Number Length of float or string param. Set 1 to convert 123.1111 to 123.1 or "123.1111" to "123.1"

Map (temporary not available)

| lat | String | If divide is true, change list info assocc Array with key = lat value | lng | String | If divide is true, change list info assocc Array with key = lng value

DatePicker

TagName Type Description
dateTime.fromFormat Array Create date from one of format. Like [Y-m-d\TH:i:s\Z, Y-m-d, timestamp].
dateTime.toFormat String Convert data to current format. Like Y-m-d\TH:i:s\Z

Boolean

TagName Type Description
toInt Boolean Convert true/false into integer 1/0
toString Boolean Boolean convert true into "true" and false into "false" Useful if need send var in url.

Number

String

Select

File

TagName Type Description
jsonParse Boolean парсит файл и вставляет в собранный JSON
base64encode Boolean закодировать содержимое файла в base64

Array

TagName Type Description
keyValue Array Use to create key=>value from array with params key and value.
keyValue.key String Work only with Arrays. Create key->value array from multi-dimensional array. Set one of the structure parameters as the key. Do the same with the value.
keyValue.value String Work only with Arrays. Create key->value array from multi-dimensional array. Set one of the structure parameters as the key. Do the same with the value.

List

TagName Type Description
toArray Boolean Convert string into List (use slug to implode)
toString Boolean Convert List into String with delimetr slug. Default slug = ,
slug String Implode or explode arrays/strings by this slug. Default slug = ,
toFloat Boolean Convert list of values into Float
floatLength? Number Length of float param. Set 1 to convert 123.1111 to 123.1

All tags (work with all dataTypes)

TagName Type Description
wrapName String используется для вложенности параметров. Создания дерева вложенности переменных. forum.post.comment создаст массивы forum:{post:{comment:{name}}} где name имя переменной, для которой указан wrapName. Соотв не забывать что последнее всегда будет имя переменной. Не стоит дублировать name: commentContent, wrapName: forum.post.comment.commentContent. Будет: forum:{post:{comment:{commentContetn:{commentContent:{value}}}}}
vendorName String имя аргумента, которое хочет получить вендор. Если не указано, вендор получит имя аргумента в snake case.
urlParam Boolean параметр используется в ссылке. В ссылке никаких {var=value&foo=bar} не надо. Просто эта переменная (по name или vendorName) будет добавлена со своим значением к ссылке. Использовать с GET параметром не надо. Параметры автоматически будут переданы в url
snakeCase Boolean true/false. Если стоит true, даже если у блока стоит false, переменная будет преобразована в camel_case
complex Array сложный параметр. Когда значение одного поля является ключ, другого - значение. Например когда хотят получить {type: email, value: {value}}. Соотв будет только одно поле email и его значение {value}. Но добавится параметр complex: true
complex.key String имя для ключа. В примере выше это будет "type". Используется когда complex: true
complex.value String имя для значения. В примере выше это будет "value". Используется когда complex: true

Пример комплекса

{"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 И ожидает получить title, content, attachment

{
  "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 И ожидает получить title, content, attachment

{
  "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 такого вида

{
  "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"
    }
  ]
}

ustal/rapidapi-library 适用场景与选型建议

ustal/rapidapi-library 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 79 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 05 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「api」 「RapidAPI」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ustal/rapidapi-library 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ustal/rapidapi-library 我们能提供哪些服务?
定制开发 / 二次开发

基于 ustal/rapidapi-library 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 79
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-05-22