growl-atom 0.0.4-universal-darwin-9

Sign up to get free protection for your applications and to get access to all the features.
data/bin/growl-atom ADDED
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # == Synopsis
4
+ #
5
+ # Makes growl notifications from new Atom entries.
6
+ #
7
+ # == Usage
8
+ #
9
+ # growl-atom [COMMAND]
10
+ #
11
+ # help:
12
+ # Show this help page
13
+ #
14
+ # check:
15
+ # Check the current feeds defined in the current user's config file, found at
16
+ # ~/.growl-atom/config This command is run from the LaunchAgent setup by the install command
17
+ #
18
+ # install:
19
+ # Install this for the current user, installs an OS X LaunchAgent (daemon process) for
20
+ # the current user and creates an empty config file in ~/.growl-atom/config
21
+ #
22
+ # uninstall:
23
+ # Uninstall the LaunchAgent for the current user, also delete all config and cache
24
+ # files under ~/.growl-atom/
25
+ #
26
+ # clear-caches:
27
+ # Clear all cache files for the current user. Cache files stop notifications being repeated.
28
+ # Atom entry IDs are stored in them once a notification has been shown. They can be found in
29
+ # ~/.growl-atom/caches/
30
+ #
31
+ require 'rubygems'
32
+ require 'growl-atom'
33
+ require 'rdoc/usage'
34
+
35
+ user_dir = File.expand_path('~')
36
+ gem_dir = GrowlAtom.gem_dir
37
+ launch_agent = "growl.atom"
38
+ launch_agent_plist = launch_agent + ".plist"
39
+ launch_agents_dir = user_dir + "/Library/LaunchAgents/"
40
+
41
+ case ARGV[0]
42
+ when 'check'
43
+
44
+ GrowlAtom.check(File.join(user_dir, '.growl-atom'))
45
+ exit
46
+
47
+ when 'install'
48
+
49
+ # Create user config dir
50
+ system 'mkdir -p ' + File.join(user_dir, '.growl-atom/caches')
51
+ system "cp -i #{File.join(gem_dir, 'config')} #{File.join(user_dir, '.growl-atom/config')}"
52
+ system "cp -ri #{File.join(gem_dir, 'icons')} #{File.join(user_dir, '.growl-atom/icons')}"
53
+
54
+ # Create Launch Agent dir
55
+ if (!File.directory?(launch_agents_dir))
56
+ system "mkdir #{launch_agents_dir}"
57
+ end
58
+
59
+ # Install and start launch agent
60
+ system "sed -e 's/@USER.HOME@/#{user_dir.gsub(/\//, '\/')}/g' #{File.join(gem_dir, launch_agent_plist)} > #{launch_agents_dir + launch_agent_plist}"
61
+ system "launchctl load #{launch_agents_dir + launch_agent_plist}"
62
+ system "launchctl start #{launch_agent}"
63
+ exit
64
+
65
+ when 'uninstall'
66
+
67
+ puts("Are you sure you want to uninstall? This will delete your config file. (y/n)")
68
+ input=STDIN.gets
69
+
70
+ if (input.chomp.downcase != 'y' )
71
+ puts "Uninstall aborted"
72
+ exit
73
+ end
74
+
75
+ # Remove Launch Agent
76
+ system "launchctl unload #{launch_agents_dir + launch_agent_plist}"
77
+ system "rm #{launch_agents_dir + launch_agent_plist}"
78
+ system 'rm -rdf ' + File.join(user_dir, '.growl-atom')
79
+ exit
80
+
81
+ when 'clear-caches'
82
+
83
+ system 'rm -rdf ' + File.join(user_dir, '.growl-atom/caches/*')
84
+ exit
85
+
86
+ else
87
+
88
+ RDoc::usage
89
+ exit
90
+ end
data/config ADDED
@@ -0,0 +1,43 @@
1
+ ---
2
+
3
+ # Example config for growl-atom, note this is a YAML file, see http://yaml.org/
4
+
5
+ # Available options:
6
+ #
7
+ # global:
8
+ # growl_host : localhost
9
+ # growl_pass : your_pass
10
+ # proxy_host: your.proxy
11
+ # proxy_port: 80
12
+ # proxy_user: username
13
+ # proxy_pass: password
14
+ #
15
+ # feeds:
16
+ # name: Growl Application Name
17
+ # url: http://your.feed.com
18
+ # auth_user: http_user
19
+ # auth_pass: http_pass
20
+ # cert: /path/to/your/client/cert.pem
21
+ # title: Name of Atom entry node to be used as notification title, default is title
22
+ # message: Name of Atom entry node to be used as notification message, default is summary
23
+ # image: /path/to/notification/icon.png
24
+ # sticky: true default is false
25
+ #
26
+
27
+ # Global configs
28
+ #
29
+ # These config options can be overwritten on a per feed basis
30
+
31
+ global:
32
+ growl_host : localhost
33
+
34
+ feeds:
35
+ - name: Gmail
36
+ url: https://mail.google.com/mail/feed/atom/
37
+ auth_user: your_gmail_username
38
+ auth_pass: your_gmail_password
39
+ image: ~/.growl-atom/icons/gmail.png
40
+ title: author/email
41
+ message: title
42
+ sticky: false
43
+
data/growl.atom.plist ADDED
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>Label</key>
6
+ <string>growl.atom</string>
7
+ <key>ProgramArguments</key>
8
+ <array>
9
+ <string>growl-atom</string>
10
+ <string>check</string>
11
+ </array>
12
+ <key>StartInterval</key>
13
+ <integer>90</integer>
14
+ <key>EnvironmentVariables</key>
15
+ <dict>
16
+ <key>PATH</key>
17
+ <string>/usr/bin:/usr/local/bin:/bin</string>
18
+ <key>HOME</key>
19
+ <string>@USER.HOME@</string>
20
+ </dict>
21
+ </dict>
22
+ </plist>
data/icons/gmail.png ADDED
Binary file
data/lib/growl-atom.rb ADDED
@@ -0,0 +1,118 @@
1
+ require 'rubygems'
2
+ require 'growl'
3
+ require 'yaml'
4
+ require 'digest/md5'
5
+ require 'uri'
6
+ require 'net/http'
7
+ require 'net/https'
8
+ require 'rexml/document'
9
+
10
+ module GrowlAtom
11
+
12
+ VERSION = "0.0.4"
13
+
14
+ class Error < StandardError; end
15
+
16
+ # The Installation directory of this gem package
17
+ def GrowlAtom.gem_dir
18
+ File.expand_path(File.join(File.dirname(__FILE__), '..'))
19
+ end
20
+
21
+ # Check all URLs in this config file
22
+ def GrowlAtom.check(config_dir)
23
+
24
+ default_options = {
25
+ :name => 'growl-atom',
26
+ :title => 'title',
27
+ :message => 'summary',
28
+ :growl_host => 'localhost',
29
+ :sticky => false
30
+ }
31
+
32
+ config = YAML.load_file(File.join(config_dir, 'config'))
33
+ cache_dir = File.join(config_dir, 'caches')
34
+
35
+ config['feeds'].each {|feed|
36
+ options = default_options.merge(config['global']).merge(feed)
37
+ self.parse_feed(self.get_feed(options), options, cache_dir)
38
+ }
39
+
40
+ end
41
+
42
+ # Download feed respecting any http proxy, auth type stuff set in options
43
+ def GrowlAtom.get_feed(options)
44
+
45
+ raise Error, "No url set for feed" unless options['url'] != nil
46
+
47
+ uri = URI.parse(options['url'])
48
+
49
+ http = Net::HTTP::Proxy(options['proxy_host'], options['proxy_port'],
50
+ options['proxy_user'], options['proxy_pass']).new(uri.host, uri.port)
51
+
52
+ req = Net::HTTP::Get.new(uri.path)
53
+
54
+ if (uri.scheme == 'https')
55
+ http.use_ssl = true
56
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
57
+ end
58
+
59
+ if (options['auth_user'] && options['auth_pass'])
60
+ req.basic_auth options['auth_user'], options['auth_pass']
61
+ end
62
+
63
+ if (options['cert'])
64
+ File.open(File.expand_path(options['cert'])) do |cert_file|
65
+ key_data = cert_file.read
66
+ http.cert = OpenSSL::X509::Certificate.new(key_data)
67
+ http.key = OpenSSL::PKey::RSA.new(key_data, nil)
68
+ end
69
+ end
70
+
71
+ response = http.request(req)
72
+
73
+ if (!response.kind_of?(Net::HTTPClientError) && !response.kind_of?(Net::HTTPServerError))
74
+ return response.body
75
+ end
76
+
77
+ raise Error, "#{response.code} Error in HTTP Response for #{options['url']}"
78
+
79
+ end
80
+
81
+ # Parse feed xml
82
+ def GrowlAtom.parse_feed(feed_xml, options, cache_dir)
83
+
84
+ cache_file = File.join(cache_dir, Digest::MD5.hexdigest(options['url']))
85
+ system("touch #{cache_file}")
86
+
87
+ include REXML
88
+
89
+ doc = Document.new feed_xml
90
+ doc.elements.each('//entry') {|entry|
91
+
92
+ id = entry.elements['id'].text
93
+
94
+ if (!system("grep #{id} #{cache_file} > /dev/null"))
95
+
96
+ growl_options = {}
97
+
98
+ growl_options['name'] = options['name']
99
+ growl_options['host'] = options['growl_host']
100
+ growl_options['sticky'] = options['sticky']
101
+ growl_options['title'] = entry.elements[options['title']].text
102
+ growl_options['message'] = entry.elements[options['message']].text
103
+
104
+ growl_options['password'] = options['growl_pass'] unless(options['growl_pass'] == nil)
105
+ growl_options['image'] = File.expand_path(options['image']) unless(options['image'] == nil)
106
+
107
+ Growl.notify(growl_options['message'], growl_options)
108
+
109
+ system("echo #{id} >> #{cache_file}")
110
+ system("tail -n 500 #{cache_file} > #{cache_file}.tmp")
111
+ system("mv #{cache_file}.tmp #{cache_file}")
112
+
113
+ end
114
+
115
+ }
116
+ end
117
+
118
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: growl-atom
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: universal-darwin-9
6
+ authors:
7
+ - Matt Haynes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-18 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: growl
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.6
24
+ version:
25
+ description:
26
+ email: matt@matthaynes.net
27
+ executables:
28
+ - growl-atom
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - config
35
+ - growl.atom.plist
36
+ - lib/growl-atom.rb
37
+ - icons/gmail.png
38
+ has_rdoc: true
39
+ homepage: http://github.com/matth/growl-atom/tree/master
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.3.5
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Creates growl notifications for Atom entries
66
+ test_files: []
67
+