铁路 / 声音切片
通过Soundslice API进行通信
Requires
- php: >=7.1.3
- guzzlehttp/guzzle: ~6.0
- laravel/framework: 5.6.*
Requires (Dev)
- orchestra/database: ~3.6
- orchestra/testbench: ~3.5
- phpunit/php-code-coverage: ~6.0
- phpunit/phpunit: ~7.0
README
端点和服务,用于通过它们的API连接您的应用程序到Soundslice。
Soundslice API文档: https://www.soundslice.com/help/data-api/
安装
安装
注册服务提供商
将SoundsliceServiceProvider添加到您的应用程序服务提供商列表(/config/app.php中的"providers"属性,数组)中。
发布配置
运行此命令以将包的配置文件发布到您的应用程序配置目录。
$ php artisan vendor:publish
提供Soundslice凭证
提供以下环境变量
SOUNDSLICE_APP_IDSOUNDSLICE_SECRET
见Lastpass Secure Note "Musora - Local .env" (在"Shared Railroad Web Development" -> "Local Dev" -> )
(对于验收测试,复制.env.testing.example并重命名为".env.testing",并在那里提供相应的环境变量。它已添加到.gitignore)
API参考
注意
端点
在以下所有端点前加上/soundslice/。
花括号中的内容是内联参数。
例如,如果下面说get/{slug},那么您针对slug foo的实际端点将是/soundslice/get/foo。
默认值
除非另有说明,否则所有可选布尔值默认为false。
可用方法列表
- createScore
- list
- get
- delete
- move
- 文件夹创建
- 文件夹删除
- 创建符号
错误
所有错误都作为Json响应的errors数组(它存在于data数组的位置)中的项可用。
示例
{
"errors":[
{
"status":"Internal Server Error",
"code":500,
"title":"SoundSliceJsonController@createScore failed",
"detail":"flux capacitor exceeded threshold with gamma output of 28937u4893 hertz."
}
]
}
这是我试图理解json-api文档的尝试。
每个错误项都将具有以下示例中的字段
状态:
适用于此问题的HTTP状态码,以字符串值表示。
代码:
以字符串值表示的应用程序特定错误代码。
标题:
对问题的简短、易于阅读的总结,不应随问题的发生而改变,除非用于本地化。
详细说明:
针对此问题发生的特定解释。像标题一样,此字段的值可以是本地化的。
验证错误
详细信息
将返回包含有关验证失败原因的"error"对象的400 Bad Request。该错误中的"detail"项将包含有关验证失败的信息。
对于每个失败的字段都有一个项,每个字段项将包含针对每个失败原因的项。
例如,如果我们试图创建一个新的"baz",如果"foo"字段失败,因为它不是数字并且长度超过16个字符,我们会看到以下内容
{
"errors":[
{
"status":"Bad Request",
"code":400,
"title":"create baz request validation failure",
"detail":{
"foo":[
"The foo must be a number."
]
}
}
]
}
如果有那种失败 - 只有一个字段的两个验证失败,然后另一个字段的整个验证失败,它看起来会是这样:(假设"artist"字段是必填的)
{
"errors":[
{
"status":"Bad Request",
"code":400,
"title":"create baz request validation failure",
"detail":{
"foo":[
"The foo may not be greater than 16.",
"The foo must be a number."
],
"bar":[
"The bar field is required."
]
}
}
]
}
详细子值是失败的人性化原因。
方法
创建分数
PUT "create"
有关这些参数的说明,请参阅下文的“创建分数参数说明”部分。
成功时返回
- 状态码
201 - 状态文本
Created slug字符串
{
"statusText":"Created",
"status":201,
"data":{
"slug": "fo1337br"
}
}
列出分数
GET "list"
成功时返回
- 状态码
200 - 状态文本
OK scores数组,包含账户的所有分数。
示例(此示例中账户只有两个分数)
{
"statusText":"OK",
"status":200,
"data":{
"scores":[
{
"status":1,
"show_notation":true,
"print_status":1,
"can_print":false,
"embed_status":1,
"name":"nameFoo ex",
"artist":"artistFoo pariatur ab",
"slug":"fo154364br",
"recording_count":0,
"has_notation":false
}
]
}
}
获取分数
GET "get/{slug}"
成功时返回
- 状态码
200 - 状态文本
OK score数组
{
"statusText":"OK",
"status":200,
"data":{
"score": {
"status":1,
"show_notation":true,
"print_status":1,
"can_print":false,
"embed_status":1,
"name":"nameFoo labore natus",
"artist":"artistFoo atque repellendus iusto",
"url":"/scores/154453/",
"recording_count":0,
"has_notation":false
}
}
}
删除分数
DELETE "delete"
成功时返回
- 状态码
200 - 状态文本
OK deleted表示布尔值的整数
{
"statusText":"OK",
"status":200,
"data":{
"deleted": 1
}
}
移动分数
建设中
POST "move"
成功时返回
文件夹创建
PUT "folder/create"
成功时返回
- 状态码
201 - 状态文本
Created folder-id字符串
{
"statusText":"Created",
"status":201,
"data":{
"folder-id": "fo1337br"
}
}
文件夹删除
DELETE "folder/delete"
成功时返回
- 状态码
200 - 状态文本
Created delete表示布尔值的整数
{
"statusText":"OK",
"status":200,
"data":{
"deleted": 1
}
}
创建符号
PUT "notation"
asset-url 应该是一个公开可访问的URL,提供相关的媒体文件(例如:musicxml 文件)
成功时返回
- 状态码
200(因为不创建) - 状态文本
OK(因为不创建) notation表示布尔值的整数。 不表示符号的创建,仅表示尝试创建过程中的成功 - 您必须请求GET以确定成功。
{
"statusText":"OK",
"status":200,
"data":{
"notation": 1
}
}
创建分数参数说明
"publicly-listed"
指定谁可以在soundSlice.com上查看分数。(嵌入时忽略此设置并使用embed_status。)
false - “仅我”
true - “任何知道其URL的人”
嵌入选项
参考:[Soundslice的嵌入文档](https://www.soundslice.com/help/management/#embedding)。
"embed-white-list-only"
false - 不仅限于白名单域名 - 延迟到embed-globally选项
true - 仅允许在白名单域名上
"embed-globally"
false - 禁用(默认值,如果未提供)
true - 允许在任何域名上
有关embed-white-list-only和embed-globally选项的说明
这是此soundslice集成包的选项,抽象了实际Soundslice API的选项。
因此,如果您直接查看Soundslice API,您将看到以下内容
embed_status Optional
An integer specifying embed options. For more, see embedding docs.
1 — Disabled (default value, if not provided)
2 — Allowed on any domain
4 — Allowed on whitelist domains
此包确定用于该(embed_status)选项的整数值的方法如下
$embedWhiteListOnly ? 4 : ($embedGlobally ? 2 : 1)
仅此而已,以防您在尝试使用此集成包的方法时查看soundSlice的API文档。
这些是我们的测试用例
(在[soundslice/tests/Acceptance/SoundsliceTest.php](https://github.com/railroadmedia/soundslice/blob/master/tests/Acceptance/SoundsliceTest.php)中)
- create_score
- create_score_fails_folder_id_not_whole_number
- create_score_fails_folder_does_not_exist
- create_score_fails_already_exists
- create_score_validation_fail
- list
- get_score
- get_score_not_found
- delete_score
- delete_score_not_found
- delete_score_validation_failure
- create_folder
- create_nested_folder
- create_folder_validation_failure
- create_folder_failure_invalid_parent_id
- delete_folder
- delete_folder_not_found
- delete_folder_validation_failure
- create_notation
- create_notation_validation_failure
- create_notation_upload_more_than_one
- create_notation_with_same_values