cloudapp 2.0.0.beta.11 → 2.0.0.beta.12
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/bin/cloudapp +62 -61
- data/cloudapp.gemspec +4 -2
- data/lib/cloudapp/cli/options.rb +51 -0
- data/lib/cloudapp/cli/prompt.rb +0 -1
- data/lib/cloudapp.rb +1 -1
- data/spec/cloudapp/cli/options_spec.rb +112 -0
- metadata +5 -3
data/Gemfile.lock
CHANGED
data/bin/cloudapp
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'cloudapp'
|
4
4
|
require 'cloudapp/credentials'
|
5
|
+
require 'cloudapp/cli/options'
|
5
6
|
require 'cloudapp/cli/prompt'
|
6
7
|
require 'cloudapp/service'
|
7
8
|
require 'clipboard'
|
@@ -22,28 +23,39 @@ def service_error_handler representation
|
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
def token
|
27
|
+
Credentials.token
|
28
|
+
end
|
29
|
+
|
30
|
+
def valid_token?
|
31
|
+
!token.nil? and service.root.authorized?
|
29
32
|
end
|
30
33
|
|
31
|
-
def
|
34
|
+
def authenticate
|
35
|
+
while not valid_token?
|
36
|
+
credentials = CloudApp::CLI::Prompt.new.ask_for_credentials
|
37
|
+
token = token_for_account credentials
|
38
|
+
Credentials.save_token token
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def fetch_link drop, link_type, copy_link
|
43
|
+
link = drop.link(link_type)
|
44
|
+
copy link if copy_link
|
32
45
|
$stdout.puts link
|
33
46
|
$stderr.puts link unless $stdout.tty?
|
34
47
|
end
|
35
48
|
|
36
|
-
def error message
|
37
|
-
print_error message
|
38
|
-
exit 1
|
39
|
-
end
|
40
49
|
|
41
|
-
def
|
42
|
-
|
50
|
+
def print_error message
|
51
|
+
$stderr.puts
|
52
|
+
$stderr.puts "! #{message}"
|
53
|
+
$stderr.puts
|
43
54
|
end
|
44
55
|
|
45
|
-
def
|
46
|
-
|
56
|
+
def error message
|
57
|
+
print_error message
|
58
|
+
exit 1
|
47
59
|
end
|
48
60
|
|
49
61
|
def print_version
|
@@ -51,64 +63,53 @@ def print_version
|
|
51
63
|
exit
|
52
64
|
end
|
53
65
|
|
54
|
-
def
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
66
|
+
def print_help io = $stdout
|
67
|
+
io.puts <<EOS
|
68
|
+
Usage:
|
69
|
+
cloudapp bookmark http://getcloudapp.com
|
70
|
+
cloudapp upload screenshot.png
|
71
|
+
EOS
|
60
72
|
end
|
61
73
|
|
62
|
-
def
|
63
|
-
|
74
|
+
def copy content
|
75
|
+
Clipboard.copy content
|
64
76
|
end
|
65
77
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
while not valid_token?
|
70
|
-
credentials = CloudApp::CLI::Prompt.new.ask_for_credentials
|
71
|
-
token = token_for_account credentials
|
72
|
-
Credentials.save_token token
|
78
|
+
def invalid_command
|
79
|
+
print_help $stderr
|
80
|
+
exit 1
|
73
81
|
end
|
74
82
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
link_type = :canonical # No such thing as an embed link for a bookmark.
|
83
|
-
while url = ARGV.shift
|
84
|
-
$stderr.print "Bookmarking #{url}... "
|
85
|
-
validate_url url
|
86
|
-
bookmark = service.bookmark(url)
|
83
|
+
def bookmark options
|
84
|
+
error 'Missing URL to bookmark.' if options.arguments.empty?
|
85
|
+
authenticate
|
86
|
+
options.arguments.each do |arg|
|
87
|
+
$stderr.print "Bookmarking #{arg}... "
|
88
|
+
error "#{arg} doesn't look like a valid URL" unless arg =~ URI.regexp
|
89
|
+
bookmark = service.bookmark(arg)
|
87
90
|
exit 1 unless bookmark
|
88
|
-
|
89
|
-
link = bookmark.link(link_type)
|
90
|
-
copy link if copy
|
91
|
-
print_link link
|
91
|
+
fetch_link bookmark, options.link_type, options.copy_link?
|
92
92
|
end
|
93
|
+
end
|
93
94
|
|
94
|
-
|
95
|
-
error 'Missing file' if
|
96
|
-
|
97
|
-
|
98
|
-
$stderr.print "Uploading #{File.basename(
|
99
|
-
|
100
|
-
upload = service.upload(
|
95
|
+
def upload options
|
96
|
+
error 'Missing file to upload.' if options.arguments.empty?
|
97
|
+
authenticate
|
98
|
+
options.arguments.each do |arg|
|
99
|
+
$stderr.print "Uploading #{File.basename(arg)}... "
|
100
|
+
error "#{arg.inspect} doesn't exist" unless File.exists? arg
|
101
|
+
upload = service.upload(arg)
|
101
102
|
exit 1 unless upload
|
102
|
-
|
103
|
-
link = upload.link(link_type)
|
104
|
-
copy link if copy
|
105
|
-
print_link link
|
103
|
+
fetch_link upload, options.link_type, options.copy_link?
|
106
104
|
end
|
105
|
+
end
|
107
106
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
107
|
+
|
108
|
+
options = CloudApp::CLI::Options.parse ARGV
|
109
|
+
case options.action
|
110
|
+
when :help then print_help
|
111
|
+
when :version then print_version
|
112
|
+
when :bookmark then bookmark options
|
113
|
+
when :upload then upload options
|
114
|
+
else invalid_command
|
114
115
|
end
|
data/cloudapp.gemspec
CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
|
|
13
13
|
## If your rubyforge_project name is different, then edit it and comment out
|
14
14
|
## the sub! line in the Rakefile
|
15
15
|
s.name = 'cloudapp'
|
16
|
-
s.version = '2.0.0.beta.
|
17
|
-
s.date = '2012-12-
|
16
|
+
s.version = '2.0.0.beta.12'
|
17
|
+
s.date = '2012-12-31'
|
18
18
|
s.rubyforge_project = 'cloudapp'
|
19
19
|
|
20
20
|
## Make sure your summary is short. The description may be as long
|
@@ -69,6 +69,7 @@ Gem::Specification.new do |s|
|
|
69
69
|
cloudapp.gemspec
|
70
70
|
lib/cloudapp.rb
|
71
71
|
lib/cloudapp/authorized.rb
|
72
|
+
lib/cloudapp/cli/options.rb
|
72
73
|
lib/cloudapp/cli/prompt.rb
|
73
74
|
lib/cloudapp/collection_json.rb
|
74
75
|
lib/cloudapp/collection_json/collection.rb
|
@@ -81,6 +82,7 @@ Gem::Specification.new do |s|
|
|
81
82
|
man/cloudapp.1.ronn
|
82
83
|
script/docs
|
83
84
|
spec/cloudapp/authorized_spec.rb
|
85
|
+
spec/cloudapp/cli/options_spec.rb
|
84
86
|
spec/cloudapp/collection_json/collection_spec.rb
|
85
87
|
spec/cloudapp/collection_json/item_spec.rb
|
86
88
|
spec/cloudapp/collection_json/template_spec.rb
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module CloudApp
|
2
|
+
module CLI
|
3
|
+
class Options
|
4
|
+
def self.parse args
|
5
|
+
options = {}
|
6
|
+
if args.delete('--direct') || args.delete('-d')
|
7
|
+
options[:direct] = true
|
8
|
+
end
|
9
|
+
options[:copy_link] = true unless args.delete('--no-copy')
|
10
|
+
options[:help] = args.delete('--help') || args.delete('-h')
|
11
|
+
options[:version] = args.delete('--version')
|
12
|
+
options[:action] = args.shift unless args.empty?
|
13
|
+
options[:arguments] = args unless args.empty?
|
14
|
+
|
15
|
+
Options.new options
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_accessor :arguments
|
19
|
+
def initialize options
|
20
|
+
@copy_link = options.fetch :copy_link, false
|
21
|
+
@direct = options.fetch :direct, false
|
22
|
+
@help = options.fetch :help, false
|
23
|
+
@version = options.fetch :version, false
|
24
|
+
@action = options.fetch :action, nil
|
25
|
+
@arguments = options.fetch :arguments, []
|
26
|
+
end
|
27
|
+
|
28
|
+
def copy_link?
|
29
|
+
@copy_link
|
30
|
+
end
|
31
|
+
|
32
|
+
def link_type
|
33
|
+
@direct && action != :bookmark ? :embed : :canonical
|
34
|
+
end
|
35
|
+
|
36
|
+
def action
|
37
|
+
if @help or @action == 'help'
|
38
|
+
:help
|
39
|
+
elsif @version
|
40
|
+
:version
|
41
|
+
elsif @action == 'bookmark'
|
42
|
+
:bookmark
|
43
|
+
elsif @action == 'upload'
|
44
|
+
:upload
|
45
|
+
else
|
46
|
+
:invalid
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/cloudapp/cli/prompt.rb
CHANGED
data/lib/cloudapp.rb
CHANGED
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'cloudapp/cli/options'
|
3
|
+
|
4
|
+
describe CloudApp::CLI::Options do
|
5
|
+
describe '#copy_link?' do
|
6
|
+
subject { described_class.parse(args).copy_link? }
|
7
|
+
|
8
|
+
context 'with no args' do
|
9
|
+
let(:args) {[ '' ]}
|
10
|
+
it { should eq(true) }
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'with --no-copy' do
|
14
|
+
let(:args) { %w(--no-copy) }
|
15
|
+
it { should eq(false) }
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'with --copy' do
|
19
|
+
let(:args) { %w(--copy) }
|
20
|
+
it { should eq(true) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#link_type' do
|
25
|
+
subject { described_class.parse(args).link_type }
|
26
|
+
|
27
|
+
context 'with no args' do
|
28
|
+
let(:args) {[ '' ]}
|
29
|
+
it { should eq(:canonical) }
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'with --direct' do
|
33
|
+
let(:args) { %w(--direct) }
|
34
|
+
it { should eq(:embed) }
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'with -d' do
|
38
|
+
let(:args) { %w(-d) }
|
39
|
+
it { should eq(:embed) }
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'with --direct when bookmarking' do
|
43
|
+
let(:args) { %w(bookmark --direct) }
|
44
|
+
it { should eq(:canonical) }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#action' do
|
49
|
+
subject { described_class.parse(args).action }
|
50
|
+
|
51
|
+
context 'with bookmark' do
|
52
|
+
let(:args) { %w(bookmark) }
|
53
|
+
it { should eq(:bookmark) }
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'with upload' do
|
57
|
+
let(:args) { %w(upload) }
|
58
|
+
it { should eq(:upload) }
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'with help' do
|
62
|
+
let(:args) { %w(help) }
|
63
|
+
it { should eq(:help) }
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'with --help' do
|
67
|
+
let(:args) { %w(--help) }
|
68
|
+
it { should eq(:help) }
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'with -h' do
|
72
|
+
let(:args) { %w(-h) }
|
73
|
+
it { should eq(:help) }
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'with --version' do
|
77
|
+
let(:args) { %w(--version) }
|
78
|
+
it { should eq(:version) }
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'with no args' do
|
82
|
+
let(:args) {[ '' ]}
|
83
|
+
it { should eq(:invalid) }
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'with an invalid command' do
|
87
|
+
let(:args) {[ '' ]}
|
88
|
+
it { should eq(:invalid) }
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '#arguments' do
|
93
|
+
subject { described_class.parse(args).arguments }
|
94
|
+
|
95
|
+
context 'with no args' do
|
96
|
+
let(:args) {[ '' ]}
|
97
|
+
it { should be_empty }
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'with no args when bookmarking' do
|
101
|
+
let(:args) { %w(bookmark) }
|
102
|
+
it { should be_empty }
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'with args when bookmarking' do
|
106
|
+
let(:args) { %w(bookmark one two) }
|
107
|
+
it { should eq(%w(one two)) }
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# it "doesn't mutate array"
|
112
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudapp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.beta.
|
4
|
+
version: 2.0.0.beta.12
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: clipboard
|
@@ -157,6 +157,7 @@ files:
|
|
157
157
|
- cloudapp.gemspec
|
158
158
|
- lib/cloudapp.rb
|
159
159
|
- lib/cloudapp/authorized.rb
|
160
|
+
- lib/cloudapp/cli/options.rb
|
160
161
|
- lib/cloudapp/cli/prompt.rb
|
161
162
|
- lib/cloudapp/collection_json.rb
|
162
163
|
- lib/cloudapp/collection_json/collection.rb
|
@@ -169,6 +170,7 @@ files:
|
|
169
170
|
- man/cloudapp.1.ronn
|
170
171
|
- script/docs
|
171
172
|
- spec/cloudapp/authorized_spec.rb
|
173
|
+
- spec/cloudapp/cli/options_spec.rb
|
172
174
|
- spec/cloudapp/collection_json/collection_spec.rb
|
173
175
|
- spec/cloudapp/collection_json/item_spec.rb
|
174
176
|
- spec/cloudapp/collection_json/template_spec.rb
|
@@ -189,7 +191,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
189
191
|
version: '0'
|
190
192
|
segments:
|
191
193
|
- 0
|
192
|
-
hash: -
|
194
|
+
hash: -3445886834563878524
|
193
195
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
194
196
|
none: false
|
195
197
|
requirements:
|