twog 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +12 -0
- data/.github/workflows/ruby.yml +12 -9
- data/.ruby-version +1 -1
- data/Gemfile +13 -9
- data/Gemfile.lock +88 -56
- data/Rakefile +15 -14
- data/VERSION.yml +4 -4
- data/bin/twog +39 -33
- data/lib/twog.rb +10 -7
- data/lib/twog/blog_posts_handler.rb +4 -1
- data/lib/twog/post.rb +6 -4
- data/lib/twog/rss_entry_to_twog_post_mapper.rb +2 -0
- data/lib/twog/rss_parser.rb +5 -4
- data/lib/twog/twitter_handler.rb +17 -13
- data/spec/spec_helper.rb +30 -30
- data/spec/twog/blog_posts_handler_spec.rb +8 -6
- data/spec/twog/post_spec.rb +24 -23
- data/spec/twog/rss_entry_to_twog_post_mapper_spec.rb +11 -9
- data/spec/twog/rss_parser_spec.rb +8 -6
- data/spec/twog/twitter_handler_spec.rb +18 -17
- data/spec/twog/twog_spec.rb +3 -1
- data/twog.gemspec +25 -20
- metadata +60 -31
data/lib/twog.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubygems
|
2
4
|
require 'rubygems'
|
3
5
|
|
4
6
|
# 3rd party
|
@@ -14,7 +16,6 @@ require 'twog/blog_posts_handler'
|
|
14
16
|
require 'twog/twitter_handler'
|
15
17
|
require 'twog/post'
|
16
18
|
|
17
|
-
|
18
19
|
module Twog
|
19
20
|
module Twog
|
20
21
|
include RssParser
|
@@ -24,26 +25,28 @@ module Twog
|
|
24
25
|
|
25
26
|
def run(conf)
|
26
27
|
posts = get_posts_to_tweet(conf)
|
27
|
-
return unless posts
|
28
|
+
return unless posts&.length&.positive?
|
29
|
+
|
28
30
|
bitly = get_bitly_from(conf)
|
29
31
|
tweet(posts, conf, bitly)
|
30
32
|
end
|
31
33
|
|
32
34
|
def get_posts_to_tweet(conf)
|
33
35
|
posts = parse_feed(conf['rss_feed'])
|
34
|
-
posts = map(posts)
|
36
|
+
posts = map(posts)
|
35
37
|
posts = get_new_blog_posts(posts, conf['last_blog_post_tweeted'])
|
36
38
|
end
|
37
39
|
|
38
40
|
def get_bitly_from(conf)
|
39
41
|
bitly_username = conf['bitly_username']
|
40
42
|
bitly_api_key = conf['bitly_api_key']
|
41
|
-
return nil unless
|
43
|
+
return nil unless bitly_username && bitly_api_key
|
44
|
+
|
42
45
|
Bitly.new(bitly_username, bitly_api_key)
|
43
46
|
end
|
44
|
-
|
47
|
+
|
45
48
|
def version
|
46
|
-
yml = YAML.
|
49
|
+
yml = YAML.safe_load(File.read(File.join(File.dirname(__FILE__), *%w[.. VERSION.yml])))
|
47
50
|
"#{yml[:major]}.#{yml[:minor]}.#{yml[:patch]}"
|
48
51
|
end
|
49
52
|
end
|
@@ -1,8 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Twog
|
2
4
|
module BlogPostsHandler
|
3
5
|
def get_new_blog_posts(posts, last_blog_post_tweeted)
|
4
|
-
return [] unless posts
|
6
|
+
return [] unless posts&.length&.positive?
|
5
7
|
return posts unless last_blog_post_tweeted
|
8
|
+
|
6
9
|
new_posts = posts.reject do |post|
|
7
10
|
Time.parse(post.date.to_s) <= Time.parse(last_blog_post_tweeted.to_s)
|
8
11
|
end
|
data/lib/twog/post.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Twog
|
2
4
|
class Post
|
3
5
|
def initialize(post)
|
@@ -11,13 +13,13 @@ module Twog
|
|
11
13
|
def date
|
12
14
|
@post.respond_to?('updated') ? @post.updated.content : @post.pubDate
|
13
15
|
end
|
14
|
-
|
16
|
+
|
15
17
|
def title
|
16
18
|
@post.title.respond_to?('content') ? @post.title.content : @post.title
|
17
19
|
end
|
18
|
-
|
19
|
-
def <=>(
|
20
|
-
Time.parse(
|
20
|
+
|
21
|
+
def <=>(other)
|
22
|
+
Time.parse(date.to_s) <=> Time.parse(other.date.to_s)
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
data/lib/twog/rss_parser.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Twog
|
2
4
|
module RssParser
|
3
5
|
def parse_feed(rss_feed_url)
|
4
|
-
raise
|
6
|
+
raise StandardError, 'RSS feed missing' unless rss_feed_url
|
7
|
+
|
5
8
|
rss = RSS::Parser.parse(get_content(rss_feed_url), false)
|
6
9
|
rss.items
|
7
10
|
end
|
8
11
|
|
9
12
|
def get_content(rss_feed_url)
|
10
|
-
open(rss_feed_url)
|
11
|
-
f.read
|
12
|
-
end
|
13
|
+
open(rss_feed_url, &:read)
|
13
14
|
end
|
14
15
|
end
|
15
16
|
end
|
data/lib/twog/twitter_handler.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Twog
|
2
4
|
module TwitterHandler
|
3
5
|
def tweet(posts, conf, bitly)
|
4
|
-
return unless posts
|
5
|
-
raise
|
6
|
-
raise
|
7
|
-
raise
|
8
|
-
raise
|
6
|
+
return unless posts&.length&.positive?
|
7
|
+
raise StandardError, 'OAuth Consumer Key missing' unless conf['consumer_key']
|
8
|
+
raise StandardError, 'OAuth Consumer Secret missing' unless conf['consumer_secret']
|
9
|
+
raise StandardError, 'OAuth Access Token missing' unless conf['access_token']
|
10
|
+
raise StandardError, 'OAuth Access Secret missing' unless conf['access_secret']
|
11
|
+
|
9
12
|
posts.sort.each do |post|
|
10
13
|
link = bitly ? bitly.shorten(post.link).short_url : item.link
|
11
14
|
use_twitter_oauth(post, link, conf)
|
@@ -15,25 +18,26 @@ module Twog
|
|
15
18
|
|
16
19
|
def use_twitter_oauth(post, link, conf)
|
17
20
|
client = TwitterOAuth::Client.new(
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
21
|
-
:
|
21
|
+
consumer_key: conf['consumer_key'],
|
22
|
+
consumer_secret: conf['consumer_secret'],
|
23
|
+
token: conf['access_token'],
|
24
|
+
secret: conf['access_secret']
|
22
25
|
)
|
23
|
-
raise
|
26
|
+
raise StandardError, 'TwitterOAuth unauthorized' unless client.authorized?
|
27
|
+
|
24
28
|
text = ensure_text_is_of_length(140, post.title, link)
|
25
29
|
client.update(text)
|
26
30
|
end
|
27
31
|
|
28
32
|
def ensure_text_is_of_length(length, title, link)
|
29
|
-
blogged =
|
30
|
-
title = title[0,(length-((
|
33
|
+
blogged = 'blogged:'
|
34
|
+
title = title[0, (length - ((' ' * 2).length + blogged.length + link.length))]
|
31
35
|
[blogged, title, link].join(' ')
|
32
36
|
end
|
33
37
|
|
34
38
|
def update_config_file_with_latest_tweet_date(last_blog_post_tweeted, conf)
|
35
39
|
conf['last_blog_post_tweeted'] = last_blog_post_tweeted
|
36
|
-
File.open("#{ENV['HOME']}/.twog/conf.yaml",
|
40
|
+
File.open("#{ENV['HOME']}/.twog/conf.yaml", 'w') { |out| out.write(conf.to_yaml) }
|
37
41
|
end
|
38
42
|
end
|
39
43
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), '/../lib')
|
2
4
|
|
3
5
|
require 'rubygems'
|
4
6
|
require 'twog'
|
@@ -13,35 +15,34 @@ if ENV['COVERAGE']
|
|
13
15
|
end
|
14
16
|
|
15
17
|
def test_conf
|
16
|
-
@conf = {'rss_feed' => 'rss feed',
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
@conf = { 'rss_feed' => 'rss feed',
|
19
|
+
'bitly_username' => 'username',
|
20
|
+
'bitly_api_key' => 'api key',
|
21
|
+
'consumer_key' => 'consumerkey',
|
22
|
+
'consumer_secret' => 'consumersecret',
|
23
|
+
'access_token' => 'accesstoken',
|
24
|
+
'access_secret' => 'accesssecret',
|
25
|
+
'last_blog_post_tweeted' => '31 Mar 2010 07:52:17 -0600' }
|
24
26
|
end
|
25
27
|
|
26
28
|
def rss_feed_entry
|
27
|
-
|
28
|
-
|
29
|
-
<title>Gocode Vim Plugin and Go Modules</title>
|
30
|
-
<description>
|
31
|
-
<p><strong>Update</strong>: My friend <a href="https://twitter.com/_seemethere">Eli Uriegas</a> let me know that you don’t need <code class="highlighter-rouge">gocode</code> anymore since <code class="highlighter-rouge">vim-go</code> has autocompletion. I tested it out and he is correct. <a href="https://twitter.com/_seemethere/status/1081626050717728770">Here</a> is his tweet with a link to his dotfiles on how he sets up his <code class="highlighter-rouge">.vimrc</code> to use <code class="highlighter-rouge">vim-go</code></p> <p><em>Original Post:</em></p> <p>I recently purchased <a href="https://lets-go.alexedwards.net/">Let’s Go</a> from Alex Edwards. I wanted an end-to-end Golang website tutorial. It has been great. Lots learned.</p> <p>Unfortunately, he is using Go’s modules and the version of the gocode Vim plugin I was using did not support Go modules.</p> <h3 id="solution">Solution:</h3> <p>Use <a href="https://github.com/stamblerre/gocode">this fork</a> of the gocode Vim plugin and you’ll get support for Go modules.</p> <p>I use <a href="https://github.com/junegunn/vim-plug">Vim Plug</a> for my Vim plugins. Huge fan of Vundle but I like the post-actions feature of Plug. I just had to change one line of my vimrc and re-run updates.</p> <div class="language-diff highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="gh">diff --git a/vimrc b/vimrc index 3e8edf1..8395705 100644 </span><span class="gd">--- a/vimrc </span><span class="gi">+++ b/vimrc </span><span class="gu">@@ -73,7 +73,7 @@ endif </span> let editor_name='nvim' Plug 'zchee/deoplete-go', { 'do': 'make'} endif <span class="gd">- Plug 'nsf/gocode', { 'rtp': 'vim', 'do': '~/.config/nvim/plugged/gocode/vim/symlink.sh' } </span><span class="gi">+ Plug 'stamblerre/gocode', { 'rtp': 'vim', 'do': '~/.vim/plugged/gocode/vim/symlink.sh' } </span> Plug 'godoctor/godoctor.vim', {'for': 'go'} " Gocode refactoring tool " } </code></pre></div></div> <p>That is the line I had to change then run <code class="highlighter-rouge">:PlugUpdate!</code> and the new plugin was installed.</p> <p>I figured all of this out due to <a href="https://github.com/zchee/deoplete-go/issues/134#issuecomment-435436305">this comment</a> by <a href="https://github.com/cippaciong">Tommaso Sardelli</a> on Github. Thank you Tommaso.</p>
|
32
|
-
</description>
|
33
|
-
<pubDate>Sat, 05 Jan 2019 11:09:26 -0600</pubDate>
|
34
|
-
<link>
|
35
|
-
https://blog.jasonmeridth.com/posts/gocode-vim-plugin-and-go-modules/
|
36
|
-
</link>
|
37
|
-
<guid isPermaLink="true">
|
38
|
-
https://blog.jasonmeridth.com/posts/gocode-vim-plugin-and-go-modules/
|
39
|
-
</guid>
|
40
|
-
<category>go</category>
|
41
|
-
<category>vim</category>
|
42
|
-
</item>
|
43
|
-
|
44
|
-
return entry
|
29
|
+
<<~EOS
|
30
|
+
<item>
|
31
|
+
<title>Gocode Vim Plugin and Go Modules</title>
|
32
|
+
<description>
|
33
|
+
<p><strong>Update</strong>: My friend <a href="https://twitter.com/_seemethere">Eli Uriegas</a> let me know that you don’t need <code class="highlighter-rouge">gocode</code> anymore since <code class="highlighter-rouge">vim-go</code> has autocompletion. I tested it out and he is correct. <a href="https://twitter.com/_seemethere/status/1081626050717728770">Here</a> is his tweet with a link to his dotfiles on how he sets up his <code class="highlighter-rouge">.vimrc</code> to use <code class="highlighter-rouge">vim-go</code></p> <p><em>Original Post:</em></p> <p>I recently purchased <a href="https://lets-go.alexedwards.net/">Let’s Go</a> from Alex Edwards. I wanted an end-to-end Golang website tutorial. It has been great. Lots learned.</p> <p>Unfortunately, he is using Go’s modules and the version of the gocode Vim plugin I was using did not support Go modules.</p> <h3 id="solution">Solution:</h3> <p>Use <a href="https://github.com/stamblerre/gocode">this fork</a> of the gocode Vim plugin and you’ll get support for Go modules.</p> <p>I use <a href="https://github.com/junegunn/vim-plug">Vim Plug</a> for my Vim plugins. Huge fan of Vundle but I like the post-actions feature of Plug. I just had to change one line of my vimrc and re-run updates.</p> <div class="language-diff highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="gh">diff --git a/vimrc b/vimrc index 3e8edf1..8395705 100644 </span><span class="gd">--- a/vimrc </span><span class="gi">+++ b/vimrc </span><span class="gu">@@ -73,7 +73,7 @@ endif </span> let editor_name='nvim' Plug 'zchee/deoplete-go', { 'do': 'make'} endif <span class="gd">- Plug 'nsf/gocode', { 'rtp': 'vim', 'do': '~/.config/nvim/plugged/gocode/vim/symlink.sh' } </span><span class="gi">+ Plug 'stamblerre/gocode', { 'rtp': 'vim', 'do': '~/.vim/plugged/gocode/vim/symlink.sh' } </span> Plug 'godoctor/godoctor.vim', {'for': 'go'} " Gocode refactoring tool " } </code></pre></div></div> <p>That is the line I had to change then run <code class="highlighter-rouge">:PlugUpdate!</code> and the new plugin was installed.</p> <p>I figured all of this out due to <a href="https://github.com/zchee/deoplete-go/issues/134#issuecomment-435436305">this comment</a> by <a href="https://github.com/cippaciong">Tommaso Sardelli</a> on Github. Thank you Tommaso.</p>
|
34
|
+
</description>
|
35
|
+
<pubDate>Sat, 05 Jan 2019 11:09:26 -0600</pubDate>
|
36
|
+
<link>
|
37
|
+
https://blog.jasonmeridth.com/posts/gocode-vim-plugin-and-go-modules/
|
38
|
+
</link>
|
39
|
+
<guid isPermaLink="true">
|
40
|
+
https://blog.jasonmeridth.com/posts/gocode-vim-plugin-and-go-modules/
|
41
|
+
</guid>
|
42
|
+
<category>go</category>
|
43
|
+
<category>vim</category>
|
44
|
+
</item>
|
45
|
+
EOS
|
45
46
|
end
|
46
47
|
|
47
48
|
def rss_entry
|
@@ -50,7 +51,7 @@ def rss_entry
|
|
50
51
|
end
|
51
52
|
|
52
53
|
def rss_feed_url_content
|
53
|
-
rss_header
|
54
|
+
rss_header = <<-EOS
|
54
55
|
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
|
55
56
|
<channel>
|
56
57
|
<title>Learn, Converse, Share</title>
|
@@ -61,6 +62,5 @@ def rss_feed_url_content
|
|
61
62
|
<lastBuildDate>Fri, 01 Mar 2019 13:02:56 -0600</lastBuildDate>
|
62
63
|
<generator>Jekyll v3.7.4</generator>
|
63
64
|
EOS
|
64
|
-
|
65
|
+
"#{rss_header}#{rss_feed_entry}</channel></rss>"
|
65
66
|
end
|
66
|
-
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), '/../spec_helper')
|
2
4
|
|
3
5
|
describe BlogPostsHandler do
|
4
6
|
include BlogPostsHandler
|
@@ -9,27 +11,27 @@ describe BlogPostsHandler do
|
|
9
11
|
@last_blog_post_tweeted = test_conf['last_blog_post_tweeted']
|
10
12
|
end
|
11
13
|
|
12
|
-
it
|
14
|
+
it 'should determine that there is one new blog post to tweet' do
|
13
15
|
posts = get_new_blog_posts(@posts, @last_blog_post_tweeted)
|
14
16
|
expect(posts.length).to eq(1)
|
15
17
|
end
|
16
18
|
|
17
|
-
it
|
19
|
+
it 'should return zero if posts are nil' do
|
18
20
|
posts = get_new_blog_posts(nil, @last_blog_post_tweeted)
|
19
21
|
expect(posts.length).to eq(0)
|
20
22
|
end
|
21
23
|
|
22
|
-
it
|
24
|
+
it 'should return zero if no posts are passed' do
|
23
25
|
posts = get_new_blog_posts([], @last_blog_post_tweeted)
|
24
26
|
expect(posts.length).to eq(0)
|
25
27
|
end
|
26
28
|
|
27
|
-
it
|
29
|
+
it 'should return the posts if there is no last_blog_post_tweeted in the conf file' do
|
28
30
|
posts = get_new_blog_posts(@posts, nil)
|
29
31
|
expect(posts.length).to eq(1)
|
30
32
|
end
|
31
33
|
|
32
|
-
it
|
34
|
+
it 'should return zero posts if the date is older than the last blog post date tweeted' do
|
33
35
|
post = Twog::Post.new(double('', pubDate: (Date.parse(@last_blog_post_tweeted.to_s) - 10).to_s, link: 'http://tinyurl.com'))
|
34
36
|
@posts = [post]
|
35
37
|
posts = get_new_blog_posts(@posts, @last_blog_post_tweeted)
|
data/spec/twog/post_spec.rb
CHANGED
@@ -1,33 +1,34 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), '/../spec_helper')
|
2
4
|
|
3
5
|
describe Post do
|
4
|
-
context
|
6
|
+
context 'when rss entry has updated and link.href' do
|
5
7
|
before(:each) do
|
6
|
-
updated =double('update', content: '2010-04-02T01:00:00-06:00')
|
8
|
+
updated = double('update', content: '2010-04-02T01:00:00-06:00')
|
7
9
|
link = double('link', href: 'http://tinyurl.com')
|
8
10
|
title = double('title', content: 'test title')
|
9
11
|
@post = double('post', updated: updated, link: link, title: title)
|
10
|
-
|
11
12
|
end
|
12
13
|
|
13
|
-
it
|
14
|
+
it 'should return a link' do
|
14
15
|
twog_post = Twog::Post.new(@post)
|
15
|
-
expect(twog_post.date).to eq(
|
16
|
+
expect(twog_post.date).to eq('2010-04-02T01:00:00-06:00')
|
16
17
|
end
|
17
18
|
|
18
|
-
it
|
19
|
+
it 'should return a date' do
|
19
20
|
twog_post = Twog::Post.new(@post)
|
20
|
-
expect(twog_post.date).to eq(
|
21
|
+
expect(twog_post.date).to eq('2010-04-02T01:00:00-06:00')
|
21
22
|
end
|
22
23
|
|
23
|
-
it
|
24
|
+
it 'should return a title' do
|
24
25
|
twog_post = Twog::Post.new(@post)
|
25
|
-
expect(twog_post.title).to eq(
|
26
|
+
expect(twog_post.title).to eq('test title')
|
26
27
|
end
|
27
28
|
|
28
|
-
it
|
29
|
+
it 'should sort multiple posts' do
|
29
30
|
unsorted = (1..10).sort_by { rand }.collect do |i|
|
30
|
-
updated = double('update', content: (Time.now + (60*60*24*i)).to_s)
|
31
|
+
updated = double('update', content: (Time.now + (60 * 60 * 24 * i)).to_s)
|
31
32
|
link = double('link', href: 'http://tinyurl.com')
|
32
33
|
post = double('post', updated: updated, link: link)
|
33
34
|
Twog::Post.new(post)
|
@@ -35,12 +36,12 @@ describe Post do
|
|
35
36
|
sorted = unsorted.sort!
|
36
37
|
expect(sorted.length).to eq(10)
|
37
38
|
|
38
|
-
sorted.inject {|i, j| expect(Time.parse(i.date.to_s)).to be < Time.parse(j.date.to_s); j }
|
39
|
+
sorted.inject { |i, j| expect(Time.parse(i.date.to_s)).to be < Time.parse(j.date.to_s); j }
|
39
40
|
end
|
40
41
|
|
41
|
-
it
|
42
|
-
unsorted = (1..10).collect do |
|
43
|
-
updated = double('update', content: (Time.now + (60*60*24*3)).to_s)
|
42
|
+
it 'should leave meeting list alone if all the times are the same' do
|
43
|
+
unsorted = (1..10).collect do |_i|
|
44
|
+
updated = double('update', content: (Time.now + (60 * 60 * 24 * 3)).to_s)
|
44
45
|
link = double('link', href: 'http://tinyurl.com')
|
45
46
|
post = double('post', updated: updated, link: link)
|
46
47
|
Twog::Post.new(post)
|
@@ -51,27 +52,27 @@ describe Post do
|
|
51
52
|
end
|
52
53
|
end
|
53
54
|
|
54
|
-
context
|
55
|
+
context 'when rss entry has pubDate and link' do
|
55
56
|
before(:each) do
|
56
57
|
@post = double('post', pubDate: '2010-04-02T01:00:00-06:00', link: 'http://tinyurl.com')
|
57
58
|
end
|
58
59
|
|
59
|
-
it
|
60
|
+
it 'should return a link' do
|
60
61
|
twog_post = Twog::Post.new(@post)
|
61
62
|
|
62
|
-
expect(twog_post.link).to eq(
|
63
|
-
expect(twog_post.date).to eq(
|
63
|
+
expect(twog_post.link).to eq('http://tinyurl.com')
|
64
|
+
expect(twog_post.date).to eq('2010-04-02T01:00:00-06:00')
|
64
65
|
end
|
65
66
|
|
66
|
-
it
|
67
|
+
it 'should sort multiple posts again' do
|
67
68
|
unsorted = (1..10).sort_by { rand }.collect do |i|
|
68
|
-
post = double('post', pubDate: (Time.now + (60*60*24*i)).to_s, link: 'http://tinyurl.com')
|
69
|
+
post = double('post', pubDate: (Time.now + (60 * 60 * 24 * i)).to_s, link: 'http://tinyurl.com')
|
69
70
|
Twog::Post.new(post)
|
70
71
|
end
|
71
72
|
sorted = unsorted.sort!
|
72
73
|
expect(sorted.length).to eq(10)
|
73
74
|
|
74
|
-
sorted.inject {|i, j| expect(Time.parse(i.date.to_s)).to be < Time.parse(j.date.to_s); j }
|
75
|
+
sorted.inject { |i, j| expect(Time.parse(i.date.to_s)).to be < Time.parse(j.date.to_s); j }
|
75
76
|
end
|
76
77
|
end
|
77
78
|
end
|
@@ -1,32 +1,34 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), '/../spec_helper')
|
2
4
|
|
3
5
|
describe RssEntryToTwogPostMapper do
|
4
6
|
include RssEntryToTwogPostMapper
|
5
7
|
|
6
|
-
it
|
8
|
+
it 'should convert rss entries that have updated.content and link.href' do
|
7
9
|
updated = double('update', content: '2010-04-02T01:00:00-06:00')
|
8
10
|
link = double('link', href: 'http://tinyurl.com')
|
9
11
|
post = double('post', updated: updated, link: link)
|
10
12
|
|
11
|
-
posts = (0..20).collect { |
|
13
|
+
posts = (0..20).collect { |_x| post }
|
12
14
|
|
13
15
|
twog_posts = map(posts)
|
14
16
|
expect(twog_posts.length).to eq(21)
|
15
17
|
twog_posts.each do |p|
|
16
|
-
expect(p.date).to eq(
|
17
|
-
expect(p.link).to eq(
|
18
|
+
expect(p.date).to eq('2010-04-02T01:00:00-06:00')
|
19
|
+
expect(p.link).to eq('http://tinyurl.com')
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
|
-
it
|
23
|
+
it 'should convert rss entries that have pubDate and link' do
|
22
24
|
post = double('post', pubDate: '2010-04-02T01:00:00-06:00', link: 'http://tinyurl.com')
|
23
|
-
posts = (0..20).collect { |
|
25
|
+
posts = (0..20).collect { |_x| post }
|
24
26
|
|
25
27
|
twog_posts = map(posts)
|
26
28
|
expect(twog_posts.length).to eq(21)
|
27
29
|
twog_posts.each do |p|
|
28
|
-
expect(p.date).to eq(
|
29
|
-
expect(p.link).to eq(
|
30
|
+
expect(p.date).to eq('2010-04-02T01:00:00-06:00')
|
31
|
+
expect(p.link).to eq('http://tinyurl.com')
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
@@ -1,17 +1,19 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), '/../spec_helper')
|
2
4
|
|
3
5
|
describe RssParser do
|
4
6
|
include RssParser
|
5
7
|
|
6
|
-
it
|
7
|
-
expect{ parse_feed(nil)}.to raise_error('RSS feed missing')
|
8
|
+
it 'should throw exception if rss_feed is not provided' do
|
9
|
+
expect { parse_feed(nil) }.to raise_error('RSS feed missing')
|
8
10
|
end
|
9
11
|
|
10
|
-
it
|
12
|
+
it 'should read the rss_feed_url and parse the items' do
|
11
13
|
allow(self).to receive(:get_content).and_return(rss_feed_url_content)
|
12
14
|
items = parse_feed('http://tinyurl.com')
|
13
15
|
expect(items.length).to eq(1)
|
14
|
-
expect(items[0].title.strip).to eq(
|
15
|
-
expect(items[0].link.strip).to eq(
|
16
|
+
expect(items[0].title.strip).to eq('Gocode Vim Plugin and Go Modules')
|
17
|
+
expect(items[0].link.strip).to eq('https://blog.jasonmeridth.com/posts/gocode-vim-plugin-and-go-modules/')
|
16
18
|
end
|
17
19
|
end
|