matth-growl-atom 0.0.1-universal-darwin-9 → 0.0.2-universal-darwin-9

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/bin/growl-atom CHANGED
@@ -29,8 +29,6 @@
29
29
  # ~/.growl-atom/caches/
30
30
  #
31
31
 
32
- $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
33
-
34
32
  require 'rubygems'
35
33
  require 'growl-atom'
36
34
  require 'rdoc/usage'
@@ -44,7 +42,7 @@ launch_agents_dir = user_dir + "/Library/LaunchAgents/"
44
42
  case ARGV[0]
45
43
  when 'check'
46
44
 
47
- puts GrowlAtom.gem_dir
45
+ GrowlAtom.check(File.join(user_dir, '.growl-atom'))
48
46
  exit
49
47
 
50
48
  when 'install'
@@ -52,6 +50,7 @@ case ARGV[0]
52
50
  # Create user config dir
53
51
  system 'mkdir -p ' + File.join(user_dir, '.growl-atom/caches')
54
52
  system "cp #{File.join(gem_dir, 'config')} #{File.join(user_dir, '.growl-atom/config')}"
53
+ system "cp -r #{File.join(gem_dir, 'icons')} #{File.join(user_dir, '.growl-atom/icons')}"
55
54
 
56
55
  # Create Launch Agent dir
57
56
  if (!File.directory?(launch_agents_dir))
data/config ADDED
@@ -0,0 +1,37 @@
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
+ #
11
+ # feeds:
12
+ # name: Growl Application Name
13
+ # url: http://your.feed.com
14
+ # auth_user: http_user
15
+ # auth_pass: http_pass
16
+ # title: Name of Atom entry node to be used as notification title, default is title
17
+ # message: Name of Atom entry node to be used as notification message, default is summary
18
+ # image: /path/to/notification/icon.png
19
+ # sticky: true default is false
20
+ #
21
+
22
+ # Global configs
23
+ #
24
+ # These config options can be overwritten on a per feed basis
25
+
26
+ global:
27
+ growl_host : localhost
28
+
29
+ feeds:
30
+ - name: Gmail
31
+ url: https://mail.google.com/mail/feed/atom/
32
+ auth_user: your_gmail_username
33
+ auth_pass: your_gmail_password
34
+ image: ~/.growl-atom/icons/gmail.png
35
+ title: author/email
36
+ message: title
37
+ sticky: false
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 CHANGED
@@ -1,71 +1,107 @@
1
1
  require 'rubygems'
2
2
  require 'growl'
3
+ require 'yaml'
4
+ require 'digest/md5'
5
+ require 'uri'
3
6
  require 'net/http'
4
7
  require 'net/https'
5
8
  require 'rexml/document'
6
9
 
7
10
  module GrowlAtom
8
11
 
9
- VERSION = "0.0.1"
12
+ VERSION = "0.0.2"
10
13
 
14
+ class Error < StandardError; end
15
+
16
+ # The Installation directory of this gem package
11
17
  def GrowlAtom.gem_dir
12
18
  File.expand_path(File.join(File.dirname(__FILE__), '..'))
13
19
  end
14
20
 
15
- class Error < StandardError; end
16
-
17
- class Checker
18
-
19
- def initialize(config_file)
20
-
21
- @config_file = config_file
21
+ # Check all URLs in this config file
22
+ def GrowlAtom.check(config_dir)
22
23
 
23
- end
24
+ default_options = {
25
+ :name => 'growl-atom',
26
+ :title => 'title',
27
+ :message => 'summary',
28
+ :growl_host => 'localhost',
29
+ :sticky => false
30
+ }
24
31
 
25
- def check(url, options = {})
26
- =begin
27
- cache_file = 'cache'
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
+ }
28
39
 
29
- system("touch #{cache_file}")
40
+ end
30
41
 
31
- # Download it
32
- http = Net::HTTP.new('mail.google.com', 443)
33
- req = Net::HTTP::Get.new('/mail/feed/atom/')
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.new(uri.host, uri.port)
50
+
51
+ req = Net::HTTP::Get.new(uri.path)
52
+
53
+ if (uri.scheme == 'https')
34
54
  http.use_ssl = true
35
55
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
36
- req.basic_auth '', ''
37
- response = http.request(req)
38
-
39
- # Parse it
40
- include REXML
41
-
42
- doc = Document.new response.body
43
- doc.elements.each('//entry') {|entry|
44
-
45
- id = entry.elements['id'].text
46
-
47
- if (!system("grep #{id} #{cache_file} > /dev/null"))
48
-
49
- GrowlGmail.notify({
50
- :message => entry.elements['title'].text,
51
- :title => entry.elements['author/name'].text
52
- })
53
-
54
- system("echo #{id} >> #{cache_file}")
55
-
56
- end
57
-
58
- }
59
-
60
- =end
61
56
  end
62
57
 
63
- def notify(options)
64
- # #image = File.join(File.expand_path(File.dirname(__FILE__)), "gmail.png")
65
- Growl.notify 'Growl Atom', options.merge({:name => 'GrowlGmail', :image => image, :host => 'localhost'})
58
+ if (options['auth_user'] && options['auth_pass'])
59
+ req.basic_auth options['auth_user'], options['auth_pass']
66
60
  end
67
61
 
62
+ response = http.request(req)
63
+
64
+ if (!response.kind_of?(Net::HTTPClientError) && !response.kind_of?(Net::HTTPServerError))
65
+ return response.body
66
+ end
67
+
68
+ raise Error, "#{response.code} Error in HTTP Response for #{options['url']}"
68
69
 
69
70
  end
70
71
 
72
+ # Parse feed xml
73
+ def GrowlAtom.parse_feed(feed_xml, options, cache_dir)
74
+
75
+ cache_file = File.join(cache_dir, Digest::MD5.hexdigest(options['url']))
76
+ system("touch #{cache_file}")
77
+
78
+ include REXML
79
+
80
+ doc = Document.new feed_xml
81
+ doc.elements.each('//entry') {|entry|
82
+
83
+ id = entry.elements['id'].text
84
+
85
+ if (!system("grep #{id} #{cache_file} > /dev/null"))
86
+
87
+ growl_options = {}
88
+
89
+ growl_options['name'] = options['name']
90
+ growl_options['host'] = options['growl_host']
91
+ growl_options['sticky'] = options['sticky']
92
+ growl_options['title'] = entry.elements[options['title']].text
93
+ growl_options['message'] = entry.elements[options['message']].text
94
+
95
+ growl_options['password'] = options['growl_pass'] unless(options['growl_pass'] == nil)
96
+ growl_options['image'] = File.expand_path(options['image']) unless(options['image'] == nil)
97
+
98
+ Growl.notify(growl_options['message'], growl_options)
99
+
100
+ system("echo #{id} >> #{cache_file}")
101
+
102
+ end
103
+
104
+ }
105
+ end
106
+
71
107
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: matth-growl-atom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: universal-darwin-9
6
6
  authors:
7
7
  - Matt Haynes
@@ -13,7 +13,7 @@ date: 2009-04-08 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: growl
16
+ name: visionmedia-growl
17
17
  type: :runtime
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
@@ -31,7 +31,10 @@ extensions: []
31
31
  extra_rdoc_files: []
32
32
 
33
33
  files:
34
+ - config
35
+ - growl.atom.plist
34
36
  - lib/growl-atom.rb
37
+ - icons/gmail.png
35
38
  has_rdoc: false
36
39
  homepage: http://matthaynes.net/blog/
37
40
  post_install_message:
@@ -57,6 +60,6 @@ rubyforge_project:
57
60
  rubygems_version: 1.2.0
58
61
  signing_key:
59
62
  specification_version: 2
60
- summary: Create growl notifications for Atom entries
63
+ summary: Creates growl notifications for Atom entries
61
64
  test_files: []
62
65