syoboi_calendar 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/LICENSE +1 -1
- data/README.md +109 -775
- data/lib/syoboi_calendar/client.rb +39 -24
- data/lib/syoboi_calendar/queries/{channel_group_query.rb → list_channel_groups_query.rb} +1 -1
- data/lib/syoboi_calendar/queries/{channel_query.rb → list_channels_query.rb} +1 -1
- data/lib/syoboi_calendar/queries/{program_query.rb → list_programs_query.rb} +1 -1
- data/lib/syoboi_calendar/queries/{title_query.rb → list_titles_query.rb} +1 -1
- data/lib/syoboi_calendar/resources/base_resource.rb +2 -0
- data/lib/syoboi_calendar/resources/program_resource.rb +2 -0
- data/lib/syoboi_calendar/responses/base_response.rb +93 -0
- data/lib/syoboi_calendar/{response_parsers/channel_groups_response_parser.rb → responses/list_channel_groups_response.rb} +8 -3
- data/lib/syoboi_calendar/{response_parsers/channels_response_parser.rb → responses/list_channels_response.rb} +8 -3
- data/lib/syoboi_calendar/{response_parsers/programs_response_parser.rb → responses/list_programs_response.rb} +8 -3
- data/lib/syoboi_calendar/{response_parsers/titles_response_parser.rb → responses/list_titles_response.rb} +8 -3
- data/lib/syoboi_calendar/version.rb +1 -1
- data/lib/syoboi_calendar.rb +9 -14
- data/spec/spec_helper.rb +0 -1
- data/spec/syoboi_calendar/client_spec.rb +119 -143
- data/syoboi_calendar.gemspec +0 -1
- metadata +11 -26
- data/lib/syoboi_calendar/response.rb +0 -49
- data/lib/syoboi_calendar/response_parsers/base_response_parser.rb +0 -52
@@ -3,150 +3,33 @@ describe ::SyoboiCalendar::Client do
|
|
3
3
|
described_class.new
|
4
4
|
end
|
5
5
|
|
6
|
-
let(:dummy_channel_groups_response) do
|
7
|
-
<<-EOS.strip_heredoc
|
8
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
9
|
-
<ChGroupLookupResponse>
|
10
|
-
<Result>
|
11
|
-
<Code>200</Code>
|
12
|
-
<Message>
|
13
|
-
</Message>
|
14
|
-
</Result>
|
15
|
-
<ChGroupItems>
|
16
|
-
<ChGroupItem id="3">
|
17
|
-
<ChGroupComment>DummyComment</ChGroupComment>
|
18
|
-
<ChGID>1</ChGID>
|
19
|
-
<ChGroupName>DummyChannelName</ChGroupName>
|
20
|
-
<Order>1000</Order>
|
21
|
-
<LastUpdate>2000-01-01 00:00:00</LastUpdate>
|
22
|
-
</ChGroupItem>
|
23
|
-
</ChGroupItems>
|
24
|
-
</ChGroupLookupResponse>
|
25
|
-
EOS
|
26
|
-
end
|
27
|
-
|
28
|
-
let(:dummy_channels_response) do
|
29
|
-
<<-EOS.strip_heredoc
|
30
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
31
|
-
<ChLookupResponse>
|
32
|
-
<Result>
|
33
|
-
<Code>200</Code>
|
34
|
-
<Message>
|
35
|
-
</Message>
|
36
|
-
</Result>
|
37
|
-
<ChItems>
|
38
|
-
<ChItem id="3">
|
39
|
-
<ChComment>DummyComment</ChComment>
|
40
|
-
<ChEPGURL>http://example.com/epg-url</ChEPGURL>
|
41
|
-
<ChGID>1</ChGID>
|
42
|
-
<ChID>3</ChID>
|
43
|
-
<ChName>DummyChannelName</ChName>
|
44
|
-
<ChNumber>3</ChNumber>
|
45
|
-
<ChURL>http://example.com/</ChURL>
|
46
|
-
<ChiEPGName>DummyiEPGName</ChiEPGName>
|
47
|
-
<LastUpdate>2000-01-01 00:00:00</LastUpdate>
|
48
|
-
</ChItem>
|
49
|
-
</ChItems>
|
50
|
-
</ChLookupResponse>
|
51
|
-
EOS
|
52
|
-
end
|
53
|
-
|
54
|
-
let(:dummy_programs_response) do
|
55
|
-
<<-EOS.strip_heredoc
|
56
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
57
|
-
<ProgLookupResponse>
|
58
|
-
<ProgItems>
|
59
|
-
<ProgItem id="1">
|
60
|
-
<ChID>3</ChID>
|
61
|
-
<Count>1</Count>
|
62
|
-
<Deleted>0</Deleted>
|
63
|
-
<EdTime>2000-01-01 00:00:00</EdTime>
|
64
|
-
<Flag>9</Flag>
|
65
|
-
<LastUpdate>2000-01-01 00:00:00</LastUpdate>
|
66
|
-
<PID>1</PID>
|
67
|
-
<ProgComment>DummyComment</ProgComment>
|
68
|
-
<Revision>2</Revision>
|
69
|
-
<STSubTitle>DummySubTitle</STSubTitle>
|
70
|
-
<StOffset>0</StOffset>
|
71
|
-
<StTime>2000-01-01 00:00:00</StTime>
|
72
|
-
<SubTitle></SubTitle>
|
73
|
-
<TID>2</TID>
|
74
|
-
<Warn>1</Warn>
|
75
|
-
</ProgItem>
|
76
|
-
</ProgItems>
|
77
|
-
<Result>
|
78
|
-
<Code>200</Code>
|
79
|
-
<Message>
|
80
|
-
</Message>
|
81
|
-
</Result>
|
82
|
-
</ProgLookupResponse>
|
83
|
-
EOS
|
84
|
-
end
|
85
|
-
|
86
|
-
let(:dummy_titles_response) do
|
87
|
-
<<-EOS.strip_heredoc
|
88
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
89
|
-
<TitleLookupResponse>
|
90
|
-
<Result>
|
91
|
-
<Code>200</Code>
|
92
|
-
<Message>
|
93
|
-
</Message>
|
94
|
-
</Result>
|
95
|
-
<TitleItems>
|
96
|
-
<TitleItem id="2">
|
97
|
-
<Cat>4</Cat>
|
98
|
-
<Comment>DummyComment</Comment>
|
99
|
-
<FirstCh>DummyChannel</FirstCh>
|
100
|
-
<FirstEndMonth>1</FirstEndMonth>
|
101
|
-
<FirstEndYear>2000</FirstEndYear>
|
102
|
-
<FirstMonth>1</FirstMonth>
|
103
|
-
<FirstYear>2000</FirstYear>
|
104
|
-
<Keywords>DummyKeywords</Keywords>
|
105
|
-
<LastUpdate>2000-01-01 00:00:00</LastUpdate>
|
106
|
-
<ShortTitle>DummyShortTitle</ShortTitle>
|
107
|
-
<SubTitles>DummySubTitles</SubTitles>
|
108
|
-
<TID>2</TID>
|
109
|
-
<Title>DummyTitle</Title>
|
110
|
-
<TitleEN>DummyEnglishTitle</TitleEN>
|
111
|
-
<TitleFlag>0</TitleFlag>
|
112
|
-
<TitleYomi>ダミータイトル</TitleYomi>
|
113
|
-
<UserPoint>6</UserPoint>
|
114
|
-
<UserPointRank>1</UserPointRank>
|
115
|
-
</TitleItem>
|
116
|
-
</TitleItems>
|
117
|
-
</TitleLookupResponse>
|
118
|
-
EOS
|
119
|
-
end
|
120
|
-
|
121
|
-
let(:app) do
|
122
|
-
->(env) do
|
123
|
-
[
|
124
|
-
200,
|
125
|
-
{ "Content-type" => "application/xml" },
|
126
|
-
[
|
127
|
-
case env["QUERY_STRING"]
|
128
|
-
when /ProgLookup/
|
129
|
-
dummy_programs_response
|
130
|
-
when /ChLookup/
|
131
|
-
dummy_channels_response
|
132
|
-
else
|
133
|
-
dummy_titles_response
|
134
|
-
end,
|
135
|
-
],
|
136
|
-
]
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
subject do
|
141
|
-
call
|
142
|
-
request
|
143
|
-
end
|
144
|
-
|
145
6
|
describe "#list_channel_groups" do
|
146
7
|
subject do
|
147
8
|
client.list_channel_groups(options)
|
148
9
|
end
|
149
10
|
|
11
|
+
let(:dummy_channel_groups_response) do
|
12
|
+
<<-EOS.strip_heredoc
|
13
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
14
|
+
<ChGroupLookupResponse>
|
15
|
+
<Result>
|
16
|
+
<Code>200</Code>
|
17
|
+
<Message>
|
18
|
+
</Message>
|
19
|
+
</Result>
|
20
|
+
<ChGroupItems>
|
21
|
+
<ChGroupItem id="3">
|
22
|
+
<ChGroupComment>DummyComment</ChGroupComment>
|
23
|
+
<ChGID>1</ChGID>
|
24
|
+
<ChGroupName>DummyChannelName</ChGroupName>
|
25
|
+
<Order>1000</Order>
|
26
|
+
<LastUpdate>2000-01-01 00:00:00</LastUpdate>
|
27
|
+
</ChGroupItem>
|
28
|
+
</ChGroupItems>
|
29
|
+
</ChGroupLookupResponse>
|
30
|
+
EOS
|
31
|
+
end
|
32
|
+
|
150
33
|
let(:options) do
|
151
34
|
{}
|
152
35
|
end
|
@@ -215,6 +98,32 @@ describe ::SyoboiCalendar::Client do
|
|
215
98
|
client.list_channels(options)
|
216
99
|
end
|
217
100
|
|
101
|
+
let(:dummy_channels_response) do
|
102
|
+
<<-EOS.strip_heredoc
|
103
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
104
|
+
<ChLookupResponse>
|
105
|
+
<Result>
|
106
|
+
<Code>200</Code>
|
107
|
+
<Message>
|
108
|
+
</Message>
|
109
|
+
</Result>
|
110
|
+
<ChItems>
|
111
|
+
<ChItem id="3">
|
112
|
+
<ChComment>DummyComment</ChComment>
|
113
|
+
<ChEPGURL>http://example.com/epg-url</ChEPGURL>
|
114
|
+
<ChGID>1</ChGID>
|
115
|
+
<ChID>3</ChID>
|
116
|
+
<ChName>DummyChannelName</ChName>
|
117
|
+
<ChNumber>3</ChNumber>
|
118
|
+
<ChURL>http://example.com/</ChURL>
|
119
|
+
<ChiEPGName>DummyiEPGName</ChiEPGName>
|
120
|
+
<LastUpdate>2000-01-01 00:00:00</LastUpdate>
|
121
|
+
</ChItem>
|
122
|
+
</ChItems>
|
123
|
+
</ChLookupResponse>
|
124
|
+
EOS
|
125
|
+
end
|
126
|
+
|
218
127
|
let(:options) do
|
219
128
|
{}
|
220
129
|
end
|
@@ -278,8 +187,8 @@ describe ::SyoboiCalendar::Client do
|
|
278
187
|
end
|
279
188
|
|
280
189
|
context "with real response" do
|
281
|
-
|
282
|
-
stub_request(:get, //).
|
190
|
+
before do
|
191
|
+
stub_request(:get, //).to_return(body: dummy_channels_response)
|
283
192
|
end
|
284
193
|
|
285
194
|
it "returns channels" do
|
@@ -301,6 +210,38 @@ describe ::SyoboiCalendar::Client do
|
|
301
210
|
client.list_programs(options)
|
302
211
|
end
|
303
212
|
|
213
|
+
let(:dummy_programs_response) do
|
214
|
+
<<-EOS.strip_heredoc
|
215
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
216
|
+
<ProgLookupResponse>
|
217
|
+
<ProgItems>
|
218
|
+
<ProgItem id="1">
|
219
|
+
<ChID>3</ChID>
|
220
|
+
<Count>1</Count>
|
221
|
+
<Deleted>0</Deleted>
|
222
|
+
<EdTime>2000-01-01 00:00:00</EdTime>
|
223
|
+
<Flag>9</Flag>
|
224
|
+
<LastUpdate>2000-01-01 00:00:00</LastUpdate>
|
225
|
+
<PID>1</PID>
|
226
|
+
<ProgComment>DummyComment</ProgComment>
|
227
|
+
<Revision>2</Revision>
|
228
|
+
<STSubTitle>DummySubTitle</STSubTitle>
|
229
|
+
<StOffset>0</StOffset>
|
230
|
+
<StTime>2000-01-01 00:00:00</StTime>
|
231
|
+
<SubTitle></SubTitle>
|
232
|
+
<TID>2</TID>
|
233
|
+
<Warn>1</Warn>
|
234
|
+
</ProgItem>
|
235
|
+
</ProgItems>
|
236
|
+
<Result>
|
237
|
+
<Code>200</Code>
|
238
|
+
<Message>
|
239
|
+
</Message>
|
240
|
+
</Result>
|
241
|
+
</ProgLookupResponse>
|
242
|
+
EOS
|
243
|
+
end
|
244
|
+
|
304
245
|
let(:options) do
|
305
246
|
{}
|
306
247
|
end
|
@@ -454,7 +395,7 @@ describe ::SyoboiCalendar::Client do
|
|
454
395
|
|
455
396
|
context "with real response" do
|
456
397
|
let!(:request) do
|
457
|
-
stub_request(:get, //).
|
398
|
+
stub_request(:get, //).to_return(body: dummy_programs_response)
|
458
399
|
end
|
459
400
|
|
460
401
|
it "returns programs" do
|
@@ -481,6 +422,41 @@ describe ::SyoboiCalendar::Client do
|
|
481
422
|
client.list_titles(options)
|
482
423
|
end
|
483
424
|
|
425
|
+
let(:dummy_titles_response) do
|
426
|
+
<<-EOS.strip_heredoc
|
427
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
428
|
+
<TitleLookupResponse>
|
429
|
+
<Result>
|
430
|
+
<Code>200</Code>
|
431
|
+
<Message>
|
432
|
+
</Message>
|
433
|
+
</Result>
|
434
|
+
<TitleItems>
|
435
|
+
<TitleItem id="2">
|
436
|
+
<Cat>4</Cat>
|
437
|
+
<Comment>DummyComment</Comment>
|
438
|
+
<FirstCh>DummyChannel</FirstCh>
|
439
|
+
<FirstEndMonth>1</FirstEndMonth>
|
440
|
+
<FirstEndYear>2000</FirstEndYear>
|
441
|
+
<FirstMonth>1</FirstMonth>
|
442
|
+
<FirstYear>2000</FirstYear>
|
443
|
+
<Keywords>DummyKeywords</Keywords>
|
444
|
+
<LastUpdate>2000-01-01 00:00:00</LastUpdate>
|
445
|
+
<ShortTitle>DummyShortTitle</ShortTitle>
|
446
|
+
<SubTitles>DummySubTitles</SubTitles>
|
447
|
+
<TID>2</TID>
|
448
|
+
<Title>DummyTitle</Title>
|
449
|
+
<TitleEN>DummyEnglishTitle</TitleEN>
|
450
|
+
<TitleFlag>0</TitleFlag>
|
451
|
+
<TitleYomi>ダミータイトル</TitleYomi>
|
452
|
+
<UserPoint>6</UserPoint>
|
453
|
+
<UserPointRank>1</UserPointRank>
|
454
|
+
</TitleItem>
|
455
|
+
</TitleItems>
|
456
|
+
</TitleLookupResponse>
|
457
|
+
EOS
|
458
|
+
end
|
459
|
+
|
484
460
|
let(:options) do
|
485
461
|
{}
|
486
462
|
end
|
@@ -550,7 +526,7 @@ describe ::SyoboiCalendar::Client do
|
|
550
526
|
|
551
527
|
context "with real response" do
|
552
528
|
let!(:request) do
|
553
|
-
stub_request(:get, //).
|
529
|
+
stub_request(:get, //).to_return(body: dummy_titles_response)
|
554
530
|
end
|
555
531
|
|
556
532
|
it "returns titles" do
|
data/syoboi_calendar.gemspec
CHANGED
@@ -23,7 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency "multi_xml"
|
24
24
|
spec.add_development_dependency "activesupport"
|
25
25
|
spec.add_development_dependency "pry"
|
26
|
-
spec.add_development_dependency "rack"
|
27
26
|
spec.add_development_dependency "rake"
|
28
27
|
spec.add_development_dependency "rspec", "2.14.1"
|
29
28
|
spec.add_development_dependency "webmock"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syoboi_calendar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rack
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: rake
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -153,21 +139,20 @@ files:
|
|
153
139
|
- lib/syoboi_calendar.rb
|
154
140
|
- lib/syoboi_calendar/client.rb
|
155
141
|
- lib/syoboi_calendar/queries/base_query.rb
|
156
|
-
- lib/syoboi_calendar/queries/
|
157
|
-
- lib/syoboi_calendar/queries/
|
158
|
-
- lib/syoboi_calendar/queries/
|
159
|
-
- lib/syoboi_calendar/queries/
|
142
|
+
- lib/syoboi_calendar/queries/list_channel_groups_query.rb
|
143
|
+
- lib/syoboi_calendar/queries/list_channels_query.rb
|
144
|
+
- lib/syoboi_calendar/queries/list_programs_query.rb
|
145
|
+
- lib/syoboi_calendar/queries/list_titles_query.rb
|
160
146
|
- lib/syoboi_calendar/resources/base_resource.rb
|
161
147
|
- lib/syoboi_calendar/resources/channel_group_resource.rb
|
162
148
|
- lib/syoboi_calendar/resources/channel_resource.rb
|
163
149
|
- lib/syoboi_calendar/resources/program_resource.rb
|
164
150
|
- lib/syoboi_calendar/resources/title_resource.rb
|
165
|
-
- lib/syoboi_calendar/
|
166
|
-
- lib/syoboi_calendar/
|
167
|
-
- lib/syoboi_calendar/
|
168
|
-
- lib/syoboi_calendar/
|
169
|
-
- lib/syoboi_calendar/
|
170
|
-
- lib/syoboi_calendar/response_parsers/titles_response_parser.rb
|
151
|
+
- lib/syoboi_calendar/responses/base_response.rb
|
152
|
+
- lib/syoboi_calendar/responses/list_channel_groups_response.rb
|
153
|
+
- lib/syoboi_calendar/responses/list_channels_response.rb
|
154
|
+
- lib/syoboi_calendar/responses/list_programs_response.rb
|
155
|
+
- lib/syoboi_calendar/responses/list_titles_response.rb
|
171
156
|
- lib/syoboi_calendar/version.rb
|
172
157
|
- spec/spec_helper.rb
|
173
158
|
- spec/syoboi_calendar/client_spec.rb
|
@@ -1,49 +0,0 @@
|
|
1
|
-
module SyoboiCalendar
|
2
|
-
class Response
|
3
|
-
include ::Enumerable
|
4
|
-
|
5
|
-
# @param faraday_response [Faraday::Response]
|
6
|
-
# @param response_parser_class [Class]
|
7
|
-
def initialize(faraday_response:, response_parser_class:)
|
8
|
-
@faraday_response = faraday_response
|
9
|
-
@response_parser_class = response_parser_class
|
10
|
-
end
|
11
|
-
|
12
|
-
# @return [String]
|
13
|
-
def body
|
14
|
-
faraday_response.body
|
15
|
-
end
|
16
|
-
|
17
|
-
# @note Implementation for Enumerable
|
18
|
-
def each(&block)
|
19
|
-
resources.each(&block)
|
20
|
-
end
|
21
|
-
|
22
|
-
# @return [Hash]
|
23
|
-
def headers
|
24
|
-
faraday_response.headers
|
25
|
-
end
|
26
|
-
|
27
|
-
# @return [Array<SyoboiCalendar::Resources::BaseResource>]
|
28
|
-
def resources
|
29
|
-
@resources ||= response_parser_class.new(body).parse
|
30
|
-
end
|
31
|
-
|
32
|
-
# @return [Integer]
|
33
|
-
def status
|
34
|
-
faraday_response.status
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
# @return [Faraday::Response]
|
40
|
-
def faraday_response
|
41
|
-
@faraday_response
|
42
|
-
end
|
43
|
-
|
44
|
-
# @return [Class]
|
45
|
-
def response_parser_class
|
46
|
-
@response_parser_class
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
module SyoboiCalendar
|
2
|
-
module ResponseParsers
|
3
|
-
class BaseResponseParser
|
4
|
-
# @param body [String]
|
5
|
-
def initialize(body)
|
6
|
-
@body = body
|
7
|
-
end
|
8
|
-
|
9
|
-
# @return [Array<SyoboiCalendar::Resources::BaseResource>]
|
10
|
-
def parse
|
11
|
-
sources.map do |source|
|
12
|
-
resource_class.new(source)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
# @return [String]
|
19
|
-
def body
|
20
|
-
@body
|
21
|
-
end
|
22
|
-
|
23
|
-
# @return [Hash]
|
24
|
-
def parsed_body
|
25
|
-
::MultiXml.parse(body)
|
26
|
-
end
|
27
|
-
|
28
|
-
# @return [Class]
|
29
|
-
def resource_class
|
30
|
-
raise ::NotImplementedError
|
31
|
-
end
|
32
|
-
|
33
|
-
# @return [Array<Hash>, Hash]
|
34
|
-
def source_or_sources
|
35
|
-
raise ::NotImplementedError
|
36
|
-
end
|
37
|
-
|
38
|
-
# @return [Array]
|
39
|
-
def sources
|
40
|
-
object = source_or_sources
|
41
|
-
case
|
42
|
-
when object.nil?
|
43
|
-
[]
|
44
|
-
when object.respond_to?(:to_ary)
|
45
|
-
object.to_ary || [object]
|
46
|
-
else
|
47
|
-
[object]
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|