PerfectlyNormal-Twitorious 0.2.7 → 0.2.8
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/TODO +0 -1
- data/lib/twitorious.rb +34 -1
- data/lib/twitorious/api/twitter.rb +6 -3
- data/lib/twitorious/image.rb +5 -4
- data/lib/twitorious/notifier.rb +5 -2
- data/lib/twitorious/timeline.rb +1 -0
- data/twitorious.gemspec +2 -2
- metadata +2 -2
data/TODO
CHANGED
data/lib/twitorious.rb
CHANGED
@@ -1,7 +1,40 @@
|
|
1
1
|
module Twitorious
|
2
|
-
VERSION = '0.2.
|
2
|
+
VERSION = '0.2.8'
|
3
3
|
|
4
4
|
class TooLongUpdate < StandardError; end
|
5
|
+
|
6
|
+
# Shamelessly stolen from Rails and stripped of its localization-code.
|
7
|
+
# Hard-coded strings in english!
|
8
|
+
def self.time_ago_in_words(from, to, include_seconds = false, options = {})
|
9
|
+
from_time = Time.mktime(from.year, from.month, from.day, from.hour, from.min, from.sec)
|
10
|
+
to_time = Time.mktime(to.year, to.month, to.day, to.hour, to.min, to.sec)
|
11
|
+
distance_in_minutes = (((to_time - from_time).abs)/60).round
|
12
|
+
distance_in_seconds = ((to_time - from_time).abs).round
|
13
|
+
|
14
|
+
case distance_in_minutes
|
15
|
+
when 0..1
|
16
|
+
return distance_in_minutes == 0 ? "less than a minute ago" : "#{distance_in_minutes} minutes ago" unless include_seconds
|
17
|
+
|
18
|
+
case distance_in_seconds
|
19
|
+
when 0..4 then "less than five seconds ago"
|
20
|
+
when 5..9 then "less than ten seconds ago"
|
21
|
+
when 10..19 then "less than twenty seconds ago"
|
22
|
+
when 20..39 then "half a minute ago"
|
23
|
+
when 40..59 then "less than a minute ago"
|
24
|
+
else "one minute ago"
|
25
|
+
end
|
26
|
+
|
27
|
+
when 2..44 then "#{distance_in_minutes} minutes ago"
|
28
|
+
when 45..89 then "about one hour ago"
|
29
|
+
when 90..1439 then "about #{(distance_in_minutes.to_f / 60.0).round} hours ago"
|
30
|
+
when 1440..2879 then "about a day ago"
|
31
|
+
when 2880..43199 then "#{(distance_in_minutes / 1440).round} days ago"
|
32
|
+
when 43200..86399 then "about a month ago"
|
33
|
+
when 86400..525599 then "about #{(distance_in_minutes / 43200).round} months ago"
|
34
|
+
when 525600..1051199 then "about a year ago"
|
35
|
+
else "#{(distance_in_minutes / 525600).round} years ago"
|
36
|
+
end
|
37
|
+
end
|
5
38
|
end
|
6
39
|
|
7
40
|
require 'twitorious/config'
|
@@ -14,29 +14,32 @@ module Twitorious
|
|
14
14
|
|
15
15
|
def update(status)
|
16
16
|
puts "Updating #{@site[:name]}"
|
17
|
-
req = Net::HTTP::Post.new(@site[:url].path + "/statuses/update.json")
|
17
|
+
req = Net::HTTP::Post.new(@site[:url].path + "/statuses/update.json", { "User-Agent" => "Twitorious/#{Twitorious::VERSION}"})
|
18
18
|
req.basic_auth @site[:user], @site[:pass]
|
19
19
|
req.set_form_data({'status' => status}, ';')
|
20
20
|
res = Net::HTTP.new(@site[:url].host, @site[:url].port).start { |http| http.request(req) }
|
21
21
|
end
|
22
22
|
|
23
23
|
def fetch_timeline
|
24
|
+
puts "Fetching timeline from #{@site[:name]}"
|
24
25
|
res = nil
|
25
26
|
Net::HTTP.start(@site[:url].host, @site[:url].port) do |http|
|
26
27
|
path = @site[:url].path + "/statuses/friends_timeline.json"
|
27
28
|
path += "?count=200&since_id=#{@site[:since_id]}" if @site[:since_id]
|
28
|
-
req = Net::HTTP::Get.new(path)
|
29
|
+
req = Net::HTTP::Get.new(path, { "User-Agent" => "Twitorious/#{Twitorious::VERSION}"})
|
29
30
|
req.basic_auth @site[:user], @site[:pass]
|
30
31
|
res = http.request(req)
|
31
32
|
end
|
32
33
|
|
33
34
|
updates = JSON.parse(res.body)
|
35
|
+
puts " No updates" if updates.empty?
|
34
36
|
return if updates.empty?
|
35
37
|
|
38
|
+
puts " Got #{updates.size} update#{"s" if updates.size > 1}"
|
36
39
|
updates.reverse.each do |update|
|
37
40
|
image = Twitorious::Image.from_url(update["user"]["profile_image_url"], @config.image_store)
|
38
41
|
filename = image ? image.filename : @site[:icon]
|
39
|
-
@notifier.notify(update["user"]["screen_name"], update["text"], filename)
|
42
|
+
@notifier.notify(update["user"]["screen_name"], update["text"], update["created_at"], filename)
|
40
43
|
sleep @config.sleep_between_notifications.to_i
|
41
44
|
end
|
42
45
|
|
data/lib/twitorious/image.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'uri'
|
2
2
|
require 'net/http'
|
3
|
+
require 'net/https'
|
3
4
|
require 'digest/md5'
|
4
5
|
|
5
6
|
module Twitorious
|
@@ -19,10 +20,10 @@ module Twitorious
|
|
19
20
|
return Image.new(file) if File.exists?(file)
|
20
21
|
|
21
22
|
site = URI.parse(url)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
http = Net::HTTP.new(site.host, site.port)
|
24
|
+
http.use_ssl = (site.scheme == 'https')
|
25
|
+
req = Net::HTTP::Get.new(site.path, { "User-Agent" => "Twitorious/#{Twitorious::VERSION}"})
|
26
|
+
res = http.request(req)
|
26
27
|
|
27
28
|
return nil unless res.class == Net::HTTPOK
|
28
29
|
File.mkdirs(path) if !File.exists?(path)
|
data/lib/twitorious/notifier.rb
CHANGED
@@ -8,11 +8,14 @@ module Twitorious
|
|
8
8
|
@meow = Meow.new("Twitorious")
|
9
9
|
end
|
10
10
|
|
11
|
-
def notify(sender, message, icon = nil)
|
11
|
+
def notify(sender, message, created, icon = nil)
|
12
|
+
created = DateTime.parse(created)
|
13
|
+
now = DateTime.parse(Time.now.to_s).new_offset(created.offset)
|
14
|
+
time_ago = Twitorious.time_ago_in_words(created, now, true)
|
12
15
|
opts = {}
|
13
16
|
opts[:icon] = icon if icon
|
14
17
|
|
15
|
-
@meow.notify("
|
18
|
+
@meow.notify("#{sender} (#{time_ago})", message, opts) do
|
16
19
|
urls = URI.extract(message, ['http', 'https'])
|
17
20
|
urls.each do |url|
|
18
21
|
%x{open #{url}}
|
data/lib/twitorious/timeline.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-
|
3
|
+
s.version = "0.2.8"
|
4
|
+
s.date = "2009-04-01"
|
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.8
|
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-
|
12
|
+
date: 2009-04-01 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|