Skip to content

Commit 799e1d8

Browse files
committed
Add Subscription Pocket Plugins.
1 parent ec73370 commit 799e1d8

File tree

5 files changed

+182
-0
lines changed

5 files changed

+182
-0
lines changed

doc/PLUGINS

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,26 @@ SubscriptionWeather
135135
retry: RETRY_COUNT
136136

137137

138+
SubscriptionPocket
139+
----------------
140+
[Path]
141+
/plugins/subscription/pocket.rb
142+
143+
[Abstract]
144+
Pocket API is struck and it is creation of feed.
145+
146+
[Syntax]
147+
- module: SubscriptionPocket
148+
config:
149+
consumer_key: 'your_consumer_key'
150+
access_token: 'your_access_token'
151+
optional: # see http://getpocket.com/developer/docs/v3/retrieve
152+
favorite: 1
153+
count: 2
154+
interval: INTERVAL_FOR_SCRAPING (in seconds.)
155+
retry: RETRY_COUNT
156+
157+
138158
FilterSort
139159
----------
140160
[Path]

doc/PLUGINS.ja

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,26 @@ SubscriptionText
135135
retry: エラー時のリトライ回数 (回数, 省略時 0)
136136

137137

138+
SubscriptionPocket
139+
----------------
140+
[パス]
141+
/plugins/subscription/pocket.rb
142+
143+
[概要]
144+
Pocket APIをたたいてfeedの作成
145+
146+
[レシピ記法]
147+
- module: SubscriptionPocket
148+
config:
149+
consumer_key: 'your_consumer_key'
150+
access_token: 'your_access_token'
151+
optional: # see http://getpocket.com/developer/docs/v3/retrieve
152+
favorite: 1
153+
count: 2
154+
interval: スクレイピングの間隔 (秒数, 省略可)
155+
retry: エラー時のリトライ回数 (回数, 省略時 0)
156+
157+
138158
FilterSort
139159
----------
140160
[パス]

plugins/subscription/pocket.rb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# -*- coding: utf-8 -*-
2+
# Name:: Automatic::Plugin::Subscription::Pocket
3+
# Author:: soramugi <http://soramugi.net>
4+
# Created:: May 21, 2013
5+
# Updated:: May 21, 2013
6+
# Copyright:: soramugi Copyright (c) 2013
7+
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
8+
9+
module Automatic::Plugin
10+
class DummyFeed
11+
def initialize(link,title,description)
12+
@title = title
13+
@link = link
14+
@description = description
15+
end
16+
17+
def title() @title end
18+
def link() @link end
19+
def description() @description end
20+
end
21+
22+
class SubscriptionPocket
23+
require 'pocket'
24+
25+
def initialize(config, pipeline=[])
26+
@config = config
27+
@pipeline = pipeline
28+
Pocket.configure do |c|
29+
c.consumer_key = @config['consumer_key']
30+
c.access_token = @config['access_token']
31+
end
32+
@client = Pocket.client
33+
end
34+
35+
def run
36+
retries = 0
37+
begin
38+
dummyfeeds = cleate_dummy_feed(@client.retrieve(@config['optional']))
39+
@pipeline << Automatic::FeedParser.create(dummyfeeds)
40+
rescue
41+
retries += 1
42+
Automatic::Log.puts("error", "ErrorCount: #{retries}, Fault in parsing: #{retries}")
43+
sleep @config['interval'].to_i unless @config['interval'].nil?
44+
retry if retries <= @config['retry'].to_i unless @config['retry'].nil?
45+
end
46+
47+
@pipeline
48+
end
49+
50+
def cleate_dummy_feed(retrieve)
51+
dummyFeeds = []
52+
retrieve['list'].each {|key,list|
53+
dummyFeeds << DummyFeed.new(
54+
list['given_url'], list['given_title'], list['excerpt']
55+
)
56+
}
57+
dummyFeeds
58+
end
59+
end
60+
end
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# -*- coding: utf-8 -*-
2+
# Name:: Automatic::Plugin::Subscription::Pocket
3+
# Author:: soramugi <http://soramugi.net>
4+
# Created:: May 21, 2013
5+
# Updated:: May 21, 2013
6+
# Copyright:: soramugi Copyright (c) 2013
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/pocket'
12+
13+
def pocket(config = {}, pipeline = [])
14+
Automatic::Plugin::SubscriptionPocket.new(config,pipeline)
15+
end
16+
17+
describe 'Automatic::Plugin::SubscriptionPocket' do
18+
context 'when feed is empty' do
19+
20+
describe 'attestation error' do
21+
subject { pocket }
22+
23+
its(:run) { should be_empty }
24+
end
25+
26+
describe 'interval & retry was used error' do
27+
config = {'interval' => 1, 'retry' => 1}
28+
subject { pocket(config) }
29+
30+
its(:run) { should be_empty }
31+
end
32+
33+
end
34+
35+
context 'when feed' do
36+
37+
describe 'config optional' do
38+
config = { 'optional' => {
39+
'count' => 1,
40+
'favorite' => 1
41+
}}
42+
subject { pocket(config) }
43+
before do
44+
retrieve = {'list' => {
45+
'id' => {
46+
'given_url' => 'http://github.com',
47+
'given_title' => 'GitHub',
48+
'excerpt' => 'github'
49+
}}}
50+
client = mock("client")
51+
client.should_receive(:retrieve).
52+
with(config['optional']).
53+
and_return(retrieve)
54+
subject.instance_variable_set(:@client, client)
55+
end
56+
57+
its(:run) { should have(1).item }
58+
end
59+
60+
end
61+
end

test/integration/test_pocket.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
global:
2+
timezone: Asia/Tokyo
3+
cache:
4+
base: /tmp
5+
log:
6+
level: warn
7+
8+
plugins:
9+
- module: SubscriptionPocket
10+
config:
11+
consumer_key: 'consumer_key'
12+
access_token: 'access_token'
13+
optional:
14+
favorite: 1
15+
count: 2
16+
17+
- module: StorePermalink
18+
config:
19+
db: test_pocket.db
20+
21+
#- module: PublishConsole

0 commit comments

Comments
 (0)