mcornick-laika 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +26 -29
- data/Rakefile +2 -1
- data/bin/laika +58 -0
- data/lib/laika/blog.rb +0 -1
- data/lib/laika/version.rb +2 -2
- data/test/blog_test.rb +6 -3
- metadata +12 -3
- data/bin/laika-post +0 -10
data/README.markdown
CHANGED
@@ -2,9 +2,7 @@
|
|
2
2
|
|
3
3
|
## Description
|
4
4
|
|
5
|
-
Laika (Russian: Лайка, "barker") is a simple script to monitor an RSS feed, and post to Yammer when new articles are detected.
|
6
|
-
|
7
|
-
Currently, only the Yammer posting functionality is implemented.
|
5
|
+
Laika (Russian: Лайка, "barker") is a simple script to monitor an RSS or Atom feed, and post to Yammer when new articles are detected.
|
8
6
|
|
9
7
|
## Installation
|
10
8
|
|
@@ -22,36 +20,35 @@ Then, you'll need to do the OAuth exchange, which will give you an access token
|
|
22
20
|
|
23
21
|
This will prompt you for the client key and secret you just obtained. It will then echo a URL which you will need to visit while still logged in to Yammer as the user from the previous step. You'll be asked to authorize your application. Click the Authorize button, then go back to your terminal and hit Return. The script will then get the access token and secret from Yammer, and store all four pieces of information in a file called laika.yml. **Don't lose this file!** It constitutes the credentials that you will need to do anything useful with Laika. It is not encrypted, so keep it secure. Once you have the laika.yml file, you will not need to do these steps again unless you de-authorize the application.
|
24
22
|
|
25
|
-
|
23
|
+
Now you're ready to start barking about feeds. You can see all Laika's options by running it with the --help option:
|
24
|
+
|
25
|
+
$ ./bin/laika --help
|
26
|
+
Laika 1.0.0
|
27
|
+
Options:
|
28
|
+
--feed-file, -f <s>: File to store feed data
|
29
|
+
--credential-file, -c <s>: File with Yammer credential data (from
|
30
|
+
laika-auth) (default: laika.yml)
|
31
|
+
--url, -u <s>: URL of the feed to bark about
|
32
|
+
--dont-yammer, -d: Don't post to Yammer, just echo to standard out
|
33
|
+
--version, -v: Print version and exit
|
34
|
+
--help, -h: Show this message
|
35
|
+
|
36
|
+
The only 100% mandatory option is --feed-file, which is a YAML file to which Laika will write the feed data and the posts it has already barked about.
|
37
|
+
|
38
|
+
When running for the first time, you will also need to specify --url for the URL of the feed. You should *not* specify --url on subsequent runs unless you want to reset Laika's list of posts it has already barked.
|
26
39
|
|
27
|
-
|
28
|
-
require 'laika'
|
29
|
-
yammer = Laika::Yammer.new('laika.yml') # path to the laika.yml file; default is laika.yml in your current directory
|
30
|
-
yammer.post('I HAZ A SPASE DOG')
|
40
|
+
--credential-file specifies the location of the file written by laika-auth. It will default to "laika.yml" in the current directory, but if it is elsewhere, you can specify it here.
|
31
41
|
|
32
|
-
|
42
|
+
Finally, --dont-yammer is useful for testing, or for avoiding spamming Yammer. It will send announcements of new posts to standard output, rather than to Yammer.
|
43
|
+
|
44
|
+
You will probably want to run Laika periodically from cron. When doing so, providing only the --feed-file option should be sufficient (unless you also need to specify a non-default --credential-file.)
|
33
45
|
|
34
46
|
## License
|
35
47
|
|
36
48
|
Copyright (C) 2008 Mark Cornick of Viget Labs (http://www.viget.com/)
|
37
49
|
|
38
|
-
Permission is hereby granted, free of charge, to any person
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
copies of the Software, and to permit persons to whom the
|
44
|
-
Software is furnished to do so, subject to the following
|
45
|
-
conditions:
|
46
|
-
|
47
|
-
The above copyright notice and this permission notice shall be
|
48
|
-
included in all copies or substantial portions of the Software.
|
49
|
-
|
50
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
51
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
52
|
-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
53
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
54
|
-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
55
|
-
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
56
|
-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
57
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
50
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
51
|
+
|
52
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
53
|
+
|
54
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
CHANGED
@@ -16,10 +16,11 @@ spec = Gem::Specification.new do |s|
|
|
16
16
|
s.email = 'mark.cornick@viget.com'
|
17
17
|
s.homepage = 'http://www.viget.com/'
|
18
18
|
s.files = %w(README.markdown Rakefile) + Dir.glob("{lib,test,bin}/**/*")
|
19
|
-
s.executables = %w(laika
|
19
|
+
s.executables = %w(laika laika-auth)
|
20
20
|
|
21
21
|
s.add_dependency('oauth', '>=0.2.7')
|
22
22
|
s.add_dependency('feed-normalizer', '>=1.5.1')
|
23
|
+
s.add_dependency('trollop', '>=1.10.2')
|
23
24
|
end
|
24
25
|
|
25
26
|
Rake::GemPackageTask.new(spec) do |pkg|
|
data/bin/laika
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'laika'
|
5
|
+
require 'laika/version'
|
6
|
+
require 'trollop'
|
7
|
+
|
8
|
+
opts = Trollop::options do
|
9
|
+
version "Laika #{Laika::Version}"
|
10
|
+
opt :feed_file, "File to store feed data", :type => String
|
11
|
+
opt :credential_file, "File with Yammer credential data (from laika-auth)", :type => String, :default => 'laika.yml'
|
12
|
+
opt :url, "URL of the feed to bark about", :type => String
|
13
|
+
opt :dont_yammer, "Don't post to Yammer, just echo to standard out", :default => false
|
14
|
+
end
|
15
|
+
|
16
|
+
Trollop::die(:feed_file, "must be specified") unless opts[:feed_file]
|
17
|
+
Trollop::die(:url, "must be specified because #{opts[:feed_file]} does not yet exist") if opts[:feed_file] && !opts[:url] && !File.exist?(opts[:feed_file])
|
18
|
+
|
19
|
+
unless opts[:url].nil?
|
20
|
+
begin
|
21
|
+
blog = Laika::Blog.new(opts[:url])
|
22
|
+
rescue
|
23
|
+
Trollop::die(:url, "could not be loaded")
|
24
|
+
end
|
25
|
+
else
|
26
|
+
begin
|
27
|
+
blog = YAML.load_file(opts[:feed_file])
|
28
|
+
rescue
|
29
|
+
Trollop::die(:feed_file, "could not be loaded")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
begin
|
34
|
+
announcements = blog.get_new_entries.collect { |e| "#{e.authors.first} just posted #{e.title} to #{blog.feed.title}: #{e.urls.first}" }
|
35
|
+
rescue
|
36
|
+
Trollop::die(:feed_file, "could not be parsed")
|
37
|
+
end
|
38
|
+
|
39
|
+
if announcements.any?
|
40
|
+
begin
|
41
|
+
yammer = Laika::Yammer.new(opts[:credential_file]) unless opts[:dont_yammer]
|
42
|
+
announcements.each do |a|
|
43
|
+
unless opts[:dont_yammer]
|
44
|
+
yammer.post a
|
45
|
+
else
|
46
|
+
puts a
|
47
|
+
end
|
48
|
+
end
|
49
|
+
rescue
|
50
|
+
Trollop::die(:credential_file, "does not exist, or did not permit access to Yammer")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
begin
|
55
|
+
File.open(opts[:feed_file], 'w') { |file| YAML.dump(blog, file) }
|
56
|
+
rescue
|
57
|
+
Trollop::die(:feed_file, "could not be saved")
|
58
|
+
end
|
data/lib/laika/blog.rb
CHANGED
data/lib/laika/version.rb
CHANGED
data/test/blog_test.rb
CHANGED
@@ -11,20 +11,23 @@ class BlogTest < Test::Unit::TestCase
|
|
11
11
|
end
|
12
12
|
|
13
13
|
context 'being created' do
|
14
|
-
should '
|
15
|
-
|
14
|
+
should 'not have a feed or any entries' do
|
15
|
+
assert_nil @blog.feed
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
context 'getting new entries' do
|
20
20
|
context 'on first invocation' do
|
21
|
+
setup do
|
22
|
+
@blog.get_new_entries
|
23
|
+
end
|
21
24
|
should 'return all entries' do
|
22
|
-
# initialize calls get_new_entries the first time
|
23
25
|
assert_equal @stubbed_entries, @blog.feed.entries
|
24
26
|
end
|
25
27
|
end
|
26
28
|
context 'on subsequent invocations' do
|
27
29
|
setup do
|
30
|
+
@blog.get_new_entries
|
28
31
|
@new_entry = stub(:id => 3)
|
29
32
|
@stubbed_entries << @new_entry
|
30
33
|
@stubbed_feed.stubs(:entries).returns(@stubbed_entries)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mcornick-laika
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Cornick
|
@@ -30,11 +30,20 @@ dependencies:
|
|
30
30
|
- !ruby/object:Gem::Version
|
31
31
|
version: 1.5.1
|
32
32
|
version:
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: trollop
|
35
|
+
version_requirement:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.10.2
|
41
|
+
version:
|
33
42
|
description:
|
34
43
|
email: mark.cornick@viget.com
|
35
44
|
executables:
|
45
|
+
- laika
|
36
46
|
- laika-auth
|
37
|
-
- laika-post
|
38
47
|
extensions: []
|
39
48
|
|
40
49
|
extra_rdoc_files:
|
@@ -50,8 +59,8 @@ files:
|
|
50
59
|
- test/blog_test.rb
|
51
60
|
- test/test_common.rb
|
52
61
|
- test/yammer_test.rb
|
62
|
+
- bin/laika
|
53
63
|
- bin/laika-auth
|
54
|
-
- bin/laika-post
|
55
64
|
has_rdoc: true
|
56
65
|
homepage: http://www.viget.com/
|
57
66
|
post_install_message:
|
data/bin/laika-post
DELETED