fsgrowl 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fsgrowl.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fsgrowl (0.1.0)
5
+ daemons
6
+ json
7
+ nokogiri
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ daemons (1.1.4)
13
+ json (1.6.5)
14
+ nokogiri (1.5.0)
15
+ rake (0.8.7)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ fsgrowl!
22
+ rake
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # Formspring Growl Notifier
2
+
3
+ Provides Growl notifications for Formspring
4
+
5
+ ## Installation
6
+
7
+ Edit ~/.fsgrowl
8
+
9
+ username: your_user_name
10
+ password: your_password
11
+
12
+ The file will be chmod to 0600
13
+
14
+ ## Running
15
+
16
+ Type `fsgrowl start` in a terminal. Type `fsgrowl stop` to stop it.
17
+
18
+
19
+ ## CREDITS
20
+
21
+ https://github.com/svoop/autotest-growl
22
+
23
+ For the growl binaries
24
+
25
+ ruby-growl, ruby_gntp don't work for me (Growl 1.2.2). Id' really love it for the callback.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/fsgrowl ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #
4
+ # fsgrowl (c)2012 gilles.devaux@gmail.com
5
+ #
6
+
7
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
8
+ # Version 2, December 2004
9
+ #
10
+ # Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
11
+ #
12
+ # Everyone is permitted to copy and distribute verbatim or modified
13
+ # copies of this license document, and changing it is allowed as long
14
+ # as the name is changed.
15
+ #
16
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
17
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
18
+ #
19
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
20
+
21
+ require 'rubygems'
22
+ require 'fsgrowl'
23
+ require 'yaml'
24
+ require 'daemons'
25
+ require 'optparse'
26
+
27
+ conf_file = "#{ENV['HOME']}/.fsgrowl"
28
+ if File.exists?(conf_file)
29
+ File.chmod(0600, conf_file)
30
+ else
31
+ $stderr.puts "Can't find config file #{conf_file}'"
32
+ exit(1)
33
+ end
34
+
35
+ conf = YAML.load_file(conf_file)
36
+
37
+ @fsg = Fsgrowl::Fsgrowl.new(conf['username'], conf['password'])
38
+
39
+ def run
40
+ loop do
41
+ @fsg.check
42
+ sleep(30)
43
+ end
44
+ end
45
+
46
+ Daemons.run_proc('fsgrowl', {:multiple => false, :app_name => 'fsgrowl'}) do
47
+ run
48
+ end
data/fsgrowl.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "fsgrowl/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "fsgrowl"
7
+ s.version = Fsgrowl::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Gilles Devaux"]
10
+ s.email = ["gilles.devaux@gmail.com"]
11
+ s.homepage = "http://rubygems.org/gems/fsgrowl"
12
+ s.summary = "Growl notifier for Formspring.me"
13
+ s.description = "Growl notifier for Formspring.me"
14
+
15
+ s.rubyforge_project = "fsgrowl"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
20
+ s.require_paths = %w(lib)
21
+
22
+ s.bindir = 'bin'
23
+ s.executables=%w(fsgrowl)
24
+
25
+ s.add_dependency "nokogiri"
26
+ s.add_dependency "json"
27
+ s.add_dependency "daemons"
28
+
29
+ s.add_development_dependency "rake"
30
+
31
+ end
data/growl/growlnotify ADDED
@@ -0,0 +1,19 @@
1
+ #!/bin/bash
2
+
3
+ for application in "Growl" "GrowlHelperApp"; do
4
+ version=`osascript -e "get version of application \"$application\"" 2>/dev/null`
5
+ if [ $? -eq 0 ]; then break; fi
6
+ done
7
+
8
+ case "$version" in
9
+ "")
10
+ echo "Growl not found: please install Growl and try again"
11
+ exit 1
12
+ ;;
13
+ 1.[012]*)
14
+ $0-1.1.5 "$@"
15
+ ;;
16
+ *)
17
+ $0-1.3 "$@"
18
+ ;;
19
+ esac
Binary file
Binary file
data/img/logo.png ADDED
Binary file
data/lib/fsgrowl.rb ADDED
@@ -0,0 +1,22 @@
1
+ #
2
+ # fsgrowl (c)2012 gilles.devaux@gmail.com
3
+ #
4
+
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # Version 2, December 2004
7
+ #
8
+ # Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
9
+ #
10
+ # Everyone is permitted to copy and distribute verbatim or modified
11
+ # copies of this license document, and changing it is allowed as long
12
+ # as the name is changed.
13
+ #
14
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
15
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
16
+ #
17
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
18
+
19
+ module Fsgrowl
20
+ require 'fsgrowl/version'
21
+ require 'fsgrowl/fsgrowl'
22
+ end
@@ -0,0 +1,97 @@
1
+ require 'net/http'
2
+ require 'pstore'
3
+ require 'json'
4
+ require 'nokogiri'
5
+
6
+ module Fsgrowl
7
+
8
+ GEM_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
9
+
10
+ class Fsgrowl
11
+
12
+ def initialize(username, password)
13
+
14
+ @username = username
15
+
16
+ pstore_file = "#{ENV['HOME']}/.fsgrowl.pstore"
17
+ @store = PStore.new(pstore_file)
18
+ if File.exist?(pstore_file)
19
+ File.chmod(0600, pstore_file)
20
+ end
21
+
22
+ @store.transaction do
23
+ @cookie = @store[@username]
24
+ end
25
+
26
+ unless @cookie
27
+ login(username, password)
28
+ end
29
+ end
30
+
31
+ def login(username, password)
32
+
33
+ http = Net::HTTP.new('www.formspring.me')
34
+ path = '/account/login?ajax=1'
35
+
36
+ # POST request -> logging in
37
+ data = "username=#{username}&password=#{password}&login=true&ajax=1"
38
+ resp, rdata = http.post(path, data)
39
+ if resp.code.to_i != 200
40
+ puts "Error logging in"
41
+ exit(1)
42
+ end
43
+
44
+ @cookie = resp.response['set-cookie'].split('; ')[0]
45
+
46
+ # Save the cookie
47
+ @store.transaction do
48
+ @store[@username] = @cookie
49
+ end
50
+ end
51
+
52
+ def check(all=false)
53
+
54
+ #read last since_id
55
+ since_id = 1
56
+ unless all
57
+ @store.transaction do
58
+ since_id = @store["#{@username}:sinceid"]
59
+ since_id = 1 if since_id.nil?
60
+ end
61
+ end
62
+
63
+ http = Net::HTTP.new('www.formspring.me')
64
+ path = "/follow/streamrefresh?ajax=1&since_id=#{since_id}&with_content=true"
65
+ headers = {
66
+ 'Cookie' => @cookie,
67
+ }
68
+ resp, data = http.get(path, headers)
69
+ content = JSON.parse(data)['content']
70
+ html_doc = Nokogiri::HTML(content)
71
+ #TODO OR selector?
72
+ html_doc.css('li[class~="question"]').each do |elt|
73
+ node = elt.at_css('div[class="responder"] a[class~="username"]')
74
+ if node
75
+ response = elt.at_css('p[rel=response-text]').text
76
+ growl("New response from #{node.text}", response)
77
+ end
78
+ end
79
+ since_id = html_doc.at_css('li[rel]')
80
+ if since_id
81
+ since_id = since_id['rel']
82
+ @store.transaction do
83
+ @store["#{@username}:sinceid"] = since_id
84
+ end
85
+ end
86
+ end
87
+
88
+ def growl(title, message, priority=0, sticky=false)
89
+ growl = File.join(GEM_PATH, 'growl', 'growlnotify')
90
+ sender = 'Formspring'
91
+ icon = File.join(GEM_PATH, 'img', 'logo.png')
92
+ options = %(-n "#{sender}" --image "#{icon}" -p #{priority} -m "#{message}" "#{title}" #{'-s' if sticky})
93
+ system %(#{growl} #{options} &)
94
+ end
95
+ end
96
+
97
+ end
@@ -0,0 +1,3 @@
1
+ module Fsgrowl
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fsgrowl
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Gilles Devaux
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-02-17 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: nokogiri
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: json
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: daemons
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: rake
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ type: :development
76
+ version_requirements: *id004
77
+ description: Growl notifier for Formspring.me
78
+ email:
79
+ - gilles.devaux@gmail.com
80
+ executables:
81
+ - fsgrowl
82
+ extensions: []
83
+
84
+ extra_rdoc_files: []
85
+
86
+ files:
87
+ - .gitignore
88
+ - Gemfile
89
+ - Gemfile.lock
90
+ - README.md
91
+ - Rakefile
92
+ - bin/fsgrowl
93
+ - fsgrowl.gemspec
94
+ - growl/growlnotify
95
+ - growl/growlnotify-1.1.5
96
+ - growl/growlnotify-1.3
97
+ - img/logo.png
98
+ - lib/fsgrowl.rb
99
+ - lib/fsgrowl/fsgrowl.rb
100
+ - lib/fsgrowl/version.rb
101
+ has_rdoc: true
102
+ homepage: http://rubygems.org/gems/fsgrowl
103
+ licenses: []
104
+
105
+ post_install_message:
106
+ rdoc_options: []
107
+
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ hash: 3
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ hash: 3
125
+ segments:
126
+ - 0
127
+ version: "0"
128
+ requirements: []
129
+
130
+ rubyforge_project: fsgrowl
131
+ rubygems_version: 1.6.2
132
+ signing_key:
133
+ specification_version: 3
134
+ summary: Growl notifier for Formspring.me
135
+ test_files: []
136
+