Return error message in failure scenarios, rename checkState to guiCheckState, remove success+message response format in favour of True/False + rename ord field to fieldOrder (see readme) + updated readme.

This commit is contained in:
Charles Henry 2017-06-26 23:57:41 +01:00
parent 842dae9830
commit 54ab68feb4
2 changed files with 50 additions and 42 deletions

View File

@ -439,6 +439,8 @@ class AnkiBridge:
self.window().moveToState('review')
card = self.window().reviewer.card
if card:
return {
'success': True,
'id': card.id,
@ -446,47 +448,48 @@ class AnkiBridge:
'answer': card._getQA()['a'],
'answerButtons': self.window().reviewer._answerButtonList(),
'modelName': card.note(reload)._model['name'],
'ord': card.ord,
'fieldOrder': card.ord,
'fields': card.note(reload).fields,
'fieldMap': card.note(reload)._fmap
}
else:
return 'There are no cards left to review.'
def guiShowQuestion(self):
if self.window().reviewer.card is None or self.window().state != 'review':
self.window().moveToState('review')
self.window().reviewer._showQuestion()
return {'success': True}
return True
def guiShowAnswer(self):
if self.window().reviewer.mw.state != 'review':
return {'success': False, 'message': 'Window state is not review.'}
return 'Window state is not review.'
else:
self.window().reviewer._showAnswer()
return {'success': True}
return True
def guiAnswerCard(self, id, ease):
if self.window().reviewer.mw.state != 'review':
return {'success': False, 'message': 'Window state is not review.'}
return 'Window state is not review.'
elif self.window().reviewer.state != 'answer':
return {'success': False, 'message': 'Reviewer state is not answer.'}
return 'Reviewer state is not answer.'
elif self.window().reviewer.card.id != id:
return {'success': False, 'message': 'Given card does not match.'}
return 'Given card does not match.'
elif self.window().col.sched.answerButtons(self.window().reviewer.card) < ease:
return {'success': False, 'message': 'Invalid ease provided.'}
return 'Invalid ease provided.'
else:
self.window().reviewer._answerCard(ease)
return {'success': True}
return True
def checkState(self):
def guiCheckState(self):
return {
'success': True,
'window_state': self.window().state,
'reviewer_state': self.window().reviewer.state
'windowState': self.window().state,
'reviewerState': self.window().reviewer.state
}
@ -614,7 +617,7 @@ class AnkiConnect:
def api_checkState(self):
return self.anki.checkState()
return self.anki.guiCheckState()
#
# Entry

View File

@ -338,12 +338,12 @@ rather than raw JSON. If you are writing raw requests be sure to send valid JSON
* **guiGetNextCard**
Returns next/current card, calling this multiple times will not skip unanswered cards.
Returns next/current card, calling this multiple times will not skip unanswered cards. The low level fields and card direction can be derived from the 'fieldOrder', 'fieldMap' and 'fields' keys in the response.
*Sample request*:
```
{
action: 'getNextCard',
action: 'guiGetNextCard',
params: {}
}
```
@ -351,7 +351,7 @@ rather than raw JSON. If you are writing raw requests be sure to send valid JSON
*Sample response*:
```
{
'success': 'true',
'success': true,
'question': 'Hello',
'fieldMap': {
'Front': [
@ -399,11 +399,16 @@ rather than raw JSON. If you are writing raw requests be sure to send valid JSON
"Hola"
],
'answer': 'Hello\n\n<hr id=answer>\n\nHola',
'ord': 0,
'fieldOrder': 0,
'id': 1496751176292
}
```
*Sample error response*:
```
'There are no cards left to review.'
```
* **guiShowQuestion**
Move Anki to the state of showing a question (window state = 'review' and reviewer state = 'question'). This is required in order to show the answer and can also be used to move from the showAnswer state back to the showQuestion state.
@ -411,14 +416,14 @@ rather than raw JSON. If you are writing raw requests be sure to send valid JSON
*Sample request*:
```
{
action: 'showQuestion',
action: 'guiShowQuestion',
params: {}
}
```
*Sample response*:
```
{'success': 'true'}
true
```
* **guiShowAnswer**
@ -428,29 +433,29 @@ rather than raw JSON. If you are writing raw requests be sure to send valid JSON
*Sample request*:
```
{
action: 'showAnswer',
action: 'guiShowAnswer',
params: {}
}
```
*Sample response*:
```
{'success': 'true'}
true
```
*Sample error response*:
```
{'success': 'false', 'message': 'Window state is not review.'}
'Window state is not review.'
```
* **guiAnswerCard**
Used to answer a card that is in the showAnswer state. Valid answers for this card can be found in the getNextCard response.
Used to answer a card that is in the showAnswer state. Valid answers for this card can be found in the guiGetNextCard response.
*Sample request*:
```
{
action: 'answerCard',
action: 'guiAnswerCard',
params: {
id: 1496751176292,
ease: 1
@ -460,35 +465,35 @@ rather than raw JSON. If you are writing raw requests be sure to send valid JSON
*Sample response*:
```
{'success': 'true'}
true
```
*Sample error responses*:
```
{'success': 'false', 'message': 'Window state is not review.'}
'Window state is not review.'
```
```
{'success': 'false', 'message': 'Reviewer state is not answer.'}
'Reviewer state is not answer.'
```
```
{'success': 'false', 'message': 'Given card does not match.'}
'Given card does not match.'
```
```
{'success': 'false', 'message': 'Invalid ease provided.'}
'Invalid ease provided.'
```
* **checkState**
* **guiCheckState**
Returns the window state and the reviewer state.
*Sample request*:
```
{action: 'checkState'}
{action: 'guiCheckState'}
```
*Sample response*:
```
{'window_state': 'review', 'reviewer_state': 'answer', 'success': 'true'}
{'windowState': 'review', 'reviewerState': 'answer', 'success': true}
```
* **upgrade**