syoboi_calendar 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5346554a9e8ec0c05a1a7f9b715edd122ab8cce2
4
- data.tar.gz: 28c95e9429d5626c612476f9386504cadc048e96
3
+ metadata.gz: 8facc19f2111d8b7daa7d7baeb1893e4744b0632
4
+ data.tar.gz: 61e353b7d123d76c96dc948a605d2bb0b4e3a19c
5
5
  SHA512:
6
- metadata.gz: 54c8869860f68a1d928a7bed7bee325c66c700da04a98088cfd24942053942b3ceac230d5d41f8f030bc7a8c8f7906b68d8140ea88963637765cb88beda1cbab
7
- data.tar.gz: 7c147a0f1b67908fed9cd67ba2aab48daf161050140230e7a8f1f00d973ccd973d51450f9a0ee32f976e6b4971a46ce7c97de9ceaa99936635a1eef56f5add6d
6
+ metadata.gz: ff535c1524af5faa35d84d8ebf6918d3de6cfe9753743fc93ede02f187f63213c3b557ee207be4101058a414d7304a1b814a0b2a44b4c4b7175b449f2f65114f
7
+ data.tar.gz: 8b2efb2f7340359703684ccd38cb02cba56aae27d391f55278d3b53dfc9c0023d15e9695e49fcf0c843039754cf289e2fdf9fbfb61c3bcb3da1fd00fc07ef453
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.6.0
2
+
3
+ - Support channel groups
4
+ - Change resource attribute name from `group_id` to `channel_group_id`
5
+
1
6
  ## 0.5.1
2
7
 
3
8
  - Support :title_id options on list_programs method
data/README.md CHANGED
@@ -41,6 +41,38 @@ require "syoboi_calendar"
41
41
  client = SyoboiCalendar::Client.new
42
42
  ```
43
43
 
44
+ ### SyoboiCalendar::Client#list_channel_groups
45
+
46
+ Sends an HTTP request to `http://cal.syoboi.jp/db.php?Command=ChGroupLookup`.
47
+
48
+ ```ruby
49
+ client.list_channel_groups
50
+ ```
51
+
52
+ Sends an HTTP request to `http://cal.syoboi.jp/db.php?ChGID=1&Command=ChGroupLookup`.
53
+
54
+ ```ruby
55
+ client.list_channel_groups(channel_group_id: 1)
56
+ ```
57
+
58
+ Sends an HTTP request to `http://cal.syoboi.jp/db.php?Command=ChGroupLookup&LastUpdate=20000101_000000-`.
59
+
60
+ ```ruby
61
+ client.list_channel_groups(updated_from: Time.new(2000, 1, 1))
62
+ ```
63
+
64
+ Sends an HTTP request to `http://cal.syoboi.jp/db.php?Command=ChGroupLookup&LastUpdate=-20000101_000000`.
65
+
66
+ ```ruby
67
+ client.list_channel_groups(updated_to: Time.new(2000, 1, 1))
68
+ ```
69
+
70
+ Sends an HTTP request to `http://cal.syoboi.jp/db.php?Command=ChGroupLookup&LastUpdate=20000101_000000-20000201_000000`.
71
+
72
+ ```ruby
73
+ client.list_channel_groups(updated_from: Time.new(2000, 1, 1), updated_to: Time.new(2000, 2, 1))
74
+ ```
75
+
44
76
  ### SyoboiCalendar::Client#list_channels
45
77
 
46
78
  Sends an HTTP request to `http://cal.syoboi.jp/db.php?Command=ChLookup`.
@@ -203,40 +235,70 @@ Sends an HTTP request to `http://cal.syoboi.jp/db.php?Command=TitleLookupp&TID=*
203
235
  client.list_titles(updated_from: Time.new(2000, 1, 1), updated_to: Time.new(2000, 2, 1))
204
236
  ```
205
237
 
206
- ### SyoboiCalendar::Resources::ChannelResource#comment
238
+ ### SyoboiCalendar::Resources::ChannelGroupResource#comment
207
239
 
208
240
  ```ruby
209
- client.list_channels.first.comment
241
+ client.list_channel_groups.to_a[5].comment
210
242
  ```
211
243
 
212
244
  <details>
213
245
  <summary>Result</summary>
214
246
 
215
247
  ```ruby
216
- "http://jk.nicovideo.jp/watch/jk1"
248
+ "aa"
217
249
  ```
218
250
 
219
251
  </details>
220
252
 
221
- ### SyoboiCalendar::Resources::ChannelResource#epg_url
253
+ ### SyoboiCalendar::Resources::ChannelGroupResource#id
222
254
 
223
255
  ```ruby
224
- client.list_channels.first.epg_url
256
+ client.list_channel_groups.first.id
225
257
  ```
226
258
 
227
259
  <details>
228
260
  <summary>Result</summary>
229
261
 
230
262
  ```ruby
231
- "http://www2.nhk.or.jp/hensei/program/wk.cgi?tz=all&ch=21"
263
+ 1
264
+ ```
265
+
266
+ </details>
267
+
268
+ ### SyoboiCalendar::Resources::ChannelGroupResource#name
269
+
270
+ ```ruby
271
+ client.list_channel_groups.first.name
272
+ ```
273
+
274
+ <details>
275
+ <summary>Result</summary>
276
+
277
+ ```ruby
278
+ "テレビ 関東"
279
+ ```
280
+
281
+ </details>
282
+
283
+ ### SyoboiCalendar::Resources::ChannelGroupResource#order_score
284
+
285
+ ```ruby
286
+ client.list_channel_groups.first.order_score
287
+ ```
288
+
289
+ <details>
290
+ <summary>Result</summary>
291
+
292
+ ```ruby
293
+ 1200
232
294
  ```
233
295
 
234
296
  </details>
235
297
 
236
- ### SyoboiCalendar::Resources::ChannelResource#group_id
298
+ ### SyoboiCalendar::Resources::ChannelResource#channel_group_id
237
299
 
238
300
  ```ruby
239
- client.list_channels.first.group_id
301
+ client.list_channels.first.channel_group_id
240
302
  ```
241
303
 
242
304
  <details>
@@ -248,6 +310,36 @@ client.list_channels.first.group_id
248
310
 
249
311
  </details>
250
312
 
313
+ ### SyoboiCalendar::Resources::ChannelResource#comment
314
+
315
+ ```ruby
316
+ client.list_channels.first.comment
317
+ ```
318
+
319
+ <details>
320
+ <summary>Result</summary>
321
+
322
+ ```ruby
323
+ "http://jk.nicovideo.jp/watch/jk1"
324
+ ```
325
+
326
+ </details>
327
+
328
+ ### SyoboiCalendar::Resources::ChannelResource#epg_url
329
+
330
+ ```ruby
331
+ client.list_channels.first.epg_url
332
+ ```
333
+
334
+ <details>
335
+ <summary>Result</summary>
336
+
337
+ ```ruby
338
+ "http://www2.nhk.or.jp/hensei/program/wk.cgi?tz=all&ch=21"
339
+ ```
340
+
341
+ </details>
342
+
251
343
  ### SyoboiCalendar::Resources::ChannelResource#id
252
344
 
253
345
  ```ruby
@@ -278,6 +370,21 @@ client.list_channels.first.iepg_name
278
370
 
279
371
  </details>
280
372
 
373
+ ### SyoboiCalendar::Resources::ChannelResource#name
374
+
375
+ ```ruby
376
+ client.list_channels.first.name
377
+ ```
378
+
379
+ <details>
380
+ <summary>Result</summary>
381
+
382
+ ```ruby
383
+ "NHK総合"
384
+ ```
385
+
386
+ </details>
387
+
281
388
  ### SyoboiCalendar::Resources::ChannelResource#number
282
389
 
283
390
  ```ruby
@@ -13,6 +13,13 @@ module SyoboiCalendar
13
13
  end
14
14
  end
15
15
 
16
+ # @return [Array<SyoboiCalendar::Resources::ChannelGroup>]
17
+ def list_channel_groups(options = {})
18
+ query = ::SyoboiCalendar::Queries::ChannelGroupQuery.new(options)
19
+ faraday_response = get(query.to_hash)
20
+ ::SyoboiCalendar::Responses::ChannelGroupsResponse.new(faraday_response)
21
+ end
22
+
16
23
  # @return [Array<SyoboiCalendar::Resources::Channel>]
17
24
  def list_channels(options = {})
18
25
  query = ::SyoboiCalendar::Queries::ChannelQuery.new(options)
@@ -0,0 +1,21 @@
1
+ module SyoboiCalendar
2
+ module Queries
3
+ class ChannelGroupQuery < BaseQuery
4
+ COMMAND = "ChGroupLookup"
5
+
6
+ property :ChGID
7
+
8
+ # @return [String, nil]
9
+ def ChGID
10
+ if options[:channel_group_id]
11
+ format_comma_separated_values(options[:channel_group_id])
12
+ end
13
+ end
14
+
15
+ # @note Override
16
+ def Command
17
+ COMMAND
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ module SyoboiCalendar
2
+ module Resources
3
+ class ChannelGroupResource < BaseResource
4
+ # @return [String, nil]
5
+ def comment
6
+ response.ChGroupComment
7
+ end
8
+
9
+ # @return [Integer, nil]
10
+ def id
11
+ response.ChGID.try(:to_i)
12
+ end
13
+
14
+ # @return [String, nil]
15
+ def name
16
+ response.ChGroupName
17
+ end
18
+
19
+ # @return [Integer, nil]
20
+ def order_score
21
+ response.ChGroupOrder.try(:to_i)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,6 +1,11 @@
1
1
  module SyoboiCalendar
2
2
  module Resources
3
3
  class ChannelResource < BaseResource
4
+ # @return [Integer, nil]
5
+ def channel_group_id
6
+ response.ChGID.try(:to_i)
7
+ end
8
+
4
9
  # @return [String, nil]
5
10
  def comment
6
11
  response.ChComment
@@ -11,11 +16,6 @@ module SyoboiCalendar
11
16
  response.ChEPGURL
12
17
  end
13
18
 
14
- # @return [Integer, nil]
15
- def group_id
16
- response.ChGID.try(:to_i)
17
- end
18
-
19
19
  # @return [Integer, nil]
20
20
  def id
21
21
  response.ChID.try(:to_i)
@@ -1,6 +1,17 @@
1
1
  module SyoboiCalendar
2
2
  module Resources
3
3
  class TitleResource < BaseResource
4
+ # @note
5
+ # 0: その他
6
+ # 1: アニメ
7
+ # 2: ラジオ
8
+ # 3: テレビ
9
+ # 4: 特撮
10
+ # 5: アニメ関連
11
+ # 6: メモ
12
+ # 7: OVA
13
+ # 8: 映画
14
+ # 10: アニメ(終了/再放送)
4
15
  # @return [Integer, nil]
5
16
  def category_id
6
17
  response.Cat.try(:to_i)
@@ -0,0 +1,12 @@
1
+ module SyoboiCalendar
2
+ module Responses
3
+ class ChannelGroupsResponse < BaseResponse
4
+ # @note Override
5
+ def resources
6
+ ::Array.wrap(faraday_response.body.ChGroupLookupResponse.ChGroupItems.ChGroupItem).map do |element|
7
+ ::SyoboiCalendar::Resources::ChannelGroupResource.new(element)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module SyoboiCalendar
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -6,14 +6,17 @@ require "faraday_middleware"
6
6
 
7
7
  require "syoboi_calendar/client"
8
8
  require "syoboi_calendar/queries/base_query"
9
+ require "syoboi_calendar/queries/channel_group_query"
9
10
  require "syoboi_calendar/queries/channel_query"
10
11
  require "syoboi_calendar/queries/program_query"
11
12
  require "syoboi_calendar/queries/title_query"
12
13
  require "syoboi_calendar/resources/base_resource"
14
+ require "syoboi_calendar/resources/channel_group_resource"
13
15
  require "syoboi_calendar/resources/channel_resource"
14
16
  require "syoboi_calendar/resources/program_resource"
15
17
  require "syoboi_calendar/resources/title_resource"
16
18
  require "syoboi_calendar/responses/base_response"
19
+ require "syoboi_calendar/responses/channel_groups_response"
17
20
  require "syoboi_calendar/responses/channels_response"
18
21
  require "syoboi_calendar/responses/programs_response"
19
22
  require "syoboi_calendar/responses/titles_response"
@@ -3,6 +3,28 @@ 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</ChComment>
18
+ <ChGID>1</ChGID>
19
+ <ChGroupName>DummyChannelName</ChName>
20
+ <Order>1000</Order>
21
+ <LastUpdate>2000-01-01 00:00:00</LastUpdate>
22
+ </ChGroupItem>
23
+ </ChGroupItems>
24
+ </ChGroupLookupResponse>
25
+ EOS
26
+ end
27
+
6
28
  let(:dummy_channels_response) do
7
29
  <<-EOS.strip_heredoc
8
30
  <?xml version="1.0" encoding="UTF-8"?>
@@ -120,6 +142,74 @@ describe ::SyoboiCalendar::Client do
120
142
  request
121
143
  end
122
144
 
145
+ describe "#list_channel_groups" do
146
+ subject do
147
+ client.list_channel_groups(options)
148
+ end
149
+
150
+ let(:options) do
151
+ {}
152
+ end
153
+
154
+ [
155
+ {
156
+ options: {},
157
+ query: {
158
+ Command: "ChGroupLookup",
159
+ },
160
+ },
161
+ {
162
+ options: {
163
+ channel_group_id: 1,
164
+ },
165
+ query: {
166
+ Command: "ChGroupLookup",
167
+ ChGID: 1,
168
+ },
169
+ },
170
+ {
171
+ options: {
172
+ updated_from: ::Time.new(2000, 1, 1),
173
+ },
174
+ query: {
175
+ Command: "ChGroupLookup",
176
+ LastUpdate: "20000101_000000-",
177
+ },
178
+ },
179
+ {
180
+ options: {
181
+ updated_to: ::Time.new(2000, 1, 1),
182
+ },
183
+ query: {
184
+ Command: "ChGroupLookup",
185
+ LastUpdate: "-20000101_000000",
186
+ },
187
+ },
188
+ {
189
+ options: {
190
+ updated_from: ::Time.new(2000, 1, 1),
191
+ updated_to: ::Time.new(2000, 1, 1),
192
+ },
193
+ query: {
194
+ Command: "ChGroupLookup",
195
+ LastUpdate: "20000101_000000-20000101_000000",
196
+ },
197
+ },
198
+ ].each do |example|
199
+ context "with options #{example[:options].inspect}" do
200
+ let(:options) do
201
+ example[:options]
202
+ end
203
+
204
+ it "sends an HTTP request to http://cal.syoboi.jp/db.php?#{example[:query].to_query}" do
205
+ stub = stub_request(:get, "http://cal.syoboi.jp/db.php?#{example[:query].to_query}")
206
+ subject
207
+ expect(stub).to have_been_made
208
+ end
209
+ end
210
+ end
211
+ end
212
+
123
213
  describe "#list_channels" do
124
214
  subject do
125
215
  client.list_channels(options)
@@ -194,9 +284,9 @@ describe ::SyoboiCalendar::Client do
194
284
 
195
285
  it "returns channels" do
196
286
  channels = subject
287
+ channels.first.channel_group_id.should == 1
197
288
  channels.first.comment.should == "DummyComment"
198
289
  channels.first.epg_url.should == "http://example.com/epg-url"
199
- channels.first.group_id.should == 1
200
290
  channels.first.id.should == 3
201
291
  channels.first.iepg_name.should == "DummyiEPGName"
202
292
  channels.first.name.should == "DummyChannelName"
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.5.1
4
+ version: 0.6.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-01 00:00:00.000000000 Z
11
+ date: 2017-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -167,14 +167,17 @@ files:
167
167
  - lib/syoboi_calendar.rb
168
168
  - lib/syoboi_calendar/client.rb
169
169
  - lib/syoboi_calendar/queries/base_query.rb
170
+ - lib/syoboi_calendar/queries/channel_group_query.rb
170
171
  - lib/syoboi_calendar/queries/channel_query.rb
171
172
  - lib/syoboi_calendar/queries/program_query.rb
172
173
  - lib/syoboi_calendar/queries/title_query.rb
173
174
  - lib/syoboi_calendar/resources/base_resource.rb
175
+ - lib/syoboi_calendar/resources/channel_group_resource.rb
174
176
  - lib/syoboi_calendar/resources/channel_resource.rb
175
177
  - lib/syoboi_calendar/resources/program_resource.rb
176
178
  - lib/syoboi_calendar/resources/title_resource.rb
177
179
  - lib/syoboi_calendar/responses/base_response.rb
180
+ - lib/syoboi_calendar/responses/channel_groups_response.rb
178
181
  - lib/syoboi_calendar/responses/channels_response.rb
179
182
  - lib/syoboi_calendar/responses/programs_response.rb
180
183
  - lib/syoboi_calendar/responses/titles_response.rb