imsg 0.0.4 → 0.0.5
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bin/imsg +10 -15
- data/lib/imsg.rb +17 -57
- data/lib/imsg/version.rb +1 -1
- data/lib/model/chat.rb +34 -0
- data/lib/model/participant.rb +11 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 764296b4df5fa36643856287659a63fde3af17d9
|
4
|
+
data.tar.gz: 00e11b5b9dffca41e12ce1e230aeea630d41653e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 923bde834dc20f9f44bbee55fca2d2ebec66b1d94d3b14ace5fc3e3bbc09259df6df5f85b4daf997d3e8f8cabce45214d52f2b0de65e228aec57358e975a57d7
|
7
|
+
data.tar.gz: e31ac22f208906b84376133a72641dc860c1893682ec61cd7f844ed8d94163a9f9ddd9cfe9728b4d5c62e76ac4784225e0da062e61f9e718ec496610c36e776e
|
data/Gemfile.lock
CHANGED
data/bin/imsg
CHANGED
@@ -11,21 +11,16 @@ def interactWithUser
|
|
11
11
|
ARGV.clear
|
12
12
|
STDOUT.flush
|
13
13
|
|
14
|
-
#
|
15
|
-
ImsgHandler.
|
14
|
+
# handles user message
|
15
|
+
ImsgHandler.ask_for_buddy_with_msg str
|
16
|
+
end
|
16
17
|
|
17
|
-
# Gets the buddy name or number
|
18
|
-
response = gets.chomp
|
19
18
|
|
20
|
-
|
21
|
-
|
19
|
+
# Control+C trick in order to get out of exit() signal gracefully
|
20
|
+
trap("SIGINT") { throw :ctrl_c }
|
21
|
+
catch :ctrl_c do
|
22
|
+
begin
|
23
|
+
interactWithUser
|
24
|
+
rescue Exception
|
25
|
+
end
|
22
26
|
end
|
23
|
-
|
24
|
-
# Control+C trick in order to get out of command gracefully
|
25
|
-
trap("SIGINT") { throw :ctrl_c }
|
26
|
-
catch :ctrl_c do
|
27
|
-
begin
|
28
|
-
interactWithUser
|
29
|
-
rescue Exception
|
30
|
-
end
|
31
|
-
end
|
data/lib/imsg.rb
CHANGED
@@ -1,56 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require
|
3
|
-
require '
|
2
|
+
require 'imsg/version'
|
3
|
+
require 'model/chat'
|
4
4
|
|
5
5
|
module ImsgHandler
|
6
|
-
CHAT_DISPLAY_LIMIT =
|
7
|
-
|
8
|
-
class Chat
|
9
|
-
attr_accessor :chat_number, :updated, :participants
|
10
|
-
|
11
|
-
def initialize(chat_number, updated, participants)
|
12
|
-
self.chat_number = chat_number
|
13
|
-
self.updated = updated
|
14
|
-
self.participants = participants
|
15
|
-
end
|
16
|
-
|
17
|
-
def to_s
|
18
|
-
"#{chat_number} - #{participants.map(&:name).join(", ")}"
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.fetch_all
|
22
|
-
ascript_chats.map.with_index(1){ |chat, i| from_ascript_chat(chat, i) }
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.ascript_chats
|
26
|
-
Appscript.app("Messages").chats.get()
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.from_ascript_chat(chat, chat_number)
|
30
|
-
new(chat_number, chat.updated.get(), participants_from_ascript_chat(chat))
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.participants_from_ascript_chat(chat)
|
34
|
-
chat.participants.get().map do |participant|
|
35
|
-
Participant.from_ascript_participant(participant)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class Participant
|
41
|
-
attr_accessor :name
|
42
|
-
|
43
|
-
def initialize(name)
|
44
|
-
self.name = name
|
45
|
-
end
|
46
|
-
|
47
|
-
def self.from_ascript_participant(ascript_participant)
|
48
|
-
self.new(ascript_participant.name.get())
|
49
|
-
end
|
50
|
-
end
|
6
|
+
CHAT_DISPLAY_LIMIT = 15
|
51
7
|
|
52
8
|
def self.display_chats(chats)
|
53
|
-
|
9
|
+
chats.first(CHAT_DISPLAY_LIMIT).map.with_index{ |x, i| "#{i + 1} - #{x.to_s}"}.join("\n")
|
54
10
|
end
|
55
11
|
|
56
12
|
def self.sort_by_updated(chats)
|
@@ -58,15 +14,15 @@ module ImsgHandler
|
|
58
14
|
end
|
59
15
|
|
60
16
|
# Check if a String is a integer number
|
61
|
-
def self.is_i
|
62
|
-
|
17
|
+
def self.is_i?(str)
|
18
|
+
str =~ /\A\d+\z/
|
63
19
|
end
|
64
20
|
|
65
21
|
# Calls Applescript in order to trigger an iMessage message to a buddy
|
66
22
|
# The buddy parameter accepts a String with either a chat number or a Buddy name
|
67
|
-
def self.
|
68
|
-
if
|
69
|
-
puts "Sending \'#{message}\' to chat
|
23
|
+
def self.send_message message, buddy, chat
|
24
|
+
if (chat)
|
25
|
+
puts "Sending \'#{message}\' to chat with #{chat.to_s}"
|
70
26
|
`osascript -e 'tell application "Messages" to send \"#{message}\" to item #{buddy.to_i} of text chats'`
|
71
27
|
else
|
72
28
|
puts "Sending \'#{message}\' to buddy \'#{buddy}\'"
|
@@ -75,11 +31,15 @@ module ImsgHandler
|
|
75
31
|
end
|
76
32
|
|
77
33
|
# Shows the chat list along with their participants
|
78
|
-
|
79
|
-
chats = Chat.fetch_all
|
80
|
-
puts "\
|
34
|
+
def self.ask_for_buddy_with_msg msg
|
35
|
+
chats = sort_by_updated(Chat.fetch_all)
|
36
|
+
puts "\nTo whom would you like to send your message?"
|
81
37
|
puts "(You can choose a number or type a buddy name/email)\n\n"
|
82
38
|
puts display_chats(chats)
|
39
|
+
response = gets.chomp
|
40
|
+
chat = is_i?(response) ? chats[response.to_i - 1] : nil
|
41
|
+
response = chat ? chat.chat_number.to_s : response
|
42
|
+
|
43
|
+
send_message(msg, response, chat)
|
83
44
|
end
|
84
|
-
|
85
45
|
end
|
data/lib/imsg/version.rb
CHANGED
data/lib/model/chat.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'appscript'
|
2
|
+
require 'model/participant'
|
3
|
+
|
4
|
+
class Chat
|
5
|
+
attr_accessor :chat_number, :updated, :participants
|
6
|
+
|
7
|
+
def initialize(chat_number, updated, participants)
|
8
|
+
self.chat_number = chat_number
|
9
|
+
self.updated = updated
|
10
|
+
self.participants = participants
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
participants.map(&:name).join(", ")
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.fetch_all
|
18
|
+
ascript_chats.map.with_index(1){ |chat, i| from_ascript_chat(chat, i) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.ascript_chats
|
22
|
+
Appscript.app("Messages").chats.get()
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.from_ascript_chat(chat, chat_number)
|
26
|
+
new(chat_number, chat.updated.get(), participants_from_ascript_chat(chat))
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.participants_from_ascript_chat(chat)
|
30
|
+
chat.participants.get().map do |participant|
|
31
|
+
Participant.from_ascript_participant(participant)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imsg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Sampaio
|
@@ -71,6 +71,8 @@ files:
|
|
71
71
|
- imsg.gemspec
|
72
72
|
- lib/imsg.rb
|
73
73
|
- lib/imsg/version.rb
|
74
|
+
- lib/model/chat.rb
|
75
|
+
- lib/model/participant.rb
|
74
76
|
homepage: https://github.com/chrisfsampaio/imsg
|
75
77
|
licenses:
|
76
78
|
- MIT
|