-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpylimerc.py
858 lines (758 loc) · 32.5 KB
/
pylimerc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
import requests
from requests import Response
class PyLimeRc:
def __init__(self, url=None, base_dir="."):
self.headers = {"content-type": "application/json", "connection": "Keep-Alive"}
self.url = url
self.session_key = None
self.base_dir = base_dir
def set_headers(self, headers):
self.headers = headers
def set_url(self, url):
self.url = url
def __sort_params(self, method, params):
import yaml
with open(f"{self.base_dir}/pylimerc.yml", "r") as f:
config = yaml.safe_load(f)
sorted_params = []
if self.session_key is not None:
sorted_params.append(self.session_key)
if method not in config["lime_methods"]:
return params.values()
sequence = config["lime_methods"][method]
for s in sequence:
param = params.get(s)
if param:
sorted_params.append(param)
else:
return sorted_params
return sorted_params
def __format_params(self, params):
del params["self"]
params["sSessionKey"] = self.session_key
return dict((k, v) for k, v in params.items() if v is not None)
def call_rpc(self, method, params):
"""
Generic call. This routine makes a request to the rpc directly. Its provide more control to the user.
Moreover, this routine permits evoke new RPC's methods not implemented in this class.
More information about the RPC's methods, see: https://api.limesurvey.org/classes/remotecontrol_handle.html
Args:
method (str): The name of the RPC's method
params (dict): a list of parameters that is required by the method
Returns:
Response: The result of the activation
"""
print(f"Method: {method}")
print(f"Params before: {params}")
params = self.__sort_params(method, params)
print(f"Params sorted: {params}")
payload = {"method": method, "params": params, "id": 1}
try:
r = requests.post(url=self.url, headers=self.headers, json=payload)
return r
except Exception as ex:
print(f"Exception: {ex}")
return None
def get_session_key(self, username, password):
"""
RPC routine to create a session key.
Using this function you can create a new XML/JSON-RPC session key.
This is mandatory for all following LSRC2 function calls.
Args:
username (str): username
password (str): password
Returns:
string: The session key. Each instance keeps the session key internally.
"""
params = self.__format_params(locals().copy())
method = "get_session_key"
r = self.call_rpc(method, params)
if type(r.json()["result"]) is not dict:
self.session_key = r.json()["result"]
return self.session_key
def get_site_settings(self, sSettingName):
"""
RPC Routine to get settings.
Args:
sSettingName (str): Name of the setting to get
Returns:
string: The requested value
"""
params = self.__format_params(locals().copy())
method = "get_site_settings"
r = self.call_rpc(method, params)
return r.json()["result"]
def get_summary(self, iSurveyID, sStatName=None):
"""
RPC routine to get survey summary, regarding token usage and survey participation.
Returns the requested value as string.
Args:
iSurveyID (int): ID of the Survey to get summary
sStatName (:obj:`str`, optional): Name of the summary - valid values are 'token_count',
'token_invalid', 'token_sent', 'token_opted_out', 'token_completed', 'completed_responses',
'incomplete_responses', 'full_responses' or 'all'
Returns:
string: The requested value or a list of all values when sStatName = 'all'
"""
params = self.__format_params(locals().copy())
method = "get_summary"
r = self.call_rpc(method, params)
return r.json()["result"]
def get_survey_properties(self, iSurveyID, aSurveySettings):
"""
RPC Routine to get survey properties.
Args:
iSurveyID (int): The ID of the Survey to be checked
aSurveySettings (list): The properties to get
Returns:
list: list with the properties
"""
params = self.__format_params(locals().copy())
method = "get_survey_properties"
print(params)
r = self.call_rpc(method, params)
return r.json()["result"]
def import_group(
self,
iSurveyID,
sImportData,
sImportDataType,
sNewGroupName=None,
sNewGroupDescription=None,
):
"""
RPC Routine to import a group - imports lsg,csv
Args:
iSurveyID (int): The ID of the survey that the group will belong
sImportData (str): containing the BASE 64 encoded data of a lsg,csv
sImportDataType (str): lsg,csv
sNewGroupName (:obj:`str`, optional): New name for the group
sNewGroupDescription (:obj:`str`, optional): New description for the group
Returns:
list|int: iGroupID - ID of the new group or status
"""
params = self.__format_params(locals().copy())
method = "import_group"
r = self.call_rpc(method, params)
return r.json()["result"]
def import_survey(
self, sImportData, sImportDataType, sNewSurveyName=None, DestSurveyID=None
):
"""
RPC Routine to import a survey - imports lss,csv,xls or survey zip archive.
Args:
sImportData (str): String containing the BASE 64 encoded data of a lss,csv,xls or survey zip archive
sImportDataType (str): lss,csv,txt or zip
sNewSurveyName (:obj:`str`, optional): The optional new name of the survey
DestSurveyID (:obj:`int`, optional) This is the new ID of the survey
if already used a random one will be taken instead
Returns:
list|integer: iSurveyID - ID of the new survey
"""
params = self.__format_params(locals().copy())
method = "import_survey"
r = self.call_rpc(method, params)
return r.json()["result"]
def list_groups(self, iSurveyID):
"""
RPC Routine to return the ids and info of groups belonging to survey .
Returns list of ids and info.
Args:
iSurveyID (int): ID of the Survey containing the groups
Returns:
list: The list of groups
"""
params = self.__format_params(locals().copy())
method = "list_groups"
r = self.call_rpc(method, params)
return r.json()["result"]
def list_participants(
self, iSurveyID, iStart, iLimit, bUnused, aAttributes, aConditions=None
):
"""
RPC Routine to return the ids and info of token/participants of a survey.
if $bUnused is true, user will get the list of not completed tokens (token_return functionality).
Parameters iStart and iLimit are used to limit the number of results of this call.
Parameter aAttributes is an optional list containing more attribute that may be requested
Args:
iSurveyID (int): ID of the survey to list participants
iStart (int): Start ID of the token list
iLimit (int): Number of participants to return
bUnused (bool): If you want unused tokens, set true
aAttributes (bool|list): The extended attributes that we want
aConditions (:obj:`list`, optional): Optional conditions to limit the list,
e.g. with list('email':'[email protected]')
Returns:
list: The list of tokens
"""
params = self.__format_params(locals().copy())
method = "list_participants"
r = self.call_rpc(method, params)
return r.json()["result"]
def list_surveys(self, sUser=None):
"""
RPC Routine to list the ids and info of surveys belonging to a user.
Returns list of ids and info.
If user is admin he can get surveys of every user (parameter sUser) or all surveys (sUser=null)
Else only the surveys belonging to the user requesting will be shown.
Args:
sUser (:obj:`str`, optional) Optional username to get list of surveys
Returns:
list: The list of surveys
"""
params = self.__format_params(locals().copy())
method = "list_surveys"
r = self.call_rpc(method, params)
return r.json()["result"]
def release_session_key(self):
"""
Closes the RPC session
Returns:
Return a string with the status.
"""
if self.session_key:
params = self.__format_params(locals().copy())
method = "release_session_key"
r = self.call_rpc(method, params)
if r.json()["result"] == "OK":
self.session_key = None
return
def activate_survey(self, iSurveyID):
"""
RPC Routine that launches a newly created survey. (Access public)
Args:
iSurveyID (int): $iSurveyID The ID of the survey to be activated
Returns:
list: The result of the activation
"""
params = self.__format_params(locals().copy())
method = "activate_survey"
r = self.call_rpc(method, params)
return r.json()["result"]
def list_users(self):
"""
RPC Routine to list the ids and info of users.
Returns list of ids and info.
Returns:
list: The list of users
"""
params = self.__format_params(locals().copy())
method = "list_users"
r = self.call_rpc(method, params)
return r.json()["result"]
def list_questions(self, iSurveyID, iGroupID=None, sLanguage=None):
"""
RPC Routine to return the ids and info of (sub-)questions of a survey/group.
Returns list of ids and info.
Args:
iSurveyID (int): ID of the survey to list questions
iGroupID (:obj:`int`, optional): Optional ID of the group to list questions
sLanguage (:obj:`str`, optional): Optional parameter language for multilingual questions
Returns:
list: The list of questions
"""
params = self.__format_params(locals().copy())
method = "list_questions"
r = self.call_rpc(method, params)
return r.json()["result"]
def import_question(
self,
iSurveyID,
iGroupID,
sImportData,
sImportDataType,
sMandatory=None,
sNewQuestionTitle=None,
sNewqQuestion=None,
sNewQuestionHelp=None,
):
"""
RPC Routine to import a question - imports lsq,csv.
Args:
iSurveyID (int): The ID of the survey that the question will belong
iGroupID (int): The ID of the group that the question will belong
sImportData (str): String containing the BASE 64 encoded data of a lsg,csv
sImportDataType (str): lsq,csv
sMandatory (:obj:`str`, optional): Mandatory question option (default to No)
sNewQuestionTitle (:obj:`str`, optional): Optional new title for the question
sNewqQuestion (:obj:`str`, optional): An optional new question
sNewQuestionHelp (:obj:`str`, optional): An optional new question help text
Returns:
list|integer: iQuestionID - ID of the new question - Or status
"""
params = self.__format_params(locals().copy())
method = "import_question"
r = self.call_rpc(method, params)
return r.json()["result"]
def invite_participants(self, iSurveyID):
"""
RPC Routine to invite participants in a survey
Returns list of results of sending
Args:
iSurveyID (int): ID of the survey that participants belong
Returns:
list: Result of the action
"""
params = self.__format_params(locals().copy())
method = "invite_participants"
r = self.call_rpc(method, params)
return r.json()["result"]
def mail_registered_participants(self, iSurveyID, overrideAllConditions):
"""
RPC Routine to send register mails to participants in a survey
Returns list of results of sending
Args:
iSurveyID (int): ID of the survey that participants belong
overrideAllConditions (list): Replace the default conditions, like this:
* overrideAllConditions = list(self);
* overrideAllConditions[] = 'tid = 2';
* response = $myJSONRPCClient->mail_registered_participants( $sessionKey, $survey_id,
$overrideAllConditions );
Returns:
list: Result of the action
"""
params = self.__format_params(locals().copy())
method = "mail_registered_participants"
r = self.call_rpc(method, params)
return r.json()["result"]
def activate_tokens(self, iSurveyID, aAttributeFields):
"""
RPC routine to initialise the survey's collection of tokens where new participant tokens may be later added.
Args:
iSurveyID (int): ID of the survey where a token table will be created for
aAttributeFields (int): An list of integer describing any additional attribute fields
Returns:
list: Status=>OK when successful, otherwise the error description
"""
params = self.__format_params(locals().copy())
method = "activate_tokens"
r = self.call_rpc(method, params)
return r.json()["result"]
def add_group(self, iSurveyID, sGroupTitle, sGroupDescription=None):
"""
RPC Routine to add an empty group with minimum details.
Used as a placeholder for importing questions.
Returns the groupId of the created group.
Args:
iSurveyID (int): Dd of the Survey to add the group
sGroupTitle (str): Name of the group
sGroupDescription (:obj:`str`,optional): Optional description of the group
Returns:
list|int: The id of the new group - Or status
"""
params = self.__format_params(locals().copy())
method = "add_group"
r = self.call_rpc(method, params)
return r.json()["result"]
def add_language(self, iSurveyID, sLanguage):
"""
RPC Routine to add a survey language.
Args:
iSurveyID (int): ID of the survey where a token table will be created for
sLanguage (str): A valid language shortcut to add to the current survey.
If the language already exists no error will be given.
Returns:
list: Status=>OK when successful, otherwise the error description
"""
params = self.__format_params(locals().copy())
method = "add_language"
r = self.call_rpc(method, params)
return r.json()["result"]
def add_participants(self, iSurveyID, aParticipantData, bCreateToken=None):
"""
RPC Routine to add participants to the tokens collection of the survey.
Returns the inserted data including additional new information like the Token entry ID and the token string.
Args:
iSurveyID (int): ID of the Survey
aParticipantData (dict): Data of the participants to be added
bCreateToken (:obj:`bool`,optional): Optional - Defaults to true (rpc side) and
determines if the access token automatically created
Returns:
list: The values added
"""
params = self.__format_params(locals().copy())
method = "add_participants"
r = self.call_rpc(method, params)
return r.json()["result"]
def add_response(self, iSurveyID, aResponseData):
"""
RPC Routine to add a response to the survey responses collection.
Returns the ID of the inserted survey response
Args:
iSurveyID (int): ID of the Survey to insert responses
aResponseData (dict): The actual response
Returns:
int: The response ID
"""
params = self.__format_params(locals().copy())
method = "add_response"
r = self.call_rpc(method, params)
return r.json()["result"]
def add_survey(self, iSurveyID, sSurveyTitle, sSurveyLanguage, sformat):
"""
RPC Routine to add an empty survey with minimum details.
Used as a placeholder for importing groups and/or questions.
Args:
iSurveyID (int): The wish ID of the Survey to add
sSurveyTitle (str): Title of the new Survey
sSurveyLanguage (str): Default language of the Survey
sformat (str): Question appearance format
Returns:
list|string|int: return values (not described at RPC Api documentation)
"""
params = self.__format_params(locals().copy())
method = "add_survey"
r = self.call_rpc(method, params)
return r.json()["result"]
def cpd_importParticipants(self, aParticipants):
"""
This function import a participant to the LimeSurvey cpd.
It stores attributes as well, if they are registered before within ui
Args:
aParticipants (list): [[0] => ["email"=>"[email protected]",
"firstname"=>"max","lastname"=>"mustermann"]]
Returns:
list: List with status
"""
params = self.__format_params(locals().copy())
method = "cpd_importParticipants"
r = self.call_rpc(method, params)
return r.json()["result"]
def delete_group(self, iSurveyID, iGroupID):
"""
RPC Routine to delete a group of a survey .
Returns the ID of the deleted group.
Args:
iSurveyID (int): ID of the survey that the group belongs
iGroupID (int): ID of the group to delete
Returns:
list|int: The ID of the deleted group or status
"""
params = self.__format_params(locals().copy())
method = "delete_group"
r = self.call_rpc(method, params)
return r.json()["result"]
def delete_language(self, iSurveyID, sLanguage):
"""
RPC Routine to delete a survey language.
Args:
iSurveyID (int): ID of the survey where a token table will be created for
sLanguage (str): A valid language shortcut to delete from the current survey.
If the language does not exist in that survey no error will be given.
Returns:
list: Status=>OK when successful, otherwise the error description
"""
params = self.__format_params(locals().copy())
method = "delete_language"
r = self.call_rpc(method, params)
return r.json()["result"]
def delete_participants(self, iSurveyID, aTokenIDs):
"""
RPC Routine to delete multiple participants of a Survey.
Returns the ID of the deleted token
Args:
iSurveyID (int): ID of the Survey that the participants belong to
aTokenIDs (list): ID of the tokens/participants to delete
Returns:
list: Result of deletion
"""
params = self.__format_params(locals().copy())
method = "delete_participants"
r = self.call_rpc(method, params)
return r.json()["result"]
def delete_question(self, iQuestionID):
"""
RPC Routine to delete a question of a survey .
Returns the ID of the deleted question.
Args:
iQuestionID (int): ID of the question to delete
Returns:
list|int: ID of the deleted Question or status
"""
params = self.__format_params(locals().copy())
method = "delete_question"
r = self.call_rpc(method, params)
return r.json()["result"]
def delete_survey(self, iSurveyID):
"""
RPC Routine to delete a survey.
Args:
iSurveyID (int): The ID of the Survey to be deleted
Returns:
list: Returns Status
"""
params = self.__format_params(locals().copy())
method = "delete_survey"
r = self.call_rpc(method, params)
return r.json()["result"]
def export_responses(
self,
iSurveyID,
sDocumentType,
sLanguageCode,
sCompletionStatus=None,
sHeadingType=None,
sResponseType=None,
iFromResponseID=None,
iToResponseID=None,
aFields=None,
):
"""
RPC Routine to export responses.
Returns the requested file as base64 encoded string
Args:
iSurveyID (int): ID of the Survey
sDocumentType (str): pdf,csv,xls,doc,json
sLanguageCode (str): The language to be used
sCompletionStatus (:obj:`str`,optional): Optional 'complete','incomplete' or 'all' - defaults to 'all'
sHeadingType (:obj:`str`,optional): 'code','full' or 'abbreviated' Optional defaults to 'code'
sResponseType (:obj:`str`,optional): 'short' or 'long' Optional defaults to 'short'
iFromResponseID (:obj:`int`,optional): Optional
iToResponseID (:obj:`int`,optional): Optional
aFields (:obj:`list`,optional) Optional Selected fields
Returns:
list|string: On success: Requested file as base 64-encoded string. On failure list with error information
"""
params = self.__format_params(locals().copy())
method = "export_responses"
r = self.call_rpc(method, params)
return r.json()["result"]
def export_responses_by_token(
self,
iSurveyID,
sDocumentType,
sToken,
sLanguageCode,
sCompletionStatus=None,
sHeadingType=None,
sResponseType=None,
aFields=None,
):
"""
RPC Routine to export token response in a survey.
Returns the requested file as base64 encoded string
Args:
iSurveyID (int): ID of the Survey
sDocumentType (str): pdf,csv,xls,doc,json
sToken (str): The token for which responses needed
sLanguageCode (str): The language to be used
sCompletionStatus (:obj:`str`,optional): Optional 'complete','incomplete' or 'all' - defaults to 'all'
sHeadingType (:obj:`str`,optional): 'code','full' or 'abbreviated' Optional defaults to 'code'
sResponseType (:obj:`str`,optional): 'short' or 'long' Optional defaults to 'short'
aFields (:obj:`list`,optional) Optional Selected fields
Returns:
list|string: On success: Requested file as base 64-encoded string. On failure list with error information
"""
params = self.__format_params(locals().copy())
method = "export_responses_by_token"
r = self.call_rpc(method, params)
return r.json()["result"]
def export_statistics(
self, iSurveyID, docType, sLanguage=None, graph=None, groupIDs=None
):
"""
RPC routine to export statistics of a survey to a user.
Returns string - base64 encoding of the statistics.
Args:
iSurveyID (int): ID of the Survey
docType (str): Type of documents the exported statistics should be
sLanguage (:obj:`str`,optional): Optional language of the survey to use
graph (:obj:`str`,optional): Create graph option
groupIDs (int|list,optional): An OPTIONAL list (ot a single int) containing the groups
we choose to generate statistics from
Returns:
string: Base64 encoded string with the statistics file
"""
params = self.__format_params(locals().copy())
method = "export_statistics"
r = self.call_rpc(method, params)
return r.json()["result"]
def export_timeline(self, iSurveyID, sType, dStart, dEnd):
"""
RPC Routine to export submission timeline.
Returns a list of values (count and period)
Args:
iSurveyID (int): ID of the Survey
sType (str): (day|hour)
dStart (str): start
dEnd (str): end
Returns:
list: On success: The timeline. On failure list with error information
"""
params = self.__format_params(locals().copy())
method = "export_timeline"
r = self.call_rpc(method, params)
return r.json()["result"]
def get_group_properties(self, iGroupID, aGroupSettings):
"""
RPC Routine to return properties of a group of a survey .
Returns list of properties
Args:
iGroupID (int): ID of the group to get properties
aGroupSettings (list): The properties to get
Returns:
list: The requested values
"""
params = self.__format_params(locals().copy())
method = "get_group_properties"
r = self.call_rpc(method, params)
return r.json()["result"]
def get_language_properties(self, iSurveyID, aSurveyLocaleSettings, sLang):
"""
RPC Routine to get survey language properties.
Args:
iSurveyID (int): Dd of the Survey
aSurveyLocaleSettings (list): Properties to get
sLang (str): Language to use
Returns:
list: The requested values
"""
params = self.__format_params(locals().copy())
method = "get_language_properties"
r = self.call_rpc(method, params)
return r.json()["result"]
def get_participant_properties(self, iSurveyID, iTokenID, aTokenProperties):
"""
RPC Routine to return settings of a token/participant of a survey .
Args:
iSurveyID (int): ID of the Survey to get token properties
iTokenID (int): ID of the participant to check
aTokenProperties (list): The properties to get
Returns:
list: The requested values
"""
params = self.__format_params(locals().copy())
method = "get_participant_properties"
r = self.call_rpc(method, params)
return r.json()["result"]
def get_question_properties(self, iQuestionID, aQuestionSettings, sLanguage=None):
"""
RPC Routine to return properties of a question of a survey.
Returns string
Args:
iQuestionID (int): ID of the question to get properties
aQuestionSettings (list): The properties to get
sLanguage (:obj:`str`,optional): Optional parameter language for multilingual questions
Returns:
list: The requested values
"""
params = self.__format_params(locals().copy())
method = "get_question_properties"
r = self.call_rpc(method, params)
return r.json()["result"]
def get_response_ids(self, iSurveyID, sToken):
"""
RPC Routine to find response IDs given a survey ID and a token.
Args:
iSurveyID (int): ID of the survey
sToken (str): The token for which responses needed
"""
params = self.__format_params(locals().copy())
method = "get_response_ids"
r = self.call_rpc(method, params)
return r.json()["result"]
def remind_participants(self, iSurveyID, iMinDaysBetween=None, iMaxReminders=None):
"""
RPC Routine to send reminder for participants in a survey
Returns list of results of sending
Args:
iSurveyID (int): ID of the survey that participants belong
iMinDaysBetween (:obj:`int`,optional): Optional parameter days from last reminder
iMaxReminders (:obj:`int`,optional): Optional parameter Maximum reminders count
Returns:
list: Result of the action
"""
params = self.__format_params(locals().copy())
method = "remind_participants"
r = self.call_rpc(method, params)
return r.json()["result"]
def set_group_properties(self, iGroupID, aGroupData):
"""
RPC Routine to set group properties.
Args:
iGroupID (int): ID of the survey
aGroupData (dict): A list with the particular fieldnames as keys and
their values to set on that particular survey
Returns:
list: Of succeeded and failed modifications according to internal validation.
"""
params = self.__format_params(locals().copy())
method = "set_group_properties"
r = self.call_rpc(method, params)
return r.json()["result"]
def set_language_properties(self, iSurveyID, aSurveyLocaleData, sLanguage=None):
"""
RPC Routine to set survey language properties.
Args:
iSurveyID (int): - ID of the survey
aSurveyLocaleData (dict): An list with the particular fieldnames as keys and
their values to set on that particular survey
sLanguage (:obj:`str`,optional): Optional - Language to update -
if not give the base language of the particular survey is used
Returns:
list: Status=>OK, when save successful otherwise error text.
"""
params = self.__format_params(locals().copy())
method = "set_language_properties"
r = self.call_rpc(method, params)
return r.json()["result"]
def set_participant_properties(self, iSurveyID, iTokenID, aTokenData):
"""
RPC Routine to set properties of a survey participant/token.
Returns list
Args:
iSurveyID (int): ID of the survey that participants belong
iTokenID (int): ID of the participant to alter
aTokenData (list|dict) Data to change
Returns:
list: Result of the change action
"""
params = self.__format_params(locals().copy())
method = "set_participant_properties"
r = self.call_rpc(method, params)
return r.json()["result"]
def set_question_properties(self, iQuestionID, aQuestionData, sLanguage=None):
"""
RPC Routine to set question properties.
Args:
iQuestionID (int): ID of the question
aQuestionData (list|dict): A list with the particular fieldnames as keys and
their values to set on that particular question
sLanguage (:obj:`str`,optional): Optional parameter language for multilingual questions
Returns:
list: List of succeeded and failed modifications according to internal validation.
"""
params = self.__format_params(locals().copy())
method = "set_question_properties"
r = self.call_rpc(method, params)
return r.json()["result"]
def set_survey_properties(self, iSurveyID, aSurveyData):
"""
RPC Routine to set survey properties.
Args:
iSurveyID (int): ID of the survey
aSurveyData (list|dict): A list with the particular fieldnames as keys and
their values to set on that particular survey
Returns:
list: List of succeeded and failed notifications according to internal validation.
"""
params = self.__format_params(locals().copy())
method = "set_survey_properties"
r = self.call_rpc(method, params)
return r.json()["result"]
def update_response(self, iSurveyID, aResponseData):
"""
RPC Routine to update a response in a given survey.
Routine supports only single response updates.
Response to update will be identified either by the response ID, or the token if response ID is missing.
Routine is only applicable for active surveys with alloweditaftercompletion = Y.
Args:
iSurveyID (int): ID of the Survey to update response
aResponseData (dict): The actual response
Returns:
bool|str: True on success. errormessage on error
"""
params = self.__format_params(locals().copy())
method = "update_response"
r = self.call_rpc(method, params)
return r.json()["result"]