plurall 0.1.0

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.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.env.sample +14 -0
  3. data/.gitignore +12 -0
  4. data/CHANGELOG.md +3 -0
  5. data/CODE_OF_CONDUCT.md +84 -0
  6. data/Gemfile +6 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +65 -0
  9. data/Rakefile +12 -0
  10. data/bin/console +15 -0
  11. data/bin/setup +8 -0
  12. data/lib/plurall/administrators.rb +185 -0
  13. data/lib/plurall/api/administrators_query.rb +49 -0
  14. data/lib/plurall/api/attendants_query.rb +49 -0
  15. data/lib/plurall/api/classes_query.rb +60 -0
  16. data/lib/plurall/api/client.rb +5 -0
  17. data/lib/plurall/api/coordinators_query.rb +53 -0
  18. data/lib/plurall/api/directors_query.rb +49 -0
  19. data/lib/plurall/api/http.rb +9 -0
  20. data/lib/plurall/api/managers_query.rb +53 -0
  21. data/lib/plurall/api/person_query.rb +30 -0
  22. data/lib/plurall/api/schema.rb +5 -0
  23. data/lib/plurall/api/schools_query.rb +67 -0
  24. data/lib/plurall/api/student_classes_query.rb +71 -0
  25. data/lib/plurall/api/students_query.rb +83 -0
  26. data/lib/plurall/api/teachers_query.rb +75 -0
  27. data/lib/plurall/api.rb +139 -0
  28. data/lib/plurall/attendants.rb +185 -0
  29. data/lib/plurall/classes.rb +185 -0
  30. data/lib/plurall/configuration.rb +41 -0
  31. data/lib/plurall/coordinators.rb +185 -0
  32. data/lib/plurall/directors.rb +185 -0
  33. data/lib/plurall/errors.rb +11 -0
  34. data/lib/plurall/managers.rb +185 -0
  35. data/lib/plurall/schools.rb +169 -0
  36. data/lib/plurall/student_classes.rb +197 -0
  37. data/lib/plurall/students.rb +185 -0
  38. data/lib/plurall/teachers.rb +185 -0
  39. data/lib/plurall/version.rb +6 -0
  40. data/lib/plurall.rb +273 -0
  41. data/plurall.gemspec +45 -0
  42. data/schema/friendly.json +14653 -0
  43. data/schema/graphql.json +11907 -0
  44. data/sig/plurall.rbs +4 -0
  45. metadata +269 -0
@@ -0,0 +1,185 @@
1
+ module Plurall
2
+ ##
3
+ # Public: A list of school attendants that supports pagination.
4
+ #
5
+ # Examples
6
+ #
7
+ # Plurall.attendants(school_id: 123456).each do |attendant|
8
+ # puts attendant.name
9
+ # end
10
+ #
11
+ class Attendants
12
+ include Enumerable
13
+
14
+ # Internal: Returns the GraphQL API response as a GraphQL::Client::Response.
15
+ attr_reader :response
16
+
17
+ ##
18
+ # Internal: Create a new object from a GraphQL API response.
19
+ #
20
+ # response - The GraphQL API response as a GraphQL::Client::Response.
21
+ #
22
+ def initialize response
23
+ @response = response
24
+ end
25
+
26
+ ##
27
+ # Public: Returns the number of attendants as an Integer.
28
+ def total_count
29
+ school_node.attendants.total_count
30
+ end
31
+
32
+ ##
33
+ # Public: Returns the list of attendants as a Hash.
34
+ def data
35
+ response.data.to_h
36
+ end
37
+
38
+ ##
39
+ # Public: Returns the school id for list of attendants as a String.
40
+ def school_id
41
+ school_node.id
42
+ end
43
+
44
+ ##
45
+ # Public: Iterates the list of attendants.
46
+ #
47
+ # Examples
48
+ #
49
+ # Plurall.attendants(school_id: 123456).each do |attendant|
50
+ # puts attendant.name
51
+ # end
52
+ #
53
+ # Yields an attendant object to the block.
54
+ #
55
+ # Returns an Enumerator when no block argument is given, or nothing when when a block argument is given.
56
+ #
57
+ def each &block
58
+ return enum_for :each unless block
59
+
60
+ school_node.attendants.edges.lazy.map(&:node).each(&block)
61
+ end
62
+
63
+ ##
64
+ # Public: Iterates all attendants.
65
+ #
66
+ # Several API calls may be made to retrieve all by repeatedly calling #next until #next? returns `false`.
67
+ #
68
+ # Examples
69
+ #
70
+ # Plurall.attendants(school_id: 123456).all do |attendant|
71
+ # puts attendant.name
72
+ # end
73
+ #
74
+ # Yields an attendant object to the block.
75
+ #
76
+ # Returns an Enumerator when no block argument is given, or nothing when when a block argument is given.
77
+ #
78
+ def all &block
79
+ return enum_for :all unless block
80
+
81
+ page = self
82
+ loop do
83
+ page.each(&block)
84
+ page = page.next
85
+ break if page.nil?
86
+ end
87
+ end
88
+
89
+ ##
90
+ # Public: Whether there are more attendants available.
91
+ #
92
+ # Examples
93
+ #
94
+ # attendants = Plurall.attendants school_id: 123456
95
+ # attendants.next?
96
+ #
97
+ # Returns true or false.
98
+ #
99
+ def next?
100
+ attendants_page_info.has_next_page
101
+ end
102
+
103
+ ##
104
+ # Internal: The next cursor used for pagination.
105
+ #
106
+ # Returns the next cursor as a String, or nil.
107
+ #
108
+ def next_cursor
109
+ return nil unless next?
110
+
111
+ attendants_page_info.end_cursor
112
+ end
113
+
114
+ ##
115
+ # Public: Retrieve the next page of attendants.
116
+ #
117
+ # Returns the next page as Plurall::Attendants, or nil.
118
+ #
119
+ def next
120
+ return nil unless next?
121
+
122
+ next_response = Plurall::Api.attendants school_id: school_id, after: next_cursor
123
+ self.class.new next_response
124
+ end
125
+
126
+ ##
127
+ # Public: Whether there are previous attendants available.
128
+ #
129
+ # Examples
130
+ #
131
+ # attendants = Plurall.attendants school_id: 123456
132
+ # attendants.prev?
133
+ #
134
+ # Returns true or false.
135
+ #
136
+ def prev?
137
+ attendants_page_info.has_previous_page
138
+ end
139
+
140
+ ##
141
+ # Internal: The previous cursor used for pagination.
142
+ #
143
+ # Returns the previous cursor as a String, or nil.
144
+ #
145
+ def prev_cursor
146
+ return nil unless prev?
147
+
148
+ attendants_page_info.start_cursor
149
+ end
150
+
151
+ ##
152
+ # Public: Retrieve the previous page of attendants.
153
+ #
154
+ # Examples
155
+ #
156
+ # attendants = Plurall.attendants school_id: 123456
157
+ # prev_attendants = attendants.prev
158
+ #
159
+ # Returns the previous page as Plurall::Attendants, or nil.
160
+ #
161
+ def prev
162
+ return nil unless prev?
163
+
164
+ prev_response = Plurall::Api.attendants school_id: school_id, before: prev_cursor
165
+ self.class.new prev_response
166
+ end
167
+
168
+ ##
169
+ # Internal: Returns a string representation of the list.
170
+ #
171
+ def inspect
172
+ "#<#{self.class.name}:0x#{(object_id * 2).to_s(16).rjust(16, "0")} attendants:#{total_count}>"
173
+ end
174
+
175
+ private
176
+
177
+ def school_node
178
+ response.data.schools.first.edges.first.node
179
+ end
180
+
181
+ def attendants_page_info
182
+ school_node.attendants.page_info
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,185 @@
1
+ module Plurall
2
+ ##
3
+ # Public: A list of school classes that supports pagination.
4
+ #
5
+ # Examples
6
+ #
7
+ # Plurall.classes(school_id: 123456).each do |school_class|
8
+ # puts school_class.name
9
+ # end
10
+ #
11
+ class Classes
12
+ include Enumerable
13
+
14
+ # Internal: Returns the GraphQL API response as a GraphQL::Client::Response.
15
+ attr_reader :response
16
+
17
+ ##
18
+ # Internal: Create a new object from a GraphQL API response.
19
+ #
20
+ # response - The GraphQL API response as a GraphQL::Client::Response.
21
+ #
22
+ def initialize response
23
+ @response = response
24
+ end
25
+
26
+ ##
27
+ # Public: Returns the number of classes as an Integer.
28
+ def total_count
29
+ school_node.classes.total_count
30
+ end
31
+
32
+ ##
33
+ # Public: Returns the list of classes as a Hash.
34
+ def data
35
+ response.data.to_h
36
+ end
37
+
38
+ ##
39
+ # Public: Returns the school id for list of classes as a String.
40
+ def school_id
41
+ school_node.id
42
+ end
43
+
44
+ ##
45
+ # Public: Iterates the list of school classes.
46
+ #
47
+ # Examples
48
+ #
49
+ # Plurall.classes(school_id: 123456).each do |school_class|
50
+ # puts school_class.name
51
+ # end
52
+ #
53
+ # Yields a school class object to the block.
54
+ #
55
+ # Returns an Enumerator when no block argument is given, or nothing when when a block argument is given.
56
+ #
57
+ def each &block
58
+ return enum_for :each unless block
59
+
60
+ school_node.classes.edges.lazy.map(&:node).each(&block)
61
+ end
62
+
63
+ ##
64
+ # Public: Iterates all school classes.
65
+ #
66
+ # Several API calls may be made to retrieve all by repeatedly calling #next until #next? returns `false`.
67
+ #
68
+ # Examples
69
+ #
70
+ # Plurall.classes(school_id: 123456).all do |school_class|
71
+ # puts school_class.name
72
+ # end
73
+ #
74
+ # Yields a school class object to the block.
75
+ #
76
+ # Returns an Enumerator when no block argument is given, or nothing when when a block argument is given.
77
+ #
78
+ def all &block
79
+ return enum_for :all unless block
80
+
81
+ page = self
82
+ loop do
83
+ page.each(&block)
84
+ page = page.next
85
+ break if page.nil?
86
+ end
87
+ end
88
+
89
+ ##
90
+ # Public: Whether there are more classes available.
91
+ #
92
+ # Examples
93
+ #
94
+ # classes = Plurall.classes school_id: 123456
95
+ # classes.next?
96
+ #
97
+ # Returns true or false.
98
+ #
99
+ def next?
100
+ classes_page_info.has_next_page
101
+ end
102
+
103
+ ##
104
+ # Internal: The next cursor used for pagination.
105
+ #
106
+ # Returns the next cursor as a String, or nil.
107
+ #
108
+ def next_cursor
109
+ return nil unless next?
110
+
111
+ classes_page_info.end_cursor
112
+ end
113
+
114
+ ##
115
+ # Public: Retrieve the next page of classes.
116
+ #
117
+ # Returns the next page as Plurall::Classes, or nil.
118
+ #
119
+ def next
120
+ return nil unless next?
121
+
122
+ next_response = Plurall::Api.classes school_id: school_id, after: next_cursor
123
+ self.class.new next_response
124
+ end
125
+
126
+ ##
127
+ # Public: Whether there are previous classes available.
128
+ #
129
+ # Examples
130
+ #
131
+ # classes = Plurall.classes school_id: 123456
132
+ # classes.prev?
133
+ #
134
+ # Returns true or false.
135
+ #
136
+ def prev?
137
+ classes_page_info.has_previous_page
138
+ end
139
+
140
+ ##
141
+ # Internal: The previous cursor used for pagination.
142
+ #
143
+ # Returns the previous cursor as a String, or nil.
144
+ #
145
+ def prev_cursor
146
+ return nil unless prev?
147
+
148
+ classes_page_info.start_cursor
149
+ end
150
+
151
+ ##
152
+ # Public: Retrieve the previous page of classes.
153
+ #
154
+ # Examples
155
+ #
156
+ # classes = Plurall.classes school_id: 123456
157
+ # prev_classes = classes.prev
158
+ #
159
+ # Returns the previous page as Plurall::Classes, or nil.
160
+ #
161
+ def prev
162
+ return nil unless prev?
163
+
164
+ prev_response = Plurall::Api.classes school_id: school_id, before: prev_cursor
165
+ self.class.new prev_response
166
+ end
167
+
168
+ ##
169
+ # Internal: Returns a string representation of the list.
170
+ #
171
+ def inspect
172
+ "#<#{self.class.name}:0x#{(object_id * 2).to_s(16).rjust(16, "0")} classes:#{total_count}>"
173
+ end
174
+
175
+ private
176
+
177
+ def school_node
178
+ response.data.schools.first.edges.first.node
179
+ end
180
+
181
+ def classes_page_info
182
+ school_node.classes.page_info
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,41 @@
1
+ module Plurall
2
+ ##
3
+ # Public: The configuration instance used to configure the library.
4
+ #
5
+ # Examples
6
+ #
7
+ # Plurall.configure do |config|
8
+ # config.client_id = "YOUR_PLURALL_CLIENT_ID"
9
+ # config.client_secret = "YOUR_PLURALL_CLIENT_SECRET"
10
+ # config.id_application = "YOUR_PLURALL_APPLICATION_ID"
11
+ # end
12
+ #
13
+ class Configuration
14
+ attr_accessor :client_id, :client_secret
15
+ attr_accessor :oauth_authorize_url, :oauth_token_url, :me_url
16
+ attr_accessor :id_application, :id_auth_url, :id_graphql_url
17
+
18
+ def initialize(options = {})
19
+ @client_id = options.dig :client_id
20
+ @client_secret = options.dig :client_secret
21
+ @oauth_authorize_url = options.dig(:oauth_authorize_url) || "https://ms-api.plurall.net/oauth/authorize"
22
+ @oauth_token_url = options.dig(:oauth_token_url) || "https://ms-api.plurall.net/oauth/token"
23
+ @me_url = options.dig(:me_url) || "https://ms-api.plurall.net/me"
24
+ @id_application = options.dig :id_application
25
+ @id_auth_url = options.dig(:id_auth_url) || "https://ms-api.plurall.net/identity/data-exchange/auth"
26
+ @id_graphql_url = options.dig(:id_graphql_url) || "https://ms-api.plurall.net/identity/data-exchange/v2/graphql"
27
+ end
28
+ end
29
+
30
+ class << self
31
+ attr_writer :configuration
32
+ end
33
+
34
+ def self.configure
35
+ yield configuration
36
+ end
37
+
38
+ def self.configuration
39
+ @configuration ||= Plurall::Configuration.new
40
+ end
41
+ end
@@ -0,0 +1,185 @@
1
+ module Plurall
2
+ ##
3
+ # Public: A list of school coordinators that supports pagination.
4
+ #
5
+ # Examples
6
+ #
7
+ # Plurall.coordinators(school_id: 123456).each do |coordinator|
8
+ # puts coordinator.name
9
+ # end
10
+ #
11
+ class Coordinators
12
+ include Enumerable
13
+
14
+ # Internal: Returns the GraphQL API response as a GraphQL::Client::Response.
15
+ attr_reader :response
16
+
17
+ ##
18
+ # Internal: Create a new object from a GraphQL API response.
19
+ #
20
+ # response - The GraphQL API response as a GraphQL::Client::Response.
21
+ #
22
+ def initialize response
23
+ @response = response
24
+ end
25
+
26
+ ##
27
+ # Public: Returns the number of coordinators as an Integer.
28
+ def total_count
29
+ school_node.coordinators.total_count
30
+ end
31
+
32
+ ##
33
+ # Public: Returns the list of coordinators as a Hash.
34
+ def data
35
+ response.data.to_h
36
+ end
37
+
38
+ ##
39
+ # Public: Returns the school id for list of coordinators as a String.
40
+ def school_id
41
+ school_node.id
42
+ end
43
+
44
+ ##
45
+ # Public: Iterates the list of coordinators.
46
+ #
47
+ # Examples
48
+ #
49
+ # Plurall.coordinators(school_id: 123456).each do |coordinator|
50
+ # puts coordinator.name
51
+ # end
52
+ #
53
+ # Yields a coordinator object to the block.
54
+ #
55
+ # Returns an Enumerator when no block argument is given, or nothing when when a block argument is given.
56
+ #
57
+ def each &block
58
+ return enum_for :each unless block
59
+
60
+ school_node.coordinators.edges.lazy.map(&:node).each(&block)
61
+ end
62
+
63
+ ##
64
+ # Public: Iterates all coordinators.
65
+ #
66
+ # Several API calls may be made to retrieve all by repeatedly calling #next until #next? returns `false`.
67
+ #
68
+ # Examples
69
+ #
70
+ # Plurall.coordinators(school_id: 123456).all do |coordinator|
71
+ # puts coordinator.name
72
+ # end
73
+ #
74
+ # Yields a coordinator object to the block.
75
+ #
76
+ # Returns an Enumerator when no block argument is given, or nothing when when a block argument is given.
77
+ #
78
+ def all &block
79
+ return enum_for :all unless block
80
+
81
+ page = self
82
+ loop do
83
+ page.each(&block)
84
+ page = page.next
85
+ break if page.nil?
86
+ end
87
+ end
88
+
89
+ ##
90
+ # Public: Whether there are more coordinators available.
91
+ #
92
+ # Examples
93
+ #
94
+ # coordinators = Plurall.coordinators school_id: 123456
95
+ # coordinators.next?
96
+ #
97
+ # Returns true or false.
98
+ #
99
+ def next?
100
+ coordinators_page_info.has_next_page
101
+ end
102
+
103
+ ##
104
+ # Internal: The next cursor used for pagination.
105
+ #
106
+ # Returns the next cursor as a String, or nil.
107
+ #
108
+ def next_cursor
109
+ return nil unless next?
110
+
111
+ coordinators_page_info.end_cursor
112
+ end
113
+
114
+ ##
115
+ # Public: Retrieve the next page of coordinators.
116
+ #
117
+ # Returns the next page as Plurall::Coordinators, or nil.
118
+ #
119
+ def next
120
+ return nil unless next?
121
+
122
+ next_response = Plurall::Api.coordinators school_id: school_id, after: next_cursor
123
+ self.class.new next_response
124
+ end
125
+
126
+ ##
127
+ # Public: Whether there are previous coordinators available.
128
+ #
129
+ # Examples
130
+ #
131
+ # coordinators = Plurall.coordinators school_id: 123456
132
+ # coordinators.prev?
133
+ #
134
+ # Returns true or false.
135
+ #
136
+ def prev?
137
+ coordinators_page_info.has_previous_page
138
+ end
139
+
140
+ ##
141
+ # Internal: The previous cursor used for pagination.
142
+ #
143
+ # Returns the previous cursor as a String, or nil.
144
+ #
145
+ def prev_cursor
146
+ return nil unless prev?
147
+
148
+ coordinators_page_info.start_cursor
149
+ end
150
+
151
+ ##
152
+ # Public: Retrieve the previous page of coordinators.
153
+ #
154
+ # Examples
155
+ #
156
+ # coordinators = Plurall.coordinators school_id: 123456
157
+ # prev_coordinators = coordinators.prev
158
+ #
159
+ # Returns the previous page as Plurall::Coordinators, or nil.
160
+ #
161
+ def prev
162
+ return nil unless prev?
163
+
164
+ prev_response = Plurall::Api.coordinators school_id: school_id, before: prev_cursor
165
+ self.class.new prev_response
166
+ end
167
+
168
+ ##
169
+ # Internal: Returns a string representation of the list.
170
+ #
171
+ def inspect
172
+ "#<#{self.class.name}:0x#{(object_id * 2).to_s(16).rjust(16, "0")} coordinators:#{total_count}>"
173
+ end
174
+
175
+ private
176
+
177
+ def school_node
178
+ response.data.schools.first.edges.first.node
179
+ end
180
+
181
+ def coordinators_page_info
182
+ school_node.coordinators.page_info
183
+ end
184
+ end
185
+ end