strongmind-agilix-buzz-client 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,140 @@
1
+ module Agilix
2
+ module Buzz
3
+ module Commands
4
+ module Enrollment
5
+
6
+ def enrollment_status
7
+ {
8
+ active: 1,
9
+ withdrawn: 4,
10
+ withdrawn_failed: 5,
11
+ transferred: 6,
12
+ completed: 7,
13
+ completed_no_credit: 8,
14
+ suspended: 9,
15
+ inactive: 10
16
+ }
17
+ end
18
+
19
+ def enrollment_status_lookup_value(int)
20
+ int = int.to_i
21
+ raise ArgumentError.new("Not a valid enrollment status code") unless enrollment_status.values.include?(int)
22
+ enrollment_status.find {|k,v| v == int}.first
23
+ end
24
+
25
+ # ISSUE: API format is very inconsistent on this one, requires both query string modification & body modification
26
+ # api.create_enrollments [{userid: 57026, entityid: 57025}]
27
+ def create_enrollments(items = [], disallowduplicates: false, disallowsamestatusduplicates: false )
28
+ options = items.map do |item|
29
+ item[:status] ||= 1
30
+ argument_cleaner(required_params: %i( userid entityid status ), optional_params: %i( roleid flags domainid startdate enddate reference schema data ), options: item )
31
+ end
32
+ if [disallowduplicates, disallowsamestatusduplicates].compact.any?
33
+ query_params = {}
34
+ query_params[:disallowduplicates] = disallowduplicates
35
+ query_params[:disallowsamestatusduplicates] = disallowsamestatusduplicates
36
+ end
37
+ authenticated_bulk_post cmd: "createenrollments", root_node: 'enrollment', query_params: query_params, body: options
38
+ end
39
+
40
+ # ISSUE: Inconsistent from other delete apis. many are singular, not plural
41
+ # api.delete_enrollments [ { enrollmentid: 60997 }]
42
+ def delete_enrollments(items = {})
43
+ options = items.map do |item|
44
+ argument_cleaner(required_params: %i( enrollmentid ), optional_params: %i( ), options: item )
45
+ end
46
+ authenticated_bulk_post cmd: "deleteenrollments", root_node: 'enrollment', body: options
47
+ end
48
+
49
+ # api.get_enrollment enrollmentid: 60997
50
+ def get_enrollment3(options = {})
51
+ options = argument_cleaner(required_params: %i( enrollmentid ), optional_params: %i( select ), options: options )
52
+ authenticated_get cmd: "getenrollment3", **options
53
+ end
54
+ alias_method :get_enrollment, :get_enrollment3
55
+
56
+ # api.get_enrollment_activity enrollmentid: 60997
57
+ def get_enrollment_activity(options = {})
58
+ options = argument_cleaner(required_params: %i( enrollmentid ), optional_params: %i( last mergeoverlap ), options: options )
59
+ authenticated_get cmd: "getenrollmentactivity", **options
60
+ end
61
+
62
+ # api.get_enrollment_gradebook enrollmentid: 60997
63
+ def get_enrollment_gradebook2(options = {})
64
+ options = argument_cleaner(required_params: %i( enrollmentid ), optional_params: %i( forcerequireditems gradingschemeid gradingscheme itemid scorm zerounscored ), options: options )
65
+ authenticated_get cmd: "getenrollmentgradebook2", **options
66
+ end
67
+ alias_method :get_enrollment_gradebook, :get_enrollment_gradebook2
68
+
69
+ # api.get_enrollment_group_list enrollmentid: 60997
70
+ def get_enrollment_group_list(options = {})
71
+ options = argument_cleaner(required_params: %i( enrollmentid ), optional_params: %i( setid ), options: options )
72
+ authenticated_get cmd: "getenrollmentgrouplist", **options
73
+ end
74
+
75
+ # api.get_enrollment_metrics_report entityid: 50725, report: "Student"
76
+ # api.get_enrollment_metrics_report entityid: 50725, report: "Enrollment"
77
+ def get_enrollment_metrics_report(options = {})
78
+ raise ArgumentError.new("report can only be Student or Enrollment") unless ['Student', 'Enrollment'].include?(options[:report])
79
+ default_select = %w( user.id user.firstname user.lastname user.username user.reference)
80
+ student_select = %w( coursecount latecount failedcount paceyellows pacereds performanceyellows performancereds)
81
+ enrollment_select = %w(enrollment.id course.title course.id course.reference score achieved possible failing seconds completable completed gradable completedgradable graded percentcomplete late failed recentlyfailed pacelight pacereason performancelight performancereason lastduedatemissed calculateddate )
82
+ if options[:report] == "Student"
83
+ options[:select] ||= (default_select + student_select).flatten.join(",")
84
+ elsif options[:report] == "Enrollment"
85
+ options[:select] ||= (default_select + enrollment_select).flatten.join(",")
86
+ end
87
+ options = argument_cleaner(required_params: %i( entityid report select ), optional_params: %i( filename format ), options: options )
88
+ authenticated_get cmd: "getenrollmentmetricsreport", **options
89
+ end
90
+
91
+ # api.list_enrollments domainid: 50725
92
+ def list_enrollments(options = {})
93
+ options = argument_cleaner(required_params: %i( domainid ), optional_params: %i( includedescendantdomains limit show select query userdomainid userquery usertext coursedomainid coursequery coursetext ), options: options )
94
+ authenticated_get cmd: "listenrollments", **options
95
+ end
96
+
97
+ # api.list_enrollments_by_teacher teacheruserid: 50726
98
+ # api.list_enrollments_by_teacher
99
+ def list_enrollments_by_teacher(options = {})
100
+ options = argument_cleaner(required_params: %i( ), optional_params: %i( teacheruserid teacherallstatus teacherdaysactivepastend privileges allstatus daysactivepastend userid select ), options: options )
101
+ authenticated_get cmd: "listenrollmentsbyteacher", **options
102
+ end
103
+
104
+ # api.list_entity_enrollments entityid: 60982
105
+ def list_entity_enrollments(options = {})
106
+ options = argument_cleaner(required_params: %i( entityid ), optional_params: %i( privileges allstatus daysactivepastend userid select ), options: options )
107
+ authenticated_get cmd: "listentityenrollments", **options
108
+ end
109
+
110
+ # api.list_user_enrollments userid: 57181
111
+ def list_user_enrollments(options = {})
112
+ options = argument_cleaner(required_params: %i( userid ), optional_params: %i( allstatus entityid privileges daysactivepastend query select ), options: options )
113
+ authenticated_get cmd: "listuserenrollments", **options
114
+ end
115
+
116
+ # ISSUE: this should be a post, not a get
117
+ # api.put_self_assessment enrollmentid: 60997, understanding: 200, effort: 220, interest: 100
118
+ def put_self_assessment(options = {})
119
+ options = argument_cleaner(required_params: %i( enrollmentid ), optional_params: %i( understanding interest effort ), options: options )
120
+ authenticated_get cmd: "putselfassessment", **options
121
+ end
122
+
123
+ # api.restore_enrollment enrollmentid: 60997
124
+ def restore_enrollment(options = {})
125
+ options = argument_cleaner(required_params: %i( enrollmentid ), optional_params: %i( ), options: options )
126
+ authenticated_get cmd: "restoreenrollment", **options
127
+ end
128
+
129
+ # api.update_enrollments [{enrollmentid: 60997, status: 7}]
130
+ def update_enrollments(items)
131
+ options = items.map do |item|
132
+ argument_cleaner(required_params: %i( enrollmentid ), optional_params: %i( userid entityid domainid roleid flags status startdate enddate reference schema data ), options: item)
133
+ end
134
+ authenticated_bulk_post cmd: "updateenrollments", root_node: 'enrollment', body: options
135
+ end
136
+
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,70 @@
1
+ module Agilix
2
+ module Buzz
3
+ module Commands
4
+ module General
5
+
6
+ # api.echo test: 'param'
7
+ def echo(options= {})
8
+ post cmd: "echo", **options
9
+ end
10
+
11
+ # api.get_command_list
12
+ def get_command_list
13
+ get cmd: "getcommandlist"
14
+ end
15
+
16
+ # ISSUE: nothing saying this is an authenticated call, when others are non-authenticated
17
+ # api.get_entity_type entityid: 57025
18
+ def get_entity_type(options = {})
19
+ options = argument_cleaner(required_params: %i( entityid ), optional_params: %i( select ), options: options )
20
+ authenticated_get cmd: "getentitytype", **options
21
+ end
22
+
23
+ # ISSUE: docs in getting started reference a `level` param, actual docs suggest using rating
24
+ # api.get_status rating: 4, html: true, sms: true
25
+ def get_status(options = {})
26
+ options = argument_cleaner(required_params: %i( ), optional_params: %i( rating sms html ), options: options )
27
+ authenticated_get cmd: "getstatus", **options
28
+ end
29
+
30
+ # this is a non-authenticated call
31
+ # api.get_status
32
+ def get_basic_status(options = {})
33
+ options = argument_cleaner(required_params: %i( ), optional_params: %i( rating sms html ), options: options )
34
+ get cmd: "getstatus", **options
35
+ end
36
+
37
+ # ISSUE: Docs have cmd spelled wrong, this API doesn't seem to work at all AccessDenied. It did say experimental
38
+ # api.get_upload_limits
39
+ # api.get_upload_limits domainid: 57025
40
+ def get_upload_limits(options = {})
41
+ options = argument_cleaner(required_params: %i( ), optional_params: %i( userid domainid ), options: options )
42
+ get cmd: "getuploadlimits", **options
43
+ end
44
+
45
+ # api.send_mail subject: "Test email", body: "Did you get this?", enrollmentid: 60997, enrollment_ids: ["all"]
46
+ def send_mail(options = {})
47
+ options = argument_cleaner(required_params: %i( subject body enrollmentid enrollment_ids ), optional_params: %i( groups roles strings), options: options )
48
+ request = {email: {
49
+ subject: {"$value" => options[:subject]},
50
+ body: {"$value" => options[:body]},
51
+ enrollments: {enrollment: options[:enrollment_ids].map {|id| {id: id} } }
52
+ }}
53
+ request[:email][:groups] = {group: options[:groups].map {|id| {id: id} } } if options[:groups]
54
+ request[:email][:roles] = {role: options[:roles].map {|id| {id: id} } } if options[:roles]
55
+ if options[:strings]
56
+ request[:email][:strings] = options[:strings].map do |k,v|
57
+ [ k , {"$value" => v } ]
58
+ end.to_h
59
+ end
60
+ enrollment_response = self.get_enrollment enrollmentid: options[:enrollmentid]
61
+ user_id = enrollment_response.dig("response", "enrollment", "userid")
62
+ proxy_api = self.proxy_api userid: user_id
63
+ proxy_api.authenticated_query_post query_params: {cmd: "sendmail", enrollmentid: options[:enrollmentid] }, **request
64
+ end
65
+
66
+
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,43 @@
1
+ module Agilix
2
+ module Buzz
3
+ module Commands
4
+ module Library
5
+
6
+ # api.get_library_page domainid: 57031, pageid: "230433194a1e4699bfa576aa6e6743c6"
7
+ def get_library_page(options = {})
8
+ options = argument_cleaner(required_params: %i( domainid pageid ), optional_params: %i( ), options: options )
9
+ authenticated_get cmd: "getlibrarypage", **options
10
+ end
11
+
12
+ # api.list_library_pages domainid: 57031
13
+ def list_library_pages(options = {})
14
+ options = argument_cleaner(required_params: %i( domainid ), optional_params: %i( libraryid limit select ), options: options )
15
+ authenticated_get cmd: "listlibrarypages", **options
16
+ end
17
+
18
+ # api.create_library_page domainid: 57031, libraryid: 'testlib', title: "Greatest ever", description: "This really is the best", body: "<h1>Check it out!</h1><iframe src='https://www.google.com'></iframe>"
19
+ def create_library_page(options = {})
20
+ optional_params = argument_cleaner(required_params: %i( domainid libraryid title description ), optional_params: %i( body id name 'meta-featured' 'meta-type' 'meta-category' ), options: options )
21
+ # authenticated_query_post cmd: "putresource", **options
22
+ authenticated_post cmd: "createlibrarypage", **options
23
+ end
24
+
25
+ # # api.search_library_pages domainid: 57031, path: "banner.css"
26
+ # def search_library_pages(options = {})
27
+ # options = argument_cleaner(required_params: %i( domainid ), optional_params: %i( libraryid limit select q ), options: options )
28
+ # authenticated_get cmd: "searchlibrarypages", **options
29
+ # end
30
+
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ # createlibrarypagebookmark
37
+ # deletelibrarypage
38
+ # deletelibrarypagebookmark
39
+ # listlibrarypagebookmarks
40
+ # populatelibrarypageedits
41
+ # populatelibrarypageedits
42
+ # reindexlibrarypages
43
+ # updatelibrarypage
@@ -0,0 +1,37 @@
1
+ module Agilix
2
+ module Buzz
3
+ module Commands
4
+ module Report
5
+
6
+ # Use this one to find reports you can run
7
+ # api.get_runnable_report_list domainid: 57025
8
+ def get_runnable_report_list(options = {})
9
+ options = argument_cleaner(required_params: %i( ), optional_params: %i( entityid domainid ), options: options )
10
+ authenticated_get cmd: "getrunnablereportlist", **options
11
+ end
12
+
13
+ # Use this one to run a report
14
+ # api.run_report reportid: 127, entityid: 57025
15
+ def run_report(options = {})
16
+ options = argument_cleaner(required_params: %i( reportid entityid ), optional_params: %i( format content_disposition nodata AsOf), options: options )
17
+ authenticated_get cmd: "runreport", **options
18
+ end
19
+
20
+ # slightly more info than get_runnable_report_list
21
+ # api.get_report_info reportid: 123
22
+ def get_report_info(options = {})
23
+ options = argument_cleaner(required_params: %i( reportid ), optional_params: %i( ), options: options )
24
+ authenticated_get cmd: "getreportinfo", **options
25
+ end
26
+
27
+ # This call seems worthless, and we don't seem to have rights
28
+ # api.get_report_list domainid: 1
29
+ def get_report_list(options = {})
30
+ options = argument_cleaner(required_params: %i( domainid ), optional_params: %i( ), options: options )
31
+ authenticated_get cmd: "getreportlist", **options
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,124 @@
1
+ module Agilix
2
+ module Buzz
3
+ module Commands
4
+ module Resource
5
+
6
+ # api.copy_resources [ {sourceentityid: 57025, destinationentityid: 57031, sourcepath: "banner.css" }]
7
+ def copy_resources(items = [])
8
+ options = items.map do |item|
9
+ argument_cleaner(required_params: %i( sourceentityid destinationentityid ), optional_params: %i( sourcepath destinationpath ), options: item )
10
+ end
11
+ authenticated_bulk_post cmd: "copyresources", root_node: "resource", body: options
12
+ end
13
+
14
+ # api.delete_resources [{entityid: 57031, path: 'banner.css'}]
15
+ def delete_resources(items = [])
16
+ options = items.map do |item|
17
+ argument_cleaner(required_params: %i( entityid path ), optional_params: %i( class ), options: item )
18
+ end
19
+ authenticated_bulk_post cmd: "deleteresources", root_node: "resource", body: options
20
+ end
21
+
22
+ # api.get_entity_resource_id entityid: 57025
23
+ def get_entity_resource_id(options = {})
24
+ options = argument_cleaner(required_params: %i( entityid ), optional_params: %i( ), options: options )
25
+ authenticated_get cmd: "getentityresourceid", **options
26
+ end
27
+
28
+ # api.get_resource entityid: 57031, path: "banner.css"
29
+ def get_resource(options = {})
30
+ options = argument_cleaner(required_params: %i( entityid path ), optional_params: %i( version packagetype attachment class ), options: options )
31
+ authenticated_get cmd: "getresource", **options
32
+ end
33
+
34
+ # ISSUE: This is a get request with a POST verb. The documentation only suggests getting a single resoure, so I'm not sure why it would be a bulk post syntax. it does seem to respond to multiple resources though,so we'll adapt
35
+ # api.get_resource_info [{entityid: 57031, path: "banner.css"}]
36
+ def get_resource_info2(items = [])
37
+ options = items.map do |item|
38
+ argument_cleaner(required_params: %i( entityid path ), optional_params: %i( class ), options: item )
39
+ end
40
+ authenticated_bulk_post cmd: "getresourceinfo2", root_node: "resource", body: options
41
+ end
42
+ alias_method :get_resource_info, :get_resource_info2
43
+
44
+ # api.get_resource_list2 entityid: 57025
45
+ def get_resource_list2(options = {})
46
+ options = argument_cleaner(required_params: %i( entityid ), optional_params: %i( path recurse query allversions entries class ), options: options )
47
+ authenticated_get cmd: "getresourcelist2", **options
48
+ end
49
+ alias_method :get_resource_list, :get_resource_list2
50
+
51
+ # api.list_restorable_resources entityid: 57025
52
+ def list_restorable_resources(options = {})
53
+ options = argument_cleaner(required_params: %i( entityid ), optional_params: %i( ), options: options )
54
+ authenticated_get cmd: "listrestorableresources", **options
55
+ end
56
+
57
+ # file_name = "my-file.pdf"
58
+ # file = File.open file_name
59
+ # api.put_resource file, {entityid: 57025, path: file_name}
60
+ def put_resource(file, options = {})
61
+ options = argument_cleaner(required_params: %i( entityid path ), optional_params: %i( status class drophistory contenttype ), options: options )
62
+ # authenticated_query_post cmd: "putresource", **options
63
+ authenticated_query_post query_params: {cmd: "putresource", **options }, file: file
64
+ end
65
+
66
+ # api.put_resource_folders [{entityid: 57031, path: 'test/folder-1'}]
67
+ def put_resource_folders(items = [])
68
+ options = items.map do |item|
69
+ argument_cleaner(required_params: %i( entityid path ), optional_params: %i( ), options: item )
70
+ end
71
+ authenticated_bulk_post cmd: "putresourcefolders", root_node: "folder", body: options
72
+ end
73
+
74
+ # api.restore_resources [{entityid: 57031, path: 'banner.css'}]
75
+ def restore_resources(items = [])
76
+ options = items.map do |item|
77
+ argument_cleaner(required_params: %i( entityid path ), optional_params: %i( class ), options: item )
78
+ end
79
+ authenticated_bulk_post cmd: "restoreresources", root_node: "resource", body: options
80
+ end
81
+
82
+ # api.delete_documents
83
+ def delete_documents(items = [])
84
+ options = items.map do |item|
85
+ argument_cleaner(required_params: %i( enrollmentid itemid path ), optional_params: %i( ), options: item )
86
+ end
87
+ authenticated_bulk_post cmd: "deletedocuments", root_node: "document", body: options
88
+ end
89
+
90
+ # api.get_document enrollmentid: 60997
91
+ def get_document(options = {})
92
+ options = argument_cleaner(required_params: %i( enrollmentid itemid path ), optional_params: %i( version ), options: options )
93
+ authenticated_get cmd: "getdocument", **options
94
+ end
95
+
96
+ # ISSUE: Why is get command a bulk POST request
97
+ # api.get_document_info
98
+ def get_document_info(items = [])
99
+ options = items.map do |item|
100
+ argument_cleaner(required_params: %i( enrollmentid itemid path ), optional_params: %i( ), options: item )
101
+ end
102
+ authenticated_bulk_post cmd: "getdocumentinfo", root_node: "document", body: options
103
+ authenticated_get cmd: "", **options
104
+ end
105
+
106
+ # api.list_restorable_documents enrollmentid: 64001
107
+ def list_restorable_documents(options = {})
108
+ options = argument_cleaner(required_params: %i( enrollmentid itemid ), optional_params: %i( ), options: options )
109
+ authenticated_get cmd: "listrestorabledocuments", **options
110
+ end
111
+
112
+
113
+ # api.restore_documents
114
+ def restore_documents(items = [])
115
+ options = items.map do |item|
116
+ argument_cleaner(required_params: %i( enrollmentid itemid path), optional_params: %i( version ), options: item )
117
+ end
118
+ authenticated_bulk_post cmd: "restoredocuments", root_node: "document", body: options
119
+ end
120
+
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,234 @@
1
+ module Agilix
2
+ module Buzz
3
+ module Commands
4
+ module Right
5
+
6
+ # ISSUE: Why is this create singular, not multiple?
7
+ # api.create_role domainid: 57025, name: "Test Role", privileges: api.right_flags[:create_domain]
8
+ def create_role(options = {})
9
+ options = argument_cleaner(required_params: %i( domainid name privileges ), optional_params: %i( reference entitytype ), options: options )
10
+ raise ArgumentError.new("Not a valid entitytype. Should be D,C, or empty") unless [nil, "", "D", "C"].include?(options[:entitytype])
11
+ authenticated_post cmd: "createrole", **options
12
+ end
13
+
14
+ # api.delete_role roleid: 61316
15
+ def delete_role(options = {})
16
+ options = argument_cleaner(required_params: %i( roleid ), optional_params: %i( ), options: options )
17
+ authenticated_get cmd: "deleterole", **options
18
+ end
19
+
20
+ # api.delete_subscriptions subscriberid: 57181, entityid: 57025
21
+ def delete_subscriptions(items = [])
22
+ options = items.map do |item|
23
+ argument_cleaner(required_params: %i( subscriberid entityid ), optional_params: %i( flags ), options: item )
24
+ end
25
+ authenticated_bulk_post cmd: "deletesubscriptions", root_node: 'subscription', body: options
26
+ end
27
+
28
+ # api.get_actor_rights actorid: 5000, entitytypes: "U|S|D"
29
+ def get_actor_rights(options = {})
30
+ options = argument_cleaner(required_params: %i( actorid ), optional_params: %i( entitytypes ), options: options )
31
+ authenticated_get cmd: "getactorrights", **options
32
+ end
33
+
34
+ # api.get_effective_rights entityid: 57025
35
+ def get_effective_rights(options = {})
36
+ options = argument_cleaner(required_params: %i( entityid ), optional_params: %i( ), options: options )
37
+ authenticated_get cmd: "geteffectiverights", **options
38
+ end
39
+
40
+ # api.get_effective_subscription_list
41
+ def get_effective_subscription_list(options = {})
42
+ options = argument_cleaner(required_params: %i( ), optional_params: %i( select ), options: options )
43
+ authenticated_get cmd: "geteffectivesubscriptionlist", **options
44
+ end
45
+
46
+ # api.get_entity_rights entityid: 57025
47
+ def get_entity_rights(options = {})
48
+ options = argument_cleaner(required_params: %i( entityid ), optional_params: %i( ), options: options )
49
+ authenticated_get cmd: "getentityrights", **options
50
+ end
51
+
52
+ # api.get_entity_subscription_list entityid: 57025
53
+ def get_entity_subscription_list(options = {})
54
+ options = argument_cleaner(required_params: %i( entityid ), optional_params: %i( subscriberid), options: options )
55
+ authenticated_get cmd: "getentitysubscriptionlist", **options
56
+ end
57
+
58
+ # api.get_personas userid: 57026
59
+ def get_personas(options = {})
60
+ options = argument_cleaner(required_params: %i( ), optional_params: %i( userid domainid ), options: options )
61
+ authenticated_get cmd: "getpersonas", **options
62
+ end
63
+
64
+ # api.get_rights actorid: 57026, entityid: 57025
65
+ def get_rights(options = {})
66
+ options = argument_cleaner(required_params: %i( actorid entityid ), optional_params: %i( ), options: options )
67
+ authenticated_get cmd: "getrights", **options
68
+ end
69
+
70
+ # api.get_rights_list domainid: 57025
71
+ def get_rights_list(options = {})
72
+ options = argument_cleaner(required_params: %i( ), optional_params: %i( domainid restrictdomain ), options: options )
73
+ authenticated_get cmd: "getrightslist", **options
74
+ end
75
+
76
+ # api.get_role roleid: 61316
77
+ def get_role(options = {})
78
+ options = argument_cleaner(required_params: %i( roleid ), optional_params: %i( ), options: options )
79
+ authenticated_get cmd: "getrole", **options
80
+ end
81
+
82
+ # Get for a domain
83
+ # api.get_subscription_list subscriberid: 57025
84
+ # Get for a user
85
+ # api.get_subscription_list subscriberid: 57026
86
+ def get_subscription_list(options = {})
87
+ options = argument_cleaner(required_params: %i( subscriberid ), optional_params: %i( entityid ), options: options )
88
+ authenticated_get cmd: "getsubscriptionlist", **options
89
+ end
90
+
91
+ # api.list_roles domainid: 57025
92
+ def list_roles(options = {})
93
+ options = argument_cleaner(required_params: %i( domainid ), optional_params: %i( ), options: options )
94
+ authenticated_get cmd: "listroles", **options
95
+ end
96
+
97
+ # api.restore_role roleid: 61316
98
+ def restore_role(options = {})
99
+ options = argument_cleaner(required_params: %i( roleid ), optional_params: %i( ), options: options )
100
+ authenticated_get cmd: "restorerole", **options
101
+ end
102
+
103
+ # api.update_rights [ {actorid: 57026, entityid: 57025, roleid: 61316}]
104
+ def update_rights(items = [])
105
+ options = items.map do |item|
106
+ argument_cleaner(required_params: %i( actorid entityid ), optional_params: %i( roleid flags schema ), options: item )
107
+ end
108
+ authenticated_bulk_post cmd: "updaterights", root_node: 'rights', body: options
109
+ end
110
+
111
+ # api.update_role roleid: 61316, name: "Test Role Updates", privileges: api.right_flags[:update_domain]
112
+ def update_role(options = {})
113
+ options = argument_cleaner(required_params: %i( roleid ), optional_params: %i( name privileges reference entitytype ), options: options )
114
+ raise ArgumentError.new("Not a valid entitytype. Should be D,C, or empty") unless [nil, "", "D", "C"].include?(options[:entitytype])
115
+
116
+ authenticated_post cmd: "updaterole", **options
117
+ end
118
+
119
+ # ISSUE: Why is this root node singular?
120
+ # api.update_subscriptions subscriberid: 57181, entityid: 60982, startdate: "2019-03-15", enddate: "2019-03-15"
121
+ def update_subscriptions(items = [])
122
+ options = items.map do |item|
123
+ argument_cleaner(required_params: %i( subscriberid entityid startdate enddate ), optional_params: %i( subscriptionflags ), options: item )
124
+ end
125
+ authenticated_bulk_post cmd: "updatesubscriptions", root_node: 'subscription', body: options
126
+ end
127
+
128
+ def right_flags
129
+ {
130
+ admin: -1,
131
+ none: 0,
132
+ participate: 1,
133
+ create_domain: 16,
134
+ read_domain: 32,
135
+ update_domain: 64,
136
+ delete_domain: 128,
137
+ create_user: 256,
138
+ read_user: 512,
139
+ update_user: 1024,
140
+ delete_user: 2048,
141
+ create_course: 65536,
142
+ read_course: 131072,
143
+ update_course: 262144,
144
+ delete_course: 524288,
145
+ create_section: 1048576,
146
+ read_section: 2097152,
147
+ update_section: 4194304,
148
+ delete_section: 8388608,
149
+ grade_assignment: 16777216,
150
+ grade_forum: 33554432,
151
+ grade_exam: 67108864,
152
+ setup_gradebook: 134217728,
153
+ control_domain: 268435456,
154
+ control_course: 536870912,
155
+ control_section: 1073741824,
156
+ read_gradebook: 2147483648,
157
+ report_domain: 4294967296,
158
+ report_course: 8589934592,
159
+ report_section: 17179869184,
160
+ post_domain_announcements: 34359738368,
161
+ proxy: 68719476736,
162
+ report_user: 274877906944,
163
+ submit_final_grade: 549755813888,
164
+ control_enrollment: 1099511627776,
165
+ read_enrollment: 2199023255552,
166
+ read_course_full: 4398046511104,
167
+ control_user: 8796093022208,
168
+ read_objective: 17592186044416,
169
+ update_objective: 35184372088832
170
+ }
171
+ end
172
+
173
+ def right_flags_hex
174
+ {
175
+ admin: "-0x01",
176
+ none: "0x00",
177
+ participate: "0x01",
178
+ create_domain: "0x10",
179
+ read_domain: "0x20",
180
+ update_domain: "0x40",
181
+ delete_domain: "0x80",
182
+ create_user: "0x100",
183
+ read_user: "0x200",
184
+ update_user: "0x400",
185
+ delete_user: "0x800",
186
+ create_course: "0x10000",
187
+ read_course: "0x20000",
188
+ update_course: "0x40000",
189
+ delete_course: "0x80000",
190
+ create_section: "0x100000",
191
+ read_section: "0x200000",
192
+ update_section: "0x400000",
193
+ delete_section: "0x800000",
194
+ grade_assignment: "0x1000000",
195
+ grade_forum: "0x2000000",
196
+ grade_exam: "0x4000000",
197
+ setup_gradebook: "0x8000000",
198
+ control_domain: "0x10000000",
199
+ control_course: "0x20000000",
200
+ control_section: "0x40000000",
201
+ read_gradebook: "0x80000000",
202
+ report_domain: "0x100000000",
203
+ report_course: "0x200000000",
204
+ report_section: "0x400000000",
205
+ post_domain_announcements: "0x800000000",
206
+ proxy: "0x1000000000",
207
+ report_user: "0x4000000000",
208
+ submit_final_grade: "0x8000000000",
209
+ control_enrollment: "0x10000000000",
210
+ read_enrollment: "0x20000000000",
211
+ read_course_full: "0x40000000000",
212
+ control_user: "0x80000000000",
213
+ read_objective: "0x100000000000",
214
+ update_objective: "0x200000000000"
215
+ }
216
+ end
217
+
218
+
219
+ def right_flags_lookup_value(val)
220
+ val = val.to_s
221
+ if val.include?("x")
222
+ raise ArgumentError.new("Not a valid right flag") unless right_flags_hex.values.include?(val)
223
+ right_flags_hex.find {|k,v| v == val}.first
224
+ else
225
+ val = val.to_i
226
+ raise ArgumentError.new("Not a valid right flag") unless right_flags.values.include?(val)
227
+ right_flags.find {|k,v| v == val}.first
228
+ end
229
+ end
230
+
231
+ end
232
+ end
233
+ end
234
+ end