imessage 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +1 -1
- data/CHANGELOG.md +4 -1
- data/README.md +16 -1
- data/Rakefile +24 -4
- data/Rakefile.dev +6 -0
- data/bin/imessage +9 -53
- data/imessage.gemspec +1 -2
- data/lib/imessage.rb +3 -2
- data/lib/imessage/parser.rb +60 -0
- data/lib/imessage/sender.rb +27 -6
- data/lib/imessage/version.rb +1 -1
- metadata +11 -10
- data/lib/imessage/scripts/send_attachment.applescript +0 -15
- data/lib/imessage/scripts/send_text.applescript +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 719afa93b7a4faddb701be1378360054ee6cc3f8
|
4
|
+
data.tar.gz: 0b1bcc95053547eb357114164f94f90a0fc4181e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5806aa4ccb91ee8ca67666cad3d7ee74e9de5649d58875dc3198d14ad29e89a422a537f4fd13ab47a845476a2f76f6e0fcf612877be3e6bbf6a6f4425cca9015
|
7
|
+
data.tar.gz: 6e2ad71c81fb861dd07b971c8359a2a9e03d9a94e076aec159580b3be0cb03d5a0ae14c5fcd6fac79524c565356be3a54cb4afbcf82ccd0bc077185f9f5e582a
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## [v0.2.0](https://github.com/linjunpop/imessage/tree/v0.2.0)
|
6
|
+
|
7
|
+
* Make it possible to run imessage standalone.
|
8
|
+
|
5
9
|
## [v0.1.1](https://github.com/linjunpop/imessage/tree/v0.1.1)
|
6
10
|
|
7
11
|
* Fixes fail to send messages without attachment. [#3](https://github.com/linjunpop/imessage/issues/3)
|
@@ -17,4 +21,3 @@
|
|
17
21
|
## [v0.0.1](https://github.com/linjunpop/imessage/tree/v0.0.1)
|
18
22
|
|
19
23
|
* Implement send iMessage.
|
20
|
-
|
data/README.md
CHANGED
@@ -23,8 +23,23 @@ Or install it yourself as:
|
|
23
23
|
|
24
24
|
## Usage
|
25
25
|
|
26
|
+
```shell
|
27
|
+
Usage: imessage [options]
|
28
|
+
|
29
|
+
Specific options:
|
30
|
+
-t, --text [TEXT] The TEXT to deliver
|
31
|
+
-a, --attachment [ATTACHMENT] Add an attachment
|
32
|
+
-c, --contacts x,y,z Develier message to these CONTACTS
|
33
|
+
|
34
|
+
Common options:
|
35
|
+
-h, --help Prints this help
|
36
|
+
--version Show version
|
37
|
+
```
|
38
|
+
|
39
|
+
## Example
|
40
|
+
|
26
41
|
```
|
27
|
-
$ imessage
|
42
|
+
$ imessage --text "hello" --contacts "foo@example.com" --attachment 'bar.png'
|
28
43
|
```
|
29
44
|
|
30
45
|
## [Changelog](CHANGELOG.md)
|
data/Rakefile
CHANGED
@@ -1,7 +1,27 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
desc "Build standalone version of imessage"
|
2
|
+
task :standalone do
|
3
|
+
mkdir_p "build"
|
4
|
+
File.open("build/imessage", "w") do |f|
|
5
|
+
f.puts "#!/usr/bin/env ruby"
|
6
|
+
f.puts "# This file is generated from https://github.com/linjunpop/imessage using `rake standalone`"
|
7
|
+
f.puts "# any changes will be overwritten."
|
3
8
|
|
4
|
-
|
9
|
+
f.puts File.read("lib/imessage.rb").gsub(/^require_relative.*\n/, '')
|
10
|
+
f.puts File.read("lib/imessage/version.rb")
|
11
|
+
f.puts File.read("lib/imessage/parser.rb")
|
12
|
+
f.puts File.read("lib/imessage/sender.rb")
|
5
13
|
|
6
|
-
|
14
|
+
f.puts File.read("bin/imessage")
|
15
|
+
.gsub(/^require_relative.*\n/, '')
|
16
|
+
.gsub(%r{#!/usr/bin/env ruby}, '')
|
17
|
+
end
|
18
|
+
sh 'chmod +x build/imessage'
|
19
|
+
end
|
7
20
|
|
21
|
+
desc "Install standalone script"
|
22
|
+
task :install => :standalone do
|
23
|
+
prefix = ENV['PREFIX'] || ENV['prefix'] || '/usr/local'
|
24
|
+
|
25
|
+
FileUtils.mkdir_p "#{prefix}/bin"
|
26
|
+
FileUtils.cp "build/imessage", "#{prefix}/bin"
|
27
|
+
end
|
data/Rakefile.dev
ADDED
data/bin/imessage
CHANGED
@@ -1,58 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require 'gli'
|
3
|
-
require 'imessage'
|
4
2
|
|
5
|
-
|
3
|
+
require_relative '../lib/imessage'
|
6
4
|
|
7
|
-
|
5
|
+
ARGV << '--help' if ARGV.empty?
|
8
6
|
|
9
|
-
|
7
|
+
options = Imessage::Parser.parse(ARGV)
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
c.desc 'Contacts'
|
18
|
-
c.flag [:to, :contacts], type: Array
|
19
|
-
c.flag [:a, :attachment], type: String
|
20
|
-
|
21
|
-
c.action do |global_options, options, args|
|
22
|
-
help_now!('Message or Attachment is required') if !options[:attachment] && args.empty?
|
23
|
-
help_now!('Contacts is required') unless options[:contacts]
|
24
|
-
|
25
|
-
if attachment = options[:attachment]
|
26
|
-
if File.exists?(attachment)
|
27
|
-
attachment = File.expand_path(attachment)
|
28
|
-
else
|
29
|
-
exit_now!("Can not find file #{attachment}")
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
sender = Imessage::Sender.new
|
34
|
-
sender.deliver(
|
35
|
-
text: args.first,
|
36
|
-
attachment: attachment,
|
37
|
-
contacts: options[:contacts]
|
38
|
-
)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
pre do |global,command,options,args|
|
43
|
-
true
|
44
|
-
end
|
45
|
-
|
46
|
-
post do |global,command,options,args|
|
47
|
-
# Post logic here
|
48
|
-
# Use skips_post before a command to skip this
|
49
|
-
# block on that command only
|
50
|
-
end
|
51
|
-
|
52
|
-
on_error do |exception|
|
53
|
-
# Error logic here
|
54
|
-
# return false to skip default error handling
|
55
|
-
true
|
56
|
-
end
|
57
|
-
|
58
|
-
exit run(ARGV)
|
9
|
+
sender = Imessage::Sender.new
|
10
|
+
sender.deliver({
|
11
|
+
text: options.text,
|
12
|
+
attachment: options.attachment,
|
13
|
+
contacts: options.contacts
|
14
|
+
})
|
data/imessage.gemspec
CHANGED
@@ -21,6 +21,5 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
spec.add_development_dependency "rspec", '~> 2.14'
|
24
|
-
|
25
|
-
spec.add_runtime_dependency 'gli','~> 2.8.1'
|
24
|
+
spec.add_development_dependency "pry"
|
26
25
|
end
|
data/lib/imessage.rb
CHANGED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module Imessage
|
5
|
+
class Parser
|
6
|
+
class << self
|
7
|
+
def parse(options)
|
8
|
+
OpenStruct.new.tap do |args|
|
9
|
+
args.contacts = []
|
10
|
+
args.text = nil
|
11
|
+
args.attachment = nil
|
12
|
+
args.verbose = false
|
13
|
+
|
14
|
+
opt_parser(args).parse!(options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def opt_parser(args)
|
21
|
+
OptionParser.new do |opts|
|
22
|
+
opts.banner = "Usage: imessage [options]"
|
23
|
+
|
24
|
+
opts.separator ""
|
25
|
+
opts.separator "Specific options:"
|
26
|
+
|
27
|
+
opts.on("-t", "--text [TEXT]", String, "The TEXT to deliver") do |text|
|
28
|
+
args.text = text
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on("-a", "--attachment [ATTACHMENT]", String, "Add an attachment") do |attachment|
|
32
|
+
if File.exists?(attachment)
|
33
|
+
args.attachment = File.expand_path(attachment)
|
34
|
+
else
|
35
|
+
puts "Can not find file #{attachment}"
|
36
|
+
exit(1)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
opts.on("-c", "--contacts x,y,z", Array, "Develier message to these CONTACTS") do |contacts|
|
41
|
+
args.contacts = contacts
|
42
|
+
end
|
43
|
+
|
44
|
+
opts.separator ""
|
45
|
+
opts.separator "Common options:"
|
46
|
+
|
47
|
+
opts.on("-h", "--help", "Prints this help") do
|
48
|
+
puts opts
|
49
|
+
exit
|
50
|
+
end
|
51
|
+
|
52
|
+
opts.on_tail("--version", "Show version") do
|
53
|
+
puts "imessage v#{Imessage::VERSION}"
|
54
|
+
exit
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/imessage/sender.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
module Imessage
|
2
2
|
class Sender
|
3
|
-
TYPES = [:text, :attachment]
|
4
|
-
|
5
3
|
def deliver(options = {text:nil, attachment:nil, contacts: []})
|
6
4
|
options[:contacts].each do |contact|
|
7
5
|
_deliver(options[:text], options[:attachment], contact)
|
@@ -12,13 +10,36 @@ module Imessage
|
|
12
10
|
|
13
11
|
def _deliver(text, attachment, contact)
|
14
12
|
unless text.nil?
|
15
|
-
|
16
|
-
|
13
|
+
script = <<-SCRIPT
|
14
|
+
on run argv
|
15
|
+
set toAddress to first item of argv
|
16
|
+
set message to second item of argv
|
17
|
+
tell application "Messages"
|
18
|
+
send message to buddy toAddress of (service 1 whose service type is iMessage)
|
19
|
+
end tell
|
20
|
+
end run
|
21
|
+
SCRIPT
|
22
|
+
`osascript -e '#{script}' '#{contact}' '#{text}'`
|
17
23
|
end
|
18
24
|
|
19
25
|
unless attachment.nil?
|
20
|
-
|
21
|
-
|
26
|
+
script = <<-SCRIPT
|
27
|
+
on run argv
|
28
|
+
set toAddress to first item of argv
|
29
|
+
set theFilePath to second item of argv
|
30
|
+
set theFile to POSIX file theFilePath
|
31
|
+
tell application "System Events"
|
32
|
+
if exists file theFilePath then
|
33
|
+
tell application "Messages"
|
34
|
+
send theFile to buddy toAddress of (service 1 whose service type is iMessage)
|
35
|
+
end tell
|
36
|
+
else
|
37
|
+
error "File not exist."
|
38
|
+
end if
|
39
|
+
end tell
|
40
|
+
end run
|
41
|
+
SCRIPT
|
42
|
+
`osascript -e'#{script}' '#{contact}' '#{attachment}'`
|
22
43
|
end
|
23
44
|
end
|
24
45
|
end
|
data/lib/imessage/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imessage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jun Lin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07
|
11
|
+
date: 2015-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -53,19 +53,19 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '2.14'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: pry
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
62
|
-
type: :
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: '0'
|
69
69
|
description: Command line tool to send iMessage.
|
70
70
|
email:
|
71
71
|
- linjunpop@gmail.com
|
@@ -82,11 +82,11 @@ files:
|
|
82
82
|
- LICENSE.txt
|
83
83
|
- README.md
|
84
84
|
- Rakefile
|
85
|
+
- Rakefile.dev
|
85
86
|
- bin/imessage
|
86
87
|
- imessage.gemspec
|
87
88
|
- lib/imessage.rb
|
88
|
-
- lib/imessage/
|
89
|
-
- lib/imessage/scripts/send_text.applescript
|
89
|
+
- lib/imessage/parser.rb
|
90
90
|
- lib/imessage/sender.rb
|
91
91
|
- lib/imessage/version.rb
|
92
92
|
- spec/spec_helper.rb
|
@@ -116,3 +116,4 @@ specification_version: 4
|
|
116
116
|
summary: Command line tool to send iMessage.
|
117
117
|
test_files:
|
118
118
|
- spec/spec_helper.rb
|
119
|
+
has_rdoc:
|
@@ -1,15 +0,0 @@
|
|
1
|
-
on run argv
|
2
|
-
set toAddress to first item of argv
|
3
|
-
set theFilePath to second item of argv
|
4
|
-
set theFile to POSIX file theFilePath
|
5
|
-
|
6
|
-
tell application "System Events"
|
7
|
-
if exists file theFilePath then
|
8
|
-
tell application "Messages"
|
9
|
-
send theFile to buddy toAddress of (service 1 whose service type is iMessage)
|
10
|
-
end tell
|
11
|
-
else
|
12
|
-
error "File not exist."
|
13
|
-
end if
|
14
|
-
end tell
|
15
|
-
end run
|