qiita_mail 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +8 -0
- data/lib/qiita_mail/cli.rb +20 -4
- data/lib/qiita_mail/cli_core.rb +87 -0
- data/lib/qiita_mail/format_html.rb +51 -0
- data/lib/qiita_mail/format_text.rb +28 -0
- data/lib/qiita_mail/mailer.rb +35 -0
- data/lib/qiita_mail/marshal_file.rb +30 -0
- data/lib/qiita_mail/qiita_custom.rb +20 -0
- data/lib/qiita_mail/selector.rb +124 -0
- data/lib/qiita_mail/settings.rb +52 -0
- data/lib/qiita_mail/storage.rb +44 -0
- data/lib/qiita_mail/version.rb +1 -1
- data/qiita_mail.gemspec +3 -0
- data/test/data/pickup_cache.marshal +0 -0
- data/test/data/qiita_mail.yaml +8 -0
- data/test/file_test_utils.rb +52 -0
- data/test/test_cli.rb +33 -0
- data/test/test_helper.rb +3 -0
- data/test/test_settings.rb +38 -0
- data/test/test_storage.rb +40 -0
- metadata +57 -6
data/Rakefile
CHANGED
data/lib/qiita_mail/cli.rb
CHANGED
@@ -5,14 +5,30 @@
|
|
5
5
|
# @author ongaeshi
|
6
6
|
# @date 2012/10/12
|
7
7
|
|
8
|
-
require '
|
8
|
+
require 'rubygems'
|
9
9
|
require 'thor'
|
10
|
+
require 'qiita_mail/cli_core'
|
10
11
|
|
11
12
|
module QiitaMail
|
12
13
|
class CLI < Thor
|
13
|
-
desc "
|
14
|
-
def
|
15
|
-
|
14
|
+
desc "init", "Init setting."
|
15
|
+
def init
|
16
|
+
CliCore.new.init
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "deliver", "Deliver mail."
|
20
|
+
def deliver
|
21
|
+
CliCore.new.deliver
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "html [filename]", "Write html."
|
25
|
+
def html(filename = nil)
|
26
|
+
CliCore.new.file(:html, filename)
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "text [filename]", "Write text format."
|
30
|
+
def text(filename = nil)
|
31
|
+
CliCore.new.file(:text, filename)
|
16
32
|
end
|
17
33
|
end
|
18
34
|
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# @file
|
4
|
+
# @brief
|
5
|
+
# @author ongaeshi
|
6
|
+
# @date 2012/10/23
|
7
|
+
|
8
|
+
require 'qiita_mail/selector'
|
9
|
+
require 'qiita_mail/format_text'
|
10
|
+
require 'qiita_mail/format_html'
|
11
|
+
require 'qiita_mail/mailer'
|
12
|
+
require 'qiita_mail/storage'
|
13
|
+
require 'qiita_mail/settings'
|
14
|
+
|
15
|
+
module QiitaMail
|
16
|
+
class CliCore
|
17
|
+
def initialize
|
18
|
+
@settings = Settings.new
|
19
|
+
@storage = Storage.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def init
|
23
|
+
if (@settings.empty?)
|
24
|
+
@settings.save
|
25
|
+
puts "Create -> #{Settings.default_filename}"
|
26
|
+
puts "Please edit YAML settings!"
|
27
|
+
else
|
28
|
+
puts "Already exists '#{Settings.default_filename}'."
|
29
|
+
puts "Please edit YAML settings!"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def deliver
|
34
|
+
# ピックアップ
|
35
|
+
puts "Pickup <---- Qiita.com"
|
36
|
+
mail_body = pickup_and_format(:html)
|
37
|
+
|
38
|
+
# メールの送信
|
39
|
+
puts "Send mail -> #{@settings.email}"
|
40
|
+
mailer = Mailer.new(@settings.email, mail_body)
|
41
|
+
mailer.deliver
|
42
|
+
end
|
43
|
+
|
44
|
+
def file(format, filename = nil)
|
45
|
+
# ピックアップ
|
46
|
+
puts "Pickup <------ Qiita.com"
|
47
|
+
mail_body = pickup_and_format(format)
|
48
|
+
|
49
|
+
# ファイルに書き込み
|
50
|
+
puts "Write '#{format.to_s}' -> #{filename}"
|
51
|
+
write_or_puts(filename, mail_body)
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def pickup_and_format(kind)
|
57
|
+
# 記事をピックアップ
|
58
|
+
selector = Selector.new(@settings, @storage)
|
59
|
+
pickup_items = selector.pickup(5)
|
60
|
+
|
61
|
+
# ピックアップした記事をストレージに記録
|
62
|
+
pickup_items.each do |item|
|
63
|
+
@storage.add_reading(item.uuid)
|
64
|
+
end
|
65
|
+
@storage.save
|
66
|
+
|
67
|
+
# テキスト整形
|
68
|
+
case kind
|
69
|
+
when :html
|
70
|
+
FormatHTML.new(pickup_items).to_s
|
71
|
+
when :text
|
72
|
+
FormatText.new(pickup_items).to_s
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def write_or_puts(filename, str)
|
77
|
+
if (filename)
|
78
|
+
open(filename, "w") do |f|
|
79
|
+
f.write str
|
80
|
+
end
|
81
|
+
else
|
82
|
+
puts str
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# @file
|
4
|
+
# @brief
|
5
|
+
# @author ongaeshi
|
6
|
+
# @date 2012/10/13
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require 'qiita'
|
10
|
+
require 'nokogiri'
|
11
|
+
|
12
|
+
module QiitaMail
|
13
|
+
class FormatHTML
|
14
|
+
def initialize(items)
|
15
|
+
@items = items
|
16
|
+
end
|
17
|
+
|
18
|
+
HEADER = <<EOF
|
19
|
+
<!DOCTYPE html>
|
20
|
+
<html>
|
21
|
+
<head>
|
22
|
+
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
23
|
+
<title>Qiita Mail</title>
|
24
|
+
</head>
|
25
|
+
<body style="color:#000000; font-size:14px;">
|
26
|
+
<div id="banner" style="font-size: 36px; color:#FFFFFF; background-color:#5ABB0E">QiitaMail</div>
|
27
|
+
<p>こんにちは!</p>
|
28
|
+
<p><a href="http://qiita.com">Qiita</a>で今話題になっている記事をお届けします。</p>
|
29
|
+
EOF
|
30
|
+
|
31
|
+
FOOTER = <<EOF
|
32
|
+
</body>
|
33
|
+
</html>
|
34
|
+
EOF
|
35
|
+
|
36
|
+
def to_s
|
37
|
+
HEADER + @items.map {|item|
|
38
|
+
summary = Nokogiri::HTML(item.body).inner_text
|
39
|
+
summary = summary[0..200] + '...' if summary.length > 200
|
40
|
+
summary = summary.gsub("\n", "<br>")
|
41
|
+
|
42
|
+
<<EOF
|
43
|
+
<hr>
|
44
|
+
<div id="title" style="font-size: 28px;"><img src="#{item.user.profile_image_url}" style="margin-right: 5px; width: 72px;"/><a href="#{item.url}" style="color:#2C6EBD; text-decoration:none;">#{item.title}</a></div>
|
45
|
+
<div id="summary" style="background-color:#FCFCFC; border-style: solid; border-width: 1px; border-color: #DDDDDD; margin: 10px 5px; padding: 10px;">#{summary} <a href="#{item.url}">続きを読む</a> </div>
|
46
|
+
<div id="footer">ストック(#{item.stock_count}) コメント(#{item.comment_count}) #{item.created_at_in_words}</div>
|
47
|
+
EOF
|
48
|
+
}.join("\n") + FOOTER
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# @file
|
4
|
+
# @brief
|
5
|
+
# @author ongaeshi
|
6
|
+
# @date 2012/10/13
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require 'qiita'
|
10
|
+
require 'pp'
|
11
|
+
|
12
|
+
module QiitaMail
|
13
|
+
class FormatText
|
14
|
+
def initialize(items)
|
15
|
+
@items = items
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
@items.map {|item|
|
20
|
+
<<EOF
|
21
|
+
#{item.title}
|
22
|
+
#{item.url}
|
23
|
+
ストック(#{item.stock_count}) コメント(#{item.comment_count}) #{item.created_at_in_words}
|
24
|
+
EOF
|
25
|
+
}.join("\n")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# @file
|
4
|
+
# @brief
|
5
|
+
# @author ongaeshi
|
6
|
+
# @date 2012/10/13
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require 'mail'
|
10
|
+
|
11
|
+
module QiitaMail
|
12
|
+
class Mailer
|
13
|
+
def initialize(to, body)
|
14
|
+
@mail = Mail.new do
|
15
|
+
to to
|
16
|
+
subject 'Qiita Mail'
|
17
|
+
# body mail_body
|
18
|
+
end
|
19
|
+
|
20
|
+
@mail.charset = 'utf-8'
|
21
|
+
|
22
|
+
@mail.html_part = Mail::Part.new {
|
23
|
+
content_type 'text/html; charset=UTF-8'
|
24
|
+
body body
|
25
|
+
}
|
26
|
+
|
27
|
+
@mail.delivery_method :sendmail
|
28
|
+
end
|
29
|
+
|
30
|
+
def deliver
|
31
|
+
@mail.deliver
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# @file
|
4
|
+
# @brief
|
5
|
+
# @author ongaeshi
|
6
|
+
# @date 2012/10/21
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require 'hashie'
|
10
|
+
|
11
|
+
module QiitaMail
|
12
|
+
module MarshalFile
|
13
|
+
module_function
|
14
|
+
|
15
|
+
def save(filename, obj)
|
16
|
+
# puts "MarshalFile#save -> #{filename}"
|
17
|
+
open(filename, "w") do |f|
|
18
|
+
f.write Marshal.dump(obj)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def load(filename)
|
23
|
+
# puts "MarshalFile#load <- #{filename}"
|
24
|
+
open(filename) do |f|
|
25
|
+
Marshal.load(f.read)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# @file
|
4
|
+
# @brief
|
5
|
+
# @author ongaeshi
|
6
|
+
# @date 2012/10/27
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require 'qiita'
|
10
|
+
|
11
|
+
module Qiita
|
12
|
+
class Client
|
13
|
+
module Items
|
14
|
+
def items(params)
|
15
|
+
get "/items", params
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,124 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# @file
|
4
|
+
# @brief
|
5
|
+
# @author ongaeshi
|
6
|
+
# @date 2012/10/13
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require 'qiita_mail/marshal_file'
|
10
|
+
require 'qiita_mail/qiita_custom'
|
11
|
+
|
12
|
+
module QiitaMail
|
13
|
+
CACHE_FILE = File.join(File.dirname(__FILE__), '../../test/data/pickup_cache.marshal')
|
14
|
+
|
15
|
+
class Selector
|
16
|
+
# -----------------------
|
17
|
+
# パラメータ
|
18
|
+
|
19
|
+
TOP_BONUS = 30
|
20
|
+
PER_PAGE = 40
|
21
|
+
|
22
|
+
# デバッグ用
|
23
|
+
USE_CACHE = false # デバッグ用のキャッシュからデータをロードする(高速)
|
24
|
+
|
25
|
+
# -----------------------
|
26
|
+
|
27
|
+
def initialize(settings, storage)
|
28
|
+
@settings = settings
|
29
|
+
@storage = storage
|
30
|
+
end
|
31
|
+
|
32
|
+
def pickup(num = 5)
|
33
|
+
# 候補記事をピックアップ
|
34
|
+
container = pickup_in
|
35
|
+
|
36
|
+
puts "Calculate Score .."
|
37
|
+
|
38
|
+
# 既読記事は除外
|
39
|
+
container.each_with_index do |items, index|
|
40
|
+
container[index].delete_if do |item|
|
41
|
+
@storage.reading? item.uuid
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# ScoredItemに変換、スコア順にソート
|
46
|
+
container = container.map {|items| items.map {|item| ScoredItem.new item}.sort.reverse }
|
47
|
+
|
48
|
+
# ボーナス加算
|
49
|
+
container.each do |items|
|
50
|
+
items[0].add_score(TOP_BONUS) unless items.empty?
|
51
|
+
end
|
52
|
+
|
53
|
+
# 合算して、重複は削除、スコア順にソート
|
54
|
+
results = container.reduce([]) {|r,i| r += i}.uniq{|i| i.item.uuid}.sort.reverse
|
55
|
+
|
56
|
+
# スコアの高い物をピックアップ、Itemに戻して返す
|
57
|
+
results[0..num-1].map {|scored_item| scored_item.item}
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
class ScoredItem
|
63
|
+
attr_reader :item
|
64
|
+
attr_reader :score
|
65
|
+
|
66
|
+
def initialize(item)
|
67
|
+
@item = item
|
68
|
+
@score = item.stock_count * 10 + item.comment_count * 20
|
69
|
+
end
|
70
|
+
|
71
|
+
def add_score(v)
|
72
|
+
@score += v
|
73
|
+
end
|
74
|
+
|
75
|
+
def <=>(rhs)
|
76
|
+
self.score <=> rhs.score
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def print_container(container)
|
81
|
+
container.each_with_index do |items, index|
|
82
|
+
puts "-- #{@settings.keywords[index]} --"
|
83
|
+
print_items(items)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def print_items(items)
|
88
|
+
items.each do |item|
|
89
|
+
if item.class == ScoredItem
|
90
|
+
puts format("%3d: %s", item.score, item.item.title)
|
91
|
+
else
|
92
|
+
p [item.uuid, item.title]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def pickup_in
|
98
|
+
unless USE_CACHE
|
99
|
+
items = pickup_items
|
100
|
+
# MarshalFile.save(CACHE_FILE, items) # @debug キャッシュを保存
|
101
|
+
items
|
102
|
+
else
|
103
|
+
items = MarshalFile.load(CACHE_FILE)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def pickup_items
|
108
|
+
items = []
|
109
|
+
|
110
|
+
# 最新記事から取得
|
111
|
+
items << Qiita.items({:per_page => PER_PAGE})
|
112
|
+
|
113
|
+
# 登録したキーワードから取得
|
114
|
+
@settings.keywords.each do |tag|
|
115
|
+
# items << Qiita.tag_items(tag)
|
116
|
+
items << Qiita.search_items(tag, {:per_page => PER_PAGE})
|
117
|
+
end
|
118
|
+
|
119
|
+
items
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# @file
|
4
|
+
# @brief
|
5
|
+
# @author ongaeshi
|
6
|
+
# @date 2012/10/22
|
7
|
+
|
8
|
+
require 'yaml'
|
9
|
+
|
10
|
+
module QiitaMail
|
11
|
+
class Settings
|
12
|
+
def self.default_filename
|
13
|
+
File.expand_path('~/.qiita_mail.yaml')
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(filename = Settings.default_filename)
|
17
|
+
@filename = filename
|
18
|
+
|
19
|
+
if File.exist?(@filename)
|
20
|
+
open(@filename) do |f|
|
21
|
+
@data = YAML.load(f.read)
|
22
|
+
end
|
23
|
+
else
|
24
|
+
@data = {
|
25
|
+
'email' => '',
|
26
|
+
'keywords' => []
|
27
|
+
}
|
28
|
+
@is_empty = true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def save
|
33
|
+
open(@filename, "w") do |f|
|
34
|
+
f.write YAML.dump(@data)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def email
|
39
|
+
@data['email']
|
40
|
+
end
|
41
|
+
|
42
|
+
def keywords
|
43
|
+
@data['keywords']
|
44
|
+
end
|
45
|
+
|
46
|
+
def empty?
|
47
|
+
!@is_empty.nil?
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# @file
|
4
|
+
# @brief
|
5
|
+
# @author ongaeshi
|
6
|
+
# @date 2012/10/21
|
7
|
+
|
8
|
+
require 'qiita_mail/marshal_file'
|
9
|
+
|
10
|
+
module QiitaMail
|
11
|
+
class Storage
|
12
|
+
def self.default_filename
|
13
|
+
File.expand_path('~/.qiita_mail.marshal')
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(filename = Storage.default_filename)
|
17
|
+
@filename = filename
|
18
|
+
|
19
|
+
if File.exist?(@filename)
|
20
|
+
@data = MarshalFile.load(@filename)
|
21
|
+
else
|
22
|
+
@data = {}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def add_reading(uuid)
|
27
|
+
@data[:reading] ||= {}
|
28
|
+
@data[:reading][uuid] = true
|
29
|
+
end
|
30
|
+
|
31
|
+
def reading?(uuid)
|
32
|
+
if @data.has_key? :reading
|
33
|
+
@data[:reading].has_key? uuid
|
34
|
+
else
|
35
|
+
false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def save
|
40
|
+
MarshalFile.save(@filename, @data)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
data/lib/qiita_mail/version.rb
CHANGED
data/qiita_mail.gemspec
CHANGED
Binary file
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# @file
|
4
|
+
# @brief ファイルテスト用ユーティリティ
|
5
|
+
# @author ongaeshi
|
6
|
+
# @date 2011/02/21
|
7
|
+
#
|
8
|
+
# 使い方:
|
9
|
+
#
|
10
|
+
# class TestCdstk < Test::Unit::TestCase
|
11
|
+
# include FileTestUtils
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# すると以下のことを自動でやってくれます
|
15
|
+
#
|
16
|
+
# 1. tmpディレクトリの作成
|
17
|
+
# 2. tmpディレクトリに移動
|
18
|
+
# 3. テスト実行
|
19
|
+
# 4. 元のディレクトリに戻る
|
20
|
+
# 5. tmpディレクトリの削除
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'fileutils'
|
24
|
+
|
25
|
+
module FileTestUtils
|
26
|
+
def setup
|
27
|
+
create_tmp_dir
|
28
|
+
FileUtils.cd(@tmp_dir)
|
29
|
+
end
|
30
|
+
|
31
|
+
def teardown
|
32
|
+
teardown_custom(true)
|
33
|
+
end
|
34
|
+
|
35
|
+
def teardown_custom(is_remove_dir)
|
36
|
+
FileUtils.cd(@prev_dir)
|
37
|
+
FileUtils.rm_rf(@tmp_dir) if (is_remove_dir)
|
38
|
+
end
|
39
|
+
|
40
|
+
def tmp_path(path)
|
41
|
+
File.join @tmp_dir, path
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def create_tmp_dir
|
47
|
+
@prev_dir = Dir.pwd
|
48
|
+
@tmp_dir = File.join(File.dirname(__FILE__), "tmp")
|
49
|
+
FileUtils.rm_rf(@tmp_dir)
|
50
|
+
FileUtils.mkdir_p(@tmp_dir)
|
51
|
+
end
|
52
|
+
end
|
data/test/test_cli.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# @file
|
4
|
+
# @brief
|
5
|
+
# @author ongaeshi
|
6
|
+
# @date 2012/10/15
|
7
|
+
|
8
|
+
require 'qiita_mail/cli.rb'
|
9
|
+
require 'test_helper'
|
10
|
+
|
11
|
+
module QiitaMail
|
12
|
+
class TestCLI < Test::Unit::TestCase
|
13
|
+
def setup
|
14
|
+
$stdout = StringIO.new
|
15
|
+
@orig_stdout = $stdout
|
16
|
+
end
|
17
|
+
|
18
|
+
def teardown
|
19
|
+
$stdout = @orig_stdout
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_no_arg
|
23
|
+
assert_match /Tasks:/, command("")
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def command(arg)
|
29
|
+
CLI.start(arg.split)
|
30
|
+
$stdout.string
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# @file
|
4
|
+
# @brief
|
5
|
+
# @author ongaeshi
|
6
|
+
# @date 2012/10/21
|
7
|
+
|
8
|
+
require 'qiita_mail/settings'
|
9
|
+
require 'test_helper'
|
10
|
+
|
11
|
+
module QiitaMail
|
12
|
+
class TestSettings < Test::Unit::TestCase
|
13
|
+
include FileTestUtils
|
14
|
+
|
15
|
+
def test_default_filename
|
16
|
+
assert_match /\.qiita_mail.yaml/, Settings.default_filename
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_empty
|
20
|
+
obj = Settings.new('.qiita_mail.yaml') # データが無い場合は新規作成
|
21
|
+
assert_equal "", obj.email
|
22
|
+
assert_equal [], obj.keywords
|
23
|
+
assert_equal true, obj.empty?
|
24
|
+
obj.save
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_exist_yaml
|
28
|
+
obj = Settings.new(tmp_path('../data/qiita_mail.yaml'))
|
29
|
+
assert_equal "qiita_mail@example.com", obj.email
|
30
|
+
assert_equal ['ruby', 'javascript'], obj.keywords
|
31
|
+
assert_equal false, obj.empty?
|
32
|
+
end
|
33
|
+
|
34
|
+
def teardown
|
35
|
+
teardown_custom(true)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# @file
|
4
|
+
# @brief
|
5
|
+
# @author ongaeshi
|
6
|
+
# @date 2012/10/21
|
7
|
+
|
8
|
+
require 'qiita_mail/storage.rb'
|
9
|
+
require 'test_helper'
|
10
|
+
|
11
|
+
module QiitaMail
|
12
|
+
class TestStorage < Test::Unit::TestCase
|
13
|
+
include FileTestUtils
|
14
|
+
|
15
|
+
def test_default_filename
|
16
|
+
assert_match /\.qiita_mail.marshal/, Storage.default_filename
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_initialize
|
20
|
+
# データが無い場合は新規作成
|
21
|
+
obj = Storage.new('.qiita_mail')
|
22
|
+
assert_equal false, obj.reading?('7f15')
|
23
|
+
obj.add_reading('7f15')
|
24
|
+
assert_equal true, obj.reading?('7f15')
|
25
|
+
obj.save
|
26
|
+
|
27
|
+
# ロード
|
28
|
+
obj = Storage.new('.qiita_mail')
|
29
|
+
assert_equal true, obj.reading?('7f15')
|
30
|
+
assert_equal false, obj.reading?('7f16')
|
31
|
+
obj.add_reading('7f16')
|
32
|
+
assert_equal true, obj.reading?('7f16')
|
33
|
+
obj.save
|
34
|
+
end
|
35
|
+
|
36
|
+
def teardown
|
37
|
+
teardown_custom(true)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qiita_mail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirement: &2153154780 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,12 +21,40 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: *2153154780
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: qiita
|
27
|
+
requirement: &2153154260 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2153154260
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: mail
|
38
|
+
requirement: &2153153620 !ruby/object:Gem::Requirement
|
25
39
|
none: false
|
26
40
|
requirements:
|
27
41
|
- - ! '>='
|
28
42
|
- !ruby/object:Gem::Version
|
29
43
|
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2153153620
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: nokogiri
|
49
|
+
requirement: &2153152780 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2153152780
|
30
58
|
description: Write a gem description
|
31
59
|
email:
|
32
60
|
- ongaeshi0621@gmail.com
|
@@ -41,8 +69,24 @@ files:
|
|
41
69
|
- bin/qiita_mail
|
42
70
|
- lib/qiita_mail.rb
|
43
71
|
- lib/qiita_mail/cli.rb
|
72
|
+
- lib/qiita_mail/cli_core.rb
|
73
|
+
- lib/qiita_mail/format_html.rb
|
74
|
+
- lib/qiita_mail/format_text.rb
|
75
|
+
- lib/qiita_mail/mailer.rb
|
76
|
+
- lib/qiita_mail/marshal_file.rb
|
77
|
+
- lib/qiita_mail/qiita_custom.rb
|
78
|
+
- lib/qiita_mail/selector.rb
|
79
|
+
- lib/qiita_mail/settings.rb
|
80
|
+
- lib/qiita_mail/storage.rb
|
44
81
|
- lib/qiita_mail/version.rb
|
45
82
|
- qiita_mail.gemspec
|
83
|
+
- test/data/pickup_cache.marshal
|
84
|
+
- test/data/qiita_mail.yaml
|
85
|
+
- test/file_test_utils.rb
|
86
|
+
- test/test_cli.rb
|
87
|
+
- test/test_helper.rb
|
88
|
+
- test/test_settings.rb
|
89
|
+
- test/test_storage.rb
|
46
90
|
homepage: ''
|
47
91
|
licenses: []
|
48
92
|
post_install_message:
|
@@ -63,9 +107,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
107
|
version: '0'
|
64
108
|
requirements: []
|
65
109
|
rubyforge_project: qiita_mail
|
66
|
-
rubygems_version: 1.8.
|
110
|
+
rubygems_version: 1.8.11
|
67
111
|
signing_key:
|
68
112
|
specification_version: 3
|
69
113
|
summary: Write a gem summary
|
70
|
-
test_files:
|
114
|
+
test_files:
|
115
|
+
- test/data/pickup_cache.marshal
|
116
|
+
- test/data/qiita_mail.yaml
|
117
|
+
- test/file_test_utils.rb
|
118
|
+
- test/test_cli.rb
|
119
|
+
- test/test_helper.rb
|
120
|
+
- test/test_settings.rb
|
121
|
+
- test/test_storage.rb
|
71
122
|
has_rdoc:
|