clever_sdk 0.9.0.pre.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +26 -0
- data/.env.sample +20 -0
- data/.gitignore +22 -0
- data/.tool-versions +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +65 -0
- data/Rakefile +10 -0
- data/bin/console +31 -0
- data/bin/setup +8 -0
- data/bin/test +6 -0
- data/clever_sdk.gemspec +44 -0
- data/lib/clever_sdk/api/authentication.rb +38 -0
- data/lib/clever_sdk/api/courses.rb +54 -0
- data/lib/clever_sdk/api/districts.rb +23 -0
- data/lib/clever_sdk/api/events.rb +26 -0
- data/lib/clever_sdk/api/resources.rb +49 -0
- data/lib/clever_sdk/api/response.rb +59 -0
- data/lib/clever_sdk/api/schools.rb +68 -0
- data/lib/clever_sdk/api/sections.rb +70 -0
- data/lib/clever_sdk/api/terms.rb +46 -0
- data/lib/clever_sdk/api/users.rb +81 -0
- data/lib/clever_sdk/api.rb +81 -0
- data/lib/clever_sdk/authentication.rb +67 -0
- data/lib/clever_sdk/client/courses.rb +45 -0
- data/lib/clever_sdk/client/districts.rb +21 -0
- data/lib/clever_sdk/client/events.rb +22 -0
- data/lib/clever_sdk/client/resources.rb +40 -0
- data/lib/clever_sdk/client/schools.rb +54 -0
- data/lib/clever_sdk/client/sections.rb +59 -0
- data/lib/clever_sdk/client/terms.rb +40 -0
- data/lib/clever_sdk/client/users.rb +66 -0
- data/lib/clever_sdk/client.rb +41 -0
- data/lib/clever_sdk/configuration.rb +13 -0
- data/lib/clever_sdk/data/course/refs.rb +36 -0
- data/lib/clever_sdk/data/course.rb +44 -0
- data/lib/clever_sdk/data/courses.rb +79 -0
- data/lib/clever_sdk/data/district.rb +129 -0
- data/lib/clever_sdk/data/districts.rb +37 -0
- data/lib/clever_sdk/data/event.rb +93 -0
- data/lib/clever_sdk/data/events.rb +79 -0
- data/lib/clever_sdk/data/me.rb +34 -0
- data/lib/clever_sdk/data/resource/refs.rb +45 -0
- data/lib/clever_sdk/data/resource.rb +60 -0
- data/lib/clever_sdk/data/resources.rb +79 -0
- data/lib/clever_sdk/data/school/refs.rb +42 -0
- data/lib/clever_sdk/data/school.rb +88 -0
- data/lib/clever_sdk/data/schools.rb +79 -0
- data/lib/clever_sdk/data/section/refs.rb +45 -0
- data/lib/clever_sdk/data/section.rb +100 -0
- data/lib/clever_sdk/data/sections.rb +79 -0
- data/lib/clever_sdk/data/sso.rb +44 -0
- data/lib/clever_sdk/data/term/refs.rb +32 -0
- data/lib/clever_sdk/data/term.rb +46 -0
- data/lib/clever_sdk/data/terms.rb +79 -0
- data/lib/clever_sdk/data/token.rb +67 -0
- data/lib/clever_sdk/data/tokeninfo.rb +30 -0
- data/lib/clever_sdk/data/tokens.rb +35 -0
- data/lib/clever_sdk/data/user/contact_role.rb +19 -0
- data/lib/clever_sdk/data/user/district_admin_role.rb +19 -0
- data/lib/clever_sdk/data/user/refs.rb +56 -0
- data/lib/clever_sdk/data/user/staff_role.rb +19 -0
- data/lib/clever_sdk/data/user/student_role.rb +19 -0
- data/lib/clever_sdk/data/user/teacher_role.rb +19 -0
- data/lib/clever_sdk/data/user.rb +123 -0
- data/lib/clever_sdk/data/users.rb +79 -0
- data/lib/clever_sdk/error.rb +27 -0
- data/lib/clever_sdk/version.rb +5 -0
- data/lib/clever_sdk.rb +36 -0
- metadata +255 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "clever_sdk/data/terms"
|
4
|
+
|
5
|
+
module CleverSDK
|
6
|
+
class Client
|
7
|
+
module Terms
|
8
|
+
# count - acceptable values are nil, :true, :false, :undefined
|
9
|
+
def terms(limit: nil, starting_after: nil, ending_before: nil, count: nil)
|
10
|
+
response = api.terms(access_token: access_token,
|
11
|
+
limit: limit, starting_after: starting_after, ending_before: ending_before, count: count)
|
12
|
+
CleverSDK::Data::Terms.new(response)
|
13
|
+
end
|
14
|
+
|
15
|
+
def term(id)
|
16
|
+
response = api.term(access_token: access_token, id: id)
|
17
|
+
data = response.body.dig("data")
|
18
|
+
CleverSDK::Data::Term.new(data, response)
|
19
|
+
end
|
20
|
+
|
21
|
+
def term_district(id)
|
22
|
+
response = api.term_district(access_token: access_token, id: id)
|
23
|
+
data = response.body.dig("data")
|
24
|
+
CleverSDK::Data::District.new(data, response)
|
25
|
+
end
|
26
|
+
|
27
|
+
def term_schools(id, limit: nil, starting_after: nil, ending_before: nil)
|
28
|
+
response = api.term_schools(access_token: access_token, id: id,
|
29
|
+
limit: limit, starting_after: starting_after, ending_before: ending_before)
|
30
|
+
CleverSDK::Data::Schools.new(response)
|
31
|
+
end
|
32
|
+
|
33
|
+
def term_sections(id)
|
34
|
+
response = api.term_sections(access_token: access_token, id: id,
|
35
|
+
limit: limit, starting_after: starting_after, ending_before: ending_before)
|
36
|
+
CleverSDK::Data::Sections.new(response)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "clever_sdk/data/users"
|
4
|
+
|
5
|
+
module CleverSDK
|
6
|
+
class Client
|
7
|
+
module Users
|
8
|
+
# role - acceptable values are nil, :contact, :district_admin, :staff, :student, :teacher
|
9
|
+
# count - acceptable values are nil, :true, :false, :undefined
|
10
|
+
def users(role: nil, limit: nil, starting_after: nil, ending_before: nil, count: nil)
|
11
|
+
response = api.users(access_token: access_token, role: role,
|
12
|
+
limit: limit, starting_after: starting_after, ending_before: ending_before, count: count)
|
13
|
+
CleverSDK::Data::Users.new(response)
|
14
|
+
end
|
15
|
+
|
16
|
+
def user(id)
|
17
|
+
response = api.user(access_token: access_token, id: id)
|
18
|
+
data = response.body.dig("data")
|
19
|
+
CleverSDK::Data::User.new(data, response)
|
20
|
+
end
|
21
|
+
|
22
|
+
def user_district(id)
|
23
|
+
response = api.user_district(access_token: access_token, id: id)
|
24
|
+
data = response.body.dig("data")
|
25
|
+
CleverSDK::Data::District.new(data, response)
|
26
|
+
end
|
27
|
+
|
28
|
+
def user_resources(id, limit: nil, starting_after: nil, ending_before: nil)
|
29
|
+
response = api.user_resources(access_token: access_token, id: id,
|
30
|
+
limit: limit, starting_after: starting_after, ending_before: ending_before)
|
31
|
+
CleverSDK::Data::Resources.new(response)
|
32
|
+
end
|
33
|
+
|
34
|
+
# primary - acceptable values are nil, true
|
35
|
+
def user_schools(id, primary: nil, limit: nil, starting_after: nil, ending_before: nil)
|
36
|
+
response = api.user_schools(access_token: access_token, id: id, primary: primary,
|
37
|
+
limit: limit, starting_after: starting_after, ending_before: ending_before)
|
38
|
+
CleverSDK::Data::Schools.new(response)
|
39
|
+
end
|
40
|
+
|
41
|
+
def user_sections(id, limit: nil, starting_after: nil, ending_before: nil)
|
42
|
+
response = api.user_sections(access_token: access_token, id: id,
|
43
|
+
limit: limit, starting_after: starting_after, ending_before: ending_before)
|
44
|
+
CleverSDK::Data::Sections.new(response)
|
45
|
+
end
|
46
|
+
|
47
|
+
def user_mycontacts(id, limit: nil, starting_after: nil, ending_before: nil)
|
48
|
+
response = api.user_mycontacts(access_token: access_token, id: id,
|
49
|
+
limit: limit, starting_after: starting_after, ending_before: ending_before)
|
50
|
+
CleverSDK::Data::Users.new(response)
|
51
|
+
end
|
52
|
+
|
53
|
+
def user_mystudents(id, limit: nil, starting_after: nil, ending_before: nil)
|
54
|
+
response = api.user_mystudents(access_token: access_token, id: id,
|
55
|
+
limit: limit, starting_after: starting_after, ending_before: ending_before)
|
56
|
+
CleverSDK::Data::Users.new(response)
|
57
|
+
end
|
58
|
+
|
59
|
+
def user_myteachers(id, limit: nil, starting_after: nil, ending_before: nil)
|
60
|
+
response = api.user_myteachers(access_token: access_token, id: id,
|
61
|
+
limit: limit, starting_after: starting_after, ending_before: ending_before)
|
62
|
+
CleverSDK::Data::Users.new(response)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "clever_sdk/api"
|
4
|
+
require "clever_sdk/client/courses"
|
5
|
+
require "clever_sdk/client/districts"
|
6
|
+
require "clever_sdk/client/resources"
|
7
|
+
require "clever_sdk/client/schools"
|
8
|
+
require "clever_sdk/client/sections"
|
9
|
+
require "clever_sdk/client/terms"
|
10
|
+
require "clever_sdk/client/users"
|
11
|
+
require "clever_sdk/client/events"
|
12
|
+
|
13
|
+
module CleverSDK
|
14
|
+
class Client
|
15
|
+
include CleverSDK::Client::Courses
|
16
|
+
include CleverSDK::Client::Districts
|
17
|
+
include CleverSDK::Client::Resources
|
18
|
+
include CleverSDK::Client::Schools
|
19
|
+
include CleverSDK::Client::Sections
|
20
|
+
include CleverSDK::Client::Terms
|
21
|
+
include CleverSDK::Client::Users
|
22
|
+
include CleverSDK::Client::Events
|
23
|
+
|
24
|
+
attr_accessor :access_token, :configuration
|
25
|
+
|
26
|
+
def initialize(access_token, configuration = CleverSDK.configuration)
|
27
|
+
@access_token = access_token
|
28
|
+
@configuration = configuration
|
29
|
+
end
|
30
|
+
|
31
|
+
def inspect
|
32
|
+
"#<#{self.class.name}:0x#{(object_id * 2).to_s(16).rjust(16, "0")} #{access_token}>"
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def api
|
38
|
+
@api ||= CleverSDK::Api.new
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CleverSDK
|
4
|
+
class Configuration
|
5
|
+
attr_accessor :client_id, :client_secret, :redirect_uri
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
@client_id = options.dig(:client_id) || ENV["CLEVER_ID"]
|
9
|
+
@client_secret = options.dig(:client_secret) || ENV["CLEVER_SECRET"]
|
10
|
+
@redirect_uri = options.dig(:redirect_uri) || ENV["CLEVER_REDIRECT_URI"]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CleverSDK
|
4
|
+
module Data
|
5
|
+
class Course
|
6
|
+
class Refs
|
7
|
+
# private
|
8
|
+
def initialize(course)
|
9
|
+
@course = course
|
10
|
+
end
|
11
|
+
|
12
|
+
def district
|
13
|
+
client.course_district(@course.id)
|
14
|
+
end
|
15
|
+
|
16
|
+
def resources(limit: nil, starting_after: nil, ending_before: nil)
|
17
|
+
client.course_resources(@course.id, limit: limit, starting_after: starting_after, ending_before: ending_before)
|
18
|
+
end
|
19
|
+
|
20
|
+
def schools(limit: nil, starting_after: nil, ending_before: nil)
|
21
|
+
client.course_schools(@course.id, limit: limit, starting_after: starting_after, ending_before: ending_before)
|
22
|
+
end
|
23
|
+
|
24
|
+
def sections(limit: nil, starting_after: nil, ending_before: nil)
|
25
|
+
client.course_sections(@course.id, limit: limit, starting_after: starting_after, ending_before: ending_before)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def client
|
31
|
+
@client ||= CleverSDK::Client.new(@course.response.access_token)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "clever_sdk/data/course/refs"
|
4
|
+
|
5
|
+
module CleverSDK
|
6
|
+
module Data
|
7
|
+
class Course
|
8
|
+
# private
|
9
|
+
attr_reader :data, :response
|
10
|
+
|
11
|
+
# private
|
12
|
+
def initialize(data, response)
|
13
|
+
@data = data
|
14
|
+
@response = response
|
15
|
+
end
|
16
|
+
|
17
|
+
def id
|
18
|
+
data.dig("id")
|
19
|
+
end
|
20
|
+
|
21
|
+
def district
|
22
|
+
data.dig("district")
|
23
|
+
end
|
24
|
+
|
25
|
+
def name
|
26
|
+
data.dig("name")
|
27
|
+
end
|
28
|
+
|
29
|
+
def number
|
30
|
+
data.dig("number")
|
31
|
+
end
|
32
|
+
|
33
|
+
def refs
|
34
|
+
@refs ||= CleverSDK::Data::Course::Refs.new(self)
|
35
|
+
end
|
36
|
+
|
37
|
+
def inspect
|
38
|
+
"#<#{self.class.name}(#{id}) #{first_name} #{last_name}>"
|
39
|
+
end
|
40
|
+
|
41
|
+
alias_method :to_h, :data
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "clever_sdk/data/course"
|
4
|
+
|
5
|
+
module CleverSDK
|
6
|
+
module Data
|
7
|
+
class Courses
|
8
|
+
include Enumerable
|
9
|
+
|
10
|
+
# private
|
11
|
+
attr_reader :response
|
12
|
+
|
13
|
+
# private
|
14
|
+
def initialize(response)
|
15
|
+
@response = response
|
16
|
+
end
|
17
|
+
|
18
|
+
def data
|
19
|
+
Array(response.body.dig("data"))
|
20
|
+
end
|
21
|
+
|
22
|
+
def each &block
|
23
|
+
return enum_for :each unless block
|
24
|
+
|
25
|
+
data
|
26
|
+
.lazy
|
27
|
+
.map { |datum| CleverSDK::Data::Course.new(datum.dig("data"), response) }
|
28
|
+
.each(&block)
|
29
|
+
end
|
30
|
+
|
31
|
+
def all &block
|
32
|
+
return enum_for :all unless block
|
33
|
+
|
34
|
+
page = self
|
35
|
+
loop do
|
36
|
+
page.each(&block)
|
37
|
+
page = page.next
|
38
|
+
break if page.nil?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def next?
|
43
|
+
link = find_link("next")
|
44
|
+
!link.nil?
|
45
|
+
end
|
46
|
+
|
47
|
+
def next
|
48
|
+
link = find_link("next")
|
49
|
+
|
50
|
+
return nil if link.nil?
|
51
|
+
|
52
|
+
self.class.new(CleverSDK::Api.new.page(path: link.dig("uri"), access_token: response.access_token))
|
53
|
+
end
|
54
|
+
|
55
|
+
def prev?
|
56
|
+
link = find_link("prev")
|
57
|
+
!link.nil?
|
58
|
+
end
|
59
|
+
|
60
|
+
def prev
|
61
|
+
link = find_link("prev")
|
62
|
+
|
63
|
+
return nil if link.nil?
|
64
|
+
|
65
|
+
self.class.new(CleverSDK::Api.new.page(path: link.dig("uri"), access_token: response.access_token))
|
66
|
+
end
|
67
|
+
|
68
|
+
def inspect
|
69
|
+
"#<#{self.class.name}:0x#{(object_id * 2).to_s(16).rjust(16, "0")} courses:#{data.count}>"
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def find_link rel
|
75
|
+
Array(response.body.dig("links")).find { |link| link.dig("rel") == rel }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CleverSDK
|
4
|
+
module Data
|
5
|
+
class District
|
6
|
+
# private
|
7
|
+
attr_reader :data, :response
|
8
|
+
|
9
|
+
# private
|
10
|
+
def initialize(data, response)
|
11
|
+
@data = data
|
12
|
+
@response = response
|
13
|
+
end
|
14
|
+
|
15
|
+
def id
|
16
|
+
data.dig("id")
|
17
|
+
end
|
18
|
+
|
19
|
+
def name
|
20
|
+
data.dig("name")
|
21
|
+
end
|
22
|
+
|
23
|
+
def mdr_number
|
24
|
+
data.dig("mdr_number")
|
25
|
+
end
|
26
|
+
|
27
|
+
def nces_id
|
28
|
+
data.dig("nces_id")
|
29
|
+
end
|
30
|
+
|
31
|
+
def sis_type
|
32
|
+
data.dig("sis_type")
|
33
|
+
end
|
34
|
+
|
35
|
+
def state
|
36
|
+
data.dig("state")
|
37
|
+
end
|
38
|
+
|
39
|
+
def last_sync
|
40
|
+
DateTime.parse(data.dig("last_sync"))
|
41
|
+
rescue
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def portal_url
|
46
|
+
data.dig("portal_url")
|
47
|
+
end
|
48
|
+
|
49
|
+
def login_methods
|
50
|
+
Array(data.dig("login_methods"))
|
51
|
+
end
|
52
|
+
|
53
|
+
def launch_date
|
54
|
+
Date.parse(data.dig("launch_date"))
|
55
|
+
rescue
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
|
59
|
+
def pause_start
|
60
|
+
Date.parse(data.dig("pause_start"))
|
61
|
+
rescue
|
62
|
+
nil
|
63
|
+
end
|
64
|
+
|
65
|
+
def pause_end
|
66
|
+
Date.parse(data.dig("pause_end"))
|
67
|
+
rescue
|
68
|
+
nil
|
69
|
+
end
|
70
|
+
|
71
|
+
def district_contact
|
72
|
+
Contact.new(data.dig("district_contact"))
|
73
|
+
end
|
74
|
+
|
75
|
+
def error
|
76
|
+
data.dig("error")
|
77
|
+
end
|
78
|
+
|
79
|
+
def inspect
|
80
|
+
"#<#{self.class.name}(#{id}) #{name}>"
|
81
|
+
end
|
82
|
+
|
83
|
+
alias_method :to_h, :data
|
84
|
+
|
85
|
+
class Contact
|
86
|
+
attr_reader :data
|
87
|
+
|
88
|
+
# private
|
89
|
+
def initialize(data)
|
90
|
+
@data = data
|
91
|
+
end
|
92
|
+
|
93
|
+
def id
|
94
|
+
data.dig("id")
|
95
|
+
end
|
96
|
+
|
97
|
+
def district_id
|
98
|
+
data.dig("district_id")
|
99
|
+
end
|
100
|
+
|
101
|
+
def first_name
|
102
|
+
data.dig("name", "first")
|
103
|
+
end
|
104
|
+
|
105
|
+
def middle_name
|
106
|
+
data.dig("name", "middle")
|
107
|
+
end
|
108
|
+
|
109
|
+
def last_name
|
110
|
+
data.dig("name", "last")
|
111
|
+
end
|
112
|
+
|
113
|
+
def email
|
114
|
+
data.dig("email")
|
115
|
+
end
|
116
|
+
|
117
|
+
def title
|
118
|
+
data.dig("title")
|
119
|
+
end
|
120
|
+
|
121
|
+
def inspect
|
122
|
+
"#<#{self.class.name}(#{id}) #{first_name} #{last_name}>"
|
123
|
+
end
|
124
|
+
|
125
|
+
alias_method :to_h, :data
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "clever_sdk/data/district"
|
4
|
+
|
5
|
+
module CleverSDK
|
6
|
+
module Data
|
7
|
+
class Districts
|
8
|
+
include Enumerable
|
9
|
+
|
10
|
+
# private
|
11
|
+
attr_reader :response
|
12
|
+
|
13
|
+
# private
|
14
|
+
def initialize(response)
|
15
|
+
@response = response
|
16
|
+
end
|
17
|
+
|
18
|
+
def data
|
19
|
+
@data ||= Array(response.body.dig("data"))
|
20
|
+
end
|
21
|
+
|
22
|
+
def each &block
|
23
|
+
return enum_for :each unless block
|
24
|
+
|
25
|
+
data
|
26
|
+
.lazy
|
27
|
+
.map { |datum| CleverSDK::Data::District.new(datum.dig("data"), response) }
|
28
|
+
.each(&block)
|
29
|
+
end
|
30
|
+
alias_method :all, :each
|
31
|
+
|
32
|
+
def inspect
|
33
|
+
"#<#{self.class.name}:0x#{(object_id * 2).to_s(16).rjust(16, "0")} districts:#{data.count}>"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "clever_sdk/data/courses"
|
4
|
+
require "clever_sdk/data/districts"
|
5
|
+
require "clever_sdk/data/schools"
|
6
|
+
require "clever_sdk/data/sections"
|
7
|
+
require "clever_sdk/data/terms"
|
8
|
+
require "clever_sdk/data/users"
|
9
|
+
|
10
|
+
module CleverSDK
|
11
|
+
module Data
|
12
|
+
class Event
|
13
|
+
# private
|
14
|
+
attr_reader :data, :response
|
15
|
+
|
16
|
+
# private
|
17
|
+
def initialize(data, response)
|
18
|
+
@data = data
|
19
|
+
@response = response
|
20
|
+
end
|
21
|
+
|
22
|
+
def id
|
23
|
+
data.dig("id")
|
24
|
+
end
|
25
|
+
|
26
|
+
def type
|
27
|
+
data.dig("type")
|
28
|
+
end
|
29
|
+
|
30
|
+
def created
|
31
|
+
DateTime.parse(data.dig("created"))
|
32
|
+
rescue
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
|
36
|
+
def object
|
37
|
+
return object_class.new(object_data, response) if object_class
|
38
|
+
|
39
|
+
object_data
|
40
|
+
end
|
41
|
+
|
42
|
+
def previous_attributes
|
43
|
+
data.dig("data", "previous_attributes")
|
44
|
+
end
|
45
|
+
|
46
|
+
def inspect
|
47
|
+
"#<#{self.class.name}(#{id}) #{type}>"
|
48
|
+
end
|
49
|
+
|
50
|
+
alias_method :to_h, :data
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def object_type
|
55
|
+
# courses
|
56
|
+
# districts
|
57
|
+
# schools
|
58
|
+
# sections
|
59
|
+
# terms
|
60
|
+
# users
|
61
|
+
type.split(".").first
|
62
|
+
end
|
63
|
+
|
64
|
+
def object_data
|
65
|
+
data.dig("data", "object")
|
66
|
+
end
|
67
|
+
|
68
|
+
def object_class
|
69
|
+
case object_type
|
70
|
+
when "courses"
|
71
|
+
CleverSDK::Data::Course
|
72
|
+
when "districts"
|
73
|
+
CleverSDK::Data::District
|
74
|
+
when "schools"
|
75
|
+
CleverSDK::Data::School
|
76
|
+
when "sections"
|
77
|
+
CleverSDK::Data::Section
|
78
|
+
when "terms"
|
79
|
+
CleverSDK::Data::Term
|
80
|
+
when "users"
|
81
|
+
CleverSDK::Data::User
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def object_action
|
86
|
+
# created
|
87
|
+
# deleted
|
88
|
+
# updated
|
89
|
+
type.split(".").last
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "clever_sdk/data/event"
|
4
|
+
|
5
|
+
module CleverSDK
|
6
|
+
module Data
|
7
|
+
class Events
|
8
|
+
include Enumerable
|
9
|
+
|
10
|
+
# private
|
11
|
+
attr_reader :response
|
12
|
+
|
13
|
+
# private
|
14
|
+
def initialize(response)
|
15
|
+
@response = response
|
16
|
+
end
|
17
|
+
|
18
|
+
def data
|
19
|
+
Array(response.body.dig("data"))
|
20
|
+
end
|
21
|
+
|
22
|
+
def each &block
|
23
|
+
return enum_for :each unless block
|
24
|
+
|
25
|
+
data
|
26
|
+
.lazy
|
27
|
+
.map { |datum| CleverSDK::Data::Event.new(datum.dig("data"), response) }
|
28
|
+
.each(&block)
|
29
|
+
end
|
30
|
+
|
31
|
+
def all &block
|
32
|
+
return enum_for :all unless block
|
33
|
+
|
34
|
+
page = self
|
35
|
+
loop do
|
36
|
+
page.each(&block)
|
37
|
+
page = page.next
|
38
|
+
break if page.nil?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def next?
|
43
|
+
link = find_link("next")
|
44
|
+
!link.nil?
|
45
|
+
end
|
46
|
+
|
47
|
+
def next
|
48
|
+
link = find_link("next")
|
49
|
+
|
50
|
+
return nil if link.nil?
|
51
|
+
|
52
|
+
self.class.new(CleverSDK::Api.new.page(path: link.dig("uri"), access_token: response.access_token))
|
53
|
+
end
|
54
|
+
|
55
|
+
def prev?
|
56
|
+
link = find_link("prev")
|
57
|
+
!link.nil?
|
58
|
+
end
|
59
|
+
|
60
|
+
def prev
|
61
|
+
link = find_link("prev")
|
62
|
+
|
63
|
+
return nil if link.nil?
|
64
|
+
|
65
|
+
self.class.new(CleverSDK::Api.new.page(path: link.dig("uri"), access_token: response.access_token))
|
66
|
+
end
|
67
|
+
|
68
|
+
def inspect
|
69
|
+
"#<#{self.class.name}:0x#{(object_id * 2).to_s(16).rjust(16, "0")} events:#{data.count}>"
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def find_link rel
|
75
|
+
Array(response.body.dig("links")).find { |link| link.dig("rel") == rel }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CleverSDK
|
4
|
+
module Data
|
5
|
+
class Me
|
6
|
+
# private
|
7
|
+
attr_reader :data, :response
|
8
|
+
|
9
|
+
# private
|
10
|
+
def initialize(data, response)
|
11
|
+
@data = data
|
12
|
+
@response = response
|
13
|
+
end
|
14
|
+
|
15
|
+
def id
|
16
|
+
data.dig("id")
|
17
|
+
end
|
18
|
+
|
19
|
+
def district
|
20
|
+
data.dig("district")
|
21
|
+
end
|
22
|
+
|
23
|
+
def type
|
24
|
+
data.dig("type")
|
25
|
+
end
|
26
|
+
|
27
|
+
def inspect
|
28
|
+
"#<#{self.class.name}(#{id}:#{type})>"
|
29
|
+
end
|
30
|
+
|
31
|
+
alias_method :to_h, :data
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|