PerfectlyNormal-Twitorious 0.2.8 → 0.2.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/twit +11 -2
- data/bin/twit-notifier +1 -0
- data/lib/twitorious/api/twitter.rb +60 -14
- data/lib/twitorious/timeline.rb +13 -1
- data/lib/twitorious.rb +1 -1
- data/twitorious.gemspec +2 -2
- metadata +2 -2
data/bin/twit
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
require 'twitorious'
|
|
3
3
|
require 'readline'
|
|
4
4
|
|
|
5
|
-
Thread.abort_on_exception = true
|
|
6
|
-
|
|
7
5
|
module Twitorious
|
|
8
6
|
class Twit
|
|
9
7
|
def initialize
|
|
@@ -24,6 +22,8 @@ module Twitorious
|
|
|
24
22
|
cmd, *args = status.split(" ")
|
|
25
23
|
case cmd
|
|
26
24
|
when "!update": update
|
|
25
|
+
when "!timeline": fetch_timeline
|
|
26
|
+
when "!mentions": fetch_mentions
|
|
27
27
|
when "!quit": exit
|
|
28
28
|
when "!exit": exit
|
|
29
29
|
else Twitorious::Update.new(status)
|
|
@@ -40,6 +40,15 @@ module Twitorious
|
|
|
40
40
|
|
|
41
41
|
def update
|
|
42
42
|
@timeline.fetch_timeline
|
|
43
|
+
@timeline.fetch_mentions
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def fetch_mentions
|
|
47
|
+
@timeline.fetch_mentions
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def fetch_timeline
|
|
51
|
+
@timeline.fetch_timeline
|
|
43
52
|
end
|
|
44
53
|
end
|
|
45
54
|
end
|
data/bin/twit-notifier
CHANGED
|
@@ -22,29 +22,75 @@ module Twitorious
|
|
|
22
22
|
|
|
23
23
|
def fetch_timeline
|
|
24
24
|
puts "Fetching timeline from #{@site[:name]}"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
res = http.request(req)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
updates = JSON.parse(res.body)
|
|
25
|
+
|
|
26
|
+
path = @site[:url].path + "/statuses/friends_timeline.json"
|
|
27
|
+
path += "?count=200&since_id=#{@site[:timeline_since_id]}" if @site[:timeline_since_id]
|
|
28
|
+
res = fetch_body(@site[:url].host, @site[:url].port, path, @site[:user], @site[:pass])
|
|
29
|
+
|
|
30
|
+
updates = JSON.parse(res)
|
|
35
31
|
puts " No updates" if updates.empty?
|
|
36
32
|
return if updates.empty?
|
|
37
33
|
|
|
38
34
|
puts " Got #{updates.size} update#{"s" if updates.size > 1}"
|
|
39
|
-
updates.reverse
|
|
35
|
+
show_notifications(updates.reverse)
|
|
36
|
+
|
|
37
|
+
# Returning the last ID we saw, so we can update since_id for the site
|
|
38
|
+
return updates[0]["id"]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def fetch_mentions
|
|
42
|
+
puts "Fetching mentions from #{@site[:name]}"
|
|
43
|
+
|
|
44
|
+
path = @site[:url].path + "/statuses/mentions.json"
|
|
45
|
+
path += "?since_id=#{@site[:mentions_since_id]}" if @site[:mentions_since_id]
|
|
46
|
+
res = fetch_body(@site[:url].host, @site[:url].port, path, @site[:user], @site[:pass])
|
|
47
|
+
|
|
48
|
+
updates = JSON.parse(res)
|
|
49
|
+
puts " No new mentions" if updates.empty?
|
|
50
|
+
return if updates.empty?
|
|
51
|
+
|
|
52
|
+
puts " Got #{updates.size} new mentions" if updates.size > 1
|
|
53
|
+
puts " Got one new mention" if updates.size == 1
|
|
54
|
+
|
|
55
|
+
show_notifications(updates.reverse)
|
|
56
|
+
|
|
57
|
+
# Returning the last ID we saw, so we can update since_id for the mentions
|
|
58
|
+
return updates[0]["id"]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
private
|
|
62
|
+
|
|
63
|
+
def fetch_body(host, port, path, username = nil, password = nil)
|
|
64
|
+
res = nil
|
|
65
|
+
begin
|
|
66
|
+
Net::HTTP.start(host, port) do |http|
|
|
67
|
+
req = Net::HTTP::Get.new(path, { "User-Agent" => "Twitorious/#{Twitorious::VERSION}"})
|
|
68
|
+
req.basic_auth username, password if username
|
|
69
|
+
res = http.request(req)
|
|
70
|
+
end
|
|
71
|
+
rescue => e
|
|
72
|
+
$stderr.puts "Unhandled exception! #{e.message}"
|
|
73
|
+
rescue Timeout::Error
|
|
74
|
+
$stderr.puts "Request to #{host} timed out. Retrying in five seconds"
|
|
75
|
+
sleep 5
|
|
76
|
+
retry
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
if res.kind_of?(Net::HTTPNotFound)
|
|
80
|
+
$stderr.puts "404 Not Found! #{host}:#{port}/#{path}"
|
|
81
|
+
return "{}"
|
|
82
|
+
elsif res.kind_of?(Net::HTTPOK)
|
|
83
|
+
return res.body
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def show_notifications(updates)
|
|
88
|
+
updates.each do |update|
|
|
40
89
|
image = Twitorious::Image.from_url(update["user"]["profile_image_url"], @config.image_store)
|
|
41
90
|
filename = image ? image.filename : @site[:icon]
|
|
42
91
|
@notifier.notify(update["user"]["screen_name"], update["text"], update["created_at"], filename)
|
|
43
92
|
sleep @config.sleep_between_notifications.to_i
|
|
44
93
|
end
|
|
45
|
-
|
|
46
|
-
# Returning the last ID we saw, so we can update since_id for the site
|
|
47
|
-
return updates[0]["id"]
|
|
48
94
|
end
|
|
49
95
|
end
|
|
50
96
|
end
|
data/lib/twitorious/timeline.rb
CHANGED
|
@@ -10,11 +10,23 @@ module Twitorious
|
|
|
10
10
|
case site[:api]
|
|
11
11
|
when "Twitter":
|
|
12
12
|
since_id = Twitorious::API::Twitter.new(@config, site).fetch_timeline
|
|
13
|
-
site[:
|
|
13
|
+
site[:timeline_since_id] = since_id if since_id
|
|
14
14
|
else puts "Unknown API #{site[:api]} for site #{site[:name]}"
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
@config.save # Since we've gotten newer since_id's
|
|
18
18
|
end
|
|
19
|
+
|
|
20
|
+
def fetch_mentions
|
|
21
|
+
@config.sites.each do |site|
|
|
22
|
+
case site[:api]
|
|
23
|
+
when "Twitter":
|
|
24
|
+
since_id = Twitorious::API::Twitter.new(@config, site).fetch_mentions
|
|
25
|
+
site[:mentions_since_id] = since_id if since_id
|
|
26
|
+
else puts "Unknown API #{site[:api]} for site #{site[:name]}"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
@config.save # Newer mentions_since_id's
|
|
30
|
+
end
|
|
19
31
|
end
|
|
20
32
|
end
|
data/lib/twitorious.rb
CHANGED
data/twitorious.gemspec
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = "Twitorious"
|
|
3
|
-
s.version = "0.2.
|
|
4
|
-
s.date = "2009-04-
|
|
3
|
+
s.version = "0.2.9"
|
|
4
|
+
s.date = "2009-04-16"
|
|
5
5
|
s.author = "Per Christian B. Viken"
|
|
6
6
|
s.email = "perchr@northblue.org"
|
|
7
7
|
s.homepage = "http://eastblue.org/projects/twitorious/"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: PerfectlyNormal-Twitorious
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Per Christian B. Viken
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-04-
|
|
12
|
+
date: 2009-04-16 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|