imsg 0.0.3 → 0.0.4
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/README.md +1 -1
- data/lib/imsg.rb +53 -21
- data/lib/imsg/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebc7fd076a7c56ab0d450077012b0aa36f9cccc8
|
4
|
+
data.tar.gz: bd23220b3346f311046c51e078b5b32c5420e621
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68d1ec0492b62487b8d105569d877c211a15306bb3a6147ffcd12e465c0b59f3a00bd717f71ef087d4ac39b0be7aceb3c1fedec58334869045215c7568cf6ee6
|
7
|
+
data.tar.gz: 68409ec4ef8c10663ebf8c1bfdbbfaf6d952e72149fb6adab6f1080b9d07252d62febbe8048dd2c0991d5371699a9f0efb44b78cfb41601a1277b46ac22438b7
|
data/README.md
CHANGED
@@ -32,7 +32,7 @@ $ 4
|
|
32
32
|
```
|
33
33
|
|
34
34
|
## Common problems
|
35
|
-
###Using special characters
|
35
|
+
###Using special characters:
|
36
36
|
If you wanna use special characters like parentheses, brackets or quotes you need to escape it. i.e.:
|
37
37
|
```bash
|
38
38
|
$ imsg HELLOOO FROM TERMINAL \(ESCAPIIING\)
|
data/lib/imsg.rb
CHANGED
@@ -3,17 +3,58 @@ require "imsg/version"
|
|
3
3
|
require 'appscript'
|
4
4
|
|
5
5
|
module ImsgHandler
|
6
|
+
CHAT_DISPLAY_LIMIT = 12
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
15
37
|
end
|
16
|
-
|
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
|
51
|
+
|
52
|
+
def self.display_chats(chats)
|
53
|
+
sort_by_updated(chats).first(CHAT_DISPLAY_LIMIT).map(&:to_s).join("\n")
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.sort_by_updated(chats)
|
57
|
+
chats.sort{ |a, b| b.updated <=> a.updated }
|
17
58
|
end
|
18
59
|
|
19
60
|
# Check if a String is a integer number
|
@@ -35,19 +76,10 @@ module ImsgHandler
|
|
35
76
|
|
36
77
|
# Shows the chat list along with their participants
|
37
78
|
def self.showChatList
|
38
|
-
|
39
|
-
participants = imsg.chats.participants.get()
|
40
|
-
participantsByChat = []
|
41
|
-
participants.each do |v|
|
42
|
-
names = []
|
43
|
-
v.each do |buddy|
|
44
|
-
names.push buddy.name.get()
|
45
|
-
end
|
46
|
-
participantsByChat.push names
|
47
|
-
end
|
79
|
+
chats = Chat.fetch_all
|
48
80
|
puts "\nWho would you like to send your message to?"
|
49
81
|
puts "(You can choose a number or type a buddy name/email)\n\n"
|
50
|
-
puts
|
82
|
+
puts display_chats(chats)
|
51
83
|
end
|
52
84
|
|
53
|
-
end
|
85
|
+
end
|
data/lib/imsg/version.rb
CHANGED