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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c784bb59897bd758d21932242d40099f76a6620d
4
- data.tar.gz: 9670e8cb32bce32fba0a8be526fe8c570bcf97b0
3
+ metadata.gz: 49970d4dc6d0995fdceb42f41110ceb6377cef6c
4
+ data.tar.gz: 5a5e061756c0a3d599d4134998d7104231f59cb2
5
5
  SHA512:
6
- metadata.gz: 37c20a5b6d89934ae1ad18741d07e30052736f34beb257a595375ff9d39a952462c74c59ba2d217787c163877e8ead5294e9a489a44f7b714243113676ffb20e
7
- data.tar.gz: f2cdf3fe11d729a1d657b1e6c08e3cf9714b92e5d32790c02ae97a5656bcd3fa89377aac2aef290d440fbe5c74e9e77328944f981915518e94dcdfdc38988f0b
6
+ metadata.gz: 5b65a62a6b9d37cdc00f932f1820b1c62d97b43a44ddd6bb47733798fa54a15548a1efda8f1d992b10991a5e2ef02e0471398f8cfa320e001c5fbd813569b474
7
+ data.tar.gz: 9986bd57b3ab9e4801df776e3a1656be2ac2bfa0e958caf5b7c543c8245ae571c0aa3816e9f3610b7cbc0d0ceaea53d1bf6abba23261b677f94aa168968d5535
data/.travis.yml CHANGED
@@ -5,7 +5,6 @@ language: ruby
5
5
  rvm:
6
6
  - 1.9.3
7
7
  - 2.0.0
8
- - 2.1.0
9
8
  env:
10
9
  global:
11
10
  secure: jireAT1B+27QH2v5EUjdIu9/ELwA+fj67PtCFiw7nSvzzQV4sC94/otyrPlNqsLKijWk+fQw5XcW9HvSTXvCgGguQn5AGW+MjPu9AbuZAbWf6ayZFHIgaPxmBzFYZaC2yK9XL0kVMG/UdhDM9Vy9auf1kDPphMhwAGZ2yjuSBj0=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.3.1
2
+ * Client#programs supports `:include` option for eage-loading related resources
3
+
1
4
  ## 0.3.0
2
5
  * SyoboiCalendar::Client returns an Array of resources
3
6
 
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 #=> a Hashie::Mash instance
17
- client.programs #=> a Hashie::Mash instance
18
- client.titles #=> a Hashie::Mash instance
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,15 @@
1
+ module SyoboiCalendar
2
+ module Processors
3
+ class Channel < Base
4
+ private
5
+
6
+ def query_builder
7
+ QueryBuilders::Channel
8
+ end
9
+
10
+ def parser
11
+ Parsers::Channel
12
+ end
13
+ end
14
+ end
15
+ 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
@@ -0,0 +1,15 @@
1
+ module SyoboiCalendar
2
+ module Processors
3
+ class Title < Base
4
+ private
5
+
6
+ def query_builder
7
+ QueryBuilders::Title
8
+ end
9
+
10
+ def parser
11
+ Parsers::Title
12
+ end
13
+ end
14
+ end
15
+ end
@@ -2,8 +2,8 @@ module SyoboiCalendar
2
2
  module QueryBuilders
3
3
  class Base
4
4
  class << self
5
- def build(options)
6
- new(options).to_hash
5
+ def build(*args)
6
+ new(*args).to_hash
7
7
  end
8
8
 
9
9
  def property(*properties)
@@ -1,6 +1,8 @@
1
1
  module SyoboiCalendar
2
2
  module Resources
3
3
  class Program < Base
4
+ attr_accessor :channel, :title
5
+
4
6
  def id
5
7
  response.PID.try(:to_i)
6
8
  end
@@ -1,3 +1,3 @@
1
1
  module SyoboiCalendar
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -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.0
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