gyaazle 0.1.0 → 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/lib/gyaazle/cli.rb +15 -10
- data/lib/gyaazle/version.rb +1 -1
- data/spec/gyaazle_cli_spec.rb +89 -46
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bf8c6b6d331040b41feb688abb4d2f1bb43e424
|
4
|
+
data.tar.gz: 99a4581ba42a3641727235d0d2173916e0c13a12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64fa2b8d4dde26d1172a82a7eb2b05226b212676cf104622547f9c2899464587887b9bbca16778dc3b1c49af54927c3bd0e44a94f35b53bc02bfb3c3c7aeb28d
|
7
|
+
data.tar.gz: 1ccc3ae4c85ea328d9c941add3e3ed111c35dc1a780a47a4e90faf98716173a8bc187dac835a68e647a31920c53216041d882493c9ddcac24a2cc4a6baa83412
|
data/lib/gyaazle/cli.rb
CHANGED
@@ -29,16 +29,16 @@ TEXT
|
|
29
29
|
if @opts[:edit]
|
30
30
|
edit_config
|
31
31
|
else
|
32
|
-
if @opts[:capture]
|
32
|
+
if @opts[:capture] || @argv.empty?
|
33
33
|
@argv = [capture]
|
34
34
|
end
|
35
|
+
|
36
|
+
check_credentials!
|
35
37
|
upload
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
39
41
|
def upload
|
40
|
-
check_credentials!
|
41
|
-
|
42
42
|
@argv.each do |file|
|
43
43
|
fileobj = client.upload(file)
|
44
44
|
puts "#{file}:"
|
@@ -55,13 +55,7 @@ TEXT
|
|
55
55
|
|
56
56
|
def capture
|
57
57
|
tmpfile = "/tmp/gyaazle_capture_#{Time.now.strftime("%F %T")}.png"
|
58
|
-
capture_cmd
|
59
|
-
when /darwin/
|
60
|
-
"screencapture -i '#{tmpfile}'"
|
61
|
-
else
|
62
|
-
"import '#{tmpfile}'"
|
63
|
-
end
|
64
|
-
system capture_cmd
|
58
|
+
system capture_cmd(tmpfile)
|
65
59
|
tmpfile
|
66
60
|
end
|
67
61
|
|
@@ -89,5 +83,16 @@ TEXT
|
|
89
83
|
client.refresh_token!
|
90
84
|
end
|
91
85
|
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def capture_cmd(save_to)
|
90
|
+
case RUBY_PLATFORM
|
91
|
+
when /darwin/
|
92
|
+
"screencapture -i '#{save_to}'"
|
93
|
+
else
|
94
|
+
"import '#{save_to}'"
|
95
|
+
end
|
96
|
+
end
|
92
97
|
end
|
93
98
|
end
|
data/lib/gyaazle/version.rb
CHANGED
data/spec/gyaazle_cli_spec.rb
CHANGED
@@ -5,77 +5,95 @@ require "spec_helper"
|
|
5
5
|
describe Gyaazle::CLI do
|
6
6
|
let(:cli) { Gyaazle::CLI.new([]) }
|
7
7
|
|
8
|
-
describe "
|
9
|
-
|
10
|
-
cli.stub(:
|
11
|
-
|
12
|
-
|
13
|
-
it "invoke #check_credentials! before #upload" do
|
14
|
-
cli.should_receive(:check_credentials!)
|
8
|
+
describe "#run!" do
|
9
|
+
it "invoke #capture when ARGV is empty" do
|
10
|
+
cli.stub(:check_credentials!)
|
11
|
+
cli.stub(:upload)
|
12
|
+
cli.should_receive(:capture)
|
15
13
|
cli.run!
|
16
14
|
end
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
describe "options" do
|
17
|
+
context "-e" do
|
18
|
+
let(:cli) { Gyaazle::CLI.new(%w!-e!) }
|
19
|
+
before do
|
20
|
+
cli.stub(:edit_config)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "invoke #edit_config" do
|
24
|
+
cli.should_receive(:edit_config)
|
25
|
+
cli.run!
|
26
|
+
end
|
27
|
+
|
28
|
+
it "not invoke #upload and #check_credentials!" do
|
29
|
+
cli.should_not_receive(:check_credentials!)
|
30
|
+
cli.should_not_receive(:upload)
|
31
|
+
cli.run!
|
32
|
+
end
|
21
33
|
end
|
22
34
|
|
23
|
-
|
24
|
-
|
25
|
-
cli.
|
26
|
-
end
|
27
|
-
end
|
35
|
+
context "--config filepath" do
|
36
|
+
let(:file) { File.join("/tmp", rand.to_s) }
|
37
|
+
let(:cli) { Gyaazle::CLI.new(%W!--config #{file}!) }
|
28
38
|
|
29
|
-
|
30
|
-
|
31
|
-
|
39
|
+
it "config.file == file" do
|
40
|
+
cli.config.file.should == file
|
41
|
+
File.unlink(file) if File.exists?(file)
|
42
|
+
end
|
32
43
|
end
|
33
44
|
|
34
|
-
|
35
|
-
cli.
|
36
|
-
|
45
|
+
context "--capture" do
|
46
|
+
let(:cli) { Gyaazle::CLI.new(%W!--capture!) }
|
47
|
+
before do
|
48
|
+
cli.stub(:check_credentials!)
|
49
|
+
cli.stub(:upload)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "invoke #capture" do
|
53
|
+
cli.should_receive(:capture)
|
54
|
+
cli.run!
|
55
|
+
end
|
37
56
|
end
|
38
57
|
end
|
39
58
|
end
|
40
59
|
|
41
|
-
describe "
|
42
|
-
|
43
|
-
let(:cli) { Gyaazle::CLI.new(%w!-e!) }
|
44
|
-
before do
|
45
|
-
cli.stub(:edit_config)
|
46
|
-
end
|
60
|
+
describe "#check_credentials!" do
|
61
|
+
let(:verifier) { "verification code" }
|
47
62
|
|
48
|
-
|
49
|
-
|
50
|
-
|
63
|
+
before do
|
64
|
+
cli.stub(:authorize).and_return(verifier)
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when config is nil" do
|
68
|
+
before do
|
69
|
+
cli.config.stub(:load).and_return(nil)
|
51
70
|
end
|
52
71
|
|
53
|
-
it "
|
54
|
-
cli.
|
55
|
-
cli.
|
56
|
-
cli.run!
|
72
|
+
it "invoke #initialize_tokens" do
|
73
|
+
cli.should_receive(:initialize_tokens).with(verifier)
|
74
|
+
cli.check_credentials!
|
57
75
|
end
|
58
76
|
end
|
59
77
|
|
60
|
-
context "
|
61
|
-
|
62
|
-
|
78
|
+
context "when config is broken" do
|
79
|
+
before do
|
80
|
+
cli.config.stub(:load).and_return(:foo => :bar)
|
81
|
+
end
|
63
82
|
|
64
|
-
it "
|
65
|
-
cli.
|
66
|
-
|
83
|
+
it "invoke #initialize_tokens" do
|
84
|
+
cli.should_receive(:initialize_tokens).with(verifier)
|
85
|
+
cli.check_credentials!
|
67
86
|
end
|
68
87
|
end
|
69
88
|
|
70
|
-
context "
|
71
|
-
let(:cli) { Gyaazle::CLI.new(%W!--capture!) }
|
89
|
+
context "when config is fine" do
|
72
90
|
before do
|
73
|
-
cli.stub(:
|
91
|
+
cli.config.stub(:load).and_return(:client_id => "id", :client_secret => "secret", :refresh_token => "refresh")
|
74
92
|
end
|
75
93
|
|
76
|
-
it "invoke #
|
77
|
-
cli.should_receive(:
|
78
|
-
cli.
|
94
|
+
it "invoke client#refresh_token!" do
|
95
|
+
cli.client.should_receive(:refresh_token!)
|
96
|
+
cli.check_credentials!
|
79
97
|
end
|
80
98
|
end
|
81
99
|
end
|
@@ -111,5 +129,30 @@ describe Gyaazle::CLI do
|
|
111
129
|
cli.upload
|
112
130
|
end
|
113
131
|
end
|
132
|
+
|
133
|
+
describe "#edit_config" do
|
134
|
+
let(:conf) { "dummy_config_file" }
|
135
|
+
let(:cli) { Gyaazle::CLI.new(%W!-e --config #{conf}!) }
|
136
|
+
|
137
|
+
it "invoke #system with $EDITOR" do
|
138
|
+
cli.should_receive(:system).with(ENV["EDITOR"], conf)
|
139
|
+
cli.edit_config
|
140
|
+
File.unlink(conf) if File.exists?(conf)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "#capture" do
|
145
|
+
let(:cli) { Gyaazle::CLI.new(%W!--capture!) }
|
146
|
+
let(:cmd) { "my-capture-cmd tmpfile" }
|
147
|
+
|
148
|
+
before do
|
149
|
+
cli.stub(:capture_cmd).and_return(cmd)
|
150
|
+
end
|
151
|
+
|
152
|
+
it "invoke #system with #capture_cmd" do
|
153
|
+
cli.should_receive(:system).with(cmd)
|
154
|
+
cli.capture
|
155
|
+
end
|
156
|
+
end
|
114
157
|
end
|
115
158
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gyaazle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- uu59
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|