imsg 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2bd92b333ae71886dbe0b671e6be4f0a9e62b196
4
- data.tar.gz: 8daf19a3caef511a3fbf10b5270c640620877246
3
+ metadata.gz: a81a94e2ace83d8ccc93b41b0f081aaebc8eab97
4
+ data.tar.gz: 6b243ee65b0bd53c88b7bc1c59116059b939dc42
5
5
  SHA512:
6
- metadata.gz: 126e1710aba5d04bad91880df9d8009ef6844bf0089634c3e36a28ad4a8206a52403751a6bffb0518d29cf2db71be41a5dfa65596493de3b3608371d860ad1d1
7
- data.tar.gz: 45f6c7626fda49c2d7acfba01dc9dd6535a7e5070573f7543e0fa158855083bc597253a4a3f116df164b3fb415e707886eb84e90a2409584c013b3fb65be3e25
6
+ metadata.gz: 68fe23cc2f81337e01243412ed5aaabf5bb48156d4575fc94c346e9a50316f9a1cfdd62a1e3ee5d9e201e8660a03c262877bf54fb0caaa3c306b26c1dfd36207
7
+ data.tar.gz: 4aaf1e3c6fb502cebd810aea86bb4393eb2df6b9a6a54450dee5cce33e39248b43571743533370cf2f4a3e73d07e359dd038eafcf074f7094237c0c85922041f
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- imsg (0.0.1)
4
+ imsg (1.0.0)
5
+ rb-appscript
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
@@ -16,4 +17,3 @@ DEPENDENCIES
16
17
  bundler (~> 1.5)
17
18
  imsg!
18
19
  rake
19
- rb-appscript
data/README.md CHANGED
@@ -1,26 +1,56 @@
1
1
  # imsg
2
2
 
3
- Tired of getting off your terminal screen to answer that dickheads friends of yours?
4
- Now you can curse them right on the terminal!
3
+ Tired of getting off your terminal screen to answer those dickhead friends of yours?
4
+ Now you can curse them right from the terminal!
5
5
 
6
6
  ## Installation
7
7
 
8
- Add this line to your application's Gemfile:
8
+ It is easy as:
9
9
 
10
- gem 'imsg'
10
+ ```bash
11
+ $ gem install imsg
12
+ ```
11
13
 
12
- And then execute:
14
+ ## Usage
13
15
 
14
- $ bundle
16
+ ```bash
17
+ $ imsg HELLOOO FROM TERMINAL
18
+ ```
15
19
 
16
- Or install it yourself as:
20
+ Then select a number corresponding to the person you wish to message
17
21
 
18
- $ gem install imsg
22
+ To which chat you wanna send your message?
23
+ (You can choose a number or type a buddy name/email)
24
+ 1 - Christian Sampaio
25
+ 2 - Linus Torvalds
26
+ 3 - Tim Berners Lee
27
+ 4 - Steve Wozniak
28
+ 5 - Sergey Brin
29
+ 6 - Larry Page
30
+ ```bash
31
+ $ 4
32
+ ```
19
33
 
20
- ## Usage
34
+ ## Common problems
35
+ ###Using special characters
36
+ If you wanna use special characters like parentheses, brackets or quotes you need to escape it. i.e.:
37
+ ```bash
38
+ $ imsg HELLOOO FROM TERMINAL \(ESCAPIIING\)
39
+ ```
40
+ or
41
+ ```bash
42
+ $ imsg "HELLOOO FROM TERMINAL (ESCAPIIING)"
43
+ ```
44
+
45
+ ###Not having write permissions:
21
46
 
22
- imsg HELLLO FROM TERMINAL
47
+ If you don't have write access to your Ruby folder:
23
48
 
49
+ ```bash
50
+ $ sudo gem install imsg
51
+ ```
52
+
53
+
24
54
  ## Contributing
25
55
 
26
56
  1. Fork it ( http://github.com/chrisfsampaio/imsg/fork )
@@ -29,4 +59,9 @@ imsg HELLLO FROM TERMINAL
29
59
  4. Push to the branch (`git push origin my-new-feature`)
30
60
  5. Create new Pull Request
31
61
 
62
+ ## Contact
63
+ christian.fsampaio@gmail.com
64
+ http://chrisfsampaio.github.io
65
+
66
+
32
67
  #<3
data/bin/imsg CHANGED
@@ -1,2 +1,31 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'imsg'
3
+
4
+ def interactWithUser
5
+ # Gets the message and concatenate it into a string
6
+ str = ""
7
+ ARGV.each do |value|
8
+ str +=value+" "
9
+ end
10
+ str = str.chomp(' ');
11
+ ARGV.clear
12
+ STDOUT.flush
13
+
14
+ # Show the chat list with the buddies names
15
+ ImsgHandler.showChatList
16
+
17
+ # Gets the buddy name or number
18
+ response = gets.chomp
19
+
20
+ # Send the message captured on the beggining to the selected buddy
21
+ ImsgHandler.sendMessage str, response
22
+ 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
@@ -2,49 +2,52 @@
2
2
  require "imsg/version"
3
3
  require 'appscript'
4
4
 
5
- def formatBuddies buddies
6
- retVal = ""
7
- count = 1
8
- buddies.each do |buddy|
9
- retVal += count.to_s + " - " +buddy.join(',') +"\n"
10
- count += 1
11
- end
12
- retVal
13
- end
5
+ module ImsgHandler
14
6
 
15
- def is_i str
16
- !!(str =~ /^[-+]?[0-9]+$/)
17
- end
7
+ # Formats a list of buddies objects retrieved by Applescript into a readable list
8
+ # returns a formatted String
9
+ def self.formatBuddies buddies
10
+ formatedString = ""
11
+ count = 1
12
+ buddies.each do |buddy|
13
+ formatedString += " " + count.to_s + " - " + buddy.join(',') + "\n"
14
+ count += 1
15
+ end
16
+ formatedString
17
+ end
18
18
 
19
- str = ""
20
- ARGV.each do |value|
21
- str +=value+" "
22
- end
23
- str = str.chomp(' ');
24
- ARGV.clear
25
- STDOUT.flush
19
+ # Check if a String is a integer number
20
+ def self.is_i str
21
+ !!(str =~ /^[-+]?[0-9]+$/)
22
+ end
26
23
 
27
- imsg = Appscript.app("Messages")
28
- a = imsg.chats.participants.get()
29
- b = []
30
- a.each do |v|
31
- names = []
32
- v.each do |buddy|
33
- names.push buddy.name.get()
34
- end
35
- b.push names
36
- end
37
- puts "\n\nTo which chat you wanna send your message?"
38
- puts "(You can choose a number or type a buddy name/email)\n\n"
39
- puts formatBuddies b
24
+ # Calls Applescript in order to trigger an iMessage message to a buddy
25
+ # The buddy parameter accepts a String with either a chat number or a Buddy name
26
+ def self.sendMessage message, buddy
27
+ if is_i buddy
28
+ puts "Sending \'#{message}\' to chat number #{buddy}"
29
+ `osascript -e 'tell application "Messages" to send \"#{message}\" to item #{buddy.to_i} of text chats'`
30
+ else
31
+ puts "Sending \'#{message}\' to buddy \'#{buddy}\'"
32
+ `osascript -e 'tell application "Messages" to send \"#{message}\" to buddy \"#{buddy}\"'`
33
+ end
34
+ end
40
35
 
36
+ # Shows the chat list along with their participants
37
+ def self.showChatList
38
+ imsg = Appscript.app("Messages")
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
48
+ puts "\nWho would you like to send your message to?"
49
+ puts "(You can choose a number or type a buddy name/email)\n\n"
50
+ puts formatBuddies participantsByChat
51
+ end
41
52
 
42
- response = gets.chomp
43
-
44
- if is_i response
45
- puts "Sending \'#{str}\' to chat number #{response}"
46
- `osascript -e 'tell application "Messages" to send \"#{str}\" to item #{response.to_i} of text chats'`
47
- else
48
- puts "Sending \'#{str}\' to buddy \'#{response}\'"
49
- `osascript -e 'tell application "Messages" to send \"#{str}\" to buddy \"#{response}\"'`
50
- end
53
+ end
@@ -1,3 +1,3 @@
1
1
  module Imsg
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Sampaio