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,49 @@
1
+ module Plurall
2
+ module Api
3
+ DirectorsQuery = Plurall::Api::Client.parse <<-GRAPHQL
4
+ query ($school_id: ID!, $first: IntRangeFrom1To30!, $after: String!, $before: String!, $page: Int!, $search: String!) {
5
+ schools(id: $school_id, first: 1) {
6
+ edges {
7
+ node {
8
+ id
9
+ legalName
10
+ cnpj
11
+ tradeName
12
+ directors(first: $first, after: $after, before: $before, page: $page, search: $search) {
13
+ totalCount
14
+ pageInfo {
15
+ endCursor
16
+ hasNextPage
17
+ hasPreviousPage
18
+ startCursor
19
+ }
20
+ edges {
21
+ node {
22
+ uuid
23
+ email
24
+ name
25
+ roles {
26
+ id
27
+ name
28
+ schools {
29
+ id
30
+ legalName
31
+ cnpj
32
+ tradeName
33
+ }
34
+ }
35
+ externalReference {
36
+ applicationId
37
+ identifier
38
+ applicationName
39
+ }
40
+ }
41
+ }
42
+ }
43
+ }
44
+ }
45
+ }
46
+ }
47
+ GRAPHQL
48
+ end
49
+ end
@@ -0,0 +1,9 @@
1
+ module Plurall
2
+ module Api
3
+ HTTP = ::GraphQL::Client::HTTP.new Plurall.configuration.id_graphql_url do
4
+ def headers _context
5
+ {"Authorization" => "Bearer #{Plurall::Api.id_authorization}"}
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,53 @@
1
+ module Plurall
2
+ module Api
3
+ ManagersQuery = Plurall::Api::Client.parse <<-GRAPHQL
4
+ query ($school_id: ID!, $first: IntRangeFrom1To30!, $after: String!, $before: String!, $page: Int!) {
5
+ schools(id: $school_id, first: 1) {
6
+ edges {
7
+ node {
8
+ id
9
+ legalName
10
+ cnpj
11
+ tradeName
12
+ managers(first: $first, after: $after, before: $before, page: $page) {
13
+ totalCount
14
+ pageInfo {
15
+ endCursor
16
+ hasNextPage
17
+ hasPreviousPage
18
+ startCursor
19
+ }
20
+ edges {
21
+ node {
22
+ id
23
+ uuid
24
+ email
25
+ name
26
+ activationCode
27
+ activationDate
28
+ birthDate
29
+ cpf
30
+ createdAt
31
+ gender
32
+ inactivationDate
33
+ modifiedAt
34
+ optionInEmail
35
+ optionInSms
36
+ optionOfUse
37
+ personStatusId
38
+ rg
39
+ externalReference {
40
+ applicationId
41
+ identifier
42
+ applicationName
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }
48
+ }
49
+ }
50
+ }
51
+ GRAPHQL
52
+ end
53
+ end
@@ -0,0 +1,30 @@
1
+ module Plurall
2
+ module Api
3
+ PersonQuery = Plurall::Api::Client.parse <<-GRAPHQL
4
+ query ($uuid: String!) {
5
+ person(uuid: $uuid) {
6
+ id
7
+ uuid
8
+ name
9
+ email
10
+ roles {
11
+ id
12
+ name
13
+ schools {
14
+ id
15
+ legalName
16
+ tradeName
17
+ cnpj
18
+ mecCode
19
+ }
20
+ }
21
+ externalReference {
22
+ applicationId
23
+ identifier
24
+ applicationName
25
+ }
26
+ }
27
+ }
28
+ GRAPHQL
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ module Plurall
2
+ module Api
3
+ Schema = ::GraphQL::Client.load_schema HTTP
4
+ end
5
+ end
@@ -0,0 +1,67 @@
1
+ module Plurall
2
+ module Api
3
+ SchoolsQuery = Plurall::Api::Client.parse <<-GRAPHQL
4
+ query ($first: IntRangeFrom1To30!, $after: String!, $before: String!, $page: Int!, $search: String!) {
5
+ schools(first: $first, after: $after, before: $before, page: $page, search: $search) {
6
+ totalCount
7
+ pageInfo {
8
+ endCursor
9
+ hasNextPage
10
+ hasPreviousPage
11
+ startCursor
12
+ }
13
+ edges {
14
+ node {
15
+ id
16
+ legalName
17
+ tradeName
18
+ cnpj
19
+ mecCode
20
+ address {
21
+ address
22
+ city
23
+ neighborhood
24
+ number
25
+ state
26
+ zipCode
27
+ }
28
+ brands {
29
+ id
30
+ name
31
+ }
32
+ externalReference {
33
+ applicationId
34
+ identifier
35
+ applicationName
36
+ }
37
+ teachers(first: 1) {
38
+ totalCount
39
+ }
40
+ students(first: 1) {
41
+ totalCount
42
+ }
43
+ classes(first: 1) {
44
+ totalCount
45
+ }
46
+ administrators(first: 1) {
47
+ totalCount
48
+ }
49
+ attendants(first: 1) {
50
+ totalCount
51
+ }
52
+ coordinators(first: 1) {
53
+ totalCount
54
+ }
55
+ directors(first: 1) {
56
+ totalCount
57
+ }
58
+ managers(first: 1) {
59
+ totalCount
60
+ }
61
+ }
62
+ }
63
+ }
64
+ }
65
+ GRAPHQL
66
+ end
67
+ end
@@ -0,0 +1,71 @@
1
+ module Plurall
2
+ module Api
3
+ StudentClassesQuery = Plurall::Api::Client.parse <<-GRAPHQL
4
+ query ($school_id: ID!, $uuid: String!, $first: IntRangeFrom1To30!, $after: String!, $before: String!, $page: Int!, $search: String!) {
5
+ schools(id: $school_id, first: 1) {
6
+ edges {
7
+ node {
8
+ id
9
+ legalName
10
+ cnpj
11
+ tradeName
12
+ students(uuid: $uuid, first: 1) {
13
+ edges {
14
+ node {
15
+ id
16
+ uuid
17
+ email
18
+ enrollment
19
+ name
20
+ classes(first: $first, after: $after, before: $before, page: $page, search: $search) {
21
+ totalCount
22
+ pageInfo {
23
+ endCursor
24
+ hasNextPage
25
+ hasPreviousPage
26
+ startCursor
27
+ }
28
+ edges {
29
+ node {
30
+ id
31
+ name
32
+ period {
33
+ id
34
+ year
35
+ }
36
+ levelGrades {
37
+ gradeId
38
+ gradeName
39
+ levelId
40
+ levelName
41
+ }
42
+ materials {
43
+ id
44
+ title
45
+ description
46
+ brand {
47
+ id
48
+ name
49
+ }
50
+ status {
51
+ id
52
+ name
53
+ }
54
+ }
55
+ disciplines {
56
+ id
57
+ name
58
+ }
59
+ }
60
+ }
61
+ }
62
+ }
63
+ }
64
+ }
65
+ }
66
+ }
67
+ }
68
+ }
69
+ GRAPHQL
70
+ end
71
+ end
@@ -0,0 +1,83 @@
1
+ module Plurall
2
+ module Api
3
+ StudentsQuery = Plurall::Api::Client.parse <<-GRAPHQL
4
+ query ($school_id: ID!, $first: IntRangeFrom1To30!, $after: String!, $before: String!, $page: Int!, $search: String!) {
5
+ schools(id: $school_id, first: 1) {
6
+ edges {
7
+ node {
8
+ id
9
+ legalName
10
+ cnpj
11
+ tradeName
12
+ students(first: $first, after: $after, before: $before, page: $page, search: $search) {
13
+ totalCount
14
+ pageInfo {
15
+ endCursor
16
+ hasNextPage
17
+ hasPreviousPage
18
+ startCursor
19
+ }
20
+ edges {
21
+ node {
22
+ id
23
+ uuid
24
+ email
25
+ enrollment
26
+ name
27
+ classes(first: 1) {
28
+ totalCount
29
+ pageInfo {
30
+ endCursor
31
+ hasNextPage
32
+ hasPreviousPage
33
+ startCursor
34
+ }
35
+ edges {
36
+ node {
37
+ id
38
+ name
39
+ period {
40
+ id
41
+ year
42
+ }
43
+ levelGrades {
44
+ gradeId
45
+ gradeName
46
+ levelId
47
+ levelName
48
+ }
49
+ materials {
50
+ id
51
+ title
52
+ description
53
+ brand {
54
+ id
55
+ name
56
+ }
57
+ status {
58
+ id
59
+ name
60
+ }
61
+ }
62
+ disciplines {
63
+ id
64
+ name
65
+ }
66
+ }
67
+ }
68
+ }
69
+ externalReference {
70
+ applicationId
71
+ identifier
72
+ applicationName
73
+ }
74
+ }
75
+ }
76
+ }
77
+ }
78
+ }
79
+ }
80
+ }
81
+ GRAPHQL
82
+ end
83
+ end
@@ -0,0 +1,75 @@
1
+ module Plurall
2
+ module Api
3
+ TeachersQuery = Plurall::Api::Client.parse <<-GRAPHQL
4
+ query ($school_id: ID!, $first: IntRangeFrom1To30!, $after: String!, $before: String!, $page: Int!, $search: String!) {
5
+ schools(id: $school_id, first: 1) {
6
+ edges {
7
+ node {
8
+ id
9
+ legalName
10
+ cnpj
11
+ tradeName
12
+ teachers(first: $first, after: $after, before: $before, page: $page, search: $search) {
13
+ totalCount
14
+ pageInfo {
15
+ endCursor
16
+ hasNextPage
17
+ hasPreviousPage
18
+ startCursor
19
+ }
20
+ edges {
21
+ node {
22
+ id
23
+ uuid
24
+ email
25
+ name
26
+ classes {
27
+ id
28
+ name
29
+ period {
30
+ id
31
+ year
32
+ }
33
+ levelGrades {
34
+ gradeId
35
+ gradeName
36
+ levelId
37
+ levelName
38
+ }
39
+ materials {
40
+ id
41
+ title
42
+ description
43
+ brand {
44
+ id
45
+ name
46
+ }
47
+ status {
48
+ id
49
+ name
50
+ }
51
+ }
52
+ disciplines {
53
+ id
54
+ name
55
+ }
56
+ teacherDisciplines {
57
+ id
58
+ name
59
+ }
60
+ }
61
+ externalReference {
62
+ applicationId
63
+ identifier
64
+ applicationName
65
+ }
66
+ }
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
72
+ }
73
+ GRAPHQL
74
+ end
75
+ end
@@ -0,0 +1,139 @@
1
+ require "graphql/client"
2
+ require "graphql/client/http"
3
+ require "faraday"
4
+
5
+ module Plurall
6
+ module Api
7
+ def self.oauth_token code:, redirect_uri:, oauth_token_url: Plurall.configuration.oauth_token_url,
8
+ client_id: Plurall.configuration.client_id, client_secret: Plurall.configuration.client_secret
9
+
10
+ Faraday.post oauth_token_url, {
11
+ grant_type: :authorization_code,
12
+ code: code,
13
+ redirect_uri: redirect_uri,
14
+ client_id: client_id,
15
+ client_secret: client_secret
16
+ }
17
+ end
18
+
19
+ def self.oauth_authorize_url redirect_uri:, authorize_url: Plurall.configuration.oauth_authorize_url,
20
+ client_id: Plurall.configuration.client_id
21
+
22
+ uri = URI authorize_url
23
+ params = {response_type: :code, client_id: client_id, redirect_uri: redirect_uri}
24
+ uri.query = URI.encode_www_form params
25
+ uri.to_s
26
+ end
27
+
28
+ def self.me access_token:, me_url: Plurall.configuration.me_url
29
+ Faraday.post me_url, {}, {"Authorization" => "Bearer #{access_token}"}
30
+ end
31
+
32
+ class << self
33
+ attr_writer :id_authorization
34
+
35
+ def id_authorization
36
+ reset_id_authorization! if @id_authorization.nil?
37
+
38
+ # This value will expire after a few hours, so holding in memory is fine.
39
+ @id_authorization
40
+ end
41
+
42
+ def reset_id_authorization!
43
+ self.id_authorization = new_id_authorization!
44
+ end
45
+
46
+ def new_id_authorization! id_application: Plurall.configuration.id_application,
47
+ id_auth_url: Plurall.configuration.id_auth_url
48
+
49
+ auth_request = Faraday.post id_auth_url,
50
+ {idApplication: id_application}.to_json,
51
+ {"Content-Type" => "application/json"}
52
+ JSON.parse(auth_request.body).dig("authorization")
53
+ end
54
+ end
55
+
56
+ autoload :HTTP, "plurall/api/http.rb"
57
+ autoload :Schema, "plurall/api/schema.rb"
58
+ autoload :Client, "plurall/api/client.rb"
59
+
60
+ autoload :SchoolsQuery, "plurall/api/schools_query.rb"
61
+ autoload :TeachersQuery, "plurall/api/teachers_query.rb"
62
+ autoload :StudentsQuery, "plurall/api/students_query.rb"
63
+ autoload :StudentClassesQuery, "plurall/api/student_classes_query.rb"
64
+ autoload :ClassesQuery, "plurall/api/classes_query.rb"
65
+ autoload :AdministratorsQuery, "plurall/api/administrators_query.rb"
66
+ autoload :AttendantsQuery, "plurall/api/attendants_query.rb"
67
+ autoload :CoordinatorsQuery, "plurall/api/coordinators_query.rb"
68
+ autoload :DirectorsQuery, "plurall/api/directors_query.rb"
69
+ autoload :ManagersQuery, "plurall/api/managers_query.rb"
70
+ autoload :PersonQuery, "plurall/api/person_query.rb"
71
+
72
+ def self.schools first: 30, after: "", before: "", page: 0, search: ""
73
+ Plurall::Api.query Plurall::Api::SchoolsQuery, variables: {first: first, after: after, before: before, page: page, search: search}
74
+ end
75
+
76
+ def self.teachers school_id:, first: 30, after: "", before: "", page: 0, search: ""
77
+ Plurall::Api.query Plurall::Api::TeachersQuery, variables: {school_id: school_id, first: first, after: after, before: before, page: page, search: search}
78
+ end
79
+
80
+ def self.students school_id:, first: 30, after: "", before: "", page: 0, search: ""
81
+ Plurall::Api.query Plurall::Api::StudentsQuery, variables: {school_id: school_id, first: first, after: after, before: before, page: page, search: search}
82
+ end
83
+
84
+ def self.student_classes school_id:, uuid:, first: 30, after: "", before: "", page: 0, search: ""
85
+ Plurall::Api.query Plurall::Api::StudentClassesQuery, variables: {school_id: school_id, uuid: uuid, first: first, after: after, before: before, page: page, search: search}
86
+ end
87
+
88
+ def self.classes school_id:, first: 30, after: "", before: "", page: 0, search: ""
89
+ Plurall::Api.query Plurall::Api::ClassesQuery, variables: {school_id: school_id, first: first, after: after, before: before, page: page, search: search}
90
+ end
91
+
92
+ def self.administrators school_id:, first: 30, after: "", before: "", page: 0, search: ""
93
+ Plurall::Api.query Plurall::Api::AdministratorsQuery, variables: {school_id: school_id, first: first, after: after, before: before, page: page, search: search}
94
+ end
95
+
96
+ def self.attendants school_id:, first: 30, after: "", before: "", page: 0, search: ""
97
+ Plurall::Api.query Plurall::Api::AttendantsQuery, variables: {school_id: school_id, first: first, after: after, before: before, page: page, search: search}
98
+ end
99
+
100
+ def self.coordinators school_id:, first: 30, after: "", before: "", page: 0, search: ""
101
+ Plurall::Api.query Plurall::Api::CoordinatorsQuery, variables: {school_id: school_id, first: first, after: after, before: before, page: page, search: search}
102
+ end
103
+
104
+ def self.directors school_id:, first: 30, after: "", before: "", page: 0, search: ""
105
+ Plurall::Api.query Plurall::Api::DirectorsQuery, variables: {school_id: school_id, first: first, after: after, before: before, page: page, search: search}
106
+ end
107
+
108
+ def self.managers school_id:, first: 30, after: "", before: "", page: 0
109
+ Plurall::Api.query Plurall::Api::ManagersQuery, variables: {school_id: school_id, first: first, after: after, before: before, page: page}
110
+ end
111
+
112
+ def self.person uuid:
113
+ Plurall::Api.query Plurall::Api::PersonQuery, variables: {uuid: uuid}
114
+ end
115
+
116
+ def self.query query, **kwargs
117
+ retries ||= 0
118
+
119
+ response = Plurall::Api::Client.query query, **kwargs
120
+
121
+ raise Plurall::TokenExpiredError if response.errors.all[:data].any? { |error| error.include? "TokenExpiredError" }
122
+
123
+ # TODO: Improve partial error handling here...
124
+ raise "NIL DATA: #{query} #{kwargs} | #{response.to_h}" if response.data.nil?
125
+
126
+ if response.errors.any? || response.errors.all.any?
127
+ raise (response.errors.values + response.errors.all.values).uniq.join("|")
128
+ end
129
+
130
+ response
131
+ rescue Plurall::TokenExpiredError => e
132
+ Plurall::Api.reset_id_authorization!
133
+
134
+ retry if (retries += 1) < 2 # retry twice
135
+
136
+ raise e
137
+ end
138
+ end
139
+ end