earthquake 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -7,6 +7,13 @@ It supports ruby 1.9 only.
7
7
 
8
8
  ![http://images.instagram.com/media/2011/03/21/862f3b8d119b4eeb9c52e690a0087f5e_7.jpg](http://images.instagram.com/media/2011/03/21/862f3b8d119b4eeb9c52e690a0087f5e_7.jpg)
9
9
 
10
+ Features
11
+ ----
12
+
13
+ * You can deal Twitter on Terminal entirely.
14
+ * You can receive data in real time with Streaming API.
15
+ * You can easily extend in Ruby.
16
+
10
17
  Install
11
18
  ----
12
19
 
@@ -150,6 +157,8 @@ The 'm' is a MatchData.
150
157
  TODO
151
158
  ----
152
159
 
160
+ * unescape html
161
+ * dealing direct messages
153
162
  * more intelligent completion
154
163
  * caching statuses
155
164
  * typable id
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.4
1
+ 0.4.5
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{earthquake}
8
- s.version = "0.4.4"
8
+ s.version = "0.4.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["jugyo"]
@@ -25,10 +25,13 @@ module Earthquake
25
25
  end
26
26
 
27
27
  command %r|^:reply (\d+)\s+(.*)|, :as => :reply do |m|
28
- # TODO: fill the user name to reply
29
- async {
30
- twitter.update(m[2], :in_reply_to_status_id => m[1])
31
- } if confirm("reply '#{m[2]}' to #{m[1]}")
28
+ in_reply_to_status_id = m[1]
29
+ target = twitter.status(in_reply_to_status_id)
30
+ screen_name = target["user"]["screen_name"]
31
+ text = "@#{screen_name} #{m[2]}"
32
+ if confirm(["'@#{screen_name}: #{target["text"].u}'".c(36), "reply '#{text}'"].join("\n"))
33
+ async { twitter.update(text, :in_reply_to_status_id => in_reply_to_status_id) }
34
+ end
32
35
  end
33
36
 
34
37
  command :status do |m|
@@ -56,6 +59,10 @@ module Earthquake
56
59
  puts_items twitter.user_timeline(:screen_name => m[1]).reverse
57
60
  end
58
61
 
62
+ command :home do
63
+ puts_items twitter.home_timeline.reverse
64
+ end
65
+
59
66
  command :user do |m|
60
67
  ap twitter.show(m[1]).slice(*%w(id screen_name name profile_image_url description url location time_zone lang protected))
61
68
  end
@@ -64,7 +71,15 @@ module Earthquake
64
71
  puts_items twitter.search(m[1])["results"].each { |s|
65
72
  s["user"] = {"screen_name" => s["from_user"]}
66
73
  }.each {|s|
67
- s["highlights"] = [m[1]]
74
+ words = m[1].split(/\s+/).reject{|x| x[0] =~ /^-|^(OR|AND)$/ }.map{|x|
75
+ case x
76
+ when /^from:(.+)/, /^to:(.+)/
77
+ $1
78
+ else
79
+ x
80
+ end
81
+ }
82
+ s["highlights"] = words
68
83
  }.reverse
69
84
  end
70
85
 
@@ -40,6 +40,7 @@ module Earthquake
40
40
  loaded = ActiveSupport::Dependencies.loaded.dup
41
41
  ActiveSupport::Dependencies.clear
42
42
  loaded.each { |lib| require_dependency lib }
43
+ ensure
43
44
  _init
44
45
  end
45
46
 
@@ -2,4 +2,28 @@ class String
2
2
  def c(*codes)
3
3
  "\e[#{codes.join;}m#{self}\e[0m"
4
4
  end
5
+
6
+ def u
7
+ gsub(/&(lt|gt|amp|quot|apos);/) do |s|
8
+ case s
9
+ when '&' then '&'
10
+ when '&lt;' then '<'
11
+ when '&gt;' then '>'
12
+ when '&apos;' then "'"
13
+ when '&quot;' then '"'
14
+ end
15
+ end
16
+ end
17
+
18
+ def e
19
+ gsub(/[&<>'"]/) do |s|
20
+ case s
21
+ when '&' then '&amp;'
22
+ when '<' then '&lt;'
23
+ when '>' then '&gt;'
24
+ when "'" then '&apos;'
25
+ when '"' then '&quot;'
26
+ end
27
+ end
28
+ end
5
29
  end
@@ -20,8 +20,8 @@ module Earthquake
20
20
  def input(text)
21
21
  begin
22
22
  reload if config[:debug]
23
- if command = commands.detect { |c| c[:pattern] =~ text }
24
- command[:block].call($~)
23
+ if command = command(text)
24
+ command[:block].call(command[:pattern].match(text))
25
25
  elsif !text.empty?
26
26
  puts "Command not found".c(43)
27
27
  end
@@ -44,7 +44,7 @@ module Earthquake
44
44
  command_names << ":#{options[:as]}" if options[:as]
45
45
  commands << {:pattern => pattern, :block => block}
46
46
  else
47
- commands.detect { |c| c[:name] == name }
47
+ commands.detect {|c| c[:pattern] =~ pattern}
48
48
  end
49
49
  end
50
50
 
@@ -21,7 +21,7 @@ module Earthquake
21
21
  insert do
22
22
  while item = item_queue.shift
23
23
  item["stream"] = true
24
- puts_items(item) if filters.all? { |filter| filter.call(item) }
24
+ puts_items(item)
25
25
  end
26
26
  end
27
27
  end
@@ -29,9 +29,10 @@ module Earthquake
29
29
 
30
30
  def puts_items(items)
31
31
  [items].flatten.each do |item|
32
- outputs.each do |p|
32
+ next if filters.any? { |f| f.call(item) == false }
33
+ outputs.each do |o|
33
34
  begin
34
- p.call(item)
35
+ o.call(item)
35
36
  rescue => e
36
37
  error e
37
38
  end
@@ -62,6 +63,7 @@ module Earthquake
62
63
 
63
64
  init do
64
65
  outputs.clear
66
+ filters.clear
65
67
 
66
68
  config[:colors] ||= (31..36).to_a + (91..96).to_a
67
69
 
@@ -81,9 +83,9 @@ module Earthquake
81
83
  statuses.insert(0, "[#{Time.parse(item["created_at"]).strftime('%Y.%m.%d %X')}]")
82
84
  end
83
85
 
84
- source = item["source"] =~ />(.*)</ ? $1 : 'web'
86
+ source = item["source"].u =~ />(.*)</ ? $1 : 'web'
85
87
  user_color = color_of(item["user"]["screen_name"])
86
- text = item["text"].gsub(/[@#]([0-9A-Za-z_]+)/) do |i|
88
+ text = item["text"].u.gsub(/[@#]([0-9A-Za-z_]+)/) do |i|
87
89
  i.c(color_of($1))
88
90
  end
89
91
 
@@ -99,8 +101,8 @@ module Earthquake
99
101
  mark = item["mark"] || ""
100
102
 
101
103
  status = [
102
- "#{mark}#{statuses.join(" ")}".c(90),
103
- item["user"]["screen_name"].c(user_color),
104
+ "#{mark}" + "#{statuses.join(" ")}".c(90),
105
+ "#{item["user"]["screen_name"].c(user_color)}:",
104
106
  "#{text}",
105
107
  "#{misc} #{source}".c(90)
106
108
  ].join(" ")
@@ -15,7 +15,7 @@ module Earthquake
15
15
  s = status_without_cache(id)
16
16
  Earthquake.cache.write(key, s, :expires_in => 1.hour.ago)
17
17
  end
18
- s
18
+ s.dup
19
19
  end
20
20
  alias_method_chain :status, :cache
21
21
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: earthquake
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.4
5
+ version: 0.4.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - jugyo