Add abstraction over ApiParameters

This commit is contained in:
Joel Wachsler 2022-07-14 20:50:46 +00:00
parent 79004924ec
commit 250a1d098c
5 changed files with 1401 additions and 1230 deletions

View File

@ -8,7 +8,8 @@
"Upon success, the response will contain a cookie with your SID. You must supply the cookie whenever you want to perform an operation that requires authentication.\n\nExample showing how to login and execute a command that requires authentication using `curl`:\n\n```sh\n$ curl -i --header 'Referer: http://localhost:8080' --data 'username=admin&password=adminadmin' http://localhost:8080/api/v2/auth/login\nHTTP/1.1 200 OK\nContent-Encoding:\nContent-Length: 3\nContent-Type: text/plain; charset=UTF-8\nSet-Cookie: SID=hBc7TxF76ERhvIw0jQQ4LZ7Z1jQUV0tQ; path=/\n$ curl http://localhost:8080/api/v2/torrents/info --cookie \"SID=hBc7TxF76ERhvIw0jQQ4LZ7Z1jQUV0tQ\"\n```\n\nNote: Set `Referer` or `Origin` header to the exact same domain and port as used in the HTTP query `Host` header.",
),
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "username",
@ -32,6 +33,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "login",
@ -2599,7 +2602,9 @@
"The response is a JSON array in which each element is an entry of the log.\n\nEach element of the array has the following properties:\n\n\nExample:\n\n```JSON\n[\n {\n \"id\":0,\n \"message\":\"qBittorrent v3.4.0 started\",\n \"timestamp\":1507969127860,\n \"type\":1\n },\n {\n \"id\":1,\n \"message\":\"qBittorrent is trying to listen on any interface port: 19036\",\n \"timestamp\":1507969127869,\n \"type\":2\n },\n {\n \"id\":2,\n \"message\":\"Peer ID: -qB3400-\",\n \"timestamp\":1507969127870,\n \"type\":1\n },\n {\n \"id\":3,\n \"message\":\"HTTP User-Agent is 'qBittorrent/3.4.0'\",\n \"timestamp\":1507969127870,\n \"type\":1\n },\n {\n \"id\":4,\n \"message\":\"DHT support [ON]\",\n \"timestamp\":1507969127871,\n \"type\":2\n },\n {\n \"id\":5,\n \"message\":\"Local Peer Discovery support [ON]\",\n \"timestamp\":1507969127871,\n \"type\":2\n },\n {\n \"id\":6,\n \"message\":\"PeX support [ON]\",\n \"timestamp\":1507969127871,\n \"type\":2\n },\n {\n \"id\":7,\n \"message\":\"Anonymous mode [OFF]\",\n \"timestamp\":1507969127871,\n \"type\":2\n },\n {\n \"id\":8,\n \"message\":\"Encryption support [ON]\",\n \"timestamp\":1507969127871,\n \"type\":2\n },\n {\n \"id\":9,\n \"message\":\"Embedded Tracker [OFF]\",\n \"timestamp\":1507969127871,\n \"type\":2\n },\n {\n \"id\":10,\n \"message\":\"UPnP / NAT-PMP support [ON]\",\n \"timestamp\":1507969127873,\n \"type\":2\n },\n {\n \"id\":11,\n \"message\":\"Web UI: Now listening on port 8080\",\n \"timestamp\":1507969127883,\n \"type\":1\n },\n {\n \"id\":12,\n \"message\":\"Options were saved successfully.\",\n \"timestamp\":1507969128055,\n \"type\":1\n },\n {\n \"id\":13,\n \"message\":\"qBittorrent is successfully listening on interface :: port: TCP/19036\",\n \"timestamp\":1507969128270,\n \"type\":2\n },\n {\n \"id\":14,\n \"message\":\"qBittorrent is successfully listening on interface 0.0.0.0 port: TCP/19036\",\n \"timestamp\":1507969128271,\n \"type\":2\n },\n {\n \"id\":15,\n \"message\":\"qBittorrent is successfully listening on interface 0.0.0.0 port: UDP/19036\",\n \"timestamp\":1507969128272,\n \"type\":2\n }\n]\n```",
),
parameters: Some(
[
ApiParameters {
mandatory: [],
optional: [
Bool(
TypeInfo {
name: "normal",
@ -2656,6 +2661,7 @@
},
),
],
},
),
return_type: Some(
ReturnType {
@ -2732,7 +2738,9 @@
"The response a JSON array. Each element of the array of objects (each object is the information relative to a peer) containing the following fields",
),
parameters: Some(
[
ApiParameters {
mandatory: [],
optional: [
Number(
TypeInfo {
name: "last_known_id",
@ -2745,6 +2753,7 @@
},
),
],
},
),
return_type: None,
url: "peers",
@ -2764,7 +2773,8 @@
"The response is a JSON object with the following possible fields\n\n\nExample:\n\n```JSON\n{\n \"rid\":15,\n \"torrents\":\n {\n \"8c212779b4abde7c6bc608063a0d008b7e40ce32\":\n {\n \"state\":\"pausedUP\"\n }\n }\n}\n```",
),
parameters: Some(
[
ApiParameters {
mandatory: [
Number(
TypeInfo {
name: "rid",
@ -2777,6 +2787,8 @@
},
),
],
optional: [],
},
),
return_type: Some(
ReturnType {
@ -2928,7 +2940,8 @@
"The response is TODO",
),
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "hash",
@ -2952,6 +2965,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "torrentPeers",
@ -3146,7 +3161,8 @@
name: "setDownloadLimit",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
Number(
TypeInfo {
name: "limit",
@ -3159,6 +3175,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "setDownloadLimit",
@ -3176,7 +3194,8 @@
name: "setUploadLimit",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
Number(
TypeInfo {
name: "limit",
@ -3189,6 +3208,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "setUploadLimit",
@ -3197,7 +3218,8 @@
name: "banPeers",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "peers",
@ -3210,6 +3232,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "banPeers",
@ -3229,7 +3253,9 @@
"The response is a JSON array with the following fields\n\n\nPossible values of `state`:\n\n\nExample:\n\n```JSON\n[\n {\n \"dlspeed\":9681262,\n \"eta\":87,\n \"f_l_piece_prio\":false,\n \"force_start\":false,\n \"hash\":\"8c212779b4abde7c6bc608063a0d008b7e40ce32\",\n \"category\":\"\",\n \"tags\": \"\",\n \"name\":\"debian-8.1.0-amd64-CD-1.iso\",\n \"num_complete\":-1,\n \"num_incomplete\":-1,\n \"num_leechs\":2,\n \"num_seeds\":54,\n \"priority\":1,\n \"progress\":0.16108787059783936,\n \"ratio\":0,\n \"seq_dl\":false,\n \"size\":657457152,\n \"state\":\"downloading\",\n \"super_seeding\":false,\n \"upspeed\":0\n },\n {\n another_torrent_info\n }\n]\n```",
),
parameters: Some(
[
ApiParameters {
mandatory: [],
optional: [
String(
TypeInfo {
name: "filter",
@ -3319,6 +3345,7 @@
},
),
],
},
),
return_type: Some(
ReturnType {
@ -4091,7 +4118,8 @@
"The response is:\n\n- empty, if the torrent hash is invalid\n- otherwise, a JSON object with the following fields\n\n\nNB: `-1` is returned if the type of the property is integer but its value is not known.\n\nExample:\n\n```JSON\n{\n \"addition_date\":1438429165,\n \"comment\":\"\\\"Debian CD from cdimage.debian.org\\\"\",\n \"completion_date\":1438429234,\n \"created_by\":\"\",\n \"creation_date\":1433605214,\n \"dl_limit\":-1,\n \"dl_speed\":0,\n \"dl_speed_avg\":9736015,\n \"eta\":8640000,\n \"last_seen\":1438430354,\n \"nb_connections\":3,\n \"nb_connections_limit\":250,\n \"peers\":1,\n \"peers_total\":89,\n \"piece_size\":524288,\n \"pieces_have\":1254,\n \"pieces_num\":1254,\n \"reannounce\":672,\n \"save_path\":\"/Downloads/debian-8.1.0-amd64-CD-1.iso\",\n \"seeding_time\":1128,\n \"seeds\":1,\n \"seeds_total\":254,\n \"share_ratio\":0.00072121022562178299,\n \"time_elapsed\":1197,\n \"total_downloaded\":681521119,\n \"total_downloaded_session\":681521119,\n \"total_size\":657457152,\n \"total_uploaded\":491520,\n \"total_uploaded_session\":491520,\n \"total_wasted\":23481724,\n \"up_limit\":-1,\n \"up_speed\":0,\n \"up_speed_avg\":410\n}\n```",
),
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "hash",
@ -4104,6 +4132,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "properties",
@ -4114,7 +4144,8 @@
"The response is a JSON array, where each element contains info about one tracker, with the following fields\n\n\nPossible values of `status`:\n\n\nExample:\n\n```JSON\n[\n {\n \"msg\":\"\",\n \"num_peers\":100,\n \"status\":2,\n \"url\":\"http://bttracker.debian.org:6969/announce\"\n },\n {\n another_tracker_info\n }\n]\n```",
),
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "hash",
@ -4127,6 +4158,8 @@
},
),
],
optional: [],
},
),
return_type: Some(
ReturnType {
@ -4288,7 +4321,8 @@
"The response is a JSON array, where each element is information about one webseed, with the following fields\n\n\nExample:\n\n```JSON\n[\n {\n \"url\":\"http://some_url/\"\n },\n {\n \"url\":\"http://some_other_url/\"\n }\n]\n```",
),
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "hash",
@ -4301,6 +4335,8 @@
},
),
],
optional: [],
},
),
return_type: Some(
ReturnType {
@ -4332,7 +4368,8 @@
"The response is:\n\n- empty, if the torrent hash is invalid\n- otherwise, a JSON array, where each element contains info about one file, with the following fields\n\n\nPossible values of `priority`:\n\n\nExample:\n\n```JSON\n\n[\n {\n \"index\":0,\n \"is_seed\":false,\n \"name\":\"debian-8.1.0-amd64-CD-1.iso\",\n \"piece_range\":[0,1253],\n \"priority\":1,\n \"progress\":0,\n \"size\":657457152,\n \"availability\":0.5,\n }\n]\n```",
),
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "hash",
@ -4344,6 +4381,8 @@
type_description: None,
},
),
],
optional: [
String(
TypeInfo {
name: "indexes",
@ -4356,6 +4395,7 @@
},
),
],
},
),
return_type: None,
url: "files",
@ -4366,7 +4406,8 @@
"The response is:\n\n- empty, if the torrent hash is invalid\n- otherwise, an array of states (integers) of all pieces (in order) of a specific torrent.\n\nValue meanings are defined as below:\n\n\nExample:\n\n```JSON\n[0,0,2,1,0,0,2,1]\n```",
),
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "hash",
@ -4379,6 +4420,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "pieceStates",
@ -4389,7 +4432,8 @@
"The response is:\n\n- empty, if the torrent hash is invalid\n- otherwise, an array of hashes (strings) of all pieces (in order) of a specific torrent.\n\nExample:\n\n```JSON\n[\"54eddd830a5b58480a6143d616a97e3a6c23c439\",\"f8a99d225aa4241db100f88407fc3bdaead583ab\",\"928fb615b9bd4dd8f9e9022552c8f8f37ef76f58\"]\n```",
),
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "hash",
@ -4402,6 +4446,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "pieceHashes",
@ -4410,7 +4456,8 @@
name: "pause",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "hashes",
@ -4423,6 +4470,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "pause",
@ -4431,7 +4480,8 @@
name: "resume",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "hashes",
@ -4444,6 +4494,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "resume",
@ -4452,7 +4504,8 @@
name: "delete",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "hashes",
@ -4465,6 +4518,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "delete",
@ -4473,7 +4528,8 @@
name: "recheck",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "hashes",
@ -4486,6 +4542,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "recheck",
@ -4494,7 +4552,8 @@
name: "reannounce",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "hashes",
@ -4507,6 +4566,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "reannounce",
@ -4515,7 +4576,8 @@
name: "add",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "urls",
@ -4527,6 +4589,8 @@
type_description: None,
},
),
],
optional: [
String(
TypeInfo {
name: "savepath",
@ -4693,6 +4757,7 @@
},
),
],
},
),
return_type: None,
url: "add",
@ -4708,7 +4773,8 @@
name: "editTracker",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "hash",
@ -4743,6 +4809,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "editTracker",
@ -4751,7 +4819,8 @@
name: "removeTrackers",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "hash",
@ -4775,6 +4844,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "removeTrackers",
@ -4783,7 +4854,8 @@
name: "addPeers",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "hashes",
@ -4807,6 +4879,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "addPeers",
@ -4815,7 +4889,8 @@
name: "increasePrio",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "hashes",
@ -4828,6 +4903,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "increasePrio",
@ -4836,7 +4913,8 @@
name: "decreasePrio",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "hashes",
@ -4849,6 +4927,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "decreasePrio",
@ -4857,7 +4937,8 @@
name: "topPrio",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "hashes",
@ -4870,6 +4951,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "topPrio",
@ -4878,7 +4961,8 @@
name: "bottomPrio",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "hashes",
@ -4891,6 +4975,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "bottomPrio",
@ -4899,7 +4985,8 @@
name: "filePrio",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "hash",
@ -4934,6 +5021,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "filePrio",
@ -5061,7 +5150,8 @@
name: "toggleSequentialDownload",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "hashes",
@ -5074,6 +5164,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "toggleSequentialDownload",
@ -5082,7 +5174,8 @@
name: "toggleFirstLastPiecePrio",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "hashes",
@ -5095,6 +5188,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "toggleFirstLastPiecePrio",
@ -5117,7 +5212,8 @@
name: "renameFile",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "hash",
@ -5152,6 +5248,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "renameFile",
@ -5160,7 +5258,8 @@
name: "renameFolder",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "hash",
@ -5195,6 +5294,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "renameFolder",
@ -5212,7 +5313,8 @@
name: "addFolder",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "path",
@ -5225,6 +5327,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "addFolder",
@ -5233,7 +5337,8 @@
name: "addFeed",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "url",
@ -5245,6 +5350,8 @@
type_description: None,
},
),
],
optional: [
String(
TypeInfo {
name: "path",
@ -5257,6 +5364,7 @@
},
),
],
},
),
return_type: None,
url: "addFeed",
@ -5265,7 +5373,8 @@
name: "removeItem",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "path",
@ -5278,6 +5387,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "removeItem",
@ -5286,7 +5397,8 @@
name: "moveItem",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "itemPath",
@ -5310,6 +5422,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "moveItem",
@ -5318,7 +5432,9 @@
name: "items",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [],
optional: [
Bool(
TypeInfo {
name: "withData",
@ -5331,6 +5447,7 @@
},
),
],
},
),
return_type: None,
url: "items",
@ -5339,7 +5456,8 @@
name: "markAsRead",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "itemPath",
@ -5351,6 +5469,8 @@
type_description: None,
},
),
],
optional: [
String(
TypeInfo {
name: "articleId",
@ -5363,6 +5483,7 @@
},
),
],
},
),
return_type: None,
url: "markAsRead",
@ -5371,7 +5492,8 @@
name: "refreshItem",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "itemPath",
@ -5384,6 +5506,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "refreshItem",
@ -5392,7 +5516,8 @@
name: "setRule",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "ruleName",
@ -5416,6 +5541,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "setRule",
@ -5424,7 +5551,8 @@
name: "renameRule",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "ruleName",
@ -5448,6 +5576,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "renameRule",
@ -5456,7 +5586,8 @@
name: "removeRule",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "ruleName",
@ -5469,6 +5600,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "removeRule",
@ -5502,7 +5635,8 @@
"The response is a JSON object with the following fields\n\n\nExample:\n\n```JSON\n{\n \"id\": 12345\n}\n```",
),
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "pattern",
@ -5537,6 +5671,8 @@
},
),
],
optional: [],
},
),
return_type: Some(
ReturnType {
@ -5566,7 +5702,8 @@
name: "stop",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
Number(
TypeInfo {
name: "id",
@ -5579,6 +5716,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "stop",
@ -5589,7 +5728,9 @@
"The response is a JSON array of objects containing the following fields\n\n\nExample:\n\n```JSON\n[\n {\n \"id\": 12345,\n \"status\": \"Running\",\n \"total\": 170\n }\n]\n```",
),
parameters: Some(
[
ApiParameters {
mandatory: [],
optional: [
Number(
TypeInfo {
name: "id",
@ -5602,6 +5743,7 @@
},
),
],
},
),
return_type: Some(
ReturnType {
@ -5663,7 +5805,8 @@
"The response is a JSON object with the following fields\n\n\n\n\nExample:\n\n```JSON\n{\n \"results\": [\n {\n \"descrLink\": \"http://www.legittorrents.info/index.php?page=torrent-details&id=8d5f512e1acb687029b8d7cc6c5a84dce51d7a41\",\n \"fileName\": \"Ubuntu-10.04-32bit-NeTV.ova\",\n \"fileSize\": -1,\n \"fileUrl\": \"http://www.legittorrents.info/download.php?id=8d5f512e1acb687029b8d7cc6c5a84dce51d7a41&f=Ubuntu-10.04-32bit-NeTV.ova.torrent\",\n \"nbLeechers\": 1,\n \"nbSeeders\": 0,\n \"siteUrl\": \"http://www.legittorrents.info\"\n },\n {\n \"descrLink\": \"http://www.legittorrents.info/index.php?page=torrent-details&id=d5179f53e105dc2c2401bcfaa0c2c4936a6aa475\",\n \"fileName\": \"mangOH-Legato-17_06-Ubuntu-16_04.ova\",\n \"fileSize\": -1,\n \"fileUrl\": \"http://www.legittorrents.info/download.php?id=d5179f53e105dc2c2401bcfaa0c2c4936a6aa475&f=mangOH-Legato-17_06-Ubuntu-16_04.ova.torrent\",\n \"nbLeechers\": 0,\n \"nbSeeders\": 59,\n \"siteUrl\": \"http://www.legittorrents.info\"\n }\n ],\n \"status\": \"Running\",\n \"total\": 2\n}\n```",
),
parameters: Some(
[
ApiParameters {
mandatory: [
Number(
TypeInfo {
name: "id",
@ -5675,6 +5818,8 @@
type_description: None,
},
),
],
optional: [
Number(
TypeInfo {
name: "limit",
@ -5698,6 +5843,7 @@
},
),
],
},
),
return_type: Some(
ReturnType {
@ -5757,7 +5903,8 @@
name: "delete",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
Number(
TypeInfo {
name: "id",
@ -5770,6 +5917,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "delete",
@ -5883,7 +6032,8 @@
name: "installPlugin",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "sources",
@ -5896,6 +6046,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "installPlugin",
@ -5904,7 +6056,8 @@
name: "uninstallPlugin",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "names",
@ -5917,6 +6070,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "uninstallPlugin",
@ -5925,7 +6080,8 @@
name: "enablePlugin",
description: None,
parameters: Some(
[
ApiParameters {
mandatory: [
String(
TypeInfo {
name: "names",
@ -5949,6 +6105,8 @@
},
),
],
optional: [],
},
),
return_type: None,
url: "enablePlugin",

View File

@ -8,7 +8,7 @@ use super::{return_type::create_return_type, send_method_builder::SendMethodBuil
pub fn create_method_with_params(
group: &parser::ApiGroup,
method: &parser::ApiMethod,
params: &[types::Type],
params: &parser::ApiParameters,
method_name: &proc_macro2::Ident,
url: &str,
) -> (proc_macro2::TokenStream, Option<proc_macro2::TokenStream>) {
@ -18,10 +18,9 @@ pub fn create_method_with_params(
method.name.to_camel()
));
let mandatory_params = mandatory_params(params);
let mandatory_param_args = generate_mandatory_params(&mandatory_params);
let mandatory_param_args = generate_mandatory_params(&params.mandatory);
let mandatory_param_names = mandatory_params.iter().map(|param| {
let mandatory_param_names = params.mandatory.iter().map(|param| {
let (name, ..) = param_name(param);
quote! { #name }
});
@ -32,8 +31,8 @@ pub fn create_method_with_params(
.with_form();
let generate_send_impl = |send_method: proc_macro2::TokenStream| {
let optional_params = generate_optional_params(params);
let mandatory_param_form_build = generate_mandatory_param_builder(&mandatory_params);
let optional_params = generate_optional_params(&params.optional);
let mandatory_param_form_build = generate_mandatory_param_builder(&params.mandatory);
quote! {
impl<'a> #param_type<'a> {
@ -82,15 +81,12 @@ pub fn create_method_with_params(
(builder, Some(group_impl))
}
fn generate_mandatory_params(mandatory_params: &[&types::Type]) -> Vec<proc_macro2::TokenStream> {
mandatory_params
.iter()
.map(|param| param_with_name(param))
.collect()
fn generate_mandatory_params(mandatory_params: &[types::Type]) -> Vec<proc_macro2::TokenStream> {
mandatory_params.iter().map(param_with_name).collect()
}
fn generate_mandatory_param_builder(
mandatory_params: &[&types::Type],
mandatory_params: &[types::Type],
) -> Vec<proc_macro2::TokenStream> {
mandatory_params
.iter()
@ -102,18 +98,7 @@ fn generate_mandatory_param_builder(
}
fn generate_optional_params(params: &[types::Type]) -> Vec<proc_macro2::TokenStream> {
params
.iter()
.filter(|param| param.get_type_info().is_optional)
.map(generate_optional_param)
.collect()
}
fn mandatory_params(params: &[types::Type]) -> Vec<&types::Type> {
params
.iter()
.filter(|param| !param.get_type_info().is_optional)
.collect()
params.iter().map(generate_optional_param).collect()
}
fn generate_optional_param(param: &types::Type) -> proc_macro2::TokenStream {

View File

@ -16,11 +16,39 @@ use self::{
pub struct ApiMethod {
pub name: String,
pub description: Option<String>,
pub parameters: Option<Vec<types::Type>>,
pub parameters: Option<ApiParameters>,
pub return_type: Option<ReturnType>,
pub url: String,
}
#[derive(Debug)]
pub struct ApiParameters {
pub mandatory: Vec<types::Type>,
pub optional: Vec<types::Type>,
}
impl ApiParameters {
fn new(params: Vec<types::Type>) -> Self {
let (mandatory, optional) = params.into_iter().fold(
(vec![], vec![]),
|(mut mandatory, mut optional), parameter| {
if parameter.get_type_info().is_optional {
optional.push(parameter);
} else {
mandatory.push(parameter);
}
(mandatory, optional)
},
);
Self {
mandatory,
optional,
}
}
}
pub fn parse_api_method(child: &md_parser::TokenTree) -> Option<ApiMethod> {
util::find_content_starts_with(&child.content, "Name: ")
.map(|name| {
@ -34,7 +62,7 @@ pub fn parse_api_method(child: &md_parser::TokenTree) -> Option<ApiMethod> {
fn to_api_method(child: &md_parser::TokenTree, name: &str) -> ApiMethod {
let method_description = parse_method_description(&child.content);
let return_type = parse_return_type(&child.content);
let parameters = parse_parameters(&child.content);
let parameters = parse_parameters(&child.content).map(|params| ApiParameters::new(params));
let method_url = get_method_url(&child.content);
ApiMethod {

View File

@ -5,7 +5,7 @@ mod url;
use crate::md_parser;
use self::{description::parse_group_description, method::parse_api_method, url::get_group_url};
pub use method::{ApiMethod, ReturnType};
pub use method::*;
#[derive(Debug)]
pub struct ApiGroup {

View File

@ -12,7 +12,7 @@ pub struct ReturnTypeParameter {
pub return_type: types::Type,
}
pub use group::{ApiGroup, ApiMethod, ReturnType};
pub use group::*;
pub fn parse_api_groups(token_tree: md_parser::TokenTree) -> Vec<ApiGroup> {
parse_groups(extract_relevant_parts(token_tree))