manabu 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/manabu/client.rb +4 -0
- data/lib/manabu/connection/auth.rb +4 -0
- data/lib/manabu/connection/transactor.rb +11 -2
- data/lib/manabu/contact.rb +16 -0
- data/lib/manabu/contact_types.rb +26 -0
- data/lib/manabu/enrollment_status.rb +14 -0
- data/lib/manabu/enrollment_statuses.rb +21 -0
- data/lib/manabu/student.rb +40 -2
- data/lib/manabu/students.rb +10 -2
- data/manabu.gemspec +11 -10
- metadata +27 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d0d8774904775b780856094912549fe8e73842344fa9ed1abf2367eb6d3f432
|
4
|
+
data.tar.gz: 607865e224db1f430b3e317bfced10d724457ec7c0500a71ce6bf71390f7e1ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5edabccb9131aa2a723b57acb03c92268677cd62534b99cc4fc900156a92da92802c711d05bab9daf73615ac9e78b8a8d88cd37ea825e145afe4b1de09553384
|
7
|
+
data.tar.gz: 9a827582764ffc1856e251bb980bfc8a76d7c3a244f51b11e9dfd4401f3a93ef559708582d7fd5339b30c1bcc9d2a091bc8826760cee872fb43bfc2885099569
|
data/lib/manabu/client.rb
CHANGED
@@ -21,7 +21,7 @@ module Manabu
|
|
21
21
|
@status = :unknown
|
22
22
|
@force_secure_connection = force_secure_connection
|
23
23
|
@options = options
|
24
|
-
@api_version = options
|
24
|
+
@api_version = options.fetch(:api_version, 1)
|
25
25
|
connect
|
26
26
|
_check_server_status
|
27
27
|
end
|
@@ -29,6 +29,7 @@ module Manabu
|
|
29
29
|
def connect()
|
30
30
|
return @connection if @connection
|
31
31
|
@connection = Faraday.new do |conn|
|
32
|
+
conn.request :multipart
|
32
33
|
conn.request :url_encoded
|
33
34
|
|
34
35
|
case @transport_type
|
@@ -50,6 +51,10 @@ module Manabu
|
|
50
51
|
_check_server_status
|
51
52
|
end
|
52
53
|
|
54
|
+
def simple_get(endpoint)
|
55
|
+
Faraday.get("#{full_host}/api/v#{@api_version}/#{endpoint}")
|
56
|
+
end
|
57
|
+
|
53
58
|
# Gets data from the server
|
54
59
|
def get(endpoint, **args)
|
55
60
|
_define_action(:get, endpoint, args)
|
@@ -68,11 +73,15 @@ module Manabu
|
|
68
73
|
_define_action(:delete, endpoint, args)
|
69
74
|
end
|
70
75
|
|
76
|
+
def full_host
|
77
|
+
"#{@protocol}://#{@server_url}:#{@server_port}"
|
78
|
+
end
|
79
|
+
|
71
80
|
def _define_action(action, endpoint, args)
|
72
81
|
response = connect.send(
|
73
82
|
action,
|
74
83
|
URI.encode(
|
75
|
-
"#{
|
84
|
+
"#{full_host}/api/v#{@api_version}/#{endpoint}"),
|
76
85
|
args,
|
77
86
|
_header_hash
|
78
87
|
)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative './resource'
|
2
|
+
|
3
|
+
module Manabu
|
4
|
+
class Contact < Resource
|
5
|
+
attr_accessor :id, :data, :contact_type_id
|
6
|
+
|
7
|
+
def fill(**info)
|
8
|
+
@id = info.fetch(:id, @id)
|
9
|
+
@data = info.fetch(:data, @data)
|
10
|
+
@contact_type_id = info.fetch(:contact_type_id, @contact_type_id)
|
11
|
+
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Manabu
|
2
|
+
class ContactTypes
|
3
|
+
attr_accessor :client
|
4
|
+
|
5
|
+
def initialize(client)
|
6
|
+
@client = client
|
7
|
+
@contact_types = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def register(name)
|
11
|
+
response = @client.post("/contact_types", name: name)
|
12
|
+
response[:id]
|
13
|
+
rescue
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def all
|
18
|
+
return @contact_types unless @contact_types.empty?
|
19
|
+
|
20
|
+
response = @client.get("/contact_types")
|
21
|
+
@contact_types = response[:contact_types].each_with_object({}) do |type, obj|
|
22
|
+
obj[type[:name]] = type[:id]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Manabu
|
2
|
+
class EnrollmentStatus < Resource
|
3
|
+
attr_reader :id, :active, :code, :immutable
|
4
|
+
|
5
|
+
def fill(**info)
|
6
|
+
@id = info.fetch(:id, @id)
|
7
|
+
@code = info.fetch(:code, @code)
|
8
|
+
@active = info.fetch(:active, @active)
|
9
|
+
@immutable = info.fetch(:immutable, @immutable)
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative 'enrollment_status'
|
2
|
+
module Manabu
|
3
|
+
class EnrollmentStatuses
|
4
|
+
attr_accessor :client
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
@enrollment_statuses = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def all
|
12
|
+
return @enrollment_statuses unless @enrollment_statuses.empty?
|
13
|
+
|
14
|
+
response = @client.get("/enrollment_statuses")
|
15
|
+
|
16
|
+
@enrollment_statuses = response.map do |enrollment_status|
|
17
|
+
Manabu::EnrollmentStatus.new(@client, enrollment_status)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/manabu/student.rb
CHANGED
@@ -1,11 +1,22 @@
|
|
1
|
+
require 'filemagic'
|
1
2
|
require_relative './resource'
|
2
3
|
require_relative './guardian'
|
4
|
+
require_relative './enrollment_status'
|
5
|
+
require_relative './contact'
|
3
6
|
|
4
7
|
module Manabu
|
5
8
|
class Student < Resource
|
6
9
|
class GuardianNotAdded < StandardError; end
|
10
|
+
class ContactNotAdded < StandardError; end
|
7
11
|
attr_accessor :id, :surname, :name, :name_reading,
|
8
|
-
:surname_reading, :
|
12
|
+
:surname_reading, :middle_name,
|
13
|
+
:middle_name_reading,:birth_date, :gender, :enrollment_status
|
14
|
+
|
15
|
+
def initialize(client, **info)
|
16
|
+
super
|
17
|
+
@contacts = []
|
18
|
+
@picture = nil
|
19
|
+
end
|
9
20
|
|
10
21
|
def fill(**info)
|
11
22
|
@id = info.fetch(:id, @id)
|
@@ -15,15 +26,31 @@ module Manabu
|
|
15
26
|
@surname_reading = info.fetch(:surname_reading, @surname_reading)
|
16
27
|
@birth_date = info.fetch(:birth_date, @birth_date)
|
17
28
|
@gender = info.fetch(:gender, @gender)
|
18
|
-
|
29
|
+
@enrollment_status = Manabu::EnrollmentStatus.new(@client, info[:enrollment_status] || {})
|
19
30
|
self
|
20
31
|
end
|
21
32
|
|
33
|
+
def picture
|
34
|
+
return unless @id
|
35
|
+
return @picture if @picture
|
36
|
+
|
37
|
+
response = @client.simple_get("students/#{id}/picture")
|
38
|
+
@picture = response.body
|
39
|
+
end
|
40
|
+
|
22
41
|
def set(**info)
|
23
42
|
response = @client.patch("students/#{@id}", info)
|
24
43
|
fill(response)
|
25
44
|
end
|
26
45
|
|
46
|
+
def add_picture(path)
|
47
|
+
file = Faraday::UploadIO.new(path, FileMagic.new(FileMagic::MAGIC_MIME).file(path))
|
48
|
+
|
49
|
+
response = @client.patch("students/#{@id}", picture: file)
|
50
|
+
@picture = nil
|
51
|
+
fill(response)
|
52
|
+
end
|
53
|
+
|
27
54
|
def add_guardian(guardian)
|
28
55
|
# NOTE: detect when guardian is already added to student
|
29
56
|
response = @client.post("students/#{id}/student_guardians", guardian_id: guardian.id)
|
@@ -32,6 +59,17 @@ module Manabu
|
|
32
59
|
raise GuardianNotAdded, 'Guardian is not added to student'
|
33
60
|
end
|
34
61
|
|
62
|
+
def add_contact(contact_type_id, data)
|
63
|
+
response = @client.post("students/#{id}/contacts",
|
64
|
+
contact_type_id: contact_type_id,
|
65
|
+
data: data
|
66
|
+
)
|
67
|
+
@contacts.push Contact.new(@client, response)
|
68
|
+
self
|
69
|
+
# rescue StandardError
|
70
|
+
# raise ContactNotAdded, 'Contact is not added to student'
|
71
|
+
end
|
72
|
+
|
35
73
|
def guardians
|
36
74
|
response = @client.get("students/#{id}/guardians")
|
37
75
|
response[:guardians].map do |guardian|
|
data/lib/manabu/students.rb
CHANGED
@@ -34,6 +34,14 @@ module Manabu
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
def filter(attrs = {})
|
38
|
+
result = students.dup
|
39
|
+
if attrs.has_key?(:enrollment_status)
|
40
|
+
result.select! { |student| student.enrollment_status&.code == attrs[:enrollment_status] }
|
41
|
+
end
|
42
|
+
result
|
43
|
+
end
|
44
|
+
|
37
45
|
def register(student)
|
38
46
|
new_student = case student
|
39
47
|
when Manabu::Student
|
@@ -73,8 +81,8 @@ module Manabu
|
|
73
81
|
end
|
74
82
|
end
|
75
83
|
|
76
|
-
def whitelist_filter_attributes
|
77
|
-
[:name, :surname]
|
84
|
+
def whitelist_filter_attributes
|
85
|
+
[:id, :name, :surname]
|
78
86
|
end
|
79
87
|
|
80
88
|
def _fetch_students()
|
data/manabu.gemspec
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'manabu'
|
3
|
-
s.version = '0.0.
|
3
|
+
s.version = '0.0.4'
|
4
4
|
s.licenses = ['AGPL-3.0', 'GPL-3.0']
|
5
5
|
s.summary = 'API client for GAKU Engine'
|
6
6
|
s.description = 'Manabu is an API client module used to access the GAKU Engine API'
|
7
7
|
s.post_install_message = \
|
8
|
-
|
9
|
-
"║Manabu API Client for ⚙学 GAKU Engine [学エンジン] " +
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
"╔═════════════════════════╼\n" +
|
9
|
+
"║Manabu API Client for ⚙学 GAKU Engine [学エンジン] \n" +
|
10
|
+
"╟─────────────────────────╼\n" +
|
11
|
+
"║©2015 (株)幻創社 [Phantom Creation Inc.]\n" +
|
12
|
+
"║http://www.gakuengine.com\n" +
|
13
|
+
"╟─────────────────────────╼\n" +
|
14
|
+
"║Manabu is Open Sourced under the AGPLv3/GPLv3.\n" +
|
15
|
+
"╚═════════════════════════╼\n"
|
16
16
|
s.authors = ['Rei Kagetsuki']
|
17
17
|
s.email = 'info@gakuengine.com'
|
18
18
|
s.homepage = 'http://www.gakuengine.com'
|
@@ -25,5 +25,6 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.add_dependency 'faraday_middleware', '~> 0.12', '~> 0.12.2'
|
26
26
|
s.add_dependency 'typhoeus', '~> 1.3', '~> 1.3.0'
|
27
27
|
s.add_dependency 'msgpack', '~> 1.2', '~> 1.2.2'
|
28
|
-
s.
|
28
|
+
s.add_dependency 'ruby-filemagic'
|
29
|
+
s.add_development_dependency 'gaku', '~> 0.3', '~> 0.3.0'
|
29
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: manabu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rei Kagetsuki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -90,26 +90,40 @@ dependencies:
|
|
90
90
|
- - "~>"
|
91
91
|
- !ruby/object:Gem::Version
|
92
92
|
version: 1.2.2
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: ruby-filemagic
|
95
|
+
requirement: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
type: :runtime
|
101
|
+
prerelease: false
|
102
|
+
version_requirements: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
93
107
|
- !ruby/object:Gem::Dependency
|
94
108
|
name: gaku
|
95
109
|
requirement: !ruby/object:Gem::Requirement
|
96
110
|
requirements:
|
97
111
|
- - "~>"
|
98
112
|
- !ruby/object:Gem::Version
|
99
|
-
version: 0.3
|
113
|
+
version: '0.3'
|
100
114
|
- - "~>"
|
101
115
|
- !ruby/object:Gem::Version
|
102
|
-
version: 0.3.0
|
116
|
+
version: 0.3.0
|
103
117
|
type: :development
|
104
118
|
prerelease: false
|
105
119
|
version_requirements: !ruby/object:Gem::Requirement
|
106
120
|
requirements:
|
107
121
|
- - "~>"
|
108
122
|
- !ruby/object:Gem::Version
|
109
|
-
version: 0.3
|
123
|
+
version: '0.3'
|
110
124
|
- - "~>"
|
111
125
|
- !ruby/object:Gem::Version
|
112
|
-
version: 0.3.0
|
126
|
+
version: 0.3.0
|
113
127
|
description: Manabu is an API client module used to access the GAKU Engine API
|
114
128
|
email: info@gakuengine.com
|
115
129
|
executables: []
|
@@ -123,8 +137,12 @@ files:
|
|
123
137
|
- lib/manabu/connection/auth.rb
|
124
138
|
- lib/manabu/connection/error.rb
|
125
139
|
- lib/manabu/connection/transactor.rb
|
140
|
+
- lib/manabu/contact.rb
|
141
|
+
- lib/manabu/contact_types.rb
|
126
142
|
- lib/manabu/course.rb
|
127
143
|
- lib/manabu/courses.rb
|
144
|
+
- lib/manabu/enrollment_status.rb
|
145
|
+
- lib/manabu/enrollment_statuses.rb
|
128
146
|
- lib/manabu/guardian.rb
|
129
147
|
- lib/manabu/resource.rb
|
130
148
|
- lib/manabu/student.rb
|
@@ -136,9 +154,9 @@ licenses:
|
|
136
154
|
- AGPL-3.0
|
137
155
|
- GPL-3.0
|
138
156
|
metadata: {}
|
139
|
-
post_install_message: "
|
140
|
-
[学エンジン]
|
141
|
-
is Open Sourced under the AGPLv3/GPLv3
|
157
|
+
post_install_message: "╔═════════════════════════╼\n║Manabu API Client for ⚙学 GAKU
|
158
|
+
Engine [学エンジン] \n╟─────────────────────────╼\n║©2015 (株)幻創社 [Phantom Creation Inc.]\n║http://www.gakuengine.com\n╟─────────────────────────╼\n║Manabu
|
159
|
+
is Open Sourced under the AGPLv3/GPLv3.\n╚═════════════════════════╼\n"
|
142
160
|
rdoc_options: []
|
143
161
|
require_paths:
|
144
162
|
- lib
|