Merge pull request #79 from CharlesHenry/master

Add template field to guiCurrentCard output + increment API_VERSION
This commit is contained in:
Alex Yatskov 2018-05-25 10:46:13 -07:00 committed by GitHub
commit 6882ca642a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 62 deletions

View File

@ -37,7 +37,7 @@ from unicodedata import normalize
# Constants # Constants
# #
API_VERSION = 5 API_VERSION = 6
NET_ADDRESS = os.getenv('ANKICONNECT_BIND_ADDRESS', '127.0.0.1') NET_ADDRESS = os.getenv('ANKICONNECT_BIND_ADDRESS', '127.0.0.1')
NET_BACKLOG = 5 NET_BACKLOG = 5
NET_PORT = 8765 NET_PORT = 8765
@ -1000,7 +1000,8 @@ class AnkiConnect:
'buttons': [b[0] for b in reviewer._answerButtonList()], 'buttons': [b[0] for b in reviewer._answerButtonList()],
'modelName': model['name'], 'modelName': model['name'],
'deckName': self.deckNameFromId(card.did), 'deckName': self.deckNameFromId(card.did),
'css': model['css'] 'css': model['css'],
'template': card.template()['name']
} }

115
README.md
View File

@ -32,7 +32,7 @@ The installation process is similar to that of other Anki plugins and can be acc
Anki must be kept running in the background in order for other applications to be able to use AnkiConnect. You can Anki must be kept running in the background in order for other applications to be able to use AnkiConnect. You can
verify that AnkiConnect is running at any time by accessing [localhost:8765](http://localhost:8765) in your browser. If verify that AnkiConnect is running at any time by accessing [localhost:8765](http://localhost:8765) in your browser. If
the server is running, you should see the message *AnkiConnect v.5* displayed in your browser window. the server is running, you should see the message *AnkiConnect v.6* displayed in your browser window.
### Notes for Windows Users ### ### Notes for Windows Users ###
@ -100,7 +100,7 @@ function ankiConnectInvoke(action, version, params={}) {
} }
try { try {
const result = await ankiConnectInvoke('deckNames', 5); const result = await ankiConnectInvoke('deckNames', 6);
console.log(`got list of decks: ${result}`); console.log(`got list of decks: ${result}`);
} catch (e) { } catch (e) {
console.log(`error getting decks: ${e}`); console.log(`error getting decks: ${e}`);
@ -110,7 +110,7 @@ try {
Or using [`curl`](https://curl.haxx.se) from the command line: Or using [`curl`](https://curl.haxx.se) from the command line:
```bash ```bash
curl localhost:8765 -X POST -d "{\"action\": \"deckNames\", \"version\": 5}" curl localhost:8765 -X POST -d "{\"action\": \"deckNames\", \"version\": 6}"
``` ```
AnkiConnect will respond with an object containing two fields: `result` and `error`. The `result` field contains the AnkiConnect will respond with an object containing two fields: `result` and `error`. The `result` field contains the
@ -140,14 +140,14 @@ Below is a comprehensive list of currently supported actions. Note that deprecat
despite not being listed on this page as long as your request is labeled with a version number corresponding to when the despite not being listed on this page as long as your request is labeled with a version number corresponding to when the
API was available for use. API was available for use.
This page currently documents **version 5** of the API. Make sure to include this version number in your requests to This page currently documents **version 6** of the API. Make sure to include this version number in your requests to
guarantee that your application continues to function properly in the future. guarantee that your application continues to function properly in the future.
#### Miscellaneous #### #### Miscellaneous ####
* **version** * **version**
Gets the version of the API exposed by this plugin. Currently versions `1` through `5` are defined. Gets the version of the API exposed by this plugin. Currently versions `1` through `6` are defined.
This should be the first call you make to make sure that your application and AnkiConnect are able to communicate This should be the first call you make to make sure that your application and AnkiConnect are able to communicate
properly with each other. New versions of AnkiConnect are backwards compatible; as long as you are using actions properly with each other. New versions of AnkiConnect are backwards compatible; as long as you are using actions
@ -157,14 +157,14 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "version", "action": "version",
"version": 5 "version": 6
} }
``` ```
*Sample result*: *Sample result*:
```json ```json
{ {
"result": 5, "result": 6,
"error": null "error": null
} }
``` ```
@ -179,7 +179,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "upgrade", "action": "upgrade",
"version": 5 "version": 6
} }
``` ```
@ -199,7 +199,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "sync", "action": "sync",
"version": 5 "version": 6
} }
``` ```
@ -220,7 +220,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "multi", "action": "multi",
"version": 5, "version": 6,
"params": { "params": {
"actions": [ "actions": [
{"action": "deckNames"}, {"action": "deckNames"},
@ -254,7 +254,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "deckNames", "action": "deckNames",
"version": 5 "version": 6
} }
``` ```
@ -274,7 +274,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "deckNamesAndIds", "action": "deckNamesAndIds",
"version": 5 "version": 6
} }
``` ```
@ -295,7 +295,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "getDecks", "action": "getDecks",
"version": 5, "version": 6,
"params": { "params": {
"cards": [1502298036657, 1502298033753, 1502032366472] "cards": [1502298036657, 1502298033753, 1502032366472]
} }
@ -321,7 +321,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "createDeck", "action": "createDeck",
"version": 5, "version": 6,
"params": { "params": {
"deck": "Japanese::Tokyo" "deck": "Japanese::Tokyo"
} }
@ -343,7 +343,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "changeDeck", "action": "changeDeck",
"version": 5, "version": 6,
"params": { "params": {
"cards": [1502098034045, 1502098034048, 1502298033753], "cards": [1502098034045, 1502098034048, 1502298033753],
"deck": "Japanese::JLPT N3" "deck": "Japanese::JLPT N3"
@ -368,7 +368,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "deleteDecks", "action": "deleteDecks",
"version": 5, "version": 6,
"params": { "params": {
"decks": ["Japanese::JLPT N5", "Easy Spanish"], "decks": ["Japanese::JLPT N5", "Easy Spanish"],
"cardsToo": true "cardsToo": true
@ -392,7 +392,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "getDeckConfig", "action": "getDeckConfig",
"version": 5, "version": 6,
"params": { "params": {
"deck": "Default" "deck": "Default"
} }
@ -451,7 +451,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "saveDeckConfig", "action": "saveDeckConfig",
"version": 5, "version": 6,
"params": { "params": {
"config": { "config": {
"lapse": { "lapse": {
@ -510,7 +510,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "setDeckConfigId", "action": "setDeckConfigId",
"version": 5, "version": 6,
"params": { "params": {
"decks": ["Default"], "decks": ["Default"],
"configId": 1 "configId": 1
@ -536,7 +536,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "cloneDeckConfigId", "action": "cloneDeckConfigId",
"version": 5, "version": 6,
"params": { "params": {
"name": "Copy of Default", "name": "Copy of Default",
"cloneFrom": 1 "cloneFrom": 1
@ -561,7 +561,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "removeDeckConfigId", "action": "removeDeckConfigId",
"version": 5, "version": 6,
"params": { "params": {
"configId": 1502972374573 "configId": 1502972374573
} }
@ -586,7 +586,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "modelNames", "action": "modelNames",
"version": 5 "version": 6
} }
``` ```
@ -606,7 +606,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "modelNamesAndIds", "action": "modelNamesAndIds",
"version": 5 "version": 6
} }
``` ```
@ -631,7 +631,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "modelFieldNames", "action": "modelFieldNames",
"version": 5, "version": 6,
"params": { "params": {
"modelName": "Basic" "modelName": "Basic"
} }
@ -655,7 +655,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "modelFieldsOnTemplates", "action": "modelFieldsOnTemplates",
"version": 5, "version": 6,
"params": { "params": {
"modelName": "Basic (and reversed card)" "modelName": "Basic (and reversed card)"
} }
@ -690,7 +690,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "addNote", "action": "addNote",
"version": 5, "version": 6,
"params": { "params": {
"note": { "note": {
"deckName": "Default", "deckName": "Default",
@ -731,7 +731,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "addNotes", "action": "addNotes",
"version": 5, "version": 6,
"params": { "params": {
"notes": [ "notes": [
{ {
@ -773,7 +773,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "canAddNotes", "action": "canAddNotes",
"version": 5, "version": 6,
"params": { "params": {
"notes": [ "notes": [
{ {
@ -808,7 +808,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "updateNoteFields", "action": "updateNoteFields",
"version": 5, "version": 6,
"params": { "params": {
"note": { "note": {
"id": 1514547547030, "id": 1514547547030,
@ -837,7 +837,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "addTags", "action": "addTags",
"version": 5, "version": 6,
"params": { "params": {
"notes": [1483959289817, 1483959291695], "notes": [1483959289817, 1483959291695],
"tags": "european-languages" "tags": "european-languages"
@ -861,7 +861,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "removeTags", "action": "removeTags",
"version": 5, "version": 6,
"params": { "params": {
"notes": [1483959289817, 1483959291695], "notes": [1483959289817, 1483959291695],
"tags": "european-languages" "tags": "european-languages"
@ -885,7 +885,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "getTags", "action": "getTags",
"version": 5 "version": 6
} }
``` ```
@ -905,7 +905,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "findNotes", "action": "findNotes",
"version": 5, "version": 6,
"params": { "params": {
"query": "deck:current" "query": "deck:current"
} }
@ -929,7 +929,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "notesInfo", "action": "notesInfo",
"version": 5, "version": 6,
"params": { "params": {
"notes": [1502298033753] "notes": [1502298033753]
} }
@ -966,7 +966,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "suspend", "action": "suspend",
"version": 5, "version": 6,
"params": { "params": {
"cards": [1483959291685, 1483959293217] "cards": [1483959291685, 1483959293217]
} }
@ -990,7 +990,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "unsuspend", "action": "unsuspend",
"version": 5, "version": 6,
"params": { "params": {
"cards": [1483959291685, 1483959293217] "cards": [1483959291685, 1483959293217]
} }
@ -1013,7 +1013,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "areSuspended", "action": "areSuspended",
"version": 5, "version": 6,
"params": { "params": {
"cards": [1483959291685, 1483959293217] "cards": [1483959291685, 1483959293217]
} }
@ -1038,7 +1038,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "areDue", "action": "areDue",
"version": 5, "version": 6,
"params": { "params": {
"cards": [1483959291685, 1483959293217] "cards": [1483959291685, 1483959293217]
} }
@ -1062,7 +1062,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "getIntervals", "action": "getIntervals",
"version": 5, "version": 6,
"params": { "params": {
"cards": [1502298033753, 1502298036657] "cards": [1502298033753, 1502298036657]
} }
@ -1081,7 +1081,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "getIntervals", "action": "getIntervals",
"version": 5, "version": 6,
"params": { "params": {
"cards": [1502298033753, 1502298036657], "cards": [1502298033753, 1502298036657],
"complete": true "complete": true
@ -1109,7 +1109,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "findCards", "action": "findCards",
"version": 5, "version": 6,
"params": { "params": {
"query": "deck:current" "query": "deck:current"
} }
@ -1133,7 +1133,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "cardsToNotes", "action": "cardsToNotes",
"version": 5, "version": 6,
"params": { "params": {
"cards": [1502098034045, 1502098034048, 1502298033753] "cards": [1502098034045, 1502098034048, 1502298033753]
} }
@ -1157,7 +1157,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "cardsInfo", "action": "cardsInfo",
"version": 5, "version": 6,
"params": { "params": {
"cards": [1498938915662, 1502098034048] "cards": [1498938915662, 1502098034048]
} }
@ -1215,7 +1215,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "storeMediaFile", "action": "storeMediaFile",
"version": 5, "version": 6,
"params": { "params": {
"filename": "_hello.txt", "filename": "_hello.txt",
"data": "SGVsbG8sIHdvcmxkIQ==" "data": "SGVsbG8sIHdvcmxkIQ=="
@ -1244,7 +1244,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "retrieveMediaFile", "action": "retrieveMediaFile",
"version": 5, "version": 6,
"params": { "params": {
"filename": "_hello.txt" "filename": "_hello.txt"
} }
@ -1267,7 +1267,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "deleteMediaFile", "action": "deleteMediaFile",
"version": 5, "version": 6,
"params": { "params": {
"filename": "_hello.txt" "filename": "_hello.txt"
} }
@ -1293,7 +1293,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "guiBrowse", "action": "guiBrowse",
"version": 5, "version": 6,
"params": { "params": {
"query": "deck:current" "query": "deck:current"
} }
@ -1316,7 +1316,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "guiAddCards", "action": "guiAddCards",
"version": 5 "version": 6
} }
``` ```
@ -1336,7 +1336,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "guiCurrentCard", "action": "guiCurrentCard",
"version": 5 "version": 6
} }
``` ```
@ -1353,6 +1353,7 @@ guarantee that your application continues to function properly in the future.
"Front": {"value": "front content", "order": 0}, "Front": {"value": "front content", "order": 0},
"Back": {"value": "back content", "order": 1} "Back": {"value": "back content", "order": 1}
}, },
"template": "Forward",
"cardId": 1498938915662, "cardId": 1498938915662,
"buttons": [1, 2, 3] "buttons": [1, 2, 3]
}, },
@ -1370,7 +1371,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "guiStartCardTimer", "action": "guiStartCardTimer",
"version": 5 "version": 6
} }
``` ```
@ -1390,7 +1391,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "guiShowQuestion", "action": "guiShowQuestion",
"version": 5 "version": 6
} }
``` ```
@ -1410,7 +1411,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "guiShowAnswer", "action": "guiShowAnswer",
"version": 5 "version": 6
} }
``` ```
@ -1431,7 +1432,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "guiAnswerCard", "action": "guiAnswerCard",
"version": 5, "version": 6,
"params": { "params": {
"ease": 1 "ease": 1
} }
@ -1454,7 +1455,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "guiDeckOverview", "action": "guiDeckOverview",
"version": 5, "version": 6,
"params": { "params": {
"name": "Default" "name": "Default"
} }
@ -1477,7 +1478,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "guiDeckBrowser", "action": "guiDeckBrowser",
"version": 5 "version": 6
} }
``` ```
@ -1497,7 +1498,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "guiDeckReview", "action": "guiDeckReview",
"version": 5, "version": 6,
"params": { "params": {
"name": "Default" "name": "Default"
} }
@ -1521,7 +1522,7 @@ guarantee that your application continues to function properly in the future.
```json ```json
{ {
"action": "guiExitAnki", "action": "guiExitAnki",
"version": 5 "version": 6
} }
``` ```

View File

@ -7,7 +7,7 @@ import util
class TestMisc(unittest.TestCase): class TestMisc(unittest.TestCase):
def runTest(self): def runTest(self):
# version # version
self.assertEqual(util.invoke('version'), 5) self.assertEqual(util.invoke('version'), 6)
# upgrade # upgrade
util.invoke('upgrade') util.invoke('upgrade')
@ -21,7 +21,7 @@ class TestMisc(unittest.TestCase):
self.assertEqual(len(results), len(actions)) self.assertEqual(len(results), len(actions))
for result in results: for result in results:
self.assertIsNone(result['error']) self.assertIsNone(result['error'])
self.assertEqual(result['result'], 5) self.assertEqual(result['result'], 6)
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -1,7 +1,7 @@
import json import json
import urllib2 import urllib2
API_VERSION = 5 API_VERSION = 6
API_URL = 'http://localhost:8765' API_URL = 'http://localhost:8765'