kuport 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -2
- data/lib/kuport/version.rb +1 -1
- data/lib/kuport.rb +14 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d557006f0d56c89fbdb480e83b49968de1de417f
|
4
|
+
data.tar.gz: '08482c0c932d94505bead4d9b09c9de7601f4846'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ddcf75d7351972b180c9920de29806789d3477a0480cc92b22f88d2e9c6eced5aa68b83f0c6c680c6191a4b7a0a43679ebb81a3f3c07fa65bd6f14413b71c12
|
7
|
+
data.tar.gz: 4990062b8f8a42db7d9e35189f11c308b166497db76bf2ea239889f7ac0696c01c679f830b0ded5f59e7b12ce7a66e5f81da923d3edd81d691f420c3ab461738
|
data/README.md
CHANGED
@@ -60,8 +60,16 @@ require 'kuport'
|
|
60
60
|
kp = Kuport.new
|
61
61
|
kp.login('jx91234')
|
62
62
|
|
63
|
-
messages = kp.messages
|
64
|
-
timetable = kp.
|
63
|
+
messages = kp.messages
|
64
|
+
timetable = kp.timetable
|
65
|
+
|
66
|
+
m = messages[0]
|
67
|
+
puts m.title, m.body, m.links
|
68
|
+
puts m.json
|
69
|
+
puts messages.to_json
|
70
|
+
|
71
|
+
timetable.compact
|
72
|
+
puts timetable.to_json
|
65
73
|
|
66
74
|
kp.download(url, name)
|
67
75
|
kp.download([{name: 'File.pdf', path: 'https://example.com/file.pdf'}, ])
|
data/lib/kuport/version.rb
CHANGED
data/lib/kuport.rb
CHANGED
@@ -13,6 +13,8 @@ require 'kuport/helper'
|
|
13
13
|
class Kuport
|
14
14
|
extend Kuport::Helper
|
15
15
|
|
16
|
+
class DownloadError < StandardError; end
|
17
|
+
|
16
18
|
# Need last slash in url
|
17
19
|
@@base_url = 'https://kuport.sc.kogakuin.ac.jp/ActiveCampus/'.freeze
|
18
20
|
@@base_module = 'module/'.freeze
|
@@ -88,15 +90,16 @@ class Kuport
|
|
88
90
|
end
|
89
91
|
|
90
92
|
def login(id)
|
91
|
-
return if login_cookie
|
93
|
+
return true if login_cookie
|
92
94
|
Kuport.quit('Please student id', 4) if Kuport.blank?(id)
|
93
95
|
|
94
96
|
3.times do
|
95
|
-
return if login_passwd(id, Kuport.input_passwd)
|
97
|
+
return true if login_passwd(id, Kuport.input_passwd)
|
96
98
|
warn 'Login failed'
|
97
99
|
end
|
98
100
|
|
99
|
-
|
101
|
+
warn 'Login error'
|
102
|
+
return false
|
100
103
|
end
|
101
104
|
|
102
105
|
def messages
|
@@ -108,7 +111,7 @@ class Kuport
|
|
108
111
|
end
|
109
112
|
|
110
113
|
def messages_backno
|
111
|
-
# TODO
|
114
|
+
raise NotImplementedError.new('Kuport#messages_backno') # TODO
|
112
115
|
end
|
113
116
|
|
114
117
|
def timetable
|
@@ -116,11 +119,13 @@ class Kuport
|
|
116
119
|
end
|
117
120
|
|
118
121
|
def materials
|
119
|
-
# TODO
|
122
|
+
raise NotImplementedError.new('Kuport#materials') # TODO
|
120
123
|
end
|
121
124
|
|
122
125
|
def download_file(file_path, url)
|
123
126
|
File.write(file_path, agent.get(url).content)
|
127
|
+
rescue
|
128
|
+
DownloadError.new(file_path)
|
124
129
|
end
|
125
130
|
|
126
131
|
# url_or_json is "http://....", {name:, path:}, or [{name:, path:}, ...]
|
@@ -131,13 +136,15 @@ class Kuport
|
|
131
136
|
return
|
132
137
|
end
|
133
138
|
|
134
|
-
json = JSON.parse(url_or_json, {symbolize_names: true})
|
135
|
-
|
139
|
+
json = JSON.parse(url_or_json, {symbolize_names: true})
|
136
140
|
if Array === json
|
137
141
|
json.each{|link| download_file(link[:name], link[:path])}
|
138
142
|
else
|
139
143
|
download_file(json[:name], json[:path])
|
140
144
|
end
|
145
|
+
|
146
|
+
rescue JSON::ParserError
|
147
|
+
raise DownloadError.new("JSON parse error '#{url_or_json}'")
|
141
148
|
end
|
142
149
|
|
143
150
|
# html parser for Mechanize. force encode to UTF-8
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kuport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- u+
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|