darrenhinderer-birdy 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Darren Hinderer
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/bin/birdy ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib birdy]))
4
+
5
+ while true
6
+ begin
7
+ Birdy::Base.new
8
+ rescue => e
9
+ puts "Probably network problems, waiting for a minute to restart"
10
+ puts e
11
+ sleep 60
12
+ end
13
+ end
data/lib/birdy.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'twitter'
2
+ require 'rbus'
3
+ require 'highline'
4
+ require 'fileutils'
5
+
6
+ require File.dirname(__FILE__) + '/birdy/base'
7
+ require File.dirname(__FILE__) + '/birdy/authentication'
8
+ require File.dirname(__FILE__) + '/birdy/config'
9
+ require File.dirname(__FILE__) + '/birdy/linux_notifier'
10
+ require File.dirname(__FILE__) + '/birdy/image_download'
@@ -0,0 +1,25 @@
1
+ module Birdy
2
+ module Authentication
3
+
4
+ def authenticate
5
+ @config = Config.new
6
+ @auth = @config.read
7
+
8
+ @twitter = Twitter::Client.new
9
+
10
+ while @twitter.authenticate?(@auth[:login], @auth[:password]) == false
11
+ @config.delete
12
+
13
+ hl = HighLine.new
14
+ login = hl.ask("login: ")
15
+ password = hl.ask("password: ") {|q| q.echo = '*'}
16
+ @config.write(login, password)
17
+
18
+ @auth = @config.read
19
+ end
20
+
21
+ Twitter::Client.new(:login => @auth[:login], :password => @auth[:password])
22
+ end
23
+
24
+ end
25
+ end
data/lib/birdy/base.rb ADDED
@@ -0,0 +1,52 @@
1
+ require 'time' # twitter4r 0.3.0 needs time
2
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'authentication')
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'image_download')
4
+
5
+ module Birdy
6
+
7
+ class Base
8
+ include Birdy::Authentication
9
+ include Birdy::ImageDownload
10
+
11
+ def initialize
12
+ @twitter = authenticate
13
+ poll
14
+ end
15
+
16
+ def poll
17
+ @alert = LinuxNotifier.new
18
+
19
+ while true
20
+ tweets.reverse.each do |tweet|
21
+ image_path = download(tweet.user.profile_image_url)
22
+ @alert.show(image_path, tweet.user.name, tweet.text)
23
+ end
24
+
25
+ sleep 60
26
+ end
27
+ end
28
+
29
+ def tweets
30
+ options = {}
31
+ if @last_tweet_id
32
+ options[:since_id] = @last_tweet_id
33
+ else
34
+ options[:count] = 1
35
+ end
36
+
37
+ begin
38
+ timeline = @twitter.timeline_for(:friends, options)
39
+ rescue Twitter::RESTError => e
40
+ puts "Twitter is not responding." + e
41
+ timeline = []
42
+ end
43
+
44
+ if timeline.length > 0
45
+ @last_tweet_id = timeline.first.id
46
+ end
47
+
48
+ timeline
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,32 @@
1
+ module Birdy
2
+ class Config
3
+
4
+ CONFIG_PATH = "#{ENV['HOME']}/.config/birdy/"
5
+ CONFIG_FILE = CONFIG_PATH + "birdy.yml"
6
+
7
+ def initialize
8
+ FileUtils.mkdir_p CONFIG_PATH
9
+ end
10
+
11
+ def write(login, password)
12
+ config = {:login => login, :password => password}
13
+
14
+ File.open(CONFIG_FILE, 'w') do |out|
15
+ YAML.dump(config, out)
16
+ end
17
+ end
18
+
19
+ def read
20
+ YAML.load_file(CONFIG_FILE)
21
+ rescue
22
+ {}
23
+ end
24
+
25
+ def delete
26
+ File.delete(CONFIG_FILE)
27
+ rescue
28
+ nil
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,27 @@
1
+ module Birdy
2
+ module ImageDownload
3
+
4
+ IMAGES = "#{ENV['HOME']}/.config/birdy/images/"
5
+ ONE_DAY = 24 * 60 * 60
6
+
7
+ def download image_url
8
+ FileUtils.mkdir_p IMAGES
9
+
10
+ uri = URI.parse(image_url)
11
+ Net::HTTP.start(uri.host) do |http|
12
+ response = http.get(uri.path)
13
+ @filename = IMAGES + File.split(uri.path)[1]
14
+ yesterday = Time.now - ONE_DAY
15
+
16
+ unless File.exists?(@filename) && File.mtime(@filename) > yesterday
17
+ open(@filename, "wb") do |file|
18
+ file.write(response.body)
19
+ end
20
+ end
21
+ end
22
+
23
+ @filename
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,32 @@
1
+ class LinuxNotifier
2
+
3
+ DISPLAY_TIME_SECONDS = 5
4
+
5
+ def initialize
6
+ @notify = RBus.session_bus.get_object('org.freedesktop.Notifications',
7
+ '/org/freedesktop/Notifications')
8
+ end
9
+
10
+ def show(image_path, name, message)
11
+ app_name = 'birdy'
12
+ replaces_id = 0
13
+ app_icon = image_path
14
+ summary = name
15
+ body = wrap_links(message)
16
+ actions = []
17
+ hints = {}
18
+ expire_timeout = DISPLAY_TIME_SECONDS * 1000
19
+
20
+ @notify.Notify(app_name, replaces_id, app_icon, summary, body, actions,
21
+ hints, expire_timeout)
22
+ sleep DISPLAY_TIME_SECONDS
23
+ end
24
+
25
+ def wrap_links(text)
26
+ text.gsub(%r{ ( https?:// | www\. ) [^\s<]+ }x) do
27
+ href = $&
28
+ "<a href='" + href + "'>" + href + "</a>"
29
+ end
30
+ end
31
+
32
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: darrenhinderer-birdy
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Darren Hinderer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-26 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: twitter4r
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.3.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rbus
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: highline
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.5.0
44
+ version:
45
+ description:
46
+ email: darren.hinderer@gmail.com
47
+ executables:
48
+ - birdy
49
+ extensions: []
50
+
51
+ extra_rdoc_files: []
52
+
53
+ files:
54
+ - MIT-LICENSE
55
+ - bin/birdy
56
+ - lib/birdy.rb
57
+ - lib/birdy/authentication.rb
58
+ - lib/birdy/base.rb
59
+ - lib/birdy/config.rb
60
+ - lib/birdy/linux_notifier.rb
61
+ - lib/birdy/image_download.rb
62
+ has_rdoc: false
63
+ homepage:
64
+ post_install_message:
65
+ rdoc_options: []
66
+
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ requirements: []
82
+
83
+ rubyforge_project: birdy
84
+ rubygems_version: 1.2.0
85
+ signing_key:
86
+ specification_version: 2
87
+ summary: Twitter integration with Linux desktop notifications
88
+ test_files: []
89
+