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,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CleverSDK
|
4
|
+
module Data
|
5
|
+
class Term
|
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 name
|
24
|
+
data.dig("name")
|
25
|
+
end
|
26
|
+
|
27
|
+
def start_date
|
28
|
+
Date.parse(data.dig("start_date"))
|
29
|
+
rescue
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def end_date
|
34
|
+
Date.parse(data.dig("end_date"))
|
35
|
+
rescue
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
|
39
|
+
def inspect
|
40
|
+
"#<#{self.class.name}(#{id}) #{name}>"
|
41
|
+
end
|
42
|
+
|
43
|
+
alias_method :to_h, :data
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "clever_sdk/data/term"
|
4
|
+
|
5
|
+
module CleverSDK
|
6
|
+
module Data
|
7
|
+
class Terms
|
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::Term.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")} terms:#{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,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CleverSDK
|
4
|
+
module Data
|
5
|
+
class Token
|
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 created
|
20
|
+
DateTime.parse(data.dig("created"))
|
21
|
+
rescue
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def owner_id
|
26
|
+
data.dig("owner", "id")
|
27
|
+
end
|
28
|
+
|
29
|
+
def owner_type
|
30
|
+
data.dig("owner", "type")
|
31
|
+
end
|
32
|
+
|
33
|
+
def access_token
|
34
|
+
data.dig("access_token")
|
35
|
+
end
|
36
|
+
|
37
|
+
def scopes
|
38
|
+
data.dig("scopes")
|
39
|
+
end
|
40
|
+
|
41
|
+
def inspect
|
42
|
+
"#<#{self.class.name}(#{id}) #{access_token}>"
|
43
|
+
end
|
44
|
+
|
45
|
+
alias_method :to_h, :data
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# example response
|
51
|
+
# {
|
52
|
+
# "id"=>"63e673d9d016950008e5b5b2",
|
53
|
+
# "created"=>"2023-02-10T16:42:01.701Z",
|
54
|
+
# "owner"=>{"type"=>"district", "id"=>"63e673d91c05c2527736ba41"},
|
55
|
+
# "access_token"=>"TEST_TOKEN",
|
56
|
+
# "scopes"=>
|
57
|
+
# ["read:district_admins",
|
58
|
+
# "read:districts",
|
59
|
+
# "read:resources",
|
60
|
+
# "read:school_admins",
|
61
|
+
# "read:schools",
|
62
|
+
# "read:sections",
|
63
|
+
# "read:student_contacts",
|
64
|
+
# "read:students",
|
65
|
+
# "read:teachers",
|
66
|
+
# "read:user_id"]
|
67
|
+
# }
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CleverSDK
|
4
|
+
module Data
|
5
|
+
class Tokeninfo
|
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 client_id
|
16
|
+
data.dig("client_id")
|
17
|
+
end
|
18
|
+
|
19
|
+
def scopes
|
20
|
+
data.dig("scopes")
|
21
|
+
end
|
22
|
+
|
23
|
+
def inspect
|
24
|
+
"#<#{self.class.name}(#{client_id}) #{access_token}>"
|
25
|
+
end
|
26
|
+
|
27
|
+
alias_method :to_h, :data
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "clever_sdk/data/token"
|
4
|
+
|
5
|
+
module CleverSDK
|
6
|
+
module Data
|
7
|
+
class Tokens
|
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
|
+
tokens = Array(data).lazy.map { |datum| CleverSDK::Data::Token.new(datum, response) }
|
26
|
+
tokens.each(&block)
|
27
|
+
end
|
28
|
+
alias_method :all, :each
|
29
|
+
|
30
|
+
def inspect
|
31
|
+
"#<#{self.class.name}:0x#{(object_id * 2).to_s(16).rjust(16, "0")} tokens:#{data.count}>"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CleverSDK
|
4
|
+
module Data
|
5
|
+
class User
|
6
|
+
class ContactRole
|
7
|
+
# private
|
8
|
+
def initialize(user)
|
9
|
+
@user = user
|
10
|
+
@role = @user.roles.dig("contact")
|
11
|
+
end
|
12
|
+
|
13
|
+
def legacy_id
|
14
|
+
@role.dig("legacy_id")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CleverSDK
|
4
|
+
module Data
|
5
|
+
class User
|
6
|
+
class DistrictAdminRole
|
7
|
+
# private
|
8
|
+
def initialize(user)
|
9
|
+
@user = user
|
10
|
+
@role = @user.roles.dig("district_admin")
|
11
|
+
end
|
12
|
+
|
13
|
+
def legacy_id
|
14
|
+
@role.dig("legacy_id")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CleverSDK
|
4
|
+
module Data
|
5
|
+
class User
|
6
|
+
class Refs
|
7
|
+
# private
|
8
|
+
def initialize(user)
|
9
|
+
@user = user
|
10
|
+
end
|
11
|
+
|
12
|
+
def district
|
13
|
+
client.user_district(@user.id)
|
14
|
+
end
|
15
|
+
|
16
|
+
def resources(limit: nil, starting_after: nil, ending_before: nil)
|
17
|
+
client.user_resources(@user.id, limit: limit, starting_after: starting_after, ending_before: ending_before)
|
18
|
+
end
|
19
|
+
|
20
|
+
# primary - acceptable values are nil, true
|
21
|
+
def schools(primary: nil, limit: nil, starting_after: nil, ending_before: nil)
|
22
|
+
client.user_schools(@user.id, primary: primary,
|
23
|
+
limit: limit, starting_after: starting_after, ending_before: ending_before)
|
24
|
+
end
|
25
|
+
|
26
|
+
def sections(limit: nil, starting_after: nil, ending_before: nil)
|
27
|
+
client.user_sections(@user.id, limit: limit, starting_after: starting_after, ending_before: ending_before)
|
28
|
+
end
|
29
|
+
|
30
|
+
def mycontacts(limit: nil, starting_after: nil, ending_before: nil)
|
31
|
+
return unless @user.student?
|
32
|
+
|
33
|
+
client.user_mycontacts(@user.id, limit: limit, starting_after: starting_after, ending_before: ending_before)
|
34
|
+
end
|
35
|
+
|
36
|
+
def mystudents(limit: nil, starting_after: nil, ending_before: nil)
|
37
|
+
return unless @user.teacher?
|
38
|
+
|
39
|
+
client.user_mystudents(@user.id, limit: limit, starting_after: starting_after, ending_before: ending_before)
|
40
|
+
end
|
41
|
+
|
42
|
+
def myteachers(limit: nil, starting_after: nil, ending_before: nil)
|
43
|
+
return unless @user.student?
|
44
|
+
|
45
|
+
client.user_myteachers(@user.id, limit: limit, starting_after: starting_after, ending_before: ending_before)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def client
|
51
|
+
@client ||= CleverSDK::Client.new(@user.response.access_token)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CleverSDK
|
4
|
+
module Data
|
5
|
+
class User
|
6
|
+
class StaffRole
|
7
|
+
# private
|
8
|
+
def initialize(user)
|
9
|
+
@user = user
|
10
|
+
@role = @user.roles.dig("staff")
|
11
|
+
end
|
12
|
+
|
13
|
+
def legacy_id
|
14
|
+
@role.dig("legacy_id")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CleverSDK
|
4
|
+
module Data
|
5
|
+
class User
|
6
|
+
class StudentRole
|
7
|
+
# private
|
8
|
+
def initialize(user)
|
9
|
+
@user = user
|
10
|
+
@role = @user.roles.dig("student")
|
11
|
+
end
|
12
|
+
|
13
|
+
def sis_id
|
14
|
+
@role.dig("sis_id")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CleverSDK
|
4
|
+
module Data
|
5
|
+
class User
|
6
|
+
class TeacherRole
|
7
|
+
# private
|
8
|
+
def initialize(user)
|
9
|
+
@user = user
|
10
|
+
@role = @user.roles.dig("teacher")
|
11
|
+
end
|
12
|
+
|
13
|
+
def legacy_id
|
14
|
+
@role.dig("legacy_id")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "clever_sdk/data/user/contact_role"
|
4
|
+
require "clever_sdk/data/user/district_admin_role"
|
5
|
+
require "clever_sdk/data/user/staff_role"
|
6
|
+
require "clever_sdk/data/user/student_role"
|
7
|
+
require "clever_sdk/data/user/teacher_role"
|
8
|
+
require "clever_sdk/data/user/refs"
|
9
|
+
|
10
|
+
module CleverSDK
|
11
|
+
module Data
|
12
|
+
class User
|
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 district
|
27
|
+
data.dig("district")
|
28
|
+
end
|
29
|
+
|
30
|
+
def first_name
|
31
|
+
data.dig("name", "first")
|
32
|
+
end
|
33
|
+
|
34
|
+
def middle_name
|
35
|
+
data.dig("name", "middle")
|
36
|
+
end
|
37
|
+
|
38
|
+
def last_name
|
39
|
+
data.dig("name", "last")
|
40
|
+
end
|
41
|
+
|
42
|
+
def email
|
43
|
+
data.dig("email")
|
44
|
+
end
|
45
|
+
|
46
|
+
def roles
|
47
|
+
data.dig("roles")
|
48
|
+
end
|
49
|
+
|
50
|
+
def created
|
51
|
+
DateTime.parse(data.dig("created"))
|
52
|
+
rescue
|
53
|
+
nil
|
54
|
+
end
|
55
|
+
|
56
|
+
def last_modified
|
57
|
+
DateTime.parse(data.dig("last_modified"))
|
58
|
+
rescue
|
59
|
+
nil
|
60
|
+
end
|
61
|
+
|
62
|
+
def contact?
|
63
|
+
!roles.dig("contact").nil?
|
64
|
+
end
|
65
|
+
|
66
|
+
def contact
|
67
|
+
return unless contact?
|
68
|
+
|
69
|
+
@contact ||= CleverSDK::Data::User::ContactRole.new(self)
|
70
|
+
end
|
71
|
+
|
72
|
+
def district_admin?
|
73
|
+
!roles.dig("district_admin").nil?
|
74
|
+
end
|
75
|
+
|
76
|
+
def district_admin
|
77
|
+
return unless district_admin?
|
78
|
+
|
79
|
+
@district_admin ||= CleverSDK::Data::User::DistrictAdminRole.new(self)
|
80
|
+
end
|
81
|
+
|
82
|
+
def staff?
|
83
|
+
!roles.dig("staff").nil?
|
84
|
+
end
|
85
|
+
|
86
|
+
def staff
|
87
|
+
return unless staff?
|
88
|
+
|
89
|
+
@staff ||= CleverSDK::Data::User::StaffRole.new(self)
|
90
|
+
end
|
91
|
+
|
92
|
+
def teacher?
|
93
|
+
!roles.dig("teacher").nil?
|
94
|
+
end
|
95
|
+
|
96
|
+
def teacher
|
97
|
+
return unless teacher?
|
98
|
+
|
99
|
+
@teacher ||= CleverSDK::Data::User::TeacherRole.new(self)
|
100
|
+
end
|
101
|
+
|
102
|
+
def student?
|
103
|
+
!roles.dig("student").nil?
|
104
|
+
end
|
105
|
+
|
106
|
+
def student
|
107
|
+
return unless student?
|
108
|
+
|
109
|
+
@student ||= CleverSDK::Data::User::StudentRole.new(self)
|
110
|
+
end
|
111
|
+
|
112
|
+
def refs
|
113
|
+
@refs ||= CleverSDK::Data::User::Refs.new(self)
|
114
|
+
end
|
115
|
+
|
116
|
+
def inspect
|
117
|
+
"#<#{self.class.name}(#{id}) #{first_name} #{last_name}>"
|
118
|
+
end
|
119
|
+
|
120
|
+
alias_method :to_h, :data
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "clever_sdk/data/user"
|
4
|
+
|
5
|
+
module CleverSDK
|
6
|
+
module Data
|
7
|
+
class Users
|
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::User.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")} users:#{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,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CleverSDK
|
4
|
+
class Error < StandardError
|
5
|
+
def self.handle(typhoeus_response)
|
6
|
+
explanation = CleverSDK::Api::Response.status_code_explanations[typhoeus_response.code]
|
7
|
+
|
8
|
+
error_obj = if explanation.nil?
|
9
|
+
new
|
10
|
+
else
|
11
|
+
new([explanation[:meaning], explanation[:action_to_take]].join(": "))
|
12
|
+
end
|
13
|
+
|
14
|
+
error_obj.response = typhoeus_response
|
15
|
+
error_obj.code = typhoeus_response.code
|
16
|
+
error_obj.meaning = explanation[:meaning] if explanation
|
17
|
+
error_obj.action_to_take = explanation[:action_to_take] if explanation
|
18
|
+
error_obj
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_accessor :response, :code, :meaning, :action_to_take
|
22
|
+
|
23
|
+
def intitialize(message = "Unknown API error")
|
24
|
+
super(message)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/clever_sdk.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "typhoeus"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
require "clever_sdk/configuration"
|
7
|
+
require "clever_sdk/error"
|
8
|
+
require "clever_sdk/authentication"
|
9
|
+
require "clever_sdk/client"
|
10
|
+
require "clever_sdk/version"
|
11
|
+
|
12
|
+
module CleverSDK
|
13
|
+
class << self
|
14
|
+
attr_writer :configuration
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.configure
|
18
|
+
yield(configuration)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.configuration
|
22
|
+
@configuration ||= CleverSDK::Configuration.new
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.authentication(configuration = CleverSDK.configuration)
|
26
|
+
yield configuration if block_given?
|
27
|
+
|
28
|
+
CleverSDK::Authentication.new(configuration)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.client(access_token, configuration = CleverSDK.configuration)
|
32
|
+
yield configuration if block_given?
|
33
|
+
|
34
|
+
CleverSDK::Client.new(access_token, configuration)
|
35
|
+
end
|
36
|
+
end
|