matth-growl-atom 0.0.1-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.
Files changed (3) hide show
  1. data/bin/growl-atom +92 -0
  2. data/lib/growl-atom.rb +71 -0
  3. metadata +62 -0
data/bin/growl-atom ADDED
@@ -0,0 +1,92 @@
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
+
32
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
33
+
34
+ require 'rubygems'
35
+ require 'growl-atom'
36
+ require 'rdoc/usage'
37
+
38
+ user_dir = File.expand_path('~')
39
+ gem_dir = GrowlAtom.gem_dir
40
+ launch_agent = "growl.atom"
41
+ launch_agent_plist = launch_agent + ".plist"
42
+ launch_agents_dir = user_dir + "/Library/LaunchAgents/"
43
+
44
+ case ARGV[0]
45
+ when 'check'
46
+
47
+ puts GrowlAtom.gem_dir
48
+ exit
49
+
50
+ when 'install'
51
+
52
+ # Create user config dir
53
+ system 'mkdir -p ' + File.join(user_dir, '.growl-atom/caches')
54
+ system "cp #{File.join(gem_dir, 'config')} #{File.join(user_dir, '.growl-atom/config')}"
55
+
56
+ # Create Launch Agent dir
57
+ if (!File.directory?(launch_agents_dir))
58
+ system "mkdir #{launch_agents_dir}"
59
+ end
60
+
61
+ # Install and start launch agent
62
+ system "sed -e 's/@USER.HOME@/#{user_dir.gsub(/\//, '\/')}/g' #{File.join(gem_dir, launch_agent_plist)} > #{launch_agents_dir + launch_agent_plist}"
63
+ system "launchctl load #{launch_agents_dir + launch_agent_plist}"
64
+ system "launchctl start #{launch_agent}"
65
+ exit
66
+
67
+ when 'uninstall'
68
+
69
+ puts("Are you sure you want to uninstall? This will delete your config file. (y/n)")
70
+ input=STDIN.gets
71
+
72
+ if (input.chomp.downcase != 'y' )
73
+ puts "Uninstall aborted"
74
+ exit
75
+ end
76
+
77
+ # Remove Launch Agent
78
+ system "launchctl unload #{launch_agents_dir + launch_agent_plist}"
79
+ system "rm #{launch_agents_dir + launch_agent_plist}"
80
+ system 'rm -rdf ' + File.join(user_dir, '.growl-atom')
81
+ exit
82
+
83
+ when 'clear-caches'
84
+
85
+ system 'rm -rdf ' + File.join(user_dir, '.growl-atom/caches/*')
86
+ exit
87
+
88
+ else
89
+
90
+ RDoc::usage
91
+ exit
92
+ end
data/lib/growl-atom.rb ADDED
@@ -0,0 +1,71 @@
1
+ require 'rubygems'
2
+ require 'growl'
3
+ require 'net/http'
4
+ require 'net/https'
5
+ require 'rexml/document'
6
+
7
+ module GrowlAtom
8
+
9
+ VERSION = "0.0.1"
10
+
11
+ def GrowlAtom.gem_dir
12
+ File.expand_path(File.join(File.dirname(__FILE__), '..'))
13
+ end
14
+
15
+ class Error < StandardError; end
16
+
17
+ class Checker
18
+
19
+ def initialize(config_file)
20
+
21
+ @config_file = config_file
22
+
23
+ end
24
+
25
+ def check(url, options = {})
26
+ =begin
27
+ cache_file = 'cache'
28
+
29
+ system("touch #{cache_file}")
30
+
31
+ # Download it
32
+ http = Net::HTTP.new('mail.google.com', 443)
33
+ req = Net::HTTP::Get.new('/mail/feed/atom/')
34
+ http.use_ssl = true
35
+ 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
+ end
62
+
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'})
66
+ end
67
+
68
+
69
+ end
70
+
71
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: matth-growl-atom
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: universal-darwin-9
6
+ authors:
7
+ - Matt Haynes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-08 00:00:00 -07: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
+ - lib/growl-atom.rb
35
+ has_rdoc: false
36
+ homepage: http://matthaynes.net/blog/
37
+ post_install_message:
38
+ rdoc_options: []
39
+
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ version:
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ requirements: []
55
+
56
+ rubyforge_project:
57
+ rubygems_version: 1.2.0
58
+ signing_key:
59
+ specification_version: 2
60
+ summary: Create growl notifications for Atom entries
61
+ test_files: []
62
+