syoboi_calendar 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/CHANGELOG.md +3 -0
- data/README.md +60 -3
- data/lib/syoboi_calendar/client.rb +3 -31
- data/lib/syoboi_calendar/processors/base.rb +43 -0
- data/lib/syoboi_calendar/processors/channel.rb +15 -0
- data/lib/syoboi_calendar/processors/program.rb +81 -0
- data/lib/syoboi_calendar/processors/title.rb +15 -0
- data/lib/syoboi_calendar/query_builders/base.rb +2 -2
- data/lib/syoboi_calendar/resources/program.rb +2 -0
- data/lib/syoboi_calendar/version.rb +1 -1
- data/lib/syoboi_calendar.rb +5 -0
- data/spec/syoboi_calendar/client_spec.rb +13 -1
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49970d4dc6d0995fdceb42f41110ceb6377cef6c
|
4
|
+
data.tar.gz: 5a5e061756c0a3d599d4134998d7104231f59cb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b65a62a6b9d37cdc00f932f1820b1c62d97b43a44ddd6bb47733798fa54a15548a1efda8f1d992b10991a5e2ef02e0471398f8cfa320e001c5fbd813569b474
|
7
|
+
data.tar.gz: 9986bd57b3ab9e4801df776e3a1656be2ac2bfa0e958caf5b7c543c8245ae571c0aa3816e9f3610b7cbc0d0ceaea53d1bf6abba23261b677f94aa168968d5535
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -13,9 +13,9 @@ gem "syoboi_calendar"
|
|
13
13
|
require "syoboi_calendar"
|
14
14
|
|
15
15
|
client = SyoboiCalendar::Client.new
|
16
|
-
client.channels #=>
|
17
|
-
client.programs #=>
|
18
|
-
client.titles #=>
|
16
|
+
client.channels #=> an Array of SyoboiCalendar::Resources::Channel
|
17
|
+
client.programs #=> an Array of SyoboiCalendar::Resources::Program
|
18
|
+
client.titles #=> an Array of SyoboiCalendar::Resources::Title
|
19
19
|
```
|
20
20
|
|
21
21
|
## API
|
@@ -73,3 +73,60 @@ SyoboiCalendar::Client
|
|
73
73
|
with options {:played_from=>2000-01-01 00:00:00 UTC, :played_to=>2000-01-01 00:00:00 UTC}
|
74
74
|
requests to http://cal.syoboi.jp/db.php?Command=ProgLookup&JOIN=SubTitles&Range=20000101_000000-20000101_000000
|
75
75
|
```
|
76
|
+
|
77
|
+
## Resources
|
78
|
+
SyoboiCalendar::Client returns an Array of resources.
|
79
|
+
|
80
|
+
### SyoboiCalendar::Resources::Channel
|
81
|
+
* comment
|
82
|
+
* epg_url
|
83
|
+
* group_id
|
84
|
+
* id
|
85
|
+
* iepg_name
|
86
|
+
* name
|
87
|
+
* number
|
88
|
+
* url
|
89
|
+
|
90
|
+
|
91
|
+
### SyoboiCalendar::Resources::Title
|
92
|
+
* category_id
|
93
|
+
* comment
|
94
|
+
* first_channel
|
95
|
+
* first_end_month
|
96
|
+
* first_end_year
|
97
|
+
* first_month
|
98
|
+
* first_year
|
99
|
+
* keywords
|
100
|
+
* short_title
|
101
|
+
* sub_titles
|
102
|
+
* id
|
103
|
+
* name
|
104
|
+
* english_name
|
105
|
+
* flag
|
106
|
+
* kana
|
107
|
+
* point
|
108
|
+
* rank
|
109
|
+
|
110
|
+
### SyoboiCalendar::Resources::Program
|
111
|
+
* channel_id
|
112
|
+
* comment
|
113
|
+
* count
|
114
|
+
* deleted?
|
115
|
+
* finished_at
|
116
|
+
* flag
|
117
|
+
* id
|
118
|
+
* revision
|
119
|
+
* started_at
|
120
|
+
* sub_title
|
121
|
+
* title_id
|
122
|
+
* updated_at
|
123
|
+
* warn
|
124
|
+
|
125
|
+
## Eager Loading
|
126
|
+
Client#programs supports `:include` option for eage-loading related resources.
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
programs = client.programs(include: [:channel, :title])
|
130
|
+
programs.first.channel #=> SyoboiCalendar::Resources::Channel
|
131
|
+
programs.first.title #=> SyoboiCalendar::Resources::title
|
132
|
+
```
|
@@ -1,43 +1,15 @@
|
|
1
1
|
module SyoboiCalendar
|
2
2
|
class Client
|
3
3
|
def channels(options = {})
|
4
|
-
process(
|
5
|
-
QueryBuilders::Channel,
|
6
|
-
Parsers::Channel,
|
7
|
-
options,
|
8
|
-
)
|
4
|
+
Processors::Channel.process(options)
|
9
5
|
end
|
10
6
|
|
11
7
|
def programs(options = {})
|
12
|
-
process(
|
13
|
-
QueryBuilders::Program,
|
14
|
-
Parsers::Program,
|
15
|
-
options,
|
16
|
-
)
|
8
|
+
Processors::Program.process(options)
|
17
9
|
end
|
18
10
|
|
19
11
|
def titles(options = {})
|
20
|
-
process(
|
21
|
-
QueryBuilders::Title,
|
22
|
-
Parsers::Title,
|
23
|
-
options,
|
24
|
-
)
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def connector
|
30
|
-
@connector ||= Connector.new
|
31
|
-
end
|
32
|
-
|
33
|
-
def get(query)
|
34
|
-
connector.get(query).body
|
35
|
-
end
|
36
|
-
|
37
|
-
def process(builder, parser, options)
|
38
|
-
query = builder.build(options)
|
39
|
-
response = get(query)
|
40
|
-
parser.parse(response)
|
12
|
+
Processors::Title.process(options)
|
41
13
|
end
|
42
14
|
end
|
43
15
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module SyoboiCalendar
|
2
|
+
module Processors
|
3
|
+
class Base
|
4
|
+
class << self
|
5
|
+
def process(*args)
|
6
|
+
new(*args).process
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :options
|
11
|
+
|
12
|
+
def initialize(options)
|
13
|
+
@options = options
|
14
|
+
end
|
15
|
+
|
16
|
+
def process
|
17
|
+
resources
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def resources
|
23
|
+
@resources ||= begin
|
24
|
+
query = query_builder.build(options)
|
25
|
+
response = get(query)
|
26
|
+
parser.parse(response)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def connector
|
31
|
+
@connector ||= Connector.new
|
32
|
+
end
|
33
|
+
|
34
|
+
def get(query)
|
35
|
+
connector.get(query).body
|
36
|
+
end
|
37
|
+
|
38
|
+
def includes
|
39
|
+
Array.wrap(options[:includes])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module SyoboiCalendar
|
2
|
+
module Processors
|
3
|
+
class Program < Base
|
4
|
+
def process
|
5
|
+
include_channel if specified_to_include_channel?
|
6
|
+
include_title if specified_to_include_title?
|
7
|
+
resources
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def query_builder
|
13
|
+
QueryBuilders::Program
|
14
|
+
end
|
15
|
+
|
16
|
+
def parser
|
17
|
+
Parsers::Program
|
18
|
+
end
|
19
|
+
|
20
|
+
def titles_indexed_by_id
|
21
|
+
@titles_indexed_by_id ||= titles.index_by(&:id)
|
22
|
+
end
|
23
|
+
|
24
|
+
def titles
|
25
|
+
Parsers::Title.parse(titles_response)
|
26
|
+
end
|
27
|
+
|
28
|
+
def titles_response
|
29
|
+
connector.get(titles_query).body
|
30
|
+
end
|
31
|
+
|
32
|
+
def titles_query
|
33
|
+
QueryBuilders::Title.build(title_id: title_ids.join(","))
|
34
|
+
end
|
35
|
+
|
36
|
+
def title_ids
|
37
|
+
resources.map(&:title_id)
|
38
|
+
end
|
39
|
+
|
40
|
+
def specified_to_include_title?
|
41
|
+
includes.include?(:title)
|
42
|
+
end
|
43
|
+
|
44
|
+
def specified_to_include_channel?
|
45
|
+
includes.include?(:channel)
|
46
|
+
end
|
47
|
+
|
48
|
+
def include_title
|
49
|
+
resources.each do |program|
|
50
|
+
program.title = titles_indexed_by_id[program.title_id]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def channels_indexed_by_id
|
55
|
+
@channels_indexed_by_id ||= channels.index_by(&:id)
|
56
|
+
end
|
57
|
+
|
58
|
+
def channels
|
59
|
+
Parsers::Channel.parse(channels_response)
|
60
|
+
end
|
61
|
+
|
62
|
+
def channels_response
|
63
|
+
connector.get(channels_query).body
|
64
|
+
end
|
65
|
+
|
66
|
+
def channels_query
|
67
|
+
QueryBuilders::Channel.build(channel_id: channel_ids.join(","))
|
68
|
+
end
|
69
|
+
|
70
|
+
def channel_ids
|
71
|
+
resources.map(&:channel_id)
|
72
|
+
end
|
73
|
+
|
74
|
+
def include_channel
|
75
|
+
resources.each do |program|
|
76
|
+
program.channel = channels_indexed_by_id[program.channel_id]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/lib/syoboi_calendar.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "active_support/concern"
|
2
2
|
require "active_support/core_ext/array/wrap"
|
3
3
|
require "active_support/core_ext/class/attribute"
|
4
|
+
require "active_support/core_ext/enumerable"
|
4
5
|
require "active_support/core_ext/object/try"
|
5
6
|
require "active_support/core_ext/string/inflections"
|
6
7
|
require "faraday"
|
@@ -12,6 +13,10 @@ require "syoboi_calendar/parsers/base"
|
|
12
13
|
require "syoboi_calendar/parsers/channel"
|
13
14
|
require "syoboi_calendar/parsers/program"
|
14
15
|
require "syoboi_calendar/parsers/title"
|
16
|
+
require "syoboi_calendar/processors/base"
|
17
|
+
require "syoboi_calendar/processors/channel"
|
18
|
+
require "syoboi_calendar/processors/program"
|
19
|
+
require "syoboi_calendar/processors/title"
|
15
20
|
require "syoboi_calendar/query_builders/base"
|
16
21
|
require "syoboi_calendar/query_builders/channel_id_queriable"
|
17
22
|
require "syoboi_calendar/query_builders/channel"
|
@@ -1,5 +1,5 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
require "spec_helper"
|
2
|
-
require "active_support/core_ext/object/to_query"
|
3
3
|
|
4
4
|
describe SyoboiCalendar::Client do
|
5
5
|
before do
|
@@ -373,5 +373,17 @@ describe SyoboiCalendar::Client do
|
|
373
373
|
programs[0].warn.should == 1
|
374
374
|
end
|
375
375
|
end
|
376
|
+
|
377
|
+
context "with :include option" do
|
378
|
+
let!(:request) do
|
379
|
+
stub_request(:get, //).to_rack(app)
|
380
|
+
end
|
381
|
+
|
382
|
+
it "eager loads related resources" do
|
383
|
+
programs = client.programs(includes: [:channel, :title])
|
384
|
+
programs[0].channel.should be_a SyoboiCalendar::Resources::Channel
|
385
|
+
programs[0].title.should be_a SyoboiCalendar::Resources::Title
|
386
|
+
end
|
387
|
+
end
|
376
388
|
end
|
377
389
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syoboi_calendar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
@@ -199,6 +199,10 @@ files:
|
|
199
199
|
- lib/syoboi_calendar/parsers/channel.rb
|
200
200
|
- lib/syoboi_calendar/parsers/program.rb
|
201
201
|
- lib/syoboi_calendar/parsers/title.rb
|
202
|
+
- lib/syoboi_calendar/processors/base.rb
|
203
|
+
- lib/syoboi_calendar/processors/channel.rb
|
204
|
+
- lib/syoboi_calendar/processors/program.rb
|
205
|
+
- lib/syoboi_calendar/processors/title.rb
|
202
206
|
- lib/syoboi_calendar/query_builders/base.rb
|
203
207
|
- lib/syoboi_calendar/query_builders/channel.rb
|
204
208
|
- lib/syoboi_calendar/query_builders/channel_id_queriable.rb
|