uec_express_api 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -2
- data/README.md +8 -3
- data/lib/uec_express_api.rb +36 -25
- data/lib/uec_express_api/version.rb +1 -1
- data/spec/spec_helper.rb +7 -0
- data/spec/uec_express_api_spec.rb +73 -0
- data/test.rb +9 -2
- metadata +6 -2
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -22,10 +22,15 @@ Or install it yourself as:
|
|
22
22
|
#!/usr/bin/ruby
|
23
23
|
require 'rubygems'
|
24
24
|
require 'uec_express_api'
|
25
|
+
require 'json'
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
puts
|
27
|
+
uec_express_faculty = UECExpressApi.new() #=> Faculty of Information
|
28
|
+
uec_express_faculty.to_s
|
29
|
+
puts uec_express_faculty.to_hash.to_json
|
30
|
+
|
31
|
+
uec_express_gs = UECExpressApi.new() #=> Graduate school of Information
|
32
|
+
uec_express_gs.to_s
|
33
|
+
puts uec_express_gs.to_hash.to_json
|
29
34
|
```
|
30
35
|
|
31
36
|
##License and copyright
|
data/lib/uec_express_api.rb
CHANGED
@@ -12,30 +12,22 @@ require 'hpricot'
|
|
12
12
|
require 'json'
|
13
13
|
require 'uec_express_api/version.rb'
|
14
14
|
|
15
|
+
BASE_URL = "http://kyoumu.office.uec.ac.jp/kyuukou/"
|
16
|
+
FACULTY = "kyuukou.html" #=> Faculty of Information
|
17
|
+
GS = "kyuukou2.html" #=> Graduate school of Information
|
18
|
+
|
15
19
|
class UECExpressApi
|
16
20
|
|
17
21
|
attr_accessor :updated, :express
|
18
22
|
|
19
23
|
@@debug = false
|
20
|
-
def initialize()
|
21
|
-
|
24
|
+
def initialize(type=1)
|
22
25
|
@updated = ""
|
23
26
|
@express = Array.new
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
def to_hash
|
28
|
-
{
|
29
|
-
:express => @express,
|
30
|
-
:updated => @updated
|
31
|
-
}
|
32
|
-
end
|
33
|
-
|
34
|
-
def to_json(*args)
|
35
|
-
to_hash().to_json(*args)
|
27
|
+
parse(type)
|
36
28
|
end
|
37
29
|
|
38
|
-
def to_s
|
30
|
+
def to_s
|
39
31
|
puts "-------------------------------------------------------------"
|
40
32
|
puts "| class | data | time | subject | staff | remark |"
|
41
33
|
@express.each do |ex|
|
@@ -44,29 +36,50 @@ class UECExpressApi
|
|
44
36
|
puts "Last Updated :" + @updated
|
45
37
|
puts "-------------------------------------------------------------"
|
46
38
|
end
|
39
|
+
|
40
|
+
def create_faculty_url
|
41
|
+
BASE_URL + FACULTY
|
42
|
+
end
|
43
|
+
|
44
|
+
def create_gs_url
|
45
|
+
BASE_URL + GS
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_hash
|
49
|
+
{
|
50
|
+
:express => @express,
|
51
|
+
:updated => @updated
|
52
|
+
}
|
53
|
+
end
|
47
54
|
|
48
55
|
private
|
49
56
|
|
50
|
-
def
|
51
|
-
url=
|
57
|
+
def parse(type=1)
|
58
|
+
url = create_faculty_url
|
59
|
+
|
60
|
+
if type != 1
|
61
|
+
url = create_gs_url
|
62
|
+
end
|
63
|
+
|
52
64
|
puts "Getting URL="+url if @@debug
|
65
|
+
|
53
66
|
doc = Hpricot(open(url,'User-Agent' => 'ruby'))
|
54
|
-
|
55
|
-
|
67
|
+
parse_express(doc.root)
|
68
|
+
parse_updated(doc.root)
|
56
69
|
end
|
57
|
-
|
58
|
-
def
|
70
|
+
|
71
|
+
def parse_updated(doc)
|
59
72
|
elements = doc/:p
|
60
73
|
if elements
|
61
74
|
begin
|
62
75
|
@updated = elements.last.inner_html.to_s.encode('utf-8', 'sjis')
|
63
76
|
rescue
|
64
|
-
|
77
|
+
@updated = elements.last.inner_html.to_s
|
65
78
|
end
|
66
79
|
end
|
67
80
|
end
|
68
81
|
|
69
|
-
def
|
82
|
+
def parse_express(doc)
|
70
83
|
express_pass = [:class, :data, :time, :subject, :staff, :remark]
|
71
84
|
(doc/:tr).each_with_index do |element, i|
|
72
85
|
next if i == 0
|
@@ -83,5 +96,3 @@ class UECExpressApi
|
|
83
96
|
end
|
84
97
|
|
85
98
|
end
|
86
|
-
|
87
|
-
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# _*_ coding: utf-8 _*_
|
2
|
+
|
3
|
+
require File.expand_path(File.join('.', 'spec_helper'), File.dirname(__FILE__))
|
4
|
+
require 'uec_express_api'
|
5
|
+
|
6
|
+
describe UECExpressApi, "UEC Express Api," do
|
7
|
+
|
8
|
+
shared_examples_for "public check test" do
|
9
|
+
|
10
|
+
it "create url check" do
|
11
|
+
base_url = "http://kyoumu.office.uec.ac.jp/kyuukou/"
|
12
|
+
@uec_express.create_faculty_url.should == base_url + "kyuukou.html"
|
13
|
+
@uec_express.create_gs_url.should == base_url + "kyuukou2.html"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "check not empty for faculty(default)" do
|
17
|
+
@uec_express.updated.should_not == ""
|
18
|
+
@uec_express.express.should_not be_empty
|
19
|
+
end
|
20
|
+
|
21
|
+
it "check not empty for faculty" do
|
22
|
+
@uec_express.updated.should_not == ""
|
23
|
+
@uec_express.express.should_not be_empty
|
24
|
+
end
|
25
|
+
|
26
|
+
it "check not empty for gs" do
|
27
|
+
@uec_express.updated.should_not == ""
|
28
|
+
@uec_express.express.should_not be_empty
|
29
|
+
end
|
30
|
+
|
31
|
+
it "check hash include express and updated for faculty(default)" do
|
32
|
+
@uec_express.to_hash.should include :express
|
33
|
+
@uec_express.to_hash.should include :updated
|
34
|
+
end
|
35
|
+
|
36
|
+
it "check hash include express and updated for faculty" do
|
37
|
+
@uec_express.to_hash.should include :express
|
38
|
+
@uec_express.to_hash.should include :updated
|
39
|
+
end
|
40
|
+
|
41
|
+
it "check hash include express and updated for gs" do
|
42
|
+
@uec_express.to_hash.should include :express
|
43
|
+
@uec_express.to_hash.should include :updated
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "defalt url," do
|
48
|
+
before(:all) do
|
49
|
+
@uec_express = UECExpressApi.new()
|
50
|
+
end
|
51
|
+
|
52
|
+
it_behaves_like "public check test"
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "faculty url," do
|
57
|
+
before(:all) do
|
58
|
+
@uec_express = UECExpressApi.new(1)
|
59
|
+
end
|
60
|
+
|
61
|
+
it_behaves_like "public check test"
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "gs url," do
|
66
|
+
before(:all) do
|
67
|
+
@uec_express = UECExpressApi.new(2)
|
68
|
+
end
|
69
|
+
|
70
|
+
it_behaves_like "public check test"
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
data/test.rb
CHANGED
@@ -1,4 +1,11 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/lib/uec_express_api')
|
2
|
+
require 'json'
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
faculty = UECExpressApi.new()
|
5
|
+
gs = UECExpressApi.new(2)
|
6
|
+
|
7
|
+
faculty.to_s
|
8
|
+
gs.to_s
|
9
|
+
|
10
|
+
puts faculty.to_hash.to_json
|
11
|
+
puts gs.to_hash.to_json
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uec_express_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -58,6 +58,8 @@ files:
|
|
58
58
|
- Rakefile
|
59
59
|
- lib/uec_express_api.rb
|
60
60
|
- lib/uec_express_api/version.rb
|
61
|
+
- spec/spec_helper.rb
|
62
|
+
- spec/uec_express_api_spec.rb
|
61
63
|
- test.rb
|
62
64
|
- uec_express_api.gemspec
|
63
65
|
homepage: http://henteko07.hatenablog.com/
|
@@ -85,4 +87,6 @@ signing_key:
|
|
85
87
|
specification_version: 3
|
86
88
|
summary: API library of the University of Electro-Communications class cancellation
|
87
89
|
information.
|
88
|
-
test_files:
|
90
|
+
test_files:
|
91
|
+
- spec/spec_helper.rb
|
92
|
+
- spec/uec_express_api_spec.rb
|