Skip to content

Commit 34b9742

Browse files
committed
Add plugins subscription Gguide
1 parent 9632cea commit 34b9742

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

plugins/subscription/g_guide.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# -*- coding: utf-8 -*-
2+
# Name:: Automatic::Plugin::Subscription::GGuide
3+
# Author:: soramugi <http://soramugi.net>
4+
# Created:: Jun 28, 2013
5+
# Updated:: Jun 28, 2013
6+
# Copyright:: Copyright (c) 2013 Automatic Ruby Developers.
7+
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
8+
9+
module Automatic::Plugin
10+
class SubscriptionGGuide
11+
G_GUIDE_RSS = 'http://tv.so-net.ne.jp/rss/schedulesBySearch.action?'
12+
13+
def initialize(config, pipeline=[])
14+
@config = config
15+
@pipeline = pipeline
16+
end
17+
18+
def run
19+
retries = 0
20+
begin
21+
@pipeline << Automatic::FeedParser.get(feed_url)
22+
rescue
23+
retries += 1
24+
Automatic::Log.puts("error", "ErrorCount: #{retries}, Fault in parsing: #{retries}")
25+
sleep @config['interval'].to_i unless @config['interval'].nil?
26+
retry if retries <= @config['retry'].to_i unless @config['retry'].nil?
27+
end
28+
29+
@pipeline
30+
end
31+
32+
def feed_url
33+
feed = G_GUIDE_RSS
34+
unless @config['keyword'].nil?
35+
feed += "condition.keyword=#{@config['keyword']}&"
36+
end
37+
feed += station_param
38+
URI.encode(feed)
39+
end
40+
41+
def station_param
42+
station = 0
43+
unless @config['station'].nil?
44+
station = '1' if @config['station'] == '地上波'
45+
end
46+
"stationPlatformId=#{station}&"
47+
end
48+
end
49+
end
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# -*- coding: utf-8 -*-
2+
# Name:: Automatic::Plugin::Subscription::g_guide
3+
# Author:: soramugi <http://soramugi.net>
4+
# Created:: May 21, 2013
5+
# Updated:: May 21, 2013
6+
# Copyright:: Copyright (c) 2012-2013 Automatic Ruby Developers.
7+
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
8+
9+
require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
10+
11+
require 'subscription/g_guide'
12+
13+
def g_guide(config = {}, pipeline = [])
14+
Automatic::Plugin::SubscriptionGGuide.new(config,pipeline)
15+
end
16+
17+
describe 'Automatic::Plugin::SubscriptionGGuide' do
18+
context 'when config' do
19+
describe 'is empty' do
20+
subject { g_guide }
21+
22+
its(:feed_url) {
23+
should == Automatic::Plugin::SubscriptionGGuide::G_GUIDE_RSS +
24+
'stationPlatformId=0&'
25+
}
26+
end
27+
describe 'keyword is anime' do
28+
config = { 'keyword' => 'anime' }
29+
subject { g_guide(config) }
30+
31+
its(:feed_url) {
32+
should == URI.encode(
33+
Automatic::Plugin::SubscriptionGGuide::G_GUIDE_RSS +
34+
"condition.keyword=#{config['keyword']}&" +
35+
'stationPlatformId=0&')
36+
}
37+
end
38+
describe 'station is 地上波' do
39+
config = { 'station' => '地上波' }
40+
subject { g_guide(config) }
41+
42+
its(:feed_url) {
43+
should == URI.encode(
44+
Automatic::Plugin::SubscriptionGGuide::G_GUIDE_RSS +
45+
'stationPlatformId=1&')
46+
}
47+
end
48+
end
49+
context 'when feed is empty' do
50+
51+
describe 'attestation error' do
52+
subject { g_guide }
53+
before do
54+
subject.should_receive(:feed_url).and_return('')
55+
end
56+
its(:run) { should be_empty }
57+
end
58+
59+
describe 'interval & retry was used error' do
60+
config = {'interval' => 1, 'retry' => 1}
61+
subject { g_guide(config) }
62+
before do
63+
subject.should_receive(:feed_url).exactly(2).times.and_return('')
64+
end
65+
its(:run) { should be_empty }
66+
end
67+
68+
end
69+
70+
context 'when feed' do
71+
describe 'config keyword' do
72+
config = { 'keyword' => 'アニメ', 'station' => '地上波' }
73+
subject { g_guide(config) }
74+
its(:run) { should have(1).feed }
75+
end
76+
77+
end
78+
end

0 commit comments

Comments
 (0)